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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
|
#ifndef UNITY_STANDARD_META_INCLUDED
#define UNITY_STANDARD_META_INCLUDED
// Functionality for Standard shader "meta" pass
// (extracts albedo/emission for lightmapper etc.)
#include "UnityCG.cginc"
#include "UnityMetaPass.cginc"
#include "custom30.cginc"
#include "eyes.cginc"
#include "face_me.cginc"
#include "false_color_visualization.cginc"
#include "features.cginc"
#include "fog.cginc"
#include "globals.cginc"
#include "harnack_tracing.cginc"
#include "interpolators.cginc"
#include "letter_grid.cginc"
#include "matcaps.cginc"
#include "math.cginc"
#include "poi.cginc"
#include "shatter_wave.cginc"
#include "ssao.cginc"
#include "ssfd.cginc"
#include "tessellation.cginc"
#include "unigram_letter_grid.cginc"
#include "vertex_domain_warping.cginc"
#include "yum_brdf.cginc"
#include "yum_pbr.cginc"
#include "yum_lighting.cginc"
struct v2f_meta
{
float4 pos : SV_POSITION;
float4 uv01 : TEXCOORD0;
float4 uv23 : TEXCOORD1;
float3 worldPos : TEXCOORD2;
float3 objPos : TEXCOORD3;
float3 normal : TEXCOORD4;
float3 tangent : TEXCOORD5;
float3 binormal : TEXCOORD6;
float4 color : COLOR;
#ifdef EDITOR_VISUALIZATION
float2 vizUV : TEXCOORD7;
float4 lightCoord : TEXCOORD8;
#endif
};
v2f_meta vert_meta (appdata v)
{
v2f_meta o;
o.pos = UnityMetaVertexPosition(v.vertex, v.uv1.xy, v.uv2.xy, unity_LightmapST, unity_DynamicLightmapST);
o.uv01.xy = v.uv0;
#if defined(LIGHTMAP_ON)
o.uv01.zw = v.uv1 * unity_LightmapST.xy + unity_LightmapST.zw;
#else
o.uv01.zw = v.uv1;
#endif
o.uv23.xy = v.uv2;
o.uv23.zw = v.uv3;
o.worldPos = mul(unity_ObjectToWorld, v.vertex);
o.objPos = v.vertex;
o.normal = v.normal;
o.tangent = v.tangent.xyz;
o.binormal = cross(o.normal, o.tangent) * v.tangent.w;
o.color = v.color;
#ifdef EDITOR_VISUALIZATION
o.vizUV = 0;
o.lightCoord = 0;
if (unity_VisualizationMode == EDITORVIZ_TEXTURE)
o.vizUV = UnityMetaVizUV(unity_EditorViz_UVIndex, v.uv0.xy, v.uv1.xy, v.uv2.xy, unity_EditorViz_Texture_ST);
else if (unity_VisualizationMode == EDITORVIZ_SHOWLIGHTMASK)
{
o.vizUV = v.uv1.xy * unity_LightmapST.xy + unity_LightmapST.zw;
o.lightCoord = mul(unity_EditorViz_WorldToLight, mul(unity_ObjectToWorld, float4(v.vertex.xyz, 1)));
}
#endif
return o;
}
float4 frag_meta (v2f_meta i) : SV_Target
{
i.normal = normalize(UnityObjectToWorldNormal(i.normal));
i.tangent = normalize(UnityObjectToWorldNormal(i.tangent));
i.binormal = normalize(UnityObjectToWorldNormal(i.binormal));
float4x4 tangentToWorld = float4x4(
float4(i.tangent.x, i.binormal.x, i.normal.x, 0),
float4(i.tangent.y, i.binormal.y, i.normal.y, 0),
float4(i.tangent.z, i.binormal.z, i.normal.z, 0),
float4(0, 0, 0, 1)
);
// Convert v2f_meta to v2f structure expected by YumPbr
v2f pbr_input;
pbr_input.uv01 = i.uv01;
pbr_input.uv23 = i.uv23;
pbr_input.worldPos = i.worldPos;
pbr_input.objPos = float4(i.objPos, 1.0);
pbr_input.normal = i.normal;
pbr_input.tangent = i.tangent;
pbr_input.binormal = i.binormal;
pbr_input.color = i.color;
YumPbr pbr = GetYumPbr(pbr_input, tangentToWorld);
#if defined(_CUSTOM30)
#if defined(_CUSTOM30_BASICCUBE)
Custom30Output c30_out = BasicCube(pbr_input, tangentToWorld);
#elif defined(_CUSTOM30_BASICWEDGE)
Custom30Output c30_out = BasicWedge(pbr_input, tangentToWorld);
#elif defined(_CUSTOM30_BASICPLATFORM)
Custom30Output c30_out = BasicPlatform(pbr_input, tangentToWorld);
#elif defined(_CUSTOM30_RAINBOW)
Custom30Output c30_out = Rainbow(pbr_input, tangentToWorld);
#else
Custom30Output c30_out = (Custom30Output) 0;
c30_out.normal = pbr_input.normal;
c30_out.objPos = pbr_input.objPos.xyz;
#endif
// Update surface properties with volumetric results
pbr_input.normal = c30_out.normal;
pbr_input.worldPos = mul(unity_ObjectToWorld, float4(c30_out.objPos, 1));
// Recalculate tangent space with new normal
tangentToWorld = float4x4(
float4(i.tangent.x, i.binormal.x, pbr_input.normal.x, 0),
float4(i.tangent.y, i.binormal.y, pbr_input.normal.y, 0),
float4(i.tangent.z, i.binormal.z, pbr_input.normal.z, 0),
float4(0, 0, 0, 1)
);
// Get PBR properties with updated surface
pbr = GetYumPbr(pbr_input, tangentToWorld);
#endif
UnityMetaInput o;
UNITY_INITIALIZE_OUTPUT(UnityMetaInput, o);
#ifdef EDITOR_VISUALIZATION
o.Albedo = pbr.albedo.rgb;
o.VizUV = i.vizUV;
o.LightCoord = i.lightCoord;
#else
// For lightmapping, we want the diffuse albedo with some contribution from rough metals
half roughness = pbr.roughness_perceptual;
half3 res = pbr.albedo.rgb;
res += pbr.metallic * roughness * 0.5;
o.Albedo = res;
#endif
o.SpecularColor = lerp(0.04, pbr.albedo.rgb, pbr.metallic);
#if defined(_EMISSION)
o.Emission = pbr.emission;
#else
o.Emission = 0;
#endif
return UnityMetaFragment(o);
}
#endif // UNITY_STANDARD_META_INCLUDED
|