我承认在着色器方面我有点迷失。下面是我没有点亮的着色器。我可以添加什么来写入深度缓冲区和深度纹理?此外,我在这个着色器中做了什么错误或不必要的事情?
Shader "Unlit/Environment Texture" {
Properties {
_MainTex ("Base (RGB)", 2D) = "white" {}
_MainTexBias ("Mip Bias (-1 to 1)", float) = -1
}
SubShader {
Tags { "RenderType"="Opaque" }
Lighting Off
Fog { Mode off }
Pass {
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
struct appdata_t {
float4 vertex : POSITION;
float2 texcoord : TEXCOORD0;
};
struct v2f {
float4 vertex : SV_POSITION;
half2 texcoord : TEXCOORD0;
};
sampler2D _MainTex;
float4 _MainTex_ST;
half _MainTexBias;
v2f vert (appdata_t v)
{
v2f o;
o.vertex = UnityObjectToClipPos(v.vertex);
o.texcoord = TRANSFORM_TEX(v.texcoord, _MainTex);
return o;
}
fixed4 frag (v2f i) : SV_Target
{
fixed4 col = tex2Dbias(_MainTex, half4(i.texcoord.x,i.texcoord.y,0.0,_MainTexBias));
return col;
}
ENDCG
}
}
}
frag应具有SV_Depth语义
struct fragOutput {
fixed4 color : SV_Target;
float depth:SV_Depth;
};
fragOutput frag (v2f i)
{
fragOutput o;
o.color = tex2D(_MainTex, i.uv);
o.depth = i.depth;
return o;
}
嗯...这应该已经写入深度缓冲区了?您可以在标签中添加“Queue”=“Opaque”以启用前后排序,但我认为它应该默认为此。 Ztest On也是隐含的。它在Unity中如何找到你?