将下面的shader属性由transparent修改为opaque Shader "Custom/Texture Splatting" { Properties { _MainTex ("Splat Map", 2D) = "white" {} [NoScaleOffset] _Texture1 ("Texture 1", 2D) = "white" {} [NoScaleOffset] _Texture2 ("Texture 2", 2D) = "white" {} [NoScaleOffset] _Texture3 ("Texture 3", 2D) = "white" {} [NoScaleOffset] _Texture4 ("Texture 4", 2D) = "white" {} } SubShader { Pass { CGPROGRAM #pragma vertex MyVertexProgram #pragma fragment MyFragmentProgram #include "UnityCG.cginc" sampler2D _MainTex; float4 _MainTex_ST; sampler2D _Texture1, _Texture2, _Texture3, _Texture4; struct VertexData { float4 position : POSITION; float2 uv : TEXCOORD0; }; struct Interpolators { float4 position : SV_POSITION; float2 uv : TEXCOORD0; float2 uvSplat : TEXCOORD1; }; Interpolators MyVertexProgram (VertexData v) { Interpolators i; i.position = UnityObjectToClipPos(v.position); i.uv = TRANSFORM_TEX(v.uv, _MainTex); i.uvSplat = v.uv; return i; } float4 MyFragmentProgram (Interpolators i) : SV_TARGET { float4 splat = tex2D(_MainTex, i.uvSplat); return tex2D(_Texture1, i.uv) * splat.r + tex2D(_Texture2, i.uv) * splat.g + tex2D(_Texture3, i.uv) * splat.b + tex2D(_Texture4, i.uv) * (1 - splat.r - splat.g - splat.b); } ENDCG } } }
时间: 2024-02-21 14:58:58 浏览: 78
将下面的代码中的 SubShader 中的 Pass 的 shader 属性由 "Transparent" 修改为 "Opaque" 即可:
```
Shader "Custom/Texture Splatting" {
Properties {
_MainTex ("Splat Map", 2D) = "white" {}
[NoScaleOffset] _Texture1 ("Texture 1", 2D) = "white" {}
[NoScaleOffset] _Texture2 ("Texture 2", 2D) = "white" {}
[NoScaleOffset] _Texture3 ("Texture 3", 2D) = "white" {}
[NoScaleOffset] _Texture4 ("Texture 4", 2D) = "white" {}
}
SubShader {
Pass {
CGPROGRAM
#pragma vertex MyVertexProgram
#pragma fragment MyFragmentProgram
#include "UnityCG.cginc"
sampler2D _MainTex;
float4 _MainTex_ST;
sampler2D _Texture1, _Texture2, _Texture3, _Texture4;
struct VertexData {
float4 position : POSITION;
float2 uv : TEXCOORD0;
};
struct Interpolators {
float4 position : SV_POSITION;
float2 uv : TEXCOORD0;
float2 uvSplat : TEXCOORD1;
};
Interpolators MyVertexProgram (VertexData v) {
Interpolators i;
i.position = UnityObjectToClipPos(v.position);
i.uv = TRANSFORM_TEX(v.uv, _MainTex);
i.uvSplat = v.uv;
return i;
}
float4 MyFragmentProgram (Interpolators i) : SV_TARGET {
float4 splat = tex2D(_MainTex, i.uvSplat);
return
tex2D(_Texture1, i.uv) * splat.r +
tex2D(_Texture2, i.uv) * splat.g +
tex2D(_Texture3, i.uv) * splat.b +
tex2D(_Texture4, i.uv) * (1 - splat.r - splat.g - splat.b);
}
ENDCG
}
// 将下面的 shader 属性由 "Transparent" 修改为 "Opaque"
Tags { "RenderType"="Opaque" }
}
}
```
阅读全文