1
+ // _____________________________ Base Diffuse Layer IBL _______________________________________
2
+ #ifdef REFLECTION
3
+ // Pass in a vector to sample teh irradiance with (to handle reflection or )
4
+ vec3 baseDiffuseEnvironmentLight = sampleIrradiance (
5
+ normalW
6
+ #if defined (NORMAL) && defined (USESPHERICALINVERTEX)
7
+ , vEnvironmentIrradiance
8
+ #endif
9
+ #if (defined (USESPHERICALFROMREFLECTIONMAP) && (!defined (NORMAL) || !defined (USESPHERICALINVERTEX))) || (defined (USEIRRADIANCEMAP) && defined (REFLECTIONMAP_3D))
10
+ , reflectionMatrix
11
+ #endif
12
+ #ifdef USEIRRADIANCEMAP
13
+ , irradianceSampler
14
+ #ifdef USE_IRRADIANCE_DOMINANT_DIRECTION
15
+ , vReflectionDominantDirection
16
+ #endif
17
+ #endif
18
+ #ifdef REALTIME_FILTERING
19
+ , vReflectionFilteringInfo
20
+ #ifdef IBL_CDF_FILTERING
21
+ , icdfSampler
22
+ #endif
23
+ #endif
24
+ , vReflectionInfos
25
+ , viewDirectionW
26
+ , base_diffuse_roughness
27
+ , base_color
28
+ );
29
+
30
+ // _____________________________ Base Specular Layer IBL _______________________________________
31
+
32
+ #ifdef REFLECTIONMAP_3D
33
+ vec3 reflectionCoords = vec3 (0 ., 0 ., 0 .);
34
+ #else
35
+ vec2 reflectionCoords = vec2 (0 ., 0 .);
36
+ #endif
37
+ reflectionCoords = createReflectionCoords (vPositionW, normalW);
38
+ float specularAlphaG = specular_roughness * specular_roughness;
39
+ vec3 baseSpecularEnvironmentLight = sampleRadiance (specularAlphaG, vReflectionMicrosurfaceInfos.rgb, vReflectionInfos
40
+ #if defined (LODINREFLECTIONALPHA) && !defined (REFLECTIONMAP_SKYBOX)
41
+ , baseGeoInfo.NdotVUnclamped
42
+ #endif
43
+ , reflectionSampler
44
+ , reflectionCoords
45
+ #ifdef REALTIME_FILTERING
46
+ , vReflectionFilteringInfo
47
+ #endif
48
+ );
49
+
50
+ baseSpecularEnvironmentLight = mix (baseSpecularEnvironmentLight.rgb, baseDiffuseEnvironmentLight, specularAlphaG);
51
+
52
+ vec3 coatEnvironmentLight = vec3 (0 ., 0 ., 0 .);
53
+ if (coat_weight > 0.0 ) {
54
+ #ifdef REFLECTIONMAP_3D
55
+ vec3 reflectionCoords = vec3 (0 ., 0 ., 0 .);
56
+ #else
57
+ vec2 reflectionCoords = vec2 (0 ., 0 .);
58
+ #endif
59
+ reflectionCoords = createReflectionCoords (vPositionW, coatNormalW);
60
+ float coatAlphaG = coat_roughness * coat_roughness;
61
+ coatEnvironmentLight = sampleRadiance (coatAlphaG, vReflectionMicrosurfaceInfos.rgb, vReflectionInfos
62
+ #if defined (LODINREFLECTIONALPHA) && !defined (REFLECTIONMAP_SKYBOX)
63
+ , coatGeoInfo.NdotVUnclamped
64
+ #endif
65
+ , reflectionSampler
66
+ , reflectionCoords
67
+ #ifdef REALTIME_FILTERING
68
+ , vReflectionFilteringInfo
69
+ #endif
70
+ );
71
+ }
72
+
73
+ // ______________________________ IBL Fresnel Reflectance ____________________________
74
+
75
+ // Dielectric IBL Fresnel
76
+ // The colored fresnel represents the % of light reflected by the base specular lobe
77
+ // The non-colored fresnel represents the % of light that doesn't penetrate through
78
+ // the base specular lobe. i.e. the specular lobe isn't energy conserving for coloured specular.
79
+ float dielectricIblFresnel = getReflectanceFromBRDFLookup (vec3 (baseDielectricReflectance.F0), vec3 (baseDielectricReflectance.F90), baseGeoInfo.environmentBrdf).r;
80
+ vec3 dielectricIblColoredFresnel = getReflectanceFromBRDFLookup (baseDielectricReflectance.coloredF0, baseDielectricReflectance.coloredF90, baseGeoInfo.environmentBrdf);
81
+
82
+ // Conductor IBL Fresnel
83
+ vec3 conductorIblFresnel = conductorIblFresnel (baseConductorReflectance, baseGeoInfo.NdotV, specular_roughness, baseGeoInfo.environmentBrdf);
84
+
85
+ // Coat IBL Fresnel
86
+ float coatIblFresnel = 0.0 ;
87
+ if (coat_weight > 0.0 ) {
88
+ coatIblFresnel = getReflectanceFromBRDFLookup (vec3 (coatReflectance.F0), vec3 (coatReflectance.F90), coatGeoInfo.environmentBrdf).r;
89
+ }
90
+
91
+
92
+ vec3 slab_diffuse_ibl = vec3 (0 ., 0 ., 0 .);
93
+ vec3 slab_glossy_ibl = vec3 (0 ., 0 ., 0 .);
94
+ vec3 slab_metal_ibl = vec3 (0 ., 0 ., 0 .);
95
+ vec3 slab_coat_ibl = vec3 (0 ., 0 ., 0 .);
96
+
97
+ slab_diffuse_ibl = baseDiffuseEnvironmentLight * vLightingIntensity.z;
98
+ slab_diffuse_ibl *= aoOut.ambientOcclusionColor;
99
+
100
+ // Add the specular environment light
101
+ slab_glossy_ibl = baseSpecularEnvironmentLight * vLightingIntensity.z;
102
+
103
+ // _____________________________ Metal Layer IBL ____________________________
104
+ slab_metal_ibl = baseSpecularEnvironmentLight * conductorIblFresnel * vLightingIntensity.z;
105
+
106
+ // _____________________________ Coat Layer IBL _____________________________
107
+ if (coat_weight > 0.0 ) {
108
+ slab_coat_ibl = coatEnvironmentLight * vLightingIntensity.z;
109
+ }
110
+
111
+ // TEMP
112
+ vec3 slab_subsurface_ibl = vec3 (0 ., 0 ., 0 .);
113
+ vec3 slab_translucent_base_ibl = vec3 (0 ., 0 ., 0 .);
114
+ vec3 slab_fuzz_ibl = vec3 (0 ., 0 ., 0 .);
115
+
116
+ slab_diffuse_ibl *= base_color.rgb;
117
+
118
+ // _____________________________ IBL Material Layer Composition ______________________________________
119
+ #define CUSTOM_FRAGMENT_BEFORE_IBLLAYERCOMPOSITION
120
+ vec3 material_opaque_base_ibl = mix (slab_diffuse_ibl, slab_subsurface_ibl, subsurface_weight);
121
+ vec3 material_dielectric_base_ibl = mix (material_opaque_base_ibl, slab_translucent_base_ibl, transmission_weight);
122
+ vec3 material_dielectric_gloss_ibl = layer (material_dielectric_base_ibl, slab_glossy_ibl, dielectricIblFresnel, vec3 (1.0 ), specular_color);
123
+ vec3 material_base_substrate_ibl = mix (material_dielectric_gloss_ibl, slab_metal_ibl, base_metalness);
124
+ vec3 material_coated_base_ibl = layer (material_base_substrate_ibl, slab_coat_ibl, coatIblFresnel, coat_color, vec3 (1.0 ));
125
+ material_surface_ibl = mix (material_coated_base_ibl, slab_fuzz_ibl, fuzz_weight);
126
+
127
+ #endif
0 commit comments