在我的项目中,我使用“丢弃”调用来执行自定义模板测试,该测试尝试仅在由模板纹理定义的指定区域上绘制内容。这是片段着色器的代码:
//get the stencil value from a texture
float value=texture2D( stencilTexture, gl_FragCoord.xy/1024.0).x;
//check if value equals the desired value, if not draw nothing
if(abs(value-desiredValue)>0.1)
{
discard;
}
Run Code Online (Sandbox Code Playgroud)
该代码可以工作,但由于“丢弃”调用而出现性能问题。是否有其他方法可以通过 GPU 着色器来实现此目的?告诉我怎么做。