From 39ec0305f9d225740beda3326de0b39f2e23c20f Mon Sep 17 00:00:00 2001 From: marauder2k7 Date: Wed, 21 Feb 2024 08:24:24 +0000 Subject: [PATCH] GLSL To match Update the glsl side to match hlsl ies profile usage --- .../lighting/advanced/gl/pointLightP.glsl | 20 ++++++++- .../lighting/advanced/gl/spotLightP.glsl | 42 +++++++++++-------- 2 files changed, 44 insertions(+), 18 deletions(-) diff --git a/Templates/BaseGame/game/core/rendering/shaders/lighting/advanced/gl/pointLightP.glsl b/Templates/BaseGame/game/core/rendering/shaders/lighting/advanced/gl/pointLightP.glsl index 81a8c7e23..7e6984e21 100644 --- a/Templates/BaseGame/game/core/rendering/shaders/lighting/advanced/gl/pointLightP.glsl +++ b/Templates/BaseGame/game/core/rendering/shaders/lighting/advanced/gl/pointLightP.glsl @@ -108,11 +108,15 @@ uniform sampler2D deferredBuffer; #include "softShadow.glsl" uniform sampler2D colorBuffer; uniform sampler2D matInfoBuffer; -#ifdef USE_COOKIE_TEX +#ifdef SHADOW_CUBE /// The texture for cookie rendering. uniform samplerCube cookieMap; +#else +uniform sampler2D cookieMap; #endif +uniform sampler2D iesProfile; + uniform vec4 rtParams0; uniform vec3 lightPosition; @@ -181,7 +185,12 @@ void main() #ifdef USE_COOKIE_TEX // Lookup the cookie sample. + #ifdef SHADOW_CUBE vec4 cookie = texture(cookieMap, tMul(worldToLightProj, -surfaceToLight.L)); + #else + vec2 cookieCoord = decodeShadowCoord( tMul( worldToLightProj, -surfaceToLight.L ) ).xy; + vec4 cookie = texture(cookieMap, cookieCoord); + #endif // Multiply the light with the cookie tex. lightCol *= cookie.rgb; // Use a maximum channel luminance to attenuate @@ -224,6 +233,15 @@ void main() //get punctual light contribution lighting = getPunctualLight(surface, surfaceToLight, lightCol, lightBrightness, lightInvSqrRange, shadow); + #ifdef UES_PHOTOMETRIC_MASK + // Lookup the cookie sample.d + float cosTheta = dot(-surfaceToLight.L, lightDirection); + float angle = acos(cosTheta) * ( M_1OVER_PI_F); + float iesMask = texture(iesProfile, vec2(angle, 0.0)).r; + // Multiply the light with the iesMask tex. + lighting *= iesMask; + #endif + } OUT_col = vec4(lighting, 0); diff --git a/Templates/BaseGame/game/core/rendering/shaders/lighting/advanced/gl/spotLightP.glsl b/Templates/BaseGame/game/core/rendering/shaders/lighting/advanced/gl/spotLightP.glsl index 42654c532..f5983eb0d 100644 --- a/Templates/BaseGame/game/core/rendering/shaders/lighting/advanced/gl/spotLightP.glsl +++ b/Templates/BaseGame/game/core/rendering/shaders/lighting/advanced/gl/spotLightP.glsl @@ -38,11 +38,8 @@ uniform sampler2D shadowMap; #include "softShadow.glsl" uniform sampler2D colorBuffer; uniform sampler2D matInfoBuffer; -#ifdef USE_COOKIE_TEX -/// The texture for cookie rendering. uniform sampler2D cookieMap; -#endif - +uniform sampler2D iesProfile; uniform vec4 rtParams0; uniform float lightBrightness; @@ -91,7 +88,7 @@ void main() if(dist < lightRange) { SurfaceToLight surfaceToLight = createSurfaceToLight(surface, L); - vec3 lightCol = lightColor.rgb; + float shadow = 1.0; #ifndef NO_SHADOW @@ -105,19 +102,22 @@ void main() //distance to light in shadow map space float distToLight = pxlPosLightProj.z / lightRange; shadow = softShadow_filter(shadowMap, ssPos.xy/ssPos.w, shadowCoord, shadowSoftness, distToLight, surfaceToLight.NdotL, lightParams.y); - #ifdef USE_COOKIE_TEX - // Lookup the cookie sample. - vec4 cookie = texture(cookieMap, shadowCoord); - // Multiply the light with the cookie tex. - lightCol *= cookie.rgb; - // Use a maximum channel luminance to attenuate - // the lighting else we get specular in the dark - // regions of the cookie texture. - lightCol *= max(cookie.r, max(cookie.g, cookie.b)); - #endif + } - #endif - + #endif + + vec3 lightCol = lightColor.rgb; + #ifdef USE_COOKIE_TEX + // Lookup the cookie sample. + vec4 cookie = texture(cookieMap, shadowCoord); + // Multiply the light with the cookie tex. + lightCol *= cookie.rgb; + // Use a maximum channel luminance to attenuate + // the lighting else we get specular in the dark + // regions of the cookie texture. + lightCol *= max(cookie.r, max(cookie.g, cookie.b)); + #endif + #ifdef DIFFUSE_LIGHT_VIZ float attenuation = getDistanceAtt(surfaceToLight.Lu, radius); @@ -156,6 +156,14 @@ void main() //get spot light contribution lighting = getSpotlight(surface, surfaceToLight, lightCol, lightBrightness, lightInvSqrRange, lightDirection, lightSpotParams, shadow); + #ifdef UES_PHOTOMETRIC_MASK + // Lookup the cookie sample.d + float cosTheta = dot(-surfaceToLight.L, lightDirection); + float angle = acos(cosTheta) * ( M_1OVER_PI_F); + float iesMask = texture(iesProfile, vec2(angle, 0.0)).r; + // Multiply the light with the iesMask tex. + lighting *= iesMask; + #endif } OUT_col = vec4(lighting, 0);