Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions package/Shaders/Common/SharedData.hlsli
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ namespace SharedData
bool OverrideComplexGrassSettings;

float BasicGrassBrightness;
float3 pad0;
bool EnableWrappedLighting;
float2 pad0;
};

struct CPMSettings
Expand Down Expand Up @@ -306,4 +307,4 @@ namespace SharedData

#endif // PSHADER
}
#endif // __SHARED_DATA_DEPENDENCY_HLSL__
#endif // __SHARED_DATA_DEPENDENCY_HLSL__
29 changes: 25 additions & 4 deletions package/Shaders/RunGrass.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -704,16 +716,25 @@ 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);

lightsDiffuseColor += lightDiffuseColor * Color::GrassDiffuseMult();

if (complex)
lightsSpecularColor += GrassLighting::GetLightSpecularInput(normalizedLightDirection, viewDirection, normal, lightColor, SharedData::grassLightingSettings.Glossiness) * Color::GrassSpecularMult();
# endif
#endif
}
}
}
Expand Down
11 changes: 9 additions & 2 deletions src/Features/GrassLighting.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_WITH_DEFAULT(
SpecularStrength,
SubsurfaceScatteringAmount,
OverrideComplexGrassSettings,
BasicGrassBrightness)
BasicGrassBrightness,
EnableWrappedLighting)

void GrassLighting::DrawSettings()
{
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -77,4 +84,4 @@ void GrassLighting::SaveSettings(json& o_json)
void GrassLighting::RestoreDefaultSettings()
{
settings = {};
}
}
3 changes: 2 additions & 1 deletion src/Features/GrassLighting.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down