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

  • 相关阅读:
    解决在QEMU上仿真STM32F429时出现的若干问题
    CentOS 7.1, 7.2 下安装dotnet core
    [尝鲜]妈妈再也不用担心 dotnet core 程序发布了: .NET Core Global Tools
    程序员节应该写博客之.NET下使用HTTP请求的正确姿势
    [开源 .NET 跨平台 Crawler 数据采集 爬虫框架: DotnetSpider] [五] 如何做全站采集?
    [开源 .NET 跨平台 Crawler 数据采集 爬虫框架: DotnetSpider] [一] 初衷与架构设计
    ubuntu15.10 或者 16.04 或者 ElementryOS 下使用 Dotnet Core
    解决 docker on windows下网络不通
    Orchestrator中 errant 的判断
    golang 中时间差的计算
  • 原文地址:https://www.cnblogs.com/wantnon/p/4679871.html
Copyright © 2011-2022 走看看