diff --git a/code/Weather/Sky/SkyComponent.cpp b/code/Weather/Sky/SkyComponent.cpp index c76d96d234..3bdc2f8575 100644 --- a/code/Weather/Sky/SkyComponent.cpp +++ b/code/Weather/Sky/SkyComponent.cpp @@ -51,6 +51,8 @@ const render::Handle s_handleWeather_SkyEyePosition(L"Weather_SkyEyePosition"); const render::Handle s_handleWeather_SkyCloudTexture(L"Weather_SkyCloudTexture"); const render::Handle s_handleWeather_SkyCloudTextureLast(L"Weather_SkyCloudTextureLast"); const render::Handle s_handleWeather_SkyTemporalBlend(L"Weather_SkyTemporalBlend"); +const render::Handle s_handleWeather_SkyCloudAmbientTop(L"Weather_SkyCloudAmbientTop"); +const render::Handle s_handleWeather_SkyCloudAmbientBottom(L"Weather_SkyCloudAmbientBottom"); const render::Handle s_handleWeather_InputTexture(L"Weather_InputTexture"); const render::Handle s_handleWeather_OutputTexture(L"Weather_OutputTexture"); @@ -65,20 +67,14 @@ const int32_t c_indexCount = c_triangleCount * 3; T_IMPLEMENT_RTTI_CLASS(L"traktor.weather.SkyComponent", SkyComponent, world::IEntityComponent) SkyComponent::SkyComponent( + const SkyComponentData& data, const resource::Proxy< render::Shader >& shader, - const resource::Proxy< render::ITexture >& texture, - float intensity, - bool clouds, - const Color4f& overHorizon, - const Color4f& underHorizon + const resource::Proxy< render::ITexture >& texture ) -: m_shader(shader) +: m_data(data) +, m_shader(shader) , m_texture(texture) , m_transform(Transform::identity()) -, m_intensity(intensity) -, m_clouds(clouds) -, m_overHorizon(overHorizon) -, m_underHorizon(underHorizon) { } @@ -149,7 +145,7 @@ bool SkyComponent::create(resource::IResourceManager* resourceManager, render::I c_vertexCount - 1 ); - if (m_clouds) + if (m_data.m_clouds) { render::SimpleTextureCreateDesc stcd = {}; render::VolumeTextureCreateDesc vtcd = {}; @@ -237,7 +233,7 @@ void SkyComponent::setup( { render::RenderGraph& renderGraph = context.getRenderGraph(); - if (m_clouds) + if (m_data.m_clouds) { if (m_shaderClouds2D.changed() || m_shaderClouds3D.changed()) { @@ -325,6 +321,8 @@ void SkyComponent::setup( renderBlock->programParams->setFloatParameter(s_handleWeather_SkyRadius, worldRenderView.getViewFrustum().getFarZ() - 10.0f); renderBlock->programParams->setVectorParameter(s_handleWeather_SkySunColor, sunColor); renderBlock->programParams->setVectorParameter(s_handleWeather_SkySunDirection, sunDirection); + renderBlock->programParams->setVectorParameter(s_handleWeather_SkyCloudAmbientTop, m_data.m_cloudAmbientTop); + renderBlock->programParams->setVectorParameter(s_handleWeather_SkyCloudAmbientBottom, m_data.m_cloudAmbientBottom); renderBlock->programParams->setFloatParameter(s_handleWeather_SkyTemporalBlend, (worldRenderView.getSnapshot() || m_cloudFrame == 0) ? 1.0f : 0.2f); renderBlock->programParams->setFloatParameter(world::s_handleTime, worldRenderView.getTime()); renderBlock->programParams->endParameters(renderContext); @@ -349,7 +347,7 @@ void SkyComponent::build( ) { auto perm = worldRenderPass.getPermutation(m_shader); - m_shader->setCombination(c_handleWeather_CloudsEnable, m_clouds, perm); + m_shader->setCombination(c_handleWeather_CloudsEnable, m_data.m_clouds, perm); auto sp = m_shader->getProgram(perm); if (!sp) return; @@ -386,15 +384,17 @@ void SkyComponent::build( worldRenderPass.setProgramParameters(renderBlock->programParams); renderBlock->programParams->setFloatParameter(s_handleWeather_SkyRadius, worldRenderView.getViewFrustum().getFarZ() - 10.0f); renderBlock->programParams->setFloatParameter(s_handleWeather_SkyRotation, rotation); - renderBlock->programParams->setFloatParameter(s_handleWeather_SkyIntensity, m_intensity); + renderBlock->programParams->setFloatParameter(s_handleWeather_SkyIntensity, m_data.m_intensity); renderBlock->programParams->setVectorParameter(s_handleWeather_SkySunDirection, sunDirection); renderBlock->programParams->setVectorParameter(s_handleWeather_SkySunColor, sunColor); - renderBlock->programParams->setVectorParameter(s_handleWeather_SkyOverHorizon, m_overHorizon); - renderBlock->programParams->setVectorParameter(s_handleWeather_SkyUnderHorizon, m_underHorizon); + renderBlock->programParams->setVectorParameter(s_handleWeather_SkyOverHorizon, m_data.m_skyOverHorizon); + renderBlock->programParams->setVectorParameter(s_handleWeather_SkyUnderHorizon, m_data.m_skyUnderHorizon); + renderBlock->programParams->setVectorParameter(s_handleWeather_SkyCloudAmbientTop, m_data.m_cloudAmbientTop); + renderBlock->programParams->setVectorParameter(s_handleWeather_SkyCloudAmbientBottom, m_data.m_cloudAmbientBottom); renderBlock->programParams->setVectorParameter(s_handleWeather_SkyEyePosition, eyePosition); renderBlock->programParams->setTextureParameter(s_handleWeather_SkyTexture, m_texture); - if (m_clouds) + if (m_data.m_clouds) { renderBlock->programParams->setFloatParameter(s_handleWeather_SkyCloudBlend, m_cloudBlend); renderBlock->programParams->setTextureParameter(s_handleWeather_SkyCloud2D, m_cloudTextures[0]); diff --git a/code/Weather/Sky/SkyComponent.h b/code/Weather/Sky/SkyComponent.h index 99b362d055..984c395910 100644 --- a/code/Weather/Sky/SkyComponent.h +++ b/code/Weather/Sky/SkyComponent.h @@ -11,6 +11,7 @@ #include "Render/ITexture.h" #include "Render/Shader.h" #include "Resource/Proxy.h" +#include "Weather/Sky/SkyComponentData.h" #include "World/IEntityComponent.h" // import/export mechanism. @@ -59,12 +60,9 @@ class T_DLLCLASS SkyComponent : public world::IEntityComponent public: explicit SkyComponent( + const SkyComponentData& data, const resource::Proxy< render::Shader >& shader, - const resource::Proxy< render::ITexture >& texture, - float intensity, - bool clouds, - const Color4f& overHorizon, - const Color4f& underHorizon + const resource::Proxy< render::ITexture >& texture ); virtual ~SkyComponent(); @@ -93,6 +91,7 @@ class T_DLLCLASS SkyComponent : public world::IEntityComponent ); private: + const SkyComponentData m_data; Ref< const render::IVertexLayout > m_vertexLayout; Ref< render::Buffer > m_vertexBuffer; Ref< render::Buffer > m_indexBuffer; @@ -106,10 +105,6 @@ class T_DLLCLASS SkyComponent : public world::IEntityComponent Ref< render::ITexture > m_cloudDomeTexture[2]; world::Entity* m_owner = nullptr; Transform m_transform; - float m_intensity = 1.0f; - bool m_clouds = true; - Color4f m_overHorizon = Color4f(0.2f, 0.5f, 0.85f, 0.0f); - Color4f m_underHorizon = Color4f(0.1f, 0.1f, 0.12f, 0.0f); int32_t m_count = 0; int32_t m_cloudFrame = 0; float m_cloudBlend = 0.0f; diff --git a/code/Weather/Sky/SkyComponentData.cpp b/code/Weather/Sky/SkyComponentData.cpp index b12b2c8a68..c521ffc18c 100644 --- a/code/Weather/Sky/SkyComponentData.cpp +++ b/code/Weather/Sky/SkyComponentData.cpp @@ -1,6 +1,6 @@ /* * TRAKTOR - * Copyright (c) 2022-2023 Anders Pistol. + * Copyright (c) 2022-2024 Anders Pistol. * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this @@ -8,6 +8,7 @@ */ #include #include "Core/Math/Const.h" +#include "Core/Serialization/AttributeHdr.h" #include "Core/Serialization/AttributePrivate.h" #include "Core/Serialization/AttributeRange.h" #include "Core/Serialization/AttributeUnit.h" @@ -29,7 +30,7 @@ const resource::Id< render::Shader > c_defaultShader(Guid(L"{4CF929EB-3A8B-C340- } -T_IMPLEMENT_RTTI_EDIT_CLASS(L"traktor.weather.SkyComponentData", 6, SkyComponentData, world::IEntityComponentData) +T_IMPLEMENT_RTTI_EDIT_CLASS(L"traktor.weather.SkyComponentData", 7, SkyComponentData, world::IEntityComponentData) SkyComponentData::SkyComponentData() : m_shader(c_defaultShader) @@ -50,12 +51,9 @@ Ref< SkyComponent > SkyComponentData::createComponent(resource::IResourceManager } Ref< SkyComponent > skyComponent = new SkyComponent( + *this, shader, - texture, - m_intensity, - m_clouds, - m_overHorizon, - m_underHorizon + texture ); skyComponent->create(resourceManager, renderSystem); return skyComponent; @@ -92,13 +90,25 @@ void SkyComponentData::serialize(ISerializer& s) if (s.getVersion< SkyComponentData >() >= 4) s >> Member< float >(L"intensity", m_intensity, AttributeRange(0.0f) | AttributeUnit(UnitType::Percent)); - if (s.getVersion< SkyComponentData >() >= 5) - s >> Member< bool >(L"clouds", m_clouds); + if (s.getVersion< SkyComponentData >() >= 7) + { + s >> Member< Color4f >(L"skyOverHorizon", m_skyOverHorizon, AttributeHdr()); + s >> Member< Color4f >(L"skyUnderHorizon", m_skyUnderHorizon, AttributeHdr()); - if (s.getVersion< SkyComponentData >() >= 6) + s >> Member< bool >(L"clouds", m_clouds); + s >> Member< Color4f >(L"cloudAmbientTop", m_cloudAmbientTop, AttributeHdr()); + s >> Member< Color4f >(L"cloudAmbientBottom", m_cloudAmbientBottom, AttributeHdr()); + } + else { - s >> Member< Color4f >(L"overHorizon", m_overHorizon); - s >> Member< Color4f >(L"underHorizon", m_underHorizon); + if (s.getVersion< SkyComponentData >() >= 5) + s >> Member< bool >(L"clouds", m_clouds); + + if (s.getVersion< SkyComponentData >() == 6) + { + s >> Member< Color4f >(L"overHorizon", m_skyOverHorizon); + s >> Member< Color4f >(L"underHorizon", m_skyUnderHorizon); + } } } diff --git a/code/Weather/Sky/SkyComponentData.h b/code/Weather/Sky/SkyComponentData.h index 1c7a14d19f..2791f4be52 100644 --- a/code/Weather/Sky/SkyComponentData.h +++ b/code/Weather/Sky/SkyComponentData.h @@ -66,12 +66,18 @@ class T_DLLCLASS SkyComponentData : public world::IEntityComponentData float getIntensity() const { return m_intensity; } private: + friend class SkyComponent; + resource::Id< render::Shader > m_shader; resource::Id< render::ITexture > m_texture; float m_intensity = 1.0f; + + Color4f m_skyOverHorizon = Color4f(0.2f, 0.5f, 0.85f, 1.0f); + Color4f m_skyUnderHorizon = Color4f(0.1f, 0.1f, 0.12f, 1.0f); + bool m_clouds = true; - Color4f m_overHorizon = Color4f(0.2f, 0.5f, 0.85f, 0.0f); - Color4f m_underHorizon = Color4f(0.1f, 0.1f, 0.12f, 0.0f); + Color4f m_cloudAmbientTop = Color4f(0.99f, 0.98f, 1.18f, 1.0f); + Color4f m_cloudAmbientBottom = Color4f(0.23f, 0.39f, 0.51f, 1.0f); }; } diff --git a/data/Source/System/Weather/Sky/Modules/Sky.xdi b/data/Source/System/Weather/Sky/Modules/Sky.xdi index 9711404f42..fecaa8acbb 100644 --- a/data/Source/System/Weather/Sky/Modules/Sky.xdi +++ b/data/Source/System/Weather/Sky/Modules/Sky.xdi @@ -8,17 +8,9 @@ vec3 GetSkyColor(vec3 sunDirection, vec3 sunColor, vec3 overHorizon, vec3 underHorizon, vec3 rd) { const float sundot = clamp(dot(rd, sunDirection), 0.0f, 1.0f); - - // Over horizon vec3 col = overHorizon - max(rd.y, 0.01f) * max(rd.y, 0.01f) * 0.5f; - - // Under horizon col = mix(col, underHorizon, pow(1.0f - max(rd.y, 0.0f), 6.0f)); - - // Add sun col += sunColor * pow(max(sundot - 0.1, 0), 8.0f); - -// col += clamp((0.1 - rd.y) * 10.0f, 0.0f, 1.0f) * underHorizon; return col; } @@ -149,7 +141,21 @@ float volumetricShadow(vec3 from, vec3 offset, float sundotrd, float time, vec3 return shadow; } -vec4 renderClouds(vec3 ro, vec3 rd, float time, vec3 sunDirection, vec3 sunColor, vec2 worldOffset, texture2D clouds2D, texture3D clouds3D, sampler cloudSampler, inout float dist) +struct CloudConfig +{ + vec3 ambientTop; + vec3 ambientBottom; +}; + +CloudConfig GetDefaultCloudConfig() +{ + CloudConfig c; + c.ambientTop = CLOUDS_AMBIENT_COLOR_TOP; + c.ambientBottom = CLOUDS_AMBIENT_COLOR_BOTTOM; + return c; +} + +vec4 RenderClouds(const CloudConfig config, vec3 ro, vec3 rd, float time, vec3 sunDirection, vec3 sunColor, vec2 worldOffset, texture2D clouds2D, texture3D clouds3D, sampler cloudSampler, inout float dist) { if (rd.y < 0.0f) return vec4(0.0f, 0.0f, 0.0f, 1.0f); @@ -188,19 +194,20 @@ vec4 renderClouds(vec3 ro, vec3 rd, float time, vec3 sunDirection, vec3 sunColor for (int s = 0; s < CLOUD_MARCH_STEPS; s++) { - vec3 p = ro + d * rd; + const vec3 p = ro + d * rd; - float norY = clamp((length(p) - (EARTH_RADIUS + CLOUDS_BOTTOM)) * (1.0f / (CLOUDS_TOP - CLOUDS_BOTTOM)), 0.0f, 1.0f); - float alpha = cloudMap( p, offset, rd, norY, time, clouds2D, clouds3D, cloudSampler ); + const float norY = clamp((length(p) - (EARTH_RADIUS + CLOUDS_BOTTOM)) * (1.0f / (CLOUDS_TOP - CLOUDS_BOTTOM)), 0.0f, 1.0f); + const float alpha = cloudMap( p, offset, rd, norY, time, clouds2D, clouds3D, cloudSampler ); if (alpha > 0.0f) { dist = min( dist, d); - vec3 ambientLight = mix( CLOUDS_AMBIENT_COLOR_BOTTOM, CLOUDS_AMBIENT_COLOR_TOP, norY ); + const vec3 ambientLight = mix(config.ambientBottom, config.ambientTop, norY); + + const vec3 S = (ambientLight + sunColor * (scattering * volumetricShadow(p, offset, sundotrd, time, sunDirection, clouds2D, clouds3D, cloudSampler))) * alpha; + const float dTrans = exp(-alpha * dD); + const vec3 Sint = (S - S * dTrans) * (1. / alpha); - vec3 S = (ambientLight + sunColor * (scattering * volumetricShadow(p, offset, sundotrd, time, sunDirection, clouds2D, clouds3D, cloudSampler))) * alpha; - float dTrans = exp(-alpha * dD); - vec3 Sint = (S - S * dTrans) * (1. / alpha); scatteredLight += transmittance * Sint; transmittance *= dTrans; } diff --git a/data/Source/System/Weather/Sky/Shaders/Dome.xdi b/data/Source/System/Weather/Sky/Shaders/Dome.xdi index 51a5be34a7..42d5c208c2 100644 --- a/data/Source/System/Weather/Sky/Shaders/Dome.xdi +++ b/data/Source/System/Weather/Sky/Shaders/Dome.xdi @@ -111,8 +111,8 @@ $Output = vec4(direction, 0.0f); {C1C98A8B-6A33-2845-8453-2D29B42A8190} - -114 - 350 + 16 + 440 Clouds @@ -120,8 +120,8 @@ $Output = vec4(direction, 0.0f); {1853FE71-10CD-2743-B521-886CDCD1130D} - -412 - 311 + -372 + 392 Clouds @@ -166,6 +166,14 @@ $Output = vec4(direction, 0.0f); {70605746-81B0-A64B-8596-3F4762DB8477} EyePosition + + {BBAD05A9-383C-E749-9AA8-7D5F71419A85} + CloudAmbientTop + + + {60A82300-B8BB-F74A-A1E6-9410C272E74C} + CloudAmbientBottom + @@ -181,11 +189,17 @@ $Output = vec4(direction, 0.0f); @@ -255,7 +268,7 @@ $Distance = dist; {4E704F36-056A-A347-B55D-6BC9EF584AA9} - -638 + -622 294 DomePosition @@ -264,7 +277,7 @@ $Distance = dist; {63663B1B-721E-A540-917A-070E4CD34188} - -686 + -670 380 Weather_SkyCloud3D @@ -275,8 +288,8 @@ $Distance = dist; {A408F529-302C-7B45-BB77-47EC4FC49ED3} - -686 - 338 + -670 + 337 Weather_SkyCloud2D Texture2D @@ -286,8 +299,8 @@ $Distance = dist; {09314B7E-7E00-6E46-A4CD-F46F7C4082A1} - -636 - 422 + -620 + 423 FtLinear FtLinear @@ -305,7 +318,7 @@ $Distance = dist; -622 - 464 + 466 World_Time Scalar @@ -315,8 +328,8 @@ $Distance = dist; {5039CD4E-D8C8-3942-BE4E-201B92D2DDB4} - -702 - 506 + -686 + 509 Weather_SkySunDirection Vector @@ -326,8 +339,8 @@ $Distance = dist; {6EC4A53C-25B5-5C4C-8DB4-4E976EB2DBA5} - -686 - 548 + -670 + 552 Weather_SkySunColor Vector @@ -337,8 +350,8 @@ $Distance = dist; {B17ADA46-C381-B64E-BACC-0975857EE8A7} - -660 - 590 + -644 + 595 0, 0, 0, 0 @@ -474,6 +487,28 @@ $Output = vec4(sz.x, sz.y, 0.0f, 0.0f); Scalar Frame + + {0971A080-14C8-0244-A654-37299B4D65E8} + + + -718 + 638 + + Weather_SkyCloudAmbientTop + Vector + Frame + + + {9BAB07A1-09A4-734C-885B-8F7749B7AA46} + + + -734 + 681 + + Weather_SkyCloudAmbientBottom + Vector + Frame + @@ -736,6 +771,26 @@ $Output = vec4(sz.x, sz.y, 0.0f, 0.0f); {5A25771B-894F-4D92-8D1E-FBF8449850E8} + + + + {1E6639B6-8B58-4694-99E7-C058E3583522} + + + + {BBAD05A9-383C-E749-9AA8-7D5F71419A85} + + + + + + {1E6639B6-8B58-4694-99E7-C058E3583522} + + + + {60A82300-B8BB-F74A-A1E6-9410C272E74C} + + diff --git a/data/Source/System/Weather/Sky/Shaders/Sky.xdi b/data/Source/System/Weather/Sky/Shaders/Sky.xdi index 8d85440aa0..d918fc0c1b 100644 --- a/data/Source/System/Weather/Sky/Shaders/Sky.xdi +++ b/data/Source/System/Weather/Sky/Shaders/Sky.xdi @@ -569,7 +569,6 @@ const vec3 clr = GetSkyColor( rd ); $Output = vec4(clr, 1.0f); - ]]> @@ -586,8 +585,8 @@ $Output = vec4(clr, 1.0f); {8FB6549E-5322-4FD8-8912-FD35D323CFF6} - -754 - 779 + -759 + 746 WorldPosition @@ -595,8 +594,8 @@ $Output = vec4(clr, 1.0f); {3D50C5B7-186C-4798-A7E6-79FB8597A7B9} - -431 - 801 + -430 + 800 Clouds @@ -641,6 +640,14 @@ $Output = vec4(clr, 1.0f); {70605746-81B0-A64B-8596-3F4762DB8477} EyePosition + + {5A6AB96D-1E34-304F-84D6-0E87D23435B4} + CloudAmbientTop + + + {FA94D259-22C0-4243-9837-74F3B1664F1F} + CloudAmbientBottom + @@ -656,11 +663,17 @@ $Output = vec4(clr, 1.0f); @@ -684,8 +696,8 @@ $Distance = dist; {2BB29238-2675-42BB-9382-17C55B6C1380} - -752 - 896 + -757 + 866 FtLinear FtLinear @@ -702,8 +714,8 @@ $Distance = dist; {1AD17D96-8F2E-457A-AAB5-8EBCE60711EA} - -802 - 818 + -807 + 786 Weather_SkyCloud2D Texture2D @@ -713,8 +725,8 @@ $Distance = dist; {20235D86-BCB0-485E-91F7-F7E2ADE78B21} - -802 - 857 + -807 + 826 Weather_SkyCloud3D Texture3D @@ -741,8 +753,8 @@ $Distance = dist; {21D1CC08-6848-49CB-BA67-E49974F893C6} - -754 - 935 + -759 + 906 World_Time Scalar @@ -752,8 +764,8 @@ $Distance = dist; {49BB686E-3893-4F3E-AFAC-FAC0AC817383} - -802 - 662 + -807 + 626 Weather_SkySunColor Vector @@ -763,8 +775,8 @@ $Distance = dist; {CFE120E4-0277-41B4-A10C-9C932F6764B0} - -818 - 623 + -823 + 586 Weather_SkySunDirection Vector @@ -808,8 +820,8 @@ $Distance = dist; {3CC2F2B4-36BD-B54E-8E1B-D12B69ADE23F} - -818 - 974 + -807 + 946 Weather_SkyEyePosition Vector @@ -875,8 +887,8 @@ $Distance = dist; {41365992-5B09-6A4D-B23B-AC507AE2A162} - -133 - 838 + -31 + 840 Clouds1 @@ -985,8 +997,8 @@ $Output = vec4(texCoord, 0.0f, 0.0f); {E7530B7B-E7A2-3C4B-8072-C3B73EE99101} - -776 - 1013 + -781 + 986 0, 0, 0, 0 @@ -1143,8 +1155,8 @@ $Output = vec4(texCoord, 0.0f, 0.0f); {0CF0ACDC-F017-5E45-8BA8-266248431786} - -818 - 701 + -823 + 666 Weather_SkyOverHorizon Vector @@ -1154,13 +1166,35 @@ $Output = vec4(texCoord, 0.0f, 0.0f); {3F5650EA-F241-BC47-B523-B8813F1C899C} - -834 - 740 + -823 + 706 Weather_SkyUnderHorizon Vector Frame + + {A1A5F0FA-50D4-3A4A-B6E4-B5B132ECC274} + + + -871 + 1066 + + Weather_SkyCloudAmbientBottom + Vector + Frame + + + {A14A6472-9C96-BE4F-96A1-420BA685CC91} + + + -855 + 1026 + + Weather_SkyCloudAmbientTop + Vector + Frame + @@ -1963,6 +1997,26 @@ $Output = vec4(texCoord, 0.0f, 0.0f); {AD277C19-9612-9141-AA5C-097F83F5B743} + + + + {1E6639B6-8B58-4694-99E7-C058E3583522} + + + + {5A6AB96D-1E34-304F-84D6-0E87D23435B4} + + + + + + {1E6639B6-8B58-4694-99E7-C058E3583522} + + + + {FA94D259-22C0-4243-9837-74F3B1664F1F} + +