From b4515f783357b9ce4753d5e330a24205eb09bfb5 Mon Sep 17 00:00:00 2001 From: 10010101001 <44052322+10010101001@users.noreply.github.com> Date: Fri, 11 Jun 2021 20:37:26 +1000 Subject: [PATCH 1/2] Change specular lighting --- data/config/glsl/deferred.cfg | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/data/config/glsl/deferred.cfg b/data/config/glsl/deferred.cfg index b1d432eb..3491875a 100644 --- a/data/config/glsl/deferred.cfg +++ b/data/config/glsl/deferred.cfg @@ -90,11 +90,9 @@ unpacknorm = [ unpackspec = [ result [ vec3 camdir = normalize(camera - pos.xyz); - float facing = 2.0*dot(normal.xyz, camdir); - float specscale = min(3.0*(diffuse.a + 0.5/255.0), 2.999), gloss = floor(specscale); - specscale -= gloss; - specscale = (0.35 + 0.15*gloss) * specscale / (1.5 - specscale); - gloss = 5.0 + 17.0*gloss; + float roughness = 1.0-diffuse.a; + float rr = roughness*roughness; + float rrrr = rr*rr; ] ] @@ -500,7 +498,12 @@ deferredlightvariantshader = [ light += diffuse.rgb*sunfacing * sunlightcolor * sunoccluded; ]] [result [ @(if (= (+ $numlights (dlopt "c")) 1) [unpackspec]) - float sunspec = pow(clamp(sunfacing*facing - dot(camdir, sunlightdir), 0.0, 1.0), gloss) * specscale; + vec3 halfAngleVector = normalize(sunlightdir+camdir); + float hdotN = clamp(dot(halfAngleVector,normal.xyz), 0.0, 1.0); + float D = ( hdotN * hdotN ) * ( rrrr - 1.0 ) + 1.0; + float ldotH = clamp( dot( sunlightdir, halfAngleVector ), 0.0, 1.0 ); + float VFapprox = ( ldotH * ldotH ) * ( roughness + 0.5 ); + float sunspec = clamp(( rrrr / ( 12.5663706144 * D * D * VFapprox ) ) * sunfacing * 0.4,0.0, 9999.0); @(if (dlopt "r") [result [ sunlight += (diffuse.rgb*sunfacing + sunspec) * sunoccluded; ]] [result [ @@ -521,6 +524,7 @@ deferredlightvariantshader = [ @(loopconcat j $numlights [result [ vec3 light@[j]dir = lightpos[@@j].xyz - pos.xyz * lightpos[@@j].w; + vec3 light@[j]dir2 = normalize(light@[j]dir); float light@[j]dist2 = dot(light@[j]dir, light@[j]dir); if(light@[j]dist2 < 1.0) { @@ -577,7 +581,12 @@ deferredlightvariantshader = [ light += diffuse.rgb*light@[j]facing * lightcolor[@@j].rgb * light@[j]atten; ]] [result [ @(if (= (+ $numlights (dlopt "c")) 1) [unpackspec]) - float light@[j]spec = pow(clamp(light@[j]facing*facing - light@[j]invdist*dot(camdir, light@[j]dir), 0.0, 1.0), gloss) * specscale; + vec3 halfAngleVector = normalize(light@[j]dir2+camdir); + float hdotN = clamp(dot(halfAngleVector,normal.xyz), 0.0, 1.0); + float D = ( hdotN * hdotN ) * ( rrrr - 1.0 ) + 1.0; + float ldotH = clamp( dot( light@[j]dir2, halfAngleVector ), 0.0, 1.0 ); + float VFapprox = ( ldotH * ldotH ) * ( roughness + 0.5 ); + float light@[j]spec = clamp(( rrrr / ( 12.5663706144 * D * D * VFapprox ) ) * light@[j]facing * 0.1, 0.0, 9999.0); @(if (dlopt "z") [result [ light@[j]spec *= lightcolor[@@j].a; ]]) @@ -685,4 +694,3 @@ deferredlightshader = [ ] ] ] - From 12054e7f2a392ddb9a585629801d2cfd0e8b85d1 Mon Sep 17 00:00:00 2001 From: 10010101001 <44052322+10010101001@users.noreply.github.com> Date: Fri, 11 Jun 2021 20:40:39 +1000 Subject: [PATCH 2/2] Update ui.cfg --- data/config/glsl/ui.cfg | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/data/config/glsl/ui.cfg b/data/config/glsl/ui.cfg index 4ead341b..a7fe196a 100644 --- a/data/config/glsl/ui.cfg +++ b/data/config/glsl/ui.cfg @@ -56,7 +56,12 @@ lazyshader 0 "modelpreview" [ pos.xyz /= pos.w; ]) @(unpackspec) - float sunspec = pow(clamp(sunfacing*facing - dot(camdir, sunlightdir), 0.0, 1.0), gloss) * specscale; + vec3 halfAngleVector = normalize(sunlightdir+camdir); + float hdotN = clamp(dot(halfAngleVector,normal.xyz), 0.0, 1.0); + float D = ( hdotN * hdotN ) * ( rrrr - 1.0 ) + 1.0; + float ldotH = clamp( dot( sunlightdir, halfAngleVector ), 0.0, 1.0 ); + float VFapprox = ( ldotH * ldotH ) * ( roughness + 0.5 ); + float sunspec = clamp(( rrrr / ( 12.5663706144 * D * D * VFapprox ) ) * sunfacing * 0.6,0.0, 9999.0); light += (diffuse.rgb*sunfacing + sunspec) * sunlightcolor; }