Hello,
I’m trying to make a shader which basically displays Black if the material is Opqaue and the Depth if the material is of rendertype Water
I’m trying to do this in the editor so I bake this texture which saves in the scene.
Currently doing this all from inside OnInspectorGUI from Editor
camera.enabled = false;
camera.orthographic = true;
camera.nearClipPlane = 0.01f;
camera.backgroundColor = Color.black;
camera.depthTextureMode |= DepthTextureMode.Depth;
camera.clearFlags = CameraClearFlags.Color;
camera.depth = 100.0f;
camera.renderingPath = RenderingPath.Forward;
camera.RenderWithShader(replacementShader, "RenderType");
Shader
Shader "Water Ambient Render Depth" {
SubShader{
Tags { "RenderType" = "Water" }
Pass {
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
sampler2D _CameraDepthTexture;
struct v2f {
float4 pos : SV_POSITION;
float2 uv : TEXCOORD0;
};
v2f vert(appdata_img v) {
v2f o;
o.pos = UnityObjectToClipPos(v.vertex);
o.uv = v.texcoord.xy;
return o;
}
half4 frag(v2f i) : COLOR{
half depth = half(Linear01Depth(tex2D(_CameraDepthTexture, i.uv).r));
return half4(depth,depth,depth,depth);
}
ENDCG
}
}
SubShader{
Tags { "RenderType" = "Opaque" }
Pass {
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
struct v2f {
float4 pos : SV_POSITION;
};
v2f vert(appdata_base v) {
v2f o;
o.pos = UnityObjectToClipPos(v.vertex);
return o;
}
half4 frag(v2f i) : SV_Target{
return half4(0.0f,0.0f,0.0f,1.0f);
}
ENDCG
}
}
}
But all i get is this
The white squares are water both at different heights. But as you can see they are a solid white.
Any advice for be great!
Best,
Tom