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

  • 相关阅读:
    【Cocos2d-X游戏实战开发】捕鱼达人之游戏场景的创建(六)
    WPF-24:绘制正多边形
    长假引起的系统审批流的变更的思考
    Linux shell编程02 shell程序的执行 及文件权限
    poj2787 算24
    REVERSE关键字之REVERSE索引
    设计模式读书笔记-----备忘录模式
    乔布斯的基本原则 (斯卡利访谈录 )
    MediaInfo源代码分析 1:整体结构
    Python 入门教程 9 ---- A Day at the Supermarket
  • 原文地址:https://www.cnblogs.com/wantnon/p/4679871.html
Copyright © 2011-2022 走看看