@@ -17,51 +17,36 @@ vec4 getSheenSample(vec3 reflection, float lod)
17
17
return textureLod(u_CharlieEnvSampler, u_EnvRotation * reflection, lod) * u_EnvIntensity;
18
18
}
19
19
20
-
21
- vec3 getIBLRadianceGGX(vec3 n, vec3 v, float roughness, vec3 F0, float specularWeight)
20
+ vec3 getIBLGGXFresnel(vec3 n, vec3 v, float roughness, vec3 F0, float specularWeight)
22
21
{
22
+ // see https://bruop.github.io/ibl/#single_scattering_results at Single Scattering Results
23
+ // Roughness dependent fresnel, from Fdez-Aguera
23
24
float NdotV = clampedDot(n, v);
24
- float lod = roughness * float (u_MipCount - 1 );
25
- vec3 reflection = normalize (reflect (- v, n));
26
-
27
25
vec2 brdfSamplePoint = clamp (vec2 (NdotV, roughness), vec2 (0.0 , 0.0 ), vec2 (1.0 , 1.0 ));
28
26
vec2 f_ab = texture(u_GGXLUT, brdfSamplePoint).rg;
29
- vec4 specularSample = getSpecularSample(reflection, lod);
30
-
31
- vec3 specularLight = specularSample.rgb;
32
-
33
- // see https://bruop.github.io/ibl/#single_scattering_results at Single Scattering Results
34
- // Roughness dependent fresnel, from Fdez-Aguera
35
27
vec3 Fr = max (vec3 (1.0 - roughness), F0) - F0;
36
28
vec3 k_S = F0 + Fr * pow (1.0 - NdotV, 5.0 );
37
- vec3 FssEss = k_S * f_ab.x + f_ab.y;
29
+ vec3 FssEss = specularWeight * ( k_S * f_ab.x + f_ab.y) ;
38
30
39
- return specularWeight * specularLight * FssEss;
40
- }
31
+ // Multiple scattering, from Fdez-Aguera
32
+ float Ems = (1.0 - (f_ab.x + f_ab.y));
33
+ vec3 F_avg = specularWeight * (F0 + (1.0 - F0) / 21.0 );
34
+ vec3 FmsEms = Ems * FssEss * F_avg / (1.0 - F_avg * Ems);
41
35
36
+ return FssEss + FmsEms;
37
+ }
42
38
43
- #ifdef MATERIAL_IRIDESCENCE
44
- vec3 getIBLRadianceGGXIridescence(vec3 n, vec3 v, float roughness, vec3 F0, vec3 iridescenceFresnel, float iridescenceFactor, float specularWeight)
39
+ vec3 getIBLRadianceGGX(vec3 n, vec3 v, float roughness)
45
40
{
46
41
float NdotV = clampedDot(n, v);
47
42
float lod = roughness * float (u_MipCount - 1 );
48
43
vec3 reflection = normalize (reflect (- v, n));
49
-
50
- vec2 brdfSamplePoint = clamp (vec2 (NdotV, roughness), vec2 (0.0 , 0.0 ), vec2 (1.0 , 1.0 ));
51
- vec2 f_ab = texture(u_GGXLUT, brdfSamplePoint).rg;
52
44
vec4 specularSample = getSpecularSample(reflection, lod);
53
45
54
46
vec3 specularLight = specularSample.rgb;
55
47
56
- // see https://bruop.github.io/ibl/#single_scattering_results at Single Scattering Results
57
- // Roughness dependent fresnel, from Fdez-Aguera
58
- vec3 Fr = max (vec3 (1.0 - roughness), F0) - F0;
59
- vec3 k_S = mix (F0 + Fr * pow (1.0 - NdotV, 5.0 ), iridescenceFresnel, iridescenceFactor);
60
- vec3 FssEss = k_S * f_ab.x + f_ab.y;
61
-
62
- return specularWeight * specularLight * FssEss;
48
+ return specularLight;
63
49
}
64
- #endif
65
50
66
51
67
52
#ifdef MATERIAL_TRANSMISSION
@@ -130,68 +115,8 @@ vec3 getIBLVolumeRefraction(vec3 n, vec3 v, float perceptualRoughness, vec3 base
130
115
#endif
131
116
132
117
133
- // specularWeight is introduced with KHR_materials_specular
134
- vec3 getIBLRadianceLambertian(vec3 n, vec3 v, float roughness, vec3 diffuseColor, vec3 F0, float specularWeight)
135
- {
136
- float NdotV = clampedDot(n, v);
137
- vec2 brdfSamplePoint = clamp (vec2 (NdotV, roughness), vec2 (0.0 , 0.0 ), vec2 (1.0 , 1.0 ));
138
- vec2 f_ab = texture(u_GGXLUT, brdfSamplePoint).rg;
139
-
140
- vec3 irradiance = getDiffuseLight(n);
141
-
142
- // see https://bruop.github.io/ibl/#single_scattering_results at Single Scattering Results
143
- // Roughness dependent fresnel, from Fdez-Aguera
144
-
145
- vec3 Fr = max (vec3 (1.0 - roughness), F0) - F0;
146
- vec3 k_S = F0 + Fr * pow (1.0 - NdotV, 5.0 );
147
- vec3 FssEss = specularWeight * k_S * f_ab.x + f_ab.y; // <--- GGX / specular light contribution (scale it down if the specularWeight is low)
148
-
149
- // Multiple scattering, from Fdez-Aguera
150
- float Ems = (1.0 - (f_ab.x + f_ab.y));
151
- vec3 F_avg = specularWeight * (F0 + (1.0 - F0) / 21.0 );
152
- vec3 FmsEms = Ems * FssEss * F_avg / (1.0 - F_avg * Ems);
153
- vec3 k_D = diffuseColor * (1.0 - FssEss + FmsEms); // we use +FmsEms as indicated by the formula in the blog post (might be a typo in the implementation)
154
-
155
- return (FmsEms + k_D) * irradiance;
156
- }
157
-
158
-
159
- #ifdef MATERIAL_IRIDESCENCE
160
- // specularWeight is introduced with KHR_materials_specular
161
- vec3 getIBLRadianceLambertianIridescence(vec3 n, vec3 v, float roughness, vec3 diffuseColor, vec3 F0, vec3 iridescenceF0, float iridescenceFactor, float specularWeight)
162
- {
163
- float NdotV = clampedDot(n, v);
164
- vec2 brdfSamplePoint = clamp (vec2 (NdotV, roughness), vec2 (0.0 , 0.0 ), vec2 (1.0 , 1.0 ));
165
- vec2 f_ab = texture(u_GGXLUT, brdfSamplePoint).rg;
166
-
167
- vec3 irradiance = getDiffuseLight(n);
168
-
169
- // Use the maximum component of the iridescence Fresnel color
170
- // Maximum is used instead of the RGB value to not get inverse colors for the diffuse BRDF
171
- vec3 iridescenceF0Max = vec3 (max (max (iridescenceF0.r, iridescenceF0.g), iridescenceF0.b));
172
-
173
- // Blend between base F0 and iridescence F0
174
- vec3 mixedF0 = mix (F0, iridescenceF0Max, iridescenceFactor);
175
-
176
- // see https://bruop.github.io/ibl/#single_scattering_results at Single Scattering Results
177
- // Roughness dependent fresnel, from Fdez-Aguera
178
-
179
- vec3 Fr = max (vec3 (1.0 - roughness), mixedF0) - mixedF0;
180
- vec3 k_S = mixedF0 + Fr * pow (1.0 - NdotV, 5.0 );
181
- vec3 FssEss = specularWeight * k_S * f_ab.x + f_ab.y; // <--- GGX / specular light contribution (scale it down if the specularWeight is low)
182
-
183
- // Multiple scattering, from Fdez-Aguera
184
- float Ems = (1.0 - (f_ab.x + f_ab.y));
185
- vec3 F_avg = specularWeight * (mixedF0 + (1.0 - mixedF0) / 21.0 );
186
- vec3 FmsEms = Ems * FssEss * F_avg / (1.0 - F_avg * Ems);
187
- vec3 k_D = diffuseColor * (1.0 - FssEss + FmsEms); // we use +FmsEms as indicated by the formula in the blog post (might be a typo in the implementation)
188
-
189
- return (FmsEms + k_D) * irradiance;
190
- }
191
- #endif
192
-
193
118
#ifdef MATERIAL_ANISOTROPY
194
- vec3 getIBLRadianceAnisotropy(vec3 n, vec3 v, float roughness, float anisotropy, vec3 anisotropyDirection, vec3 F0, float specularWeight )
119
+ vec3 getIBLRadianceAnisotropy(vec3 n, vec3 v, float roughness, float anisotropy, vec3 anisotropyDirection)
195
120
{
196
121
float NdotV = clampedDot(n, v);
197
122
@@ -205,19 +130,11 @@ vec3 getIBLRadianceAnisotropy(vec3 n, vec3 v, float roughness, float anisotropy,
205
130
float lod = roughness * float (u_MipCount - 1 );
206
131
vec3 reflection = normalize (reflect (- v, bentNormal));
207
132
208
- vec2 brdfSamplePoint = clamp (vec2 (NdotV, roughness), vec2 (0.0 , 0.0 ), vec2 (1.0 , 1.0 ));
209
- vec2 f_ab = texture(u_GGXLUT, brdfSamplePoint).rg;
210
133
vec4 specularSample = getSpecularSample(reflection, lod);
211
134
212
135
vec3 specularLight = specularSample.rgb;
213
136
214
- // see https://bruop.github.io/ibl/#single_scattering_results at Single Scattering Results
215
- // Roughness dependent fresnel, from Fdez-Aguera
216
- vec3 Fr = max (vec3 (1.0 - roughness), F0) - F0;
217
- vec3 k_S = F0 + Fr * pow (1.0 - NdotV, 5.0 );
218
- vec3 FssEss = k_S * f_ab.x + f_ab.y;
219
-
220
- return specularWeight * specularLight * FssEss;
137
+ return specularLight;
221
138
}
222
139
#endif
223
140
0 commit comments