- Home /
Object is rendered white(saturated)
Hi! I created a scene to implement a differential rendering example in AR. Even though I achieved the desired behavior, the color of my object is rendered as completely white(saturated). In the first picture, the cube is saturated but normally, in editor view and also left bottom corner, in render textures, object is rendered as red.
In my shader code, I combine these render layers to achieve differential rendering. Left bottom corner indicates from left to right, c_camera, c_shadow, c_noshadow and c_mask
float4 frag (v2f_img i) : COLOR
{
float4 c_camera = tex2D(_MainTex, i.uv);
float4 c_noshadow = tex2D(_NoShadowTex, i.uv);
float4 c_shadow = tex2D(_ShadowTex, i.uv);
bool c_mask = tex2D(_MaskTexture, i.uv).a > 0.0;
float4 c_final=c_camera+(c_shadow-c_noshadow)+c_mask;
return c_final;
}
How may I fix this?
Thanks.
Answer by BastianUrbach · Dec 10, 2021 at 09:58 AM
c_camera + (c_shadow - c_noshadow)
seems to be the camera image with the shadows from the virtual object. Then you just add a bool to that. A bool (when used as a number) is either 1 (white) or 0 (black). I think what you meant to do is something like this:
float4 c_final = c_mask ? c_shadow : (c_camera + (c_shadow - c_noshadow));
Instead of just adding the bool, you use it to decide between the color of the virtual object and the color from the camera.
Yes, that was exactly the mistake I was doing then because I thought that it also contains the original model and should be directly applied. Thank you.