在我的片段着色器中有两行如下:</p>
float depthExp=max(0.5,pow(depth,100.0));
gl_FragColor=vec4(depthExp*vec3(color),1);
我把它“优化”成:</p>
if(depth<0.99309249543703590153321021688807){//0.5^(1/100.0)
gl_FragColor=vec4(0.5*vec3(color),1);
}else{
float depthExp=pow(depth,100.0);
gl_FragColor=vec4(depthExp*vec3(color),1);
}
我可以通过这个来提高性能吗?还是我只是违背自己的意愿做事?
我在这里给出完整的片段着色器,看看是否有机会优化它:
varying vec2 TexCoord;
uniform sampler2D Texture_color;
uniform sampler2D Texture_depth;
uniform sampler2D Texture_stencil;
void main()
{
float depth=texture2D(Texture_depth,TexCoord).r;
float stencil=texture2D(Texture_stencil,TexCoord).r;
vec4 color=texture2D(Texture_color,TexCoord);
if(stencil==0.0){
gl_FragColor=color;
}else{
float depthExp=max(0.5,pow(depth,100.0));
gl_FragColor=vec4(depthExp*vec3(color),1);
}
}