• unity, unlit surface shader (texColor only surface shader)


    要实现双面透明无光照只有纹理色的surface shader。

    错误的写法:(导致带有曝光)

    Shader "Custom/doubleFaceTranspTexColor" {
      Properties {
        _Color ("Color", Color) = (1,1,1,1)
        _MainTex ("Albedo (RGB)", 2D) = "white" {}
      }
      SubShader {
        Tags { "RenderType"="Transparent" }
        LOD 200

        Cull Off

        Blend SrcAlpha OneMinusSrcAlpha // Alpha blending

        CGPROGRAM
        // Physically based Standard lighting model, and enable shadows on all light types
        #pragma surface surf MyTexColor alpha:fade

        half4 LightingMyTexColor(SurfaceOutput s, half3 lightDir, half atten){
          half4 c;
          c.rgb=s.Albedo;
          c.a=s.Alpha;
          return c;

        }
        // Use shader model 3.0 target, to get nicer looking lighting
        #pragma target 3.0

        sampler2D _MainTex;

        struct Input {
          float2 uv_MainTex;
        };

        fixed4 _Color;

        void surf (Input IN, inout SurfaceOutput o) {
          // Albedo comes from a texture tinted by color
          fixed4 c = tex2D (_MainTex, IN.uv_MainTex) * _Color;
          o.Albedo = c.rgb;
          o.Alpha = c.a;
        }
        ENDCG
      }
      FallBack "Diffuse"
    }

    正确的写法:

    Shader "Custom/doubleFaceTranspTexColor" {
        Properties {
            _Color ("Color", Color) = (1,1,1,1)
            _MainTex ("Albedo (RGB)", 2D) = "white" {}
        }
        SubShader {
            Tags { "RenderType"="Transparent" "RenderQueue"="Transparent"}
            LOD 200
            
            Cull Off
            Lighting Off
            Blend SrcAlpha OneMinusSrcAlpha // Alpha blending
            
            CGPROGRAM
            // Physically based Standard lighting model, and enable shadows on all light types
            #pragma surface surf MyTexColor alpha:fade
            
            half4 LightingMyTexColor(SurfaceOutput s, half3 lightDir, half atten){
                half4 c;
                c.rgb=half3(0,0,0);
                c.a=s.Alpha;
                return c;
            
            }
            // Use shader model 3.0 target, to get nicer looking lighting
            #pragma target 3.0
            
            

            sampler2D _MainTex;

            struct Input {
                float2 uv_MainTex;
            };

            fixed4 _Color;

            void surf (Input IN, inout SurfaceOutput o) {
                // Albedo comes from a texture tinted by color
                fixed4 c = tex2D (_MainTex, IN.uv_MainTex) * _Color;
                o.Emission = c.rgb;
                o.Albedo = fixed3(0,0,0);
                o.Alpha = c.a;
            }
            ENDCG
        } 
        FallBack "Diffuse"
    }

    参考:http://answers.unity3d.com/questions/272749/how-to-write-unlit-surface-shader.html

  • 相关阅读:
    Hadoop Avro支持多输入AvroMultipleInputs
    Java LinqCollection 仿Linq的list常用函数
    json转成java对象
    symbol lookup error: /lib64/libpango-1.0.so.0: undefined symbol: g_log_structured_standard 错误
    CentOS 6&7安装ffmpeg
    MySQL的ibdata1文件占用过大瘦身
    Centos下磁盘管理的常用命令记录(如查找大文件)
    EasyPOI 教程以及完整工具类的使用
    github最火的springboot开源学习资料
    微信机器人
  • 原文地址:https://www.cnblogs.com/wantnon/p/4679871.html
Copyright © 2020-2023  润新知