- Home /
Shader - Writing to Depth issues
I am trying to write to the depth buffer using a shader but I am facing some issues. If you look at the two screenshots, you can see that the mask is a circular gradient (black part) but it does a awful cut-out and I don't understand why.
It's quite strange because the gradient seems to be good if I render the Depth buffer from the camera. But inside the shader it does a bad simple cut-out instead of a nice gradient.
How can I fix this ?
Tags { "Queue"="Geometry+10" }
ZWrite On
Blend SrcAlpha OneMinusSrcAlpha
Pass
{
CGPROGRAM
#pragma exclude_renderers gles flash
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
sampler2D _Mask;
float4 _Mask_ST;
struct VertOut {
float4 pos : POSITION;
float2 uv : TEXCOORD0;
};
struct FragOut {
float4 color : COLOR;
float depth : DEPTH;
};
VertOut vert(appdata_base IN) {
VertOut o;
o.pos = mul(UNITY_MATRIX_MVP, IN.vertex);
o.uv = TRANSFORM_TEX(IN.texcoord, _Mask);
return o;
}
FragOut frag(VertOut IN) {
FragOut o;
float4 mask = tex2D(_Mask, IN.uv);
o.depth = mask.rgb;
o.color.rgb = mask.rgb;
o.color.a = 1.0;
return o;
}
ENDCG
}
untitled-1.jpg
(85.0 kB)
Comment
how did you do this?
i can't seem to create a struct and use that as the output from the frag function.
i always have to export COLOR
half4 frag (v2f i) : COLOR
{
i.uvproj /= i.uvproj.w;
i.uvproj = (i.uvproj + 1) * 0.5;
float3 tex = tex2D(_$$anonymous$$ainTex,i.uvproj).xyz;
return float4(tex.xyz,1.0);
}