码迷,mamicode.com
首页 > 其他好文 > 详细

SubsurfaceScattering 自发光shader

时间:2020-04-30 17:39:13      阅读:73      评论:0      收藏:0      [点我收藏+]

标签:pac   ali   view   hit   miss   ESS   oat   nes   enc   

 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

标签:pac   ali   view   hit   miss   ESS   oat   nes   enc   

原文地址:https://www.cnblogs.com/guaishoudashu/p/12809799.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!