From 04906e4cea224ca790f1285e4de6d4bb7e3a8b63 Mon Sep 17 00:00:00 2001 From: Tim <15017472+doodlum@users.noreply.github.com> Date: Thu, 13 Feb 2025 11:51:24 +0000 Subject: [PATCH] feat: vanilla ambient specular --- package/Shaders/DeferredCompositeCS.hlsl | 4 +- package/Shaders/Lighting.hlsl | 73 +++++++++++------------- package/Shaders/RunGrass.hlsl | 23 +++++--- 3 files changed, 52 insertions(+), 48 deletions(-) diff --git a/package/Shaders/DeferredCompositeCS.hlsl b/package/Shaders/DeferredCompositeCS.hlsl index e29001521..700f0333d 100644 --- a/package/Shaders/DeferredCompositeCS.hlsl +++ b/package/Shaders/DeferredCompositeCS.hlsl @@ -164,9 +164,9 @@ void SampleSSGISpecular(uint2 pixCoord, sh2 lobe, out float ao, out float3 il) ssgiIlSpecular = ssgiMixed.rgb; # endif - finalIrradiance = (finalIrradiance * ssgiAo * smoothstep(0.0, 1.0 - (1.0 / 7.0), glossiness)) + ssgiIlSpecular; + finalIrradiance = (finalIrradiance * ssgiAo) + ssgiIlSpecular; # else - finalIrradiance *= smoothstep(0.0, 1.0 - (1.0 / 7.0), glossiness); + // finalIrradiance *= sqrt(glossiness); # endif color += reflectance * finalIrradiance; diff --git a/package/Shaders/Lighting.hlsl b/package/Shaders/Lighting.hlsl index bca918c19..d2fea6522 100644 --- a/package/Shaders/Lighting.hlsl +++ b/package/Shaders/Lighting.hlsl @@ -2299,6 +2299,9 @@ PS_OUTPUT main(PS_INPUT input, bool frontFace diffuseColor += directionalAmbientColor; # endif + float3 F0 = 0.04; + float roughness = 1.0; + # if defined(ENVMAP) || defined(MULTI_LAYER_PARALLAX) || defined(EYE) float envMask = EnvmapData.x * MaterialData.x; @@ -2316,20 +2319,23 @@ PS_OUTPUT main(PS_INPUT input, bool frontFace float3 envColor = 0.0; bool dynamicCubemap = false; -# if defined(DYNAMIC_CUBEMAPS) - float3 F0 = 0.0; - float envRoughness = 1.0; -# endif - if (envMask > 0.0) { # if defined(DYNAMIC_CUBEMAPS) uint2 envSize; TexEnvSampler.GetDimensions(envSize.x, envSize.y); -# if defined(EMAT) - if (envSize.x == 1 && envSize.y == 1 || complexMaterial) { +# if defined(CREATOR) +# if defined(EMAT) + if (envSize.x == 1 && envSize.y == 1 || complexMaterial || SharedData::cubemapCreatorSettings.Enabled) { +# else + if (envSize.x == 1 && envSize.y == 1 || SharedData::cubemapCreatorSettings.Enabled) { +# endif # else +# if defined(EMAT) + if (envSize.x == 1 && envSize.y == 1 || complexMaterial) { +# else if (envSize.x == 1 && envSize.y == 1) { +# endif # endif dynamicCubemap = true; @@ -2351,6 +2357,7 @@ PS_OUTPUT main(PS_INPUT input, bool frontFace if (dynamicCubemap) { float4 envColorBase = TexEnvSampler.SampleLevel(SampEnvSampler, float3(1.0, 0.0, 0.0), 15); + float envRoughness = 1.0; if (envColorBase.a < 1.0) { F0 = Color::GammaToLinear(envColorBase.rgb); @@ -2373,14 +2380,9 @@ PS_OUTPUT main(PS_INPUT input, bool frontFace F0 = lerp(F0, Color::GammaToLinear(complexSpecular), complexMaterial); # endif - if (any(F0 > 0.0)) -# if defined(SKYLIGHTING) - envColor = DynamicCubemaps::GetDynamicCubemap(worldSpaceNormal, worldSpaceVertexNormal, worldSpaceViewDirection, envRoughness, F0, skylightingSH) * envMask; -# else - envColor = DynamicCubemaps::GetDynamicCubemap(worldSpaceNormal, worldSpaceVertexNormal, worldSpaceViewDirection, envRoughness, F0, ) * envMask; -# endif - else - envColor = 0.0; + envMask = saturate(envMask); + F0 = lerp(0.04, F0, envMask); + roughness = lerp(roughness, envRoughness, pow(envMask, 0.25)); } } # endif @@ -2393,6 +2395,16 @@ PS_OUTPUT main(PS_INPUT input, bool frontFace # endif // defined (ENVMAP) || defined (MULTI_LAYER_PARALLAX) || defined(EYE) +# if defined(DYNAMIC_CUBEMAPS) +# if defined(SKYLIGHTING) + float3 reflectance = DynamicCubemaps::GetDynamicCubemap(worldSpaceNormal, worldSpaceVertexNormal, worldSpaceViewDirection, roughness, F0, skylightingSH); +# else + float3 reflectance = DynamicCubemaps::GetDynamicCubemap(worldSpaceNormal, worldSpaceVertexNormal, worldSpaceViewDirection, roughness, F0); +# endif +# else + float3 reflectance = 0; +# endif + float2 screenMotionVector = MotionBlur::GetSSMotionVector(input.WorldPosition, input.PreviousWorldPosition, eyeIndex); # if defined(WETNESS_EFFECTS) @@ -2415,7 +2427,7 @@ PS_OUTPUT main(PS_INPUT input, bool frontFace baseColor.xyz = lerp(baseColor.xyz, pow(baseColor.xyz, 1.0 + wetnessDarkeningAmount), 0.8); # endif - float3 wetnessReflectance = WetnessEffects::GetWetnessAmbientSpecular(screenUV, wetnessNormal, worldSpaceVertexNormal, worldSpaceViewDirection, 1.0 - wetnessGlossinessSpecular) * wetnessGlossinessSpecular; + float3 wetnessReflectance = WetnessEffects::GetWetnessAmbientSpecular(screenUV, wetnessNormal, worldSpaceVertexNormal, worldSpaceViewDirection, 1.0 - wetnessGlossinessSpecular); # if !defined(DEFERRED) wetnessSpecular += wetnessReflectance; @@ -2572,9 +2584,8 @@ PS_OUTPUT main(PS_INPUT input, bool frontFace baseColor.xyz = 0.0; specularColor = 0.0; diffuseColor = 0.0; - dynamicCubemap = true; - envColor = 1.0; - envRoughness = 0.0; + reflectance = 1.0; + roughness = 0.0; color.xyz = 0; # endif @@ -2706,17 +2717,15 @@ PS_OUTPUT main(PS_INPUT input, bool frontFace # endif psout.Albedo = float4(outputAlbedo, psout.Diffuse.w); - float outGlossiness = saturate(glossiness * SSRParams.w); - # if defined(TRUE_PBR) psout.Reflectance = float4(indirectSpecularLobeWeight, psout.Diffuse.w); psout.NormalGlossiness = float4(GBuffer::EncodeNormal(screenSpaceNormal), pbrGlossiness, psout.Diffuse.w); # elif defined(WETNESS_EFFECTS) - psout.Reflectance = float4(wetnessReflectance, psout.Diffuse.w); - psout.NormalGlossiness = float4(GBuffer::EncodeNormal(screenSpaceNormal), lerp(outGlossiness, 1.0, wetnessGlossinessSpecular), psout.Diffuse.w); + psout.Reflectance = float4(max(reflectance, wetnessReflectance), psout.Diffuse.w); + psout.NormalGlossiness = float4(GBuffer::EncodeNormal(screenSpaceNormal), 1.0 - roughness, psout.Diffuse.w); # else - psout.Reflectance = float4(0.0.xxx, psout.Diffuse.w); - psout.NormalGlossiness = float4(GBuffer::EncodeNormal(screenSpaceNormal), outGlossiness, psout.Diffuse.w); + psout.Reflectance = float4(reflectance, psout.Diffuse.w); + psout.NormalGlossiness = float4(GBuffer::EncodeNormal(screenSpaceNormal), 1.0 - roughness, psout.Diffuse.w); # endif # if defined(TERRAIN_BLENDING) @@ -2727,20 +2736,6 @@ PS_OUTPUT main(PS_INPUT input, bool frontFace psout.Parameters.w = psout.Diffuse.w; # endif -# if (defined(ENVMAP) || defined(MULTI_LAYER_PARALLAX) || defined(EYE)) -# if defined(DYNAMIC_CUBEMAPS) - if (dynamicCubemap) { -# if defined(WETNESS_EFFECTS) - psout.Reflectance.xyz = max(envColor, wetnessReflectance); - psout.NormalGlossiness.z = lerp(1.0 - envRoughness, 1.0, wetnessGlossinessSpecular); -# else - psout.Reflectance.xyz = envColor; - psout.NormalGlossiness.z = 1.0 - envRoughness; -# endif - } -# endif -# endif - # if defined(SSS) && defined(SKIN) psout.Masks = float4(saturate(baseColor.a), !(Permutation::ExtraShaderDescriptor & Permutation::ExtraFlags::IsBeastRace), 0, psout.Diffuse.w); # elif defined(WETNESS_EFFECTS) diff --git a/package/Shaders/RunGrass.hlsl b/package/Shaders/RunGrass.hlsl index 9b2e7a2fb..508b409de 100644 --- a/package/Shaders/RunGrass.hlsl +++ b/package/Shaders/RunGrass.hlsl @@ -322,13 +322,8 @@ struct PS_OUTPUT float4 NormalGlossiness : SV_Target2; float4 Albedo : SV_Target3; float4 Specular : SV_Target4; -# if defined(TRUE_PBR) float4 Reflectance : SV_Target5; -# endif // TRUE_PBR float4 Masks : SV_Target6; -# if defined(TRUE_PBR) - float4 Parameters : SV_Target7; -# endif // TRUE_PBR # endif // RENDER_DEPTH }; #else @@ -717,10 +712,24 @@ PS_OUTPUT main(PS_INPUT input, bool frontFace psout.Albedo = float4(Color::LinearToGamma(indirectDiffuseLobeWeight), 1); psout.NormalGlossiness = float4(GBuffer::EncodeNormal(normalVS), 1 - pbrSurfaceProperties.Roughness, 1); psout.Reflectance = float4(indirectSpecularLobeWeight, 1); - psout.Parameters = float4(0, 0, 1, 1); # else + + float3 F0 = 0.04; + float roughness = 1.0; + +# if defined(DYNAMIC_CUBEMAPS) +# if defined(SKYLIGHTING) + float3 reflectance = DynamicCubemaps::GetDynamicCubemap(normal, normal, viewDirection, roughness, F0, 0); +# else + float3 reflectance = DynamicCubemaps::GetDynamicCubemap(normal, normal, viewDirection, roughness, F0); +# endif +# else + float3 reflectance = 0; +# endif + + psout.Reflectance = float4(reflectance, 1); psout.Albedo = float4(albedo, 1); - psout.NormalGlossiness = float4(GBuffer::EncodeNormal(normalVS), specColor.w, 1); + psout.NormalGlossiness = float4(GBuffer::EncodeNormal(normalVS), 1.0 - roughness, 1); # endif psout.Specular = float4(specularColor, 1);