• SubsurfaceScattering 自发光shader


     1 Shader "SubsurfaceScattering" {
     2     Properties {
     3         _Color ("Main Color", Color) = (1,1,1,1)
     4         _SpecColor ("Specular Color", Color) = (0.5, 0.5, 0.5, 1)
     5         _Shininess ("Shininess", Range (0.03, 1)) = 0.078125
     6         _MainTex ("Base (RGB) Gloss (A)", 2D) = "white" {}
     7         _TransMap ("Translucency Map",2D) = "white" {}
     8         _BumpMap ("Normalmap", 2D) = "bump" {}
     9         _TransDistortion ("Tranlucency Distortion",Range(0,0.5)) = 0.1
    10         _Trans ("Translucency", Range(0.0, 1.0)) = 1.0
    11         _TransPower("Tranlucency Power",Range(1.0,15.0)) = 4.0
    12         _TransScale("Translucency Scale",Range(0.0,10.0)) = 2.0
    13         
    14     }
    15     SubShader {
    16         Tags { "RenderType"="Opaque" }
    17         LOD 200
    18         
    19 CGPROGRAM
    20 #pragma surface surf TransBlinnPhong
    21 
    22 sampler2D _MainTex;
    23 sampler2D _TransMap;
    24 sampler2D _BumpMap;
    25 float4 _Color;
    26 float _Shininess;
    27 float _TransDistortion;
    28 float _TransPower;
    29 float _TransScale;
    30 float _Trans;
    31 
    32 struct Input
    33 {
    34     float2 uv_MainTex;
    35     float2 uv_BumpMap;
    36 };
    37 
    38 struct TransSurfaceOutput
    39 {
    40     fixed3 Albedo;
    41     fixed3 Normal;
    42     fixed3 Emission;
    43     half Specular;
    44     fixed Gloss;
    45     fixed Alpha;
    46     fixed3 TransCol;
    47 };
    48 
    49 inline fixed4 LightingTransBlinnPhong (TransSurfaceOutput s, fixed3 lightDir, half3 viewDir, fixed atten)
    50 {    
    51     half atten2 = (atten * 2);
    52 
    53     fixed3 diffCol;
    54     fixed3 specCol;
    55     float spec;    
    56     
    57     half NL = max(0.0h,dot (s.Normal, lightDir));
    58 
    59     half3 h = normalize (lightDir + viewDir);
    60     
    61     float nh = max (0, dot (s.Normal, h));
    62     spec = pow (nh, s.Specular*128.0) * s.Gloss;
    63     
    64     diffCol = (s.Albedo * _LightColor0.rgb * NL) * atten2;
    65     specCol = (_LightColor0.rgb * _SpecColor.rgb * spec) * atten2;
    66 
    67     half3 transLight = lightDir + s.Normal * _TransDistortion;
    68     float VinvL = saturate(dot(viewDir, -transLight));
    69     float transDot = pow(VinvL,_TransPower) * _TransScale;
    70     half3 lightAtten = _LightColor0.rgb * atten2;
    71     half3 transComponent = lightAtten * (transDot + _Color.rgb) * s.TransCol;
    72     diffCol += s.Albedo * transComponent;
    73     
    74     fixed4 c;
    75     c.rgb = diffCol + specCol;
    76     c.a = s.Alpha + _LightColor0.a * _SpecColor.a * spec * atten * _Trans;
    77     return c;
    78 }
    79 
    80  void surf (Input IN, inout TransSurfaceOutput o)
    81  {
    82     half4 tex = tex2D(_MainTex, IN.uv_MainTex);
    83     o.Albedo = tex.rgb * _Color.rgb;
    84     o.Gloss = tex.a;
    85     o.Alpha = tex.a * _Color.a * _Trans;
    86     o.Specular = _Shininess;
    87     o.Normal = UnpackNormal(tex2D(_BumpMap, IN.uv_BumpMap));
    88     o.TransCol = tex2D(_TransMap,IN.uv_MainTex).rgb;
    89 }
    90 ENDCG
    91 }
    92 
    93 FallBack "Specular"
    94 }
  • 相关阅读:
    CodeForces
    CodeForces
    springboot 入门七-静态资源处理
    springboot 入门六-多环境日志配置
    springboot 入门五-日志一
    springboot 入门四-时间类型处理
    springboot 入门三- 读取配置信息二(读取属性文件方式)
    springboot 入门二- 读取配置信息一
    springboot 入门一 hello world!
    SVN提交小结(转)
  • 原文地址:https://www.cnblogs.com/guaishoudashu/p/12809799.html
Copyright © 2020-2023  润新知