forked from microsoft/MixedRealityToolkit-Unity
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathVertexLitConfigurable.cginc
More file actions
131 lines (108 loc) · 2.98 KB
/
VertexLitConfigurable.cginc
File metadata and controls
131 lines (108 loc) · 2.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
#include "HLSLSupport.cginc"
#include "UnityCG.cginc"
#include "Lighting.cginc"
#include "AutoLight.cginc"
#if _USEMAINTEX_ON
UNITY_DECLARE_TEX2D(_MainTex);
#endif
#if _USECOLOR_ON
float4 _Color;
#endif
#if _USEEMISSIONTEX_ON
UNITY_DECLARE_TEX2D(_EmissionTex);
#endif
#if _USEMAINTEX_ON || _USEEMISSIONTEX_ON
float4 _MainTex_ST;
#endif
struct appdata_t
{
float4 vertex : POSITION;
#if _USEMAINTEX_ON || _USEEMISSIONTEX_ON
float2 texcoord : TEXCOORD0;
#endif
float3 normal : NORMAL;
UNITY_VERTEX_INPUT_INSTANCE_ID
};
struct v2f_surf
{
float4 pos : SV_POSITION;
#if _USEMAINTEX_ON || _USEEMISSIONTEX_ON
float2 pack0 : TEXCOORD0;
#endif
#ifndef LIGHTMAP_OFF
float2 lmap : TEXCOORD1;
#else
float3 vlight : TEXCOORD1;
#endif
LIGHTING_COORDS(2, 3)
UNITY_FOG_COORDS(4)
#if _NEAR_PLANE_FADE_ON
float fade : TEXCOORD5;
#endif
UNITY_VERTEX_OUTPUT_STEREO
};
inline float3 LightingLambertVS(float3 normal, float3 lightDir)
{
float diff = max(0, dot(normal, lightDir));
return _LightColor0.rgb * diff;
}
v2f_surf vert(appdata_t v)
{
UNITY_SETUP_INSTANCE_ID(v);
v2f_surf o;
UNITY_INITIALIZE_OUTPUT(v2f_surf, o);
o.pos = mul(UNITY_MATRIX_MVP, v.vertex);
#if _USEMAINTEX_ON || _USEEMISSIONTEX_ON
o.pack0.xy = TRANSFORM_TEX(v.texcoord, _MainTex);
#endif
#ifndef LIGHTMAP_OFF
o.lmap.xy = v.texcoord1.xy * unity_LightmapST.xy + unity_LightmapST.zw;
#else
float3 worldN = UnityObjectToWorldNormal(v.normal);
o.vlight = ShadeSH9(float4(worldN, 1.0));
o.vlight += LightingLambertVS(worldN, _WorldSpaceLightPos0.xyz);
#endif
#if _NEAR_PLANE_FADE_ON
o.fade = ComputeNearPlaneFadeLinear(v.vertex);
#endif
TRANSFER_VERTEX_TO_FRAGMENT(o);
UNITY_TRANSFER_FOG(o, o.pos);
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o);
return o;
}
float4 frag(v2f_surf IN) : SV_Target
{
#if _USEMAINTEX_ON || _USEEMISSIONTEX_ON
float2 uv_MainTex = IN.pack0.xy;
#endif
float4 surfaceColor;
#if _USEMAINTEX_ON
surfaceColor = UNITY_SAMPLE_TEX2D(_MainTex, uv_MainTex);
#else
surfaceColor = 1;
#endif
#if _USECOLOR_ON
surfaceColor *= _Color;
#endif
float atten = LIGHT_ATTENUATION(IN);
float4 finalColor = 0;
#ifdef LIGHTMAP_OFF
finalColor.rgb = surfaceColor.rgb * IN.vlight * atten;
#else
float3 lm = DecodeLightmap(UNITY_SAMPLE_TEX2D(unity_Lightmap, IN.lmap.xy));
#ifdef SHADOWS_SCREEN
finalColor.rgb = surfaceColor.rgb * min(lm, atten * 2);
#else
finalColor.rgb = surfaceColor.rgb * lm;
#endif
#endif
finalColor.a = surfaceColor.a;
#ifdef _USEEMISSIONTEX_ON
finalColor.rgb += UNITY_SAMPLE_TEX2D(_EmissionTex, uv_MainTex);
#endif
#if _NEAR_PLANE_FADE_ON
finalColor.rgb *= IN.fade;
#endif
UNITY_APPLY_FOG(IN.fogCoord, finalColor);
return finalColor;
}