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
170
171
172
173
174
175
176
177
178
179
180
|
#ifndef POI_MAINTEXTURE
#define POI_MAINTEXTURE
#if defined(PROP_CLIPPINGMASK) || !defined(OPTIMIZER_ENABLED)
POI_TEXTURE_NOSAMPLER(_ClippingMask);
#endif
#if defined(PROP_MAINFADETEXTURE) || !defined(OPTIMIZER_ENABLED)
POI_TEXTURE_NOSAMPLER(_MainFadeTexture);
#endif
float _Inverse_Clipping;
float4 _Color;
float _MainVertexColoring;
float _MainUseVertexColorAlpha;
float _Saturation;
float2 _MainDistanceFade;
half _MainMinAlpha;
float _MainHueShift;
#ifdef COLOR_GRADING_HDR
#if defined(PROP_MAINCOLORADJUSTTEXTURE) || !defined(OPTIMIZER_ENABLED)
POI_TEXTURE_NOSAMPLER(_MainColorAdjustTexture);
#endif
float _MainHueShiftToggle;
float _MainHueShiftSpeed;
float _MainHueShiftReplace;
float _MainSaturationShift;
float _MainBrightness;
#endif
#ifdef FINALPASS
#if defined(PROP_DETAILTEX) || !defined(OPTIMIZER_ENABLED)
POI_TEXTURE_NOSAMPLER(_DetailTex);
#endif
half _DetailTexIntensity;
half3 _DetailTint;
float _DetailBrightness;
#endif
//globals
float alphaMask;
half3 diffColor;
#include "CGI_PoiBackFace.cginc"
float3 wireframeEmission;
inline FragmentCommonData SpecularSetup(float4 i_tex, inout float4 albedo)
{
half4 specGloss = 0;
half3 specColor = specGloss.rgb;
half smoothness = specGloss.a;
half oneMinusReflectivity;
diffColor = EnergyConservationBetweenDiffuseAndSpecular(albedo.rgb, specColor, /*out*/ oneMinusReflectivity);
FragmentCommonData o = (FragmentCommonData)0;
o.diffColor = diffColor;
o.specColor = specColor;
o.oneMinusReflectivity = oneMinusReflectivity;
o.smoothness = smoothness;
return o;
}
inline FragmentCommonData FragmentSetup(float4 i_tex, half3 i_viewDirForParallax, float3 i_posWorld, inout float4 albedo)
{
i_tex = i_tex;
FragmentCommonData o = SpecularSetup(i_tex, albedo);
o.normalWorld = float3(0, 0, 0);
o.eyeVec = poiCam.viewDir;
o.posWorld = i_posWorld;
// NOTE: shader relies on pre-multiply alpha-blend (float(1) = One, float(0) = OneMinusSrcAlpha)
o.diffColor = PreMultiplyAlpha(o.diffColor, 1, o.oneMinusReflectivity, /*out*/ o.alpha);
return o;
}
void initTextureData(inout float4 albedo, inout float4 mainTexture, inout float3 backFaceEmission, inout float3 dissolveEmission, in half3 detailMask)
{
dissolveEmission = 0;
#if (defined(FORWARD_BASE_PASS) || defined(FORWARD_ADD_PASS))
#ifdef POI_MIRROR
applyMirrorTexture(mainTexture);
#endif
#endif
#if defined(PROP_CLIPPINGMASK) || !defined(OPTIMIZER_ENABLED)
alphaMask = POI2D_SAMPLER_PAN(_ClippingMask, _MainTex, poiMesh.uv[float(0)], float4(0,0,0,0)).r;
#else
alphaMask = 1;
#endif
if (float(0))
{
alphaMask = 1 - alphaMask;
}
mainTexture.a *= alphaMask;
#ifndef POI_SHADOW
albedo = float4(mainTexture.rgb * max(float4(1,1,1,1).rgb, float3(0.000000001, 0.000000001, 0.000000001)) * lerp(1, GammaToLinearSpace(poiMesh.vertexColor.rgb), float(0)), mainTexture.a * max(float4(1,1,1,1).a, 0.0000001));
#if defined(POI_LIGHTING) && defined(FORWARD_BASE_PASS)
applyShadeMaps(albedo);
#endif
albedo *= lerp(1, poiMesh.vertexColor.a, float(0));
#ifdef POI_RGBMASK
albedo.rgb = calculateRGBMask(albedo.rgb);
#endif
albedo.a = saturate(float(0) + albedo.a);
wireframeEmission = 0;
#ifdef POI_WIREFRAME
applyWireframe(wireframeEmission, albedo);
#endif
float backFaceDetailIntensity = 1;
float mixedHueShift = float(0);
applyBackFaceTexture(backFaceDetailIntensity, mixedHueShift, albedo, backFaceEmission);
#ifdef POI_FUR
calculateFur();
#endif
#ifdef COLOR_GRADING_HDR
#if defined(PROP_MAINCOLORADJUSTTEXTURE) || !defined(OPTIMIZER_ENABLED)
float4 hueShiftAlpha = POI2D_SAMPLER_PAN(_MainColorAdjustTexture, _MainTex, poiMesh.uv[float(0)], float4(0,0,0,0));
#else
float4 hueShiftAlpha = 1;
#endif
if (float(1))
{
albedo.rgb = lerp(albedo.rgb, hueShift(albedo.rgb, mixedHueShift + float(0) * _Time.x), hueShiftAlpha.r);
}
else
{
albedo.rgb = hueShift(albedo.rgb, frac((mixedHueShift - (1 - hueShiftAlpha.r) + float(0) * _Time.x)));
}
albedo.rgb = lerp(albedo.rgb, dot(albedo.rgb, float3(0.3, 0.59, 0.11)), -float(0) * hueShiftAlpha.b);
albedo.rgb = saturate(albedo.rgb + float(0) * hueShiftAlpha.g);
#endif
#ifdef FINALPASS
#if defined(PROP_DETAILTEX) || !defined(OPTIMIZER_ENABLED)
half3 detailTexture = POI2D_SAMPLER_PAN(_DetailTex, _MainTex, poiMesh.uv[float(0)], float4(0,0,0,0)).rgb * float4(1,1,1,1).rgb;
#else
half3 detailTexture = 0.21763764082 * float4(1,1,1,1).rgb;
#endif
albedo.rgb *= LerpWhiteTo(detailTexture * float(1) * unity_ColorSpaceDouble.rgb, detailMask.r * float(1) * backFaceDetailIntensity);
#endif
albedo.rgb = saturate(albedo.rgb);
#ifdef POI_HOLOGRAM
ApplyHoloAlpha(albedo);
#endif
s = FragmentSetup(float4(poiMesh.uv[0], 1, 1), poiCam.viewDir, poiMesh.worldPos, albedo);
#endif
#ifdef DISTORT
calculateDissolve(albedo, dissolveEmission);
#endif
}
void distanceFade(inout float4 albedo)
{
#if defined(PROP_MAINFADETEXTURE) || !defined(OPTIMIZER_ENABLED)
half fadeMap = POI2D_SAMPLER_PAN(_MainFadeTexture, _MainTex, poiMesh.uv[float(0)], float4(0,0,0,0)).r;
#else
half fadeMap = 1;
#endif
if (fadeMap)
{
half fadeValue = max(smoothstep(float4(0,0,0,0).x, float4(0,0,0,0).y, poiCam.distanceToVert), float(0));
albedo.a *= fadeValue;
}
}
#endif
|