From e2058f0da6ebb223992e15b26dbba6d20858ca2c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Mal=C3=BD?= Date: Mon, 9 Jul 2018 13:44:46 +0200 Subject: [PATCH] surface shader - fix uniform control flow for texture accesses --- .../data/shaders/surface.frag.glsl | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/browser/src/vts-librenderer/data/shaders/surface.frag.glsl b/browser/src/vts-librenderer/data/shaders/surface.frag.glsl index 886d2ca2..b38aa6ad 100644 --- a/browser/src/vts-librenderer/data/shaders/surface.frag.glsl +++ b/browser/src/vts-librenderer/data/shaders/surface.frag.glsl @@ -16,22 +16,25 @@ void main() { // texture color vec4 color = texture(texColor, varUvTex); - if (uniFlags.y > 0) - color = color.rrra; // monochromatic texture + + // mask + if (uniFlags.x > 0) + { + if (texture(texMask, varUvTex).r < 0.5) + discard; + } // uv clipping + // uv clipping must go after all texture accesses to allow for computation of derivatives in uniform control flow if (varUvClip.x < uniUvClip.x || varUvClip.y < uniUvClip.y || varUvClip.x > uniUvClip.z || varUvClip.y > uniUvClip.w) discard; - // mask - if (uniFlags.x > 0) - { - if (texture(texMask, varUvTex).r < 0.5) - discard; - } + // monochromatic texture + if (uniFlags.y > 0) + color = color.rrra; // base color if (uniFlags.z > 0)