【问题标题】:No transparency after converting opaque to transparent shader in Unity, need help identifying my mistake在 Unity 中将不透明着色器转换为透明着色器后没有透明度,需要帮助识别我的错误
【发布时间】: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"
}

【问题讨论】:

    标签: unity3d hlsl


    【解决方案1】:

    默认关闭,需要手动添加。

    SubShader
    {
        Tags { "Queue" = "Transparent" "RenderType"="Transparent" }
        LOD 200
    
        Blend SrcAlpha OneMinusSrcAlpha
    
    ...
    

    【讨论】:

      【解决方案2】:

      通过替换修复

      #pragma surface surf Standard fullforwardshadows 
      

      #pragma surface surf Standard fullforwardshadows alpha:fade
      

      【讨论】:

        猜你喜欢
        • 2015-02-16
        • 1970-01-01
        • 2021-06-17
        • 1970-01-01
        • 2023-03-28
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多