1- #ifndef PL_MATH_GLSL
2- #define PL_MATH_GLSL
1+ #ifndef MATH_GLSL
2+ #define MATH_GLSL
33
44// math
55#define PL_PI 3.1415926535897932384626433832795
6- const float M_PI = 3.141592653589793 ;
6+
77const float GAMMA = 2.2 ;
88const float INV_GAMMA = 1.0 / GAMMA;
99
@@ -131,86 +131,4 @@ const mat4 biasMat = mat4(
131131 0.5 , 0.5 , 0.0 , 1.0
132132);
133133
134- // -----------------------------------------------------------------------------
135- // [SECTION] BRDF
136- // -----------------------------------------------------------------------------
137-
138- // Fresnel reflectance term of the specular equation (F)
139- // Real-Time Rendering 4th Edition, Page 321, Equation 9.18 modified
140- vec3
141- pl_fresnel_schlick(vec3 f0, vec3 f90, float VdotH)
142- {
143- return f0 + (f90 - f0) * pow (clamp (1.0 - VdotH, 0.0 , 1.0 ), 5.0 );
144- }
145-
146- // Normal distribution function term of the specular equation (D)
147- // Real-Time Rendering 4th Edition, Page 340, Equation 9.41
148- float
149- pl_distribution_ggx(float NdotH, float alphaRoughness)
150- {
151- float alphaRoughnessSq = alphaRoughness * alphaRoughness;
152- float f = (NdotH * NdotH) * (alphaRoughnessSq - 1.0 ) + 1.0 ;
153- return alphaRoughnessSq / (M_PI * f * f);
154- }
155-
156- // Masking-Shadowing function (G2)
157- // Real-Time Rendering 4th Edition, Page 341, Equation 9.42
158- float
159- pl_masking_shadowing_ggx(float NdotL, float NdotV, float alphaRoughness)
160- {
161- float alphaRoughnessSq = alphaRoughness * alphaRoughness;
162-
163- float GGXV = NdotL * sqrt (NdotV * NdotV * (1.0 - alphaRoughnessSq) + alphaRoughnessSq);
164- float GGXL = NdotV * sqrt (NdotL * NdotL * (1.0 - alphaRoughnessSq) + alphaRoughnessSq);
165-
166- float GGX = GGXV + GGXL;
167- if (GGX > 0.0 )
168- {
169- return 0.5 / GGX;
170- }
171- return 0.0 ;
172- }
173-
174- // Masking-Shadowing function fast (G2)
175- // Real-Time Rendering 4th Edition, Page 341, Equation 9.42
176- float
177- pl_masking_shadowing_fast_ggx(float NdotL, float NdotV, float alphaRoughness)
178- {
179- float a2 = alphaRoughness * alphaRoughness;
180- float GGXV = NdotL * sqrt (NdotV * NdotV * (1.0 - a2) + a2);
181- float GGXL = NdotV * sqrt (NdotL * NdotL * (1.0 - a2) + a2);
182- float GGX = GGXV + GGXL;
183- if (GGX > 0.0 )
184- {
185- return 0.5 / GGX;
186- }
187- return 0.0 ;
188- }
189-
190-
191- // Simple Lambertian BRDF (fd)
192- // Real-Time Rendering 4th Edition, Page 314, Equation 9.11
193- vec3
194- pl_brdf_lambertian(vec3 diffuseColor)
195- {
196- return diffuseColor / M_PI;
197-
198- // disney
199- // float Fd_Burley(float NoV, float NoL, float LoH, float roughness) {
200- // float f90 = 0.5 + 2.0 * roughness * LoH * LoH;
201- // float lightScatter = F_Schlick(NoL, 1.0, f90);
202- // float viewScatter = F_Schlick(NoV, 1.0, f90);
203- // return lightScatter * viewScatter * (1.0 / PI);
204- // }
205- }
206-
207- // https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#acknowledgments AppendixB
208- vec3
209- BRDF_specularGGX(float alphaRoughness, float NdotL, float NdotV, float NdotH)
210- {
211- float G2 = pl_masking_shadowing_ggx(NdotL, NdotV, alphaRoughness);
212- float D = pl_distribution_ggx(NdotH, alphaRoughness);
213- return vec3 (G2 * D);
214- }
215-
216- #endif // PL_MATH_GLSL
134+ #endif // MATH_GLSL
0 commit comments