在Unity中将opaque转换为透明着色器后没有透明度,需要帮助识别我的错误

问题描述 投票:0回答:2

我有一个工作的不透明着色器,我正在尝试转换为透明着色器。我在线跟踪教程但由于某种原因,着色器仍然将对象显示为不透明。我觉得我错过了一些非常明显但却无法弄清楚它是什么的东西。

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"
}
unity3d hlsl
2个回答
0
投票

默认情况下,混合处于关闭状态,您需要手动添加它。

SubShader
{
    Tags { "Queue" = "Transparent" "RenderType"="Transparent" }
    LOD 200

    Blend SrcAlpha OneMinusSrcAlpha

...

0
投票

通过替换修复

pragma surface surf Standard fullforwardshadows

pragma surface surf Standard fullforwardshadows alpha:fade

© www.soinside.com 2019 - 2024. All rights reserved.