Skip to content

Instantly share code, notes, and snippets.

@hamid814
Created March 17, 2021 14:57
Embed
What would you like to do?
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