Skip to content

Instantly share code, notes, and snippets.

@hamid814
Created March 17, 2021 14:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hamid814/4cdc7bc51fba781cf02e65d208fe1b39 to your computer and use it in GitHub Desktop.
Save hamid814/4cdc7bc51fba781cf02e65d208fe1b39 to your computer and use it in GitHub Desktop.
Threejs mirror shader. Splits screen into four. Use in shaderpass
uniform sampler2D tDiffuse;
varying vec2 vUv;
float map(float value, float min1, float max1, float min2, float max2) {
return min2 + (value - min1) * (max2 - min2) / (max1 - min1);
}
void main() {
vec2 doubleUv = vUv * 2.0;
if(vUv.x > 0.5) doubleUv.x = map(doubleUv.x - 1.0, 0.0, 1.0, 1.0, 0.0);
if (vUv.y > 0.5) doubleUv.y = map(doubleUv.y - 1.0, 0.0, 1.0, 1.0, 0.0);
gl_FragColor = texture2D(tDiffuse, doubleUv);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment