From 796f5e7a68aed9f14bdf12675ee6f59e68357ecc Mon Sep 17 00:00:00 2001 From: Turanszki Janos Date: Wed, 29 Jul 2020 21:43:41 +0100 Subject: [PATCH] warning fixes, realistic sky is compile time switchable for now --- Editor/WeatherWindow.cpp | 34 +++++++------- WickedEngine/ShaderInterop_Renderer.h | 3 +- WickedEngine/skyHF.hlsli | 54 +++++++++++----------- WickedEngine/volumetricCloud_renderCS.hlsl | 4 +- WickedEngine/wiRenderer.cpp | 4 -- WickedEngine/wiScene.h | 3 -- 6 files changed, 47 insertions(+), 55 deletions(-) diff --git a/Editor/WeatherWindow.cpp b/Editor/WeatherWindow.cpp index 9956665ec..a04c9dea5 100644 --- a/Editor/WeatherWindow.cpp +++ b/Editor/WeatherWindow.cpp @@ -116,25 +116,25 @@ WeatherWindow::WeatherWindow(EditorComponent* editor) : GUI(&editor->GetGUI()) simpleskyCheckBox->OnClick([&](wiEventArgs args) { auto& weather = GetWeather(); weather.SetSimpleSky(args.bValue); - if (args.bValue) - { - weather.SetRealisticSky(false); - } + //if (args.bValue) + //{ + // weather.SetRealisticSky(false); + //} }); weatherWindow->AddWidget(simpleskyCheckBox); - realisticskyCheckBox = new wiCheckBox("Realistic sky: "); - realisticskyCheckBox->SetTooltip("Physically based sky rendering model."); - realisticskyCheckBox->SetPos(XMFLOAT2(x + 120, y)); - realisticskyCheckBox->OnClick([&](wiEventArgs args) { - auto& weather = GetWeather(); - weather.SetRealisticSky(args.bValue); - if (args.bValue) - { - weather.SetSimpleSky(false); - } - }); - weatherWindow->AddWidget(realisticskyCheckBox); + //realisticskyCheckBox = new wiCheckBox("Realistic sky: "); + //realisticskyCheckBox->SetTooltip("Physically based sky rendering model."); + //realisticskyCheckBox->SetPos(XMFLOAT2(x + 120, y)); + //realisticskyCheckBox->OnClick([&](wiEventArgs args) { + // auto& weather = GetWeather(); + // weather.SetRealisticSky(args.bValue); + // if (args.bValue) + // { + // weather.SetSimpleSky(false); + // } + //}); + //weatherWindow->AddWidget(realisticskyCheckBox); skyButton = new wiButton("Load Sky"); skyButton->SetTooltip("Load a skybox cubemap texture..."); @@ -527,7 +527,7 @@ void WeatherWindow::Update() horizonColorPicker->SetPickColor(wiColor::fromFloat3(weather.horizon)); zenithColorPicker->SetPickColor(wiColor::fromFloat3(weather.zenith)); simpleskyCheckBox->SetCheck(weather.IsSimpleSky()); - realisticskyCheckBox->SetCheck(weather.IsRealisticSky()); + //realisticskyCheckBox->SetCheck(weather.IsRealisticSky()); ocean_enabledCheckBox->SetCheck(weather.IsOceanEnabled()); ocean_patchSizeSlider->SetValue(weather.oceanParameters.patch_length); diff --git a/WickedEngine/ShaderInterop_Renderer.h b/WickedEngine/ShaderInterop_Renderer.h index b29d00739..36d0e3407 100644 --- a/WickedEngine/ShaderInterop_Renderer.h +++ b/WickedEngine/ShaderInterop_Renderer.h @@ -160,8 +160,7 @@ static const uint OPTION_BIT_VOXELGI_ENABLED = 1 << 2; static const uint OPTION_BIT_VOXELGI_REFLECTIONS_ENABLED = 1 << 3; static const uint OPTION_BIT_VOXELGI_RETARGETTED = 1 << 4; static const uint OPTION_BIT_SIMPLE_SKY = 1 << 5; -static const uint OPTION_BIT_REALISTIC_SKY = 1 << 6; -static const uint OPTION_BIT_RAYTRACED_SHADOWS = 1 << 7; +static const uint OPTION_BIT_RAYTRACED_SHADOWS = 1 << 6; // ---------- Common Constant buffers: ----------------- diff --git a/WickedEngine/skyHF.hlsli b/WickedEngine/skyHF.hlsli index 2cd1d74bd..e77b7ebf0 100644 --- a/WickedEngine/skyHF.hlsli +++ b/WickedEngine/skyHF.hlsli @@ -2,6 +2,9 @@ #define WI_SKY_HF #include "globals.hlsli" +// This can enable realistic sky simulation (performance heavy) +//#define REALISTIC_SKY + // Accurate Atmosphere based on: https://www.scratchapixel.com/lessons/procedural-generation-virtual-worlds/simulating-sky // Custom Atmosphere based on: https://www.shadertoy.com/view/Ml2cWG // Cloud noise based on: https://www.shadertoy.com/view/4tdSWr @@ -412,34 +415,31 @@ float3 GetDynamicSkyColor(in float3 V, bool sun_enabled = true, bool clouds_enab float3 sky = float3(0, 0, 0); - if (g_xFrame_Options & OPTION_BIT_REALISTIC_SKY) - { - AtmosphericMedium medium = CreateAtmosphericScattering(); +#ifdef REALISTIC_SKY + AtmosphericMedium medium = CreateAtmosphericScattering(); - sky = AccurateAtmosphericScattering - ( - g_xCamera_CamPos, // Ray origin - V, // Ray direction - sunDirection, // Position of the sun - float3(0.0, -6372e3, 0.0), // Center of the planet - 6371e3, // Radius of the planet in meters - 6471e3, // Radius of the atmosphere in meters - medium, // Atmospheric medium constructor. - sun_enabled, // Use sun and total - dark_enabled // Enable dark mode for light shafts etc. - ); - } - else - { - sky = CustomAtmosphericScattering - ( - V, // normalized ray direction - sunDirection, // position of the sun - sunColor, // color of the sun, for disc - sun_enabled, // use sun and total - dark_enabled // enable dark mode for light shafts etc. - ); - } + sky = AccurateAtmosphericScattering + ( + g_xCamera_CamPos, // Ray origin + V, // Ray direction + sunDirection, // Position of the sun + float3(0.0, -6372e3, 0.0), // Center of the planet + 6371e3, // Radius of the planet in meters + 6471e3, // Radius of the atmosphere in meters + medium, // Atmospheric medium constructor. + sun_enabled, // Use sun and total + dark_enabled // Enable dark mode for light shafts etc. + ); +#else + sky = CustomAtmosphericScattering + ( + V, // normalized ray direction + sunDirection, // position of the sun + sunColor, // color of the sun, for disc + sun_enabled, // use sun and total + dark_enabled // enable dark mode for light shafts etc. + ); +#endif // REALISTIC_SKY if (clouds_enabled) { diff --git a/WickedEngine/volumetricCloud_renderCS.hlsl b/WickedEngine/volumetricCloud_renderCS.hlsl index b23a52b5b..0d10d8867 100644 --- a/WickedEngine/volumetricCloud_renderCS.hlsl +++ b/WickedEngine/volumetricCloud_renderCS.hlsl @@ -204,7 +204,7 @@ float SampleCloudDensity(float3 p, float heightFraction, float3 weatherData, flo float densityHeightGradient = GetDensityHeightGradient(heightFraction, weatherData); float cloudSample = (lowFrequencyNoises.r + lowFrequencyNoises.g + lowFrequencyNoises.b + lowFrequencyNoises.a) * g_ShapeNoiseMultiplier * densityHeightGradient; - cloudSample = pow(cloudSample, min(1.0, g_ShapeNoisePower * heightFraction)); + cloudSample = pow(abs(cloudSample), min(1.0, g_ShapeNoisePower * heightFraction)); cloudSample = smoothstep(g_ShapeNoiseMinMax.x, g_ShapeNoiseMinMax.y, cloudSample); @@ -251,7 +251,7 @@ float HenyeyGreensteinPhase(float g, float cosTheta) { float numer = 1.0 - g * g; float denom = 1.0 + g * g - 2.0 * g * cosTheta; - return (numer / pow(denom, 1.5)) / 4.0 * PI; + return (numer / pow(abs(denom), 1.5)) / 4.0 * PI; } // Clamp the base, so it's never <= 0.0f (INF/NaN). diff --git a/WickedEngine/wiRenderer.cpp b/WickedEngine/wiRenderer.cpp index 18f5ed539..5cb9a4bf9 100644 --- a/WickedEngine/wiRenderer.cpp +++ b/WickedEngine/wiRenderer.cpp @@ -9296,10 +9296,6 @@ void UpdateFrameCB(CommandList cmd) { cb.g_xFrame_Options |= OPTION_BIT_SIMPLE_SKY; } - if (scene.weather.IsRealisticSky()) - { - cb.g_xFrame_Options |= OPTION_BIT_REALISTIC_SKY; - } if (GetDevice()->CheckCapability(GraphicsDevice::GRAPHICSDEVICE_CAPABILITY_RAYTRACING) && GetRaytracedShadowsEnabled()) { cb.g_xFrame_Options |= OPTION_BIT_RAYTRACED_SHADOWS; diff --git a/WickedEngine/wiScene.h b/WickedEngine/wiScene.h index c27a5837d..cea870ffa 100644 --- a/WickedEngine/wiScene.h +++ b/WickedEngine/wiScene.h @@ -958,17 +958,14 @@ namespace wiScene EMPTY = 0, OCEAN_ENABLED = 1 << 0, SIMPLE_SKY = 1 << 1, - REALISTIC_SKY = 1 << 2, }; uint32_t _flags = EMPTY; inline bool IsOceanEnabled() const { return _flags & OCEAN_ENABLED; } inline bool IsSimpleSky() const { return _flags & SIMPLE_SKY; } - inline bool IsRealisticSky() const { return _flags & REALISTIC_SKY; } inline void SetOceanEnabled(bool value = true) { if (value) { _flags |= OCEAN_ENABLED; } else { _flags &= ~OCEAN_ENABLED; } } inline void SetSimpleSky(bool value = true) { if (value) { _flags |= SIMPLE_SKY; } else { _flags &= ~SIMPLE_SKY; } } - inline void SetRealisticSky(bool value = true) { if (value) { _flags |= REALISTIC_SKY; } else { _flags &= ~REALISTIC_SKY; } } XMFLOAT3 sunColor = XMFLOAT3(0, 0, 0); XMFLOAT3 sunDirection = XMFLOAT3(0, 1, 0);