我正在尝试实现这篇文章中描述的技术:使用深度合成图像。
这个想法是利用已有的纹理(从图像加载)作为深度掩码,基本上是伪造3D效果。
我面临的问题是,在OpenglES中没有glDrawPixels可用。在iPhone上有没有一种方法可以实现同样的效果?
这个想法是利用已有的纹理(从图像加载)作为深度掩码,基本上是伪造3D效果。
我面临的问题是,在OpenglES中没有glDrawPixels可用。在iPhone上有没有一种方法可以实现同样的效果?
void main()
{
// write a value to the depth map
gl_FragColor = vec4(gl_FragCoord.w, 0.0, 0.0, 1.0);
}
uniform sampler2D depthMap;
void main()
{
// read a value from the depth map
lowp vec3 colourFromDepthMap = texture2D(depthMap, gl_FragCoord.xy);
// discard the current fragment if it is less close than the stored value
if(colourFromDepthMap.r > gl_FragCoord.w) discard;
... set gl_FragColor appropriately otherwise ...
}
编辑2:你可以在这里看到一种更智能的从深度映射到RGBA值的方法。直接与该文档相关的是,iPad或第三代iPhone肯定不支持OES_depth_texture。我还没有在其他地方进行完整的测试。
gl_FragDepth
时,如何防止覆盖可能更接近观察者的片段与可能更远离观察者的片段?似乎我们没有能力查询正在写入的纹理,以查看该位置是否已经有东西被写入。 - Brad Larson