1
+ //Written by Przemyslaw Zaworski
2
+ //https://github.com/przemyslawzaworski
3
+
4
+ Shader "Deferred (Metallic Gloss)"
5
+ {
6
+ Properties
7
+ {
8
+ _Color ( "Color" , Color ) = (1 ,1 ,1 ,1 )
9
+ _Metallic ( "Metallic" , Range (0 , 1 )) = 1
10
+ _Gloss ( "Gloss" , Range (0 , 1 )) = 0.8
11
+ }
12
+ SubShader
13
+ {
14
+ Pass
15
+ {
16
+ Tags {"LightMode" ="Deferred" }
17
+
18
+ CGPROGRAM
19
+ #pragma vertex vertex_shader
20
+ #pragma fragment pixel_shader
21
+ #pragma exclude_renderers nomrt
22
+ #pragma multi_compile ___ UNITY_HDR_ON
23
+ #pragma target 3.0
24
+
25
+ #include "UnityPBSLighting.cginc"
26
+
27
+ float4 _Color;
28
+ float _Metallic;
29
+ float _Gloss;
30
+
31
+ struct structureVS
32
+ {
33
+ float4 screen_vertex : SV_POSITION ;
34
+ float4 world_vertex : TEXCOORD0 ;
35
+ float3 normal : TEXCOORD1 ;
36
+ };
37
+
38
+ struct structurePS
39
+ {
40
+ half4 albedo : SV_Target0 ;
41
+ half4 specular : SV_Target1 ;
42
+ half4 normal : SV_Target2 ;
43
+ half4 emission : SV_Target3 ;
44
+ };
45
+
46
+ structureVS vertex_shader (float4 vertex : POSITION ,float3 normal : NORMAL )
47
+ {
48
+ structureVS vs;
49
+ vs.screen_vertex = UnityObjectToClipPos ( vertex );
50
+ vs.world_vertex = mul (unity_ObjectToWorld , vertex);
51
+ vs.normal = UnityObjectToWorldNormal (normal);
52
+ return vs;
53
+ }
54
+
55
+ structurePS pixel_shader (structureVS vs)
56
+ {
57
+ structurePS ps;
58
+ float3 normalDirection = normalize (vs.normal);
59
+ half3 specular;
60
+ half specularMonochrome;
61
+ half3 diffuseColor = DiffuseAndSpecularFromMetallic ( _Color.rgb, _Metallic, specular, specularMonochrome );
62
+ ps.albedo = half4 ( diffuseColor, 1.0 );
63
+ ps.specular = half4 ( specular, _Gloss );
64
+ ps.normal = half4 ( normalDirection * 0.5 + 0.5 , 1.0 );
65
+ ps.emission = half4 (0 ,0 ,0 ,1 );
66
+ #ifndef UNITY_HDR_ON
67
+ ps.emission.rgb = exp2 (-ps.emission.rgb);
68
+ #endif
69
+ return ps;
70
+ }
71
+ ENDCG
72
+ }
73
+ }
74
+ FallBack "Diffuse"
75
+ }
0 commit comments