【发布时间】:2019-09-26 08:11:12
【问题描述】:
我有一个正在工作的不透明着色器,我目前正试图将其转换为透明着色器。我按照在线教程进行操作,但由于某种原因,着色器仍将对象显示为不透明。我觉得我遗漏了一些非常明显的东西,但无法弄清楚它是什么。
Shader "Custom/WaterSphere"
{
Properties
{
_Color ("Color", Color) = (1,1,1,1)
_MainTex ("Albedo (RGB)", 2D) = "white" {}
_Glossiness ("Smoothness", Range(0,1)) = 0.5
_Metallic ("Metallic", Range(0,1)) = 0.0
_PlaneNormal("PlaneNormal",Vector) = (0,1,0,0)
_PlanePosition("PlanePosition",Vector) = (0,0,0,1)
_Transparency("Transparency", float) = 0.1
}
SubShader
{
Tags { "Queue" = "Transparent" "RenderType"="Transparent" }
LOD 200
CGPROGRAM
#pragma surface surf Standard fullforwardshadows
#pragma target 3.0
sampler2D _MainTex;
struct Input
{
float2 uv_MainTex;
float3 worldPos;
};
half _Glossiness;
half _Metallic;
fixed4 _Color;
fixed3 _PlaneNormal;
fixed3 _PlanePosition;
float _Transparency;
bool checkVisability(fixed3 worldPos)
{
float dotProd1 = dot(worldPos - _PlanePosition, _PlaneNormal);
return dotProd1 > 0 ;
}
UNITY_INSTANCING_BUFFER_START(Props)
UNITY_INSTANCING_BUFFER_END(Props)
void surf (Input IN, inout SurfaceOutputStandard o)
{
if (checkVisability(IN.worldPos))discard;
fixed4 c = tex2D (_MainTex, IN.uv_MainTex) * _Color;
o.Albedo = c.rgb;
o.Metallic = _Metallic;
o.Smoothness = _Glossiness;
o.Alpha = _Transparency; //Has no effect
}
ENDCG
}
FallBack "Diffuse"
}
【问题讨论】: