- Home /
Writing depth value in shader but nothing happens
Hey Guys, I really need your help.
I'm trying to change the depth values of gameObjects so that images from webcam can occlude virtual objects I'm doing this by changing the depth values in the fragment shader according to a depth camera. (depth data is stored in the texture's alpha)
fout frag(v2f i) {
fout fo;
fo.color = float4(tex2D(_MainTex, i.uv).rgb, 1);
//2000 = far plane; 0.05 = near plane
fo.depth = ((1 / (1 - tex2D(_MainTex,i.uv).a)) - 2000 / 0.5) / (1 - 2000 / 0.5);
if (fo.depth > 0.9999999)
{
fo.depth = 0.9999999;
}
return fo;
}
it works pretty well in Unity 5.4.3 but when i change to Unity 2017.3.0f3, this method just doesn't work. No matter where i place my cubes, it just won't appear in front of the image
So what happened in Unity 2017 ? Did i miss any settings or do i have to change anything? does anyone have the same problem with different versions?
Thanks for the help!
Your answer
Follow this Question
Related Questions
Shader based camera compositing. 2 Answers
Wrong Depth texture being passed into the shader. 0 Answers
Increasing the level of detail with a depth render 0 Answers
Distance from pixel to camera in shader 0 Answers
UI shader write to depth buffer 2 Answers