diff --git a/package/Shaders/Common/SharedData.hlsli b/package/Shaders/Common/SharedData.hlsli index e92797356d..6b9a2378ec 100644 --- a/package/Shaders/Common/SharedData.hlsli +++ b/package/Shaders/Common/SharedData.hlsli @@ -33,7 +33,8 @@ namespace SharedData bool OverrideComplexGrassSettings; float BasicGrassBrightness; - float3 pad0; + bool EnableWrappedLighting; + float2 pad0; }; struct CPMSettings @@ -306,4 +307,4 @@ namespace SharedData #endif // PSHADER } -#endif // __SHARED_DATA_DEPENDENCY_HLSL__ \ No newline at end of file +#endif // __SHARED_DATA_DEPENDENCY_HLSL__ diff --git a/package/Shaders/RunGrass.hlsl b/package/Shaders/RunGrass.hlsl index f216361199..731bc61591 100644 --- a/package/Shaders/RunGrass.hlsl +++ b/package/Shaders/RunGrass.hlsl @@ -629,11 +629,23 @@ PS_OUTPUT main(PS_INPUT input, bool frontFace : SV_IsFrontFace) dirLightColor *= dirShadow; dirLightColor *= dirDetailShadow; - lightsDiffuseColor += dirLightColor * saturate(dirLightAngle) * Color::GrassDiffuseMult(); + float wrapAmount = saturate(input.VertexNormal.w * 10.0)* 0.5 * (!complex); + + if (SharedData::grassLightingSettings.EnableWrappedLighting) + { + // Old Wrapped Model + float wrappedDirLight = saturate(dirLightAngle + wrapAmount) / (1.0 + wrapAmount); + lightsDiffuseColor += dirLightColor * saturate(wrappedDirLight) * Color::GrassDiffuseMult(); + } + else + { + // Original Standard Model + lightsDiffuseColor += dirLightColor * saturate(dirLightAngle) * Color::GrassDiffuseMult(); + } float3 vertexColor = input.VertexColor.xyz; -# if defined(SKYLIGHTING) +#if defined(SKYLIGHTING) float skylightingFadeOutFactor = 1.0; if (!SharedData::InInterior) { skylightingFadeOutFactor = Skylighting::getFadeOutFactor(input.WorldPosition.xyz); @@ -704,8 +716,17 @@ PS_OUTPUT main(PS_INPUT input, bool frontFace : SV_IsFrontFace) float lightAngle = dot(normal, normalizedLightDirection); float lightNoL = dot(normalizedLightDirection.xyz, viewDirection); + float3 lightDiffuseColor; - float3 lightDiffuseColor = lightColor * saturate(lightAngle); + if (SharedData::grassLightingSettings.EnableWrappedLighting) + { + float wrappedLight = saturate(lightAngle + wrapAmount) / (1.0 + wrapAmount); + lightDiffuseColor = lightColor * wrappedLight; + } + else + { + lightDiffuseColor = lightColor * saturate(lightAngle); + } sss += lightColor * saturate(-lightAngle); @@ -713,7 +734,7 @@ PS_OUTPUT main(PS_INPUT input, bool frontFace : SV_IsFrontFace) if (complex) lightsSpecularColor += GrassLighting::GetLightSpecularInput(normalizedLightDirection, viewDirection, normal, lightColor, SharedData::grassLightingSettings.Glossiness) * Color::GrassSpecularMult(); -# endif +#endif } } } diff --git a/src/Features/GrassLighting.cpp b/src/Features/GrassLighting.cpp index 3ad5bcb470..79e77015a6 100644 --- a/src/Features/GrassLighting.cpp +++ b/src/Features/GrassLighting.cpp @@ -6,7 +6,8 @@ NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_WITH_DEFAULT( SpecularStrength, SubsurfaceScatteringAmount, OverrideComplexGrassSettings, - BasicGrassBrightness) + BasicGrassBrightness, + EnableWrappedLighting) void GrassLighting::DrawSettings() { @@ -43,6 +44,12 @@ void GrassLighting::DrawSettings() } if (ImGui::TreeNodeEx("Lighting", ImGuiTreeNodeFlags_DefaultOpen)) { + ImGui::Checkbox("Enable Wrapped Lighting", (bool*)&settings.EnableWrappedLighting); + if (auto _tt = Util::HoverTooltipWrapper()) { + ImGui::Text("Enables a softer-looking wrapped lighting model from CS 1.3. Useful for certain non-complex grass textures that look too dark during mid day, when the sun is directly overhead."); + } + ImGui::Spacing(); + ImGui::Spacing(); ImGui::Checkbox("Override Complex Grass Lighting Settings", (bool*)&settings.OverrideComplexGrassSettings); if (auto _tt = Util::HoverTooltipWrapper()) { ImGui::Text( @@ -77,4 +84,4 @@ void GrassLighting::SaveSettings(json& o_json) void GrassLighting::RestoreDefaultSettings() { settings = {}; -} \ No newline at end of file +} diff --git a/src/Features/GrassLighting.h b/src/Features/GrassLighting.h index 461703b531..4c9272429a 100644 --- a/src/Features/GrassLighting.h +++ b/src/Features/GrassLighting.h @@ -35,7 +35,8 @@ struct GrassLighting : Feature float SubsurfaceScatteringAmount = 0.5f; uint OverrideComplexGrassSettings = false; float BasicGrassBrightness = 1.0f; - uint pad[3]; + uint EnableWrappedLighting = false; + uint pad[2]; }; STATIC_ASSERT_ALIGNAS_16(Settings);