| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748 |
- /* pbr.glsl -- Contains everything you need for PBR
- *
- * Copyright (c) 2025-2026 Le Juez Victor
- *
- * This software is provided 'as-is', without any express or implied warranty.
- * For conditions of distribution and use, see accompanying LICENSE file.
- */
- #include "./math.glsl"
- /* === Functions === */
- float PBR_DistributionGGX(float cosTheta, float alpha)
- {
- // Standard GGX/Trowbridge-Reitz distribution - optimized form
- float a = cosTheta * alpha;
- float k = alpha / (1.0 - cosTheta * cosTheta + a * a);
- return k * k * (1.0 / M_PI);
- }
- float PBR_GeometryGGX(float NdotL, float NdotV, float roughness)
- {
- // Hammon's optimized approximation for GGX Smith geometry term
- // This version is an efficient approximation that:
- // 1. Avoids expensive square root calculations
- // 2. Combines both G1 terms into a single expression
- // 3. Provides very close results to the exact version at a much lower cost
- // SEE: https://www.gdcvault.com/play/1024478/PBR-Diffuse-Lighting-for-GGX
- return 0.5 / mix(2.0 * NdotL * NdotV, NdotL + NdotV, roughness);
- }
- float PBR_SchlickFresnel(float u)
- {
- float m = 1.0 - u;
- float m2 = m * m;
- return m2 * m2 * m; // pow(m,5)
- }
- vec3 PBR_ComputeF0(float metallic, float specular, vec3 albedo)
- {
- // use (albedo * metallic) as colored specular reflectance at 0 angle for metallic materials
- // SEE: https://google.github.io/filament/Filament.md.html
- float dielectric = 0.16 * specular * specular;
- return mix(vec3(dielectric), albedo, vec3(metallic));
- }
|