exposed atmosphere settings in weather component, and added skyExposure

This commit is contained in:
Turanszki Janos
2021-05-10 21:12:48 +02:00
parent d71c06c869
commit fc982f19b7
19 changed files with 163 additions and 95 deletions
+9 -1
View File
@@ -11,7 +11,7 @@ using namespace wiGraphics;
void WeatherWindow::Create(EditorComponent* editor)
{
wiWindow::Create("Weather Window");
SetSize(XMFLOAT2(660, 520));
SetSize(XMFLOAT2(660, 560));
float x = 180;
float y = 20;
@@ -107,6 +107,14 @@ void WeatherWindow::Create(EditorComponent* editor)
});
AddWidget(&windRandomnessSlider);
skyExposureSlider.Create(0, 4, 1, 10000, "Sky Exposure: ");
skyExposureSlider.SetSize(XMFLOAT2(100, hei));
skyExposureSlider.SetPos(XMFLOAT2(x, y += step));
skyExposureSlider.OnSlide([&](wiEventArgs args) {
GetWeather().skyExposure = args.fValue;
});
AddWidget(&skyExposureSlider);
simpleskyCheckBox.Create("Simple sky: ");
simpleskyCheckBox.SetTooltip("Simple sky will simply blend horizon and zenith color from bottom to top.");
simpleskyCheckBox.SetSize(XMFLOAT2(hei, hei));
+1
View File
@@ -25,6 +25,7 @@ public:
wiSlider windDirectionSlider;
wiSlider windWaveSizeSlider;
wiSlider windRandomnessSlider;
wiSlider skyExposureSlider;
wiCheckBox simpleskyCheckBox;
wiCheckBox realisticskyCheckBox;
wiButton skyButton;
+1
View File
@@ -1,5 +1,6 @@
This file contains changelog of wiArchive versions
66: serialized WeatherComponent::atmosphereParameters and skyExposure
65: serialized CameraComponent focal_length, aperture_size and aperture_shape
64: serialized per-emitter gravity, velocity, drag and random_color
63: serialized wiResourceManager embedded resources
@@ -268,6 +268,88 @@ static const uint TILED_CULLING_GRANULARITY = TILED_CULLING_BLOCKSIZE / TILED_CU
static const int impostorCaptureAngles = 36;
struct AtmosphereParameters
{
float2 padding0;
// Radius of the planet (center to ground)
float bottomRadius;
// Maximum considered atmosphere height (center to atmosphere top)
float topRadius;
// Center of the planet
float3 planetCenter;
// Rayleigh scattering exponential distribution scale in the atmosphere
float rayleighDensityExpScale;
// Rayleigh scattering coefficients
float3 rayleighScattering;
// Mie scattering exponential distribution scale in the atmosphere
float mieDensityExpScale;
// Mie scattering coefficients
float3 mieScattering; float padding1;
// Mie extinction coefficients
float3 mieExtinction; float padding2;
// Mie absorption coefficients
float3 mieAbsorption;
// Mie phase function excentricity
float miePhaseG;
// Another medium type in the atmosphere
float absorptionDensity0LayerWidth;
float absorptionDensity0ConstantTerm;
float absorptionDensity0LinearTerm;
float absorptionDensity1ConstantTerm;
float3 padding3;
float absorptionDensity1LinearTerm;
// This other medium only absorb light, e.g. useful to represent ozone in the earth atmosphere
float3 absorptionExtinction; float padding4;
// The albedo of the ground.
float3 groundAlbedo; float padding5;
// Init default values (All units in kilometers)
void init(
float earthBottomRadius = 6360.0f,
float earthTopRadius = 6460.0f, // 100km atmosphere radius, less edge visible and it contain 99.99% of the atmosphere medium https://en.wikipedia.org/wiki/K%C3%A1rm%C3%A1n_line
float earthRayleighScaleHeight = 8.0f,
float earthMieScaleHeight = 1.2f
)
{
// Values shown here are the result of integration over wavelength power spectrum integrated with paricular function.
// Refer to https://github.com/ebruneton/precomputed_atmospheric_scattering for details.
// Translation from Bruneton2017 parameterisation.
rayleighDensityExpScale = -1.0f / earthRayleighScaleHeight;
mieDensityExpScale = -1.0f / earthMieScaleHeight;
absorptionDensity0LayerWidth = 25.0f;
absorptionDensity0ConstantTerm = -2.0f / 3.0f;
absorptionDensity0LinearTerm = 1.0f / 15.0f;
absorptionDensity1ConstantTerm = 8.0f / 3.0f;
absorptionDensity1LinearTerm = -1.0f / 15.0f;
miePhaseG = 0.8f;
rayleighScattering = float3(0.005802f, 0.013558f, 0.033100f);
mieScattering = float3(0.003996f, 0.003996f, 0.003996f);
mieExtinction = float3(0.004440f, 0.004440f, 0.004440f);
mieAbsorption.x = mieExtinction.x - mieScattering.x;
mieAbsorption.y = mieExtinction.y - mieScattering.y;
mieAbsorption.z = mieExtinction.z - mieScattering.z;
absorptionExtinction = float3(0.000650f, 0.001881f, 0.000085f);
groundAlbedo = float3(0.3f, 0.3f, 0.3f); // 0.3 for earths ground albedo, see https://nssdc.gsfc.nasa.gov/planetary/factsheet/earthfact.html
bottomRadius = earthBottomRadius;
topRadius = earthTopRadius;
planetCenter = float3(0.0f, -earthBottomRadius - 0.1f, 0.0f); // Spawn 100m in the air
}
#ifdef __cplusplus
AtmosphereParameters() { init(); }
#endif // __cplusplus
};
// These option bits can be read from g_xFrame_Options constant buffer value:
static const uint OPTION_BIT_TEMPORALAA_ENABLED = 1 << 0;
static const uint OPTION_BIT_TRANSPARENTSHADOWS_ENABLED = 1 << 1;
@@ -305,6 +387,9 @@ CBUFFER(FrameCB, CBSLOT_RENDERER_FRAME)
float3 g_xFrame_Ambient;
float g_xFrame_Cloudiness;
float3 g_xFrame_padding0;
float g_xFrame_SkyExposure;
float3 g_xFrame_Fog; // Fog Start,End,Height
float g_xFrame_VoxelRadianceMaxDistance; // maximum raymarch distance for voxel GI in world-space
@@ -363,6 +448,8 @@ CBUFFER(FrameCB, CBSLOT_RENDERER_FRAME)
float g_xFrame_ShadowKernelCube;
uint g_xFrame_RaytracedShadowsSampleCount;
int g_xFrame_ObjectShaderSamplerIndex;
AtmosphereParameters g_xFrame_Atmosphere;
};
CBUFFER(CameraCB, CBSLOT_RENDERER_CAMERA)
+1 -2
View File
@@ -199,8 +199,7 @@ inline void DirectionalLight(in ShaderEntity light, in Surface surface, inout Li
float3 atmosphereTransmittance = 1;
if (g_xFrame_Options & OPTION_BIT_REALISTIC_SKY)
{
AtmosphereParameters Atmosphere = GetAtmosphereParameters();
atmosphereTransmittance = GetAtmosphericLightTransmittance(Atmosphere, surface.P, L, texture_transmittancelut);
atmosphereTransmittance = GetAtmosphericLightTransmittance(g_xFrame_Atmosphere, surface.P, L, texture_transmittancelut);
}
float3 lightColor = light.GetColor().rgb * light.GetEnergy() * shadow * atmosphereTransmittance;
+1 -1
View File
@@ -211,7 +211,7 @@ void main(uint3 DTid : SV_DispatchThreadID, uint groupIndex : SV_GroupIndex)
float3 atmosphereTransmittance = 1;
if (g_xFrame_Options & OPTION_BIT_REALISTIC_SKY)
{
AtmosphereParameters Atmosphere = GetAtmosphereParameters();
AtmosphereParameters Atmosphere = g_xFrame_Atmosphere;
atmosphereTransmittance = GetAtmosphericLightTransmittance(Atmosphere, surface.P, L, texture_transmittancelut);
}
lightColor *= atmosphereTransmittance;
+1 -2
View File
@@ -65,8 +65,7 @@ float4 main(Input input) : SV_TARGET
float3 atmosphereTransmittance = 1.0;
if (g_xFrame_Options & OPTION_BIT_REALISTIC_SKY)
{
AtmosphereParameters Atmosphere = GetAtmosphereParameters();
atmosphereTransmittance = GetAtmosphericLightTransmittance(Atmosphere, surface.P, L, texture_transmittancelut);
atmosphereTransmittance = GetAtmosphericLightTransmittance(g_xFrame_Atmosphere, surface.P, L, texture_transmittancelut);
}
float3 lightColor = light.GetColor().rgb * light.GetEnergy() * atmosphereTransmittance;
+1 -79
View File
@@ -23,84 +23,6 @@ static const float2 skyViewLUTRes = float2(192.0, 104);
#define PLANET_RADIUS_OFFSET 0.001f // Float accuracy offset in Sky unit (km, so this is 1m)
struct AtmosphereParameters
{
// Radius of the planet (center to ground)
float bottomRadius;
// Maximum considered atmosphere height (center to atmosphere top)
float topRadius;
// Center of the planet
float3 planetCenter;
// Rayleigh scattering exponential distribution scale in the atmosphere
float rayleighDensityExpScale;
// Rayleigh scattering coefficients
float3 rayleighScattering;
// Mie scattering exponential distribution scale in the atmosphere
float mieDensityExpScale;
// Mie scattering coefficients
float3 mieScattering;
// Mie extinction coefficients
float3 mieExtinction;
// Mie absorption coefficients
float3 mieAbsorption;
// Mie phase function excentricity
float miePhaseG;
// Another medium type in the atmosphere
float absorptionDensity0LayerWidth;
float absorptionDensity0ConstantTerm;
float absorptionDensity0LinearTerm;
float absorptionDensity1ConstantTerm;
float absorptionDensity1LinearTerm;
// This other medium only absorb light, e.g. useful to represent ozone in the earth atmosphere
float3 absorptionExtinction;
// The albedo of the ground.
float3 groundAlbedo;
};
AtmosphereParameters GetAtmosphereParameters()
{
AtmosphereParameters parameters;
// Values shown here are the result of integration over wavelength power spectrum integrated with paricular function.
// Refer to https://github.com/ebruneton/precomputed_atmospheric_scattering for details.
// All units in kilometers
const float earthBottomRadius = 6360.0f;
const float earthTopRadius = 6460.0f; // 100km atmosphere radius, less edge visible and it contain 99.99% of the atmosphere medium https://en.wikipedia.org/wiki/K%C3%A1rm%C3%A1n_line
const float earthRayleighScaleHeight = 8.0f;
const float earthMieScaleHeight = 1.2f;
// Traslation from Bruneton2017 parameterisation.
parameters.rayleighDensityExpScale = -1.0 / earthRayleighScaleHeight;
parameters.mieDensityExpScale = -1.0 / earthMieScaleHeight;
parameters.absorptionDensity0LayerWidth = 25.0;
parameters.absorptionDensity0ConstantTerm = -2.0 / 3.0;
parameters.absorptionDensity0LinearTerm = 1.0 / 15.0;
parameters.absorptionDensity1ConstantTerm = 8.0 / 3.0;
parameters.absorptionDensity1LinearTerm = -1.0 / 15.0;
parameters.miePhaseG = 0.8;
parameters.rayleighScattering = float3(0.005802f, 0.013558f, 0.033100f);
parameters.mieScattering = float3(0.003996f, 0.003996f, 0.003996f);
parameters.mieExtinction = float3(0.004440f, 0.004440f, 0.004440f);
parameters.mieAbsorption = parameters.mieExtinction - parameters.mieScattering;
parameters.absorptionExtinction = float3(0.000650f, 0.001881f, 0.000085f);
parameters.groundAlbedo = float3(0.3, 0.3, 0.3); // 0.3 for earths ground albedo, see https://nssdc.gsfc.nasa.gov/planetary/factsheet/earthfact.html
parameters.bottomRadius = earthBottomRadius;
parameters.topRadius = earthTopRadius;
parameters.planetCenter = float3(0.0, -earthBottomRadius - 0.1, 0.0); // Spawn 100m in the air
return parameters;
}
////////////////////////////////////////////////////////////
// LUT functions
////////////////////////////////////////////////////////////
@@ -754,4 +676,4 @@ SingleScatteringResult IntegrateScatteredLuminance(
}
#endif // WI_SKYATMOSPHERE_HF
#endif // WI_SKYATMOSPHERE_HF
@@ -19,7 +19,7 @@ void main(uint3 DTid : SV_DispatchThreadID)
uv = float2(FromSubUvsToUnit(uv.x, multiScatteringLUTRes.x), FromSubUvsToUnit(uv.y, multiScatteringLUTRes.y));
AtmosphereParameters atmosphere = GetAtmosphereParameters();
AtmosphereParameters atmosphere = g_xFrame_Atmosphere;
float cosSunZenithAngle = uv.x * 2.0 - 1.0;
float3 sunDirection = float3(0.0, sqrt(saturate(1.0 - cosSunZenithAngle * cosSunZenithAngle)), cosSunZenithAngle);
@@ -16,7 +16,7 @@ void main(uint3 DTid : SV_DispatchThreadID)
float2 uv = pixelPosition * rcp(multiScatteringLUTRes);
AtmosphereParameters atmosphere = GetAtmosphereParameters();
AtmosphereParameters atmosphere = g_xFrame_Atmosphere;
float viewHeight = atmosphere.bottomRadius + skyLuminanceSampleHeight;
@@ -8,7 +8,7 @@ RWTEXTURE2D(output, float4, 0);
[numthreads(8, 8, 1)]
void main(uint3 DTid : SV_DispatchThreadID)
{
AtmosphereParameters atmosphere = GetAtmosphereParameters();
AtmosphereParameters atmosphere = g_xFrame_Atmosphere;
float2 pixelPosition = float2(DTid.xy) + 0.5;
float2 uv = pixelPosition * rcp(skyViewLUTRes);
@@ -9,7 +9,7 @@ RWTEXTURE2D(output, float4, 0);
void main(uint3 DTid : SV_DispatchThreadID)
{
float2 pixelPosition = float2(DTid.xy) + 0.5;
AtmosphereParameters atmosphere = GetAtmosphereParameters();
AtmosphereParameters atmosphere = g_xFrame_Atmosphere;
// Compute camera position from LUT coords
const float2 uv = pixelPosition * rcp(transmittanceLUTRes);
+4 -2
View File
@@ -8,7 +8,7 @@
float3 AccurateAtmosphericScattering(Texture2D<float4> skyViewLutTexture, Texture2D<float4> transmittanceLUT, Texture2D<float4> multiScatteringLUT, float3 rayOrigin, float3 rayDirection, float3 sunDirection, float sunEnergy, float3 sunColor, bool enableSun, bool darkMode, bool stationary)
{
AtmosphereParameters atmosphere = GetAtmosphereParameters();
AtmosphereParameters atmosphere = g_xFrame_Atmosphere;
float3 worldDirection = rayDirection;
@@ -244,7 +244,7 @@ float3 GetDynamicSkyColor(in float3 V, bool sun_enabled = true, bool clouds_enab
{
if (g_xFrame_Options & OPTION_BIT_SIMPLE_SKY)
{
return lerp(GetHorizonColor(), GetZenithColor(), saturate(V.y * 0.5f + 0.5f));
return lerp(GetHorizonColor(), GetZenithColor(), saturate(V.y * 0.5f + 0.5f)) * g_xFrame_SkyExposure;
}
const float3 sunDirection = GetSunDirection();
@@ -282,6 +282,8 @@ float3 GetDynamicSkyColor(in float3 V, bool sun_enabled = true, bool clouds_enab
);
}
sky *= g_xFrame_SkyExposure;
if (clouds_enabled)
{
CalculateClouds(sky, V, dark_enabled);
@@ -458,7 +458,7 @@ void RenderClouds(float3 rayOrigin, float3 rayDirection, float t, float steps, f
float2 coverageWindOffset = g_CoverageWindSpeed * g_AnimationMultiplier * coverageWindDirection * g_xFrame_Time;
AtmosphereParameters atmosphere = GetAtmosphereParameters();
AtmosphereParameters atmosphere = g_xFrame_Atmosphere;
float3 sunIlluminance = GetSunColor() * GetSunEnergy();
float3 sunDirection = GetSunDirection();
@@ -589,7 +589,7 @@ void main(uint3 DTid : SV_DispatchThreadID)
float steps;
float stepSize;
{
AtmosphereParameters parameters = GetAtmosphereParameters();
AtmosphereParameters parameters = g_xFrame_Atmosphere;
float planetRadius = parameters.bottomRadius * SKY_UNIT_TO_M;
float3 planetCenterWorld = parameters.planetCenter * SKY_UNIT_TO_M;
+1 -1
View File
@@ -4,7 +4,7 @@
#include <fstream>
// this should always be only INCREMENTED and only if a new serialization is implemeted somewhere!
uint64_t __archiveVersion = 65;
uint64_t __archiveVersion = 66;
// this is the version number of which below the archive is not compatible with the current version
uint64_t __archiveVersionBarrier = 22;
+3
View File
@@ -3685,6 +3685,7 @@ void UpdatePerFrameData(
frameCB.g_xFrame_Fog = float3(vis.scene->weather.fogStart, vis.scene->weather.fogEnd, vis.scene->weather.fogHeight);
frameCB.g_xFrame_Horizon = vis.scene->weather.horizon;
frameCB.g_xFrame_Zenith = vis.scene->weather.zenith;
frameCB.g_xFrame_SkyExposure = vis.scene->weather.skyExposure;
frameCB.g_xFrame_VoxelRadianceMaxDistance = voxelSceneData.maxDistance;
frameCB.g_xFrame_VoxelRadianceDataSize = voxelSceneData.voxelsize;
frameCB.g_xFrame_VoxelRadianceDataSize_rcp = 1.0f / (float)frameCB.g_xFrame_VoxelRadianceDataSize;
@@ -3809,6 +3810,8 @@ void UpdatePerFrameData(
{
frameCB.g_xFrame_Options |= OPTION_BIT_SHADOW_MASK;
}
frameCB.g_xFrame_Atmosphere = vis.scene->weather.atmosphereParameters;
}
void UpdateRenderData(
const Visibility& vis,
+2
View File
@@ -1118,6 +1118,7 @@ namespace wiScene
XMFLOAT3 sunColor = XMFLOAT3(0, 0, 0);
XMFLOAT3 sunDirection = XMFLOAT3(0, 1, 0);
float sunEnergy = 0;
float skyExposure = 1;
XMFLOAT3 horizon = XMFLOAT3(0.0f, 0.0f, 0.0f);
XMFLOAT3 zenith = XMFLOAT3(0.0f, 0.0f, 0.0f);
XMFLOAT3 ambient = XMFLOAT3(0.2f, 0.2f, 0.2f);
@@ -1133,6 +1134,7 @@ namespace wiScene
float windSpeed = 1;
wiOcean::OceanParameters oceanParameters;
AtmosphereParameters atmosphereParameters;
std::string skyMapName;
std::string colorGradingMapName;
+44
View File
@@ -971,6 +971,28 @@ namespace wiScene
}
}
if (archive.GetVersion() >= 66)
{
archive >> skyExposure;
archive >> atmosphereParameters.bottomRadius;
archive >> atmosphereParameters.topRadius;
archive >> atmosphereParameters.planetCenter;
archive >> atmosphereParameters.rayleighDensityExpScale;
archive >> atmosphereParameters.rayleighScattering;
archive >> atmosphereParameters.mieDensityExpScale;
archive >> atmosphereParameters.mieScattering;
archive >> atmosphereParameters.mieExtinction;
archive >> atmosphereParameters.mieAbsorption;
archive >> atmosphereParameters.absorptionDensity0LayerWidth;
archive >> atmosphereParameters.absorptionDensity0ConstantTerm;
archive >> atmosphereParameters.absorptionDensity0LinearTerm;
archive >> atmosphereParameters.absorptionDensity1ConstantTerm;
archive >> atmosphereParameters.absorptionDensity1LinearTerm;
archive >> atmosphereParameters.absorptionExtinction;
archive >> atmosphereParameters.groundAlbedo;
}
}
else
{
@@ -1019,6 +1041,28 @@ namespace wiScene
archive << colorGradingMapName;
}
if (archive.GetVersion() >= 66)
{
archive << skyExposure;
archive << atmosphereParameters.bottomRadius;
archive << atmosphereParameters.topRadius;
archive << atmosphereParameters.planetCenter;
archive << atmosphereParameters.rayleighDensityExpScale;
archive << atmosphereParameters.rayleighScattering;
archive << atmosphereParameters.mieDensityExpScale;
archive << atmosphereParameters.mieScattering;
archive << atmosphereParameters.mieExtinction;
archive << atmosphereParameters.mieAbsorption;
archive << atmosphereParameters.absorptionDensity0LayerWidth;
archive << atmosphereParameters.absorptionDensity0ConstantTerm;
archive << atmosphereParameters.absorptionDensity0LinearTerm;
archive << atmosphereParameters.absorptionDensity1ConstantTerm;
archive << atmosphereParameters.absorptionDensity1LinearTerm;
archive << atmosphereParameters.absorptionExtinction;
archive << atmosphereParameters.groundAlbedo;
}
}
}
void SoundComponent::Serialize(wiArchive& archive, EntitySerializer& seri)
+1 -1
View File
@@ -9,7 +9,7 @@ namespace wiVersion
// minor features, major updates, breaking compatibility changes
const int minor = 56;
// minor bug fixes, alterations, refactors, updates
const int revision = 12;
const int revision = 13;
const std::string version_string = std::to_string(major) + "." + std::to_string(minor) + "." + std::to_string(revision);