SubsurfaceScattering 自发光shader

Posted guaishoudashu

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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 }

 

以上是关于SubsurfaceScattering 自发光shader的主要内容,如果未能解决你的问题,请参考以下文章

unity灯光和自发光的哪个节省内存

Unity 手写PBR补充:多光源 阴影 视差 自发光

unity3d中shader cg程序的自发光怎么写

小功能⭐️Unity中利用材质自发光实现物体闪烁效果

小功能⭐️Unity中利用材质自发光实现物体闪烁效果

小功能⭐️Unity中利用材质自发光实现物体闪烁效果