zoukankan      html  css  js  c++  java
  • 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

  • 相关阅读:
    js循环小练习
    计算字符串字节数
    查找最小值
    js文本复制插件&vue
    python打包成exe(py2exe)
    window2008 64位系统没有office组件问题分析及解决
    js onchange事件
    input file里的JQ change() 事件的只生效一次
    powerdesign的license key到期,解决办法
    JQuery好用的日期选择控件 DatePicker
  • 原文地址:https://www.cnblogs.com/wantnon/p/4679871.html
Copyright © 2011-2022 走看看