From 36fd30d0638f166e6ba5655e53c4655224eb543f Mon Sep 17 00:00:00 2001 From: Matthias Blankertz Date: Mon, 4 May 2015 14:01:55 +0200 Subject: [PATCH] Optimize object shaders --- shaders/object.fs | 19 +++++++------------ shaders/object.vs | 1 + 2 files changed, 8 insertions(+), 12 deletions(-) diff --git a/shaders/object.fs b/shaders/object.fs index 0387070..f3bf1f0 100644 --- a/shaders/object.fs +++ b/shaders/object.fs @@ -8,6 +8,7 @@ layout(location = 4) uniform uint animFrame; layout(location = 5) uniform vec3 IDcolor; in vec2 fragTC; + flat in uint fragUseAnimTex; layout(location = 0) out vec4 color; @@ -15,16 +16,10 @@ layout(location = 1) out vec4 IDcolor_out; layout(depth_unchanged) out float gl_FragDepth; void main(void) { - vec2 texDx = dFdx(fragTC); - vec2 texDy = dFdy(fragTC); - - if (fragUseAnimTex > 0u) - color = textureGrad(texAnim, vec3(fragTC, animFrame), texDx, texDy); - else - color = textureGrad(texBase, fragTC, texDx, texDy); - - if (color.w < 0.5) - discard; - - IDcolor_out = vec4(IDcolor, 1.0); + color = bool(fragUseAnimTex)?texture(texAnim, vec3(fragTC, animFrame)):texture(texBase, fragTC); + + if (color.w < 0.5) + discard; + + IDcolor_out = vec4(IDcolor, 1.0); } diff --git a/shaders/object.vs b/shaders/object.vs index 73fa7ea..7becbe2 100644 --- a/shaders/object.vs +++ b/shaders/object.vs @@ -10,6 +10,7 @@ layout(location = 1) in vec2 vertexTC; layout(location = 2) in uint useAnimTex; out vec2 fragTC; + flat out uint fragUseAnimTex; void main(void) {