| 1234567891011121314151617181920212223242526272829303132333435363738394041424344 |
- /* light.glsl -- Contains everything you need to manage lights
- *
- * Copyright (c) 2025 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"
- #include "./pbr.glsl"
- /* === Defines === */
- #define LIGHT_FORWARD_COUNT 8
- #define LIGHT_DIR 0
- #define LIGHT_SPOT 1
- #define LIGHT_OMNI 2
- /* === Functions === */
- vec3 L_Diffuse(float cLdotH, float cNdotV, float cNdotL, float roughness)
- {
- float FD90_minus_1 = 2.0 * cLdotH * cLdotH * roughness - 0.5;
- float FdV = 1.0 + FD90_minus_1 * PBR_SchlickFresnel(cNdotV);
- float FdL = 1.0 + FD90_minus_1 * PBR_SchlickFresnel(cNdotL);
- return vec3(M_INV_PI * (FdV * FdL * cNdotL)); // Diffuse BRDF (Burley)
- }
- vec3 L_Specular(vec3 F0, float cLdotH, float cNdotH, float cNdotV, float cNdotL, float roughness)
- {
- roughness = max(roughness, 1e-3);
- float alphaGGX = roughness * roughness;
- float D = PBR_DistributionGGX(cNdotH, alphaGGX);
- float G = PBR_GeometryGGX(cNdotL, cNdotV, alphaGGX);
- float cLdotH5 = PBR_SchlickFresnel(cLdotH);
- float F90 = clamp(50.0 * F0.g, 0.0, 1.0);
- vec3 F = F0 + (F90 - F0) * cLdotH5;
- return cNdotL * D * F * G; // Specular BRDF (Schlick GGX)
- }
|