Skip to content

Commit

Permalink
Removed snow and fog detection logic
Browse files Browse the repository at this point in the history
  • Loading branch information
TheRiverwoodModder committed Jan 6, 2024
1 parent 3d5db8e commit 7c588fd
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 105 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,11 @@ struct PerPassWetnessEffects
row_major float3x4 DirectionalAmbientWS;
uint EnableWetnessEffects;
float MaxRainWetness;
float MaxSnowWetness;
float MaxFogWetness;
float MaxShoreWetness;
uint ShoreRange;
float PuddleRadius;
float PuddleMaxAngle;
float PuddleMinWetness;
float FogPowerThreshold;
float FogNearDistanceThreshold;
};

StructuredBuffer<PerPassWetnessEffects> perPassWetnessEffects : register(t22);
Expand Down
99 changes: 2 additions & 97 deletions src/Features/WetnessEffects.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,17 @@ const float MIN_START_PERCENTAGE = 0.05f;
const float DEFAULT_TRANSITION_PERCENTAGE = 1.0f;
const float TRANSITION_CURVE_MULTIPLIER = 2.0f;
const float TRANSITION_DENOMINATOR = 256.0f;
float FOG_POWER_THRESHOLD = 0.5f;
float FOG_NEAR_DISTANCE_THRESHOLD = 0.0f;
const float DRY_WETNESS = 0.0f;
const float DAY = 0.0f;
const float NIGHT = 1.0f;
const int TIME_BEFORE = 1800;
const int TIME_AFTER = 2700;

NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_WITH_DEFAULT(
WetnessEffects::Settings,
EnableWetnessEffects,
MaxRainWetness,
MaxSnowWetness,
MaxFogWetness,
MaxShoreWetness,
ShoreRange,
PuddleRadius,
PuddleMaxAngle,
PuddleMinWetness,
FogPowerThreshold,
FogNearDistanceThreshold)
PuddleMinWetness)

void WetnessEffects::DrawSettings()
{
Expand All @@ -40,8 +30,6 @@ void WetnessEffects::DrawSettings()
}

ImGui::SliderFloat("Max Rain Wetness", &settings.MaxRainWetness, 0.0f, 1.0f);
ImGui::SliderFloat("Max Snow Wetness", &settings.MaxSnowWetness, 0.0f, 1.0f);
ImGui::SliderFloat("Max Fog Wetness", &settings.MaxFogWetness, 0.0f, 1.0f);
ImGui::SliderFloat("Max Shore Wetness", &settings.MaxShoreWetness, 0.0f, 1.0f);

ImGui::SliderInt("Shore Range", (int*)&settings.ShoreRange, 1, 64);
Expand All @@ -50,24 +38,6 @@ void WetnessEffects::DrawSettings()
ImGui::SliderFloat("Puddle Max Angle", &settings.PuddleMaxAngle, 0.0f, 1.0f);
ImGui::SliderFloat("Puddle Min Wetness", &settings.PuddleMinWetness, 0.0f, 1.0f);

ImGui::SliderFloat("Max Fog Power", &settings.FogPowerThreshold, 0.0f, 1.0f);
if (ImGui::IsItemHovered()) {
ImGui::BeginTooltip();
ImGui::PushTextWrapPos(ImGui::GetFontSize() * 35.0f);
ImGui::Text("The maxiumum Fog Power considered foggy weather. (Try raising this if foggy weather isn't causing wetness)");
ImGui::PopTextWrapPos();
ImGui::EndTooltip();
}

ImGui::SliderFloat("Max Fog Distance", &settings.FogNearDistanceThreshold, 0.0f, 10000.0f);
if (ImGui::IsItemHovered()) {
ImGui::BeginTooltip();
ImGui::PushTextWrapPos(ImGui::GetFontSize() * 35.0f);
ImGui::Text("The maximum Fog Distance considered foggy weather. (Try raising this if foggy weather isn't causing wetness)");
ImGui::PopTextWrapPos();
ImGui::EndTooltip();
}

ImGui::TreePop();
}
}
Expand Down Expand Up @@ -97,70 +67,7 @@ float WetnessEffects::CalculateWetness(RE::TESWeather* weather, RE::Sky* sky)
if (weather->precipitationData && weather->data.flags.any(RE::TESWeather::WeatherDataFlag::kRainy)) {
// Raining
wetness = settings.MaxRainWetness;
} else if (weather->precipitationData && weather->data.flags.any(RE::TESWeather::WeatherDataFlag::kSnow)) {
// Snowing
wetness = settings.MaxSnowWetness;
} else if ((weather->fogData.dayNear <= FOG_NEAR_DISTANCE_THRESHOLD && weather->fogData.dayPower <= FOG_POWER_THRESHOLD) ||
(weather->fogData.nightNear <= FOG_NEAR_DISTANCE_THRESHOLD && weather->fogData.nightPower <= FOG_POWER_THRESHOLD)) {
// Foggy - could be foggy during day, night, or both
float dayWetness = (weather->fogData.dayNear <= FOG_NEAR_DISTANCE_THRESHOLD && weather->fogData.dayPower <= FOG_POWER_THRESHOLD) ? settings.MaxFogWetness : DRY_WETNESS;
float nightWetness = (weather->fogData.nightNear <= FOG_NEAR_DISTANCE_THRESHOLD && weather->fogData.nightPower <= FOG_POWER_THRESHOLD) ? settings.MaxFogWetness : DRY_WETNESS;
// If both, skip interpolating between day and night values
if (dayWetness == nightWetness) {
wetness = dayWetness;
} else {
float DayNightTransition = DEFAULT_TRANSITION_PERCENTAGE;
// Set the Day Night Transition with Day = 0, and Night = 1
if (auto calendar = RE::Calendar::GetSingleton()) {
if (auto currentClimate = sky->currentClimate) {
struct tm sunriseBeginTM = currentClimate->timing.sunrise.GetBeginTime();
struct tm sunriseEndTM = currentClimate->timing.sunrise.GetEndTime();
struct tm sunsetBeginTM = currentClimate->timing.sunset.GetBeginTime();
struct tm sunsetEndTM = currentClimate->timing.sunset.GetEndTime();
float gameHour = calendar->GetHour();
// Skyrim doesn't seem to use seconds, but doing this in seconds just in case
// Skyrim transitions weather values between day and night in one hour starting 30 minutes before sunrise starts or sunset ends
int sunriseBeginTime = (sunriseBeginTM.tm_hour * 3600) + (sunriseBeginTM.tm_min * 60) + sunriseBeginTM.tm_sec;
int sunsetEndTime = (sunsetEndTM.tm_hour * 3600) + (sunsetEndTM.tm_min * 60) + sunsetEndTM.tm_sec;
int time = static_cast<int>(gameHour * 3600);
int nightToDayBegin = sunriseBeginTime - TIME_BEFORE;
int nightToDayEnd = sunriseBeginTime + TIME_AFTER;
int dayToNightBegin = sunsetEndTime - TIME_BEFORE;
int dayToNightEnd = sunsetEndTime + TIME_AFTER;

if (dayToNightEnd > dayToNightBegin && dayToNightBegin >= nightToDayEnd && nightToDayEnd > nightToDayBegin && nightToDayBegin >= 0) {
if ((time - nightToDayBegin) < 0 || (time - dayToNightEnd) > 0) {
// Night
DayNightTransition = NIGHT;
} else if ((time - nightToDayEnd) <= 0) {
// During sunrise, night 1 -> day 0
DayNightTransition = 1.0f - (static_cast<float>(time - nightToDayBegin) / static_cast<float>(nightToDayEnd - nightToDayBegin));
} else if ((time - dayToNightBegin) < 0) {
// During day
DayNightTransition = DAY;
} else if ((time - dayToNightEnd) <= 0) {
// During sunset, day 0 -> night 1
DayNightTransition = static_cast<float>(time - dayToNightBegin) / static_cast<float>(dayToNightEnd - dayToNightBegin);
} else {
// This should never happen
logger::error("Invalid Time Calculating Fog");
}
}

// Adjust the transition curve to ease in/out of the transition
DayNightTransition = (exp2(TRANSITION_CURVE_MULTIPLIER * log2(DayNightTransition)));
}
}
// Handle wetness transition between day and night
wetness = std::lerp(dayWetness, nightWetness, DayNightTransition);
}
} else if (weather->data.flags.any(RE::TESWeather::WeatherDataFlag::kCloudy)) {
// Cloudy
wetness = DRY_WETNESS;
} else {
// Pleasant
wetness = DRY_WETNESS;
}
}
}
}
return wetness;
Expand All @@ -175,8 +82,6 @@ void WetnessEffects::Draw(const RE::BSShader* shader, const uint32_t)

PerPass data{};
data.Wetness = DRY_WETNESS;
FOG_POWER_THRESHOLD = settings.FogPowerThreshold;
FOG_NEAR_DISTANCE_THRESHOLD = settings.FogNearDistanceThreshold;

if (settings.EnableWetnessEffects) {
if (auto player = RE::PlayerCharacter::GetSingleton()) {
Expand Down
4 changes: 0 additions & 4 deletions src/Features/WetnessEffects.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,11 @@ struct WetnessEffects : Feature
{
uint EnableWetnessEffects = true;
float MaxRainWetness = 1.0f;
float MaxSnowWetness = 0.8f;
float MaxFogWetness = 0.5f;
float MaxShoreWetness = 0.5f;
uint ShoreRange = 32;
float PuddleRadius = 1.0f;
float PuddleMaxAngle = 0.95f;
float PuddleMinWetness = 0.75f;
float FogPowerThreshold = 0.5f;
float FogNearDistanceThreshold = 0.0f;
};

struct alignas(16) PerPass
Expand Down

0 comments on commit 7c588fd

Please sign in to comment.