diff --git a/Editor/AnimationWindow.cpp b/Editor/AnimationWindow.cpp index 018acab35..5931b8b39 100644 --- a/Editor/AnimationWindow.cpp +++ b/Editor/AnimationWindow.cpp @@ -1,6 +1,8 @@ #include "stdafx.h" #include "AnimationWindow.h" +#include + using namespace wiECS; using namespace wiSceneSystem; @@ -125,7 +127,9 @@ void AnimationWindow::Update() Entity e = scene.animations.GetEntity(i); NameComponent& name = *scene.names.GetComponent(e); - animationsComboBox->AddItem(name.name); + std::stringstream ss(""); + ss << name.name << " (" << e << ")"; + animationsComboBox->AddItem(ss.str()); if (e == entity) { diff --git a/Editor/Editor.cpp b/Editor/Editor.cpp index 383f543a5..c0f20b961 100644 --- a/Editor/Editor.cpp +++ b/Editor/Editor.cpp @@ -1280,7 +1280,7 @@ void EditorComponent::Update(float dt) for (size_t i = 0; i < count; ++i) { Picked picked; - picked.entity = scene.Entity_Serialize(*clipboard, INVALID_ENTITY, wiRandom::getRandom(1, INT_MAX)); + picked.entity = scene.Entity_Serialize(*clipboard, INVALID_ENTITY, wiRandom::getRandom(1, INT_MAX), false); AddSelected(picked); } diff --git a/Editor/MaterialWindow.cpp b/Editor/MaterialWindow.cpp index 64fccbdbf..61848484d 100644 --- a/Editor/MaterialWindow.cpp +++ b/Editor/MaterialWindow.cpp @@ -1,6 +1,8 @@ #include "stdafx.h" #include "MaterialWindow.h" +#include + #include // openfile #include @@ -545,8 +547,10 @@ void MaterialWindow::SetEntity(Entity entity) material->SetUserStencilRef(0); const NameComponent& name = *scene.names.GetComponent(entity); + stringstream ss(""); + ss << name.name << " (" << entity << ")"; - materialNameField->SetValue(name.name); + materialNameField->SetValue(ss.str()); waterCheckBox->SetCheck(material->IsWater()); planarReflCheckBox->SetCheck(material->HasPlanarReflection()); shadowCasterCheckBox->SetCheck(material->IsCastingShadow()); diff --git a/Editor/Translator.cpp b/Editor/Translator.cpp index 1364cdfd0..894773274 100644 --- a/Editor/Translator.cpp +++ b/Editor/Translator.cpp @@ -3,6 +3,7 @@ #include "wiRenderer.h" #include "wiInputManager.h" #include "wiMath.h" +#include "ShaderInterop_Renderer.h" using namespace wiGraphicsTypes; using namespace wiECS; @@ -449,7 +450,7 @@ void Translator::Draw(const CameraComponent& camera, GRAPHICSTHREAD threadID) XMMATRIX VP = camera.GetViewProjection(); - wiRenderer::MiscCB sb; + MiscCB sb; XMMATRIX mat = XMMatrixScaling(dist, dist, dist)*XMMatrixTranslationFromVector(transform.GetPositionV()) * VP; XMMATRIX matX = XMMatrixTranspose(mat); @@ -469,20 +470,20 @@ void Translator::Draw(const CameraComponent& camera, GRAPHICSTHREAD threadID) } // xy - sb.mTransform = matX; - sb.mColor = state == TRANSLATOR_XY ? XMFLOAT4(1, 1, 1, 1) : XMFLOAT4(0.2f, 0.2f, 0, 0.2f); + XMStoreFloat4x4(&sb.g_xTransform, matX); + sb.g_xColor = state == TRANSLATOR_XY ? XMFLOAT4(1, 1, 1, 1) : XMFLOAT4(0.2f, 0.2f, 0, 0.2f); device->UpdateBuffer(wiRenderer::constantBuffers[CBTYPE_MISC], &sb, threadID); device->Draw(vertexCount_Plane, 0, threadID); // xz - sb.mTransform = matZ; - sb.mColor = state == TRANSLATOR_XZ ? XMFLOAT4(1, 1, 1, 1) : XMFLOAT4(0.2f, 0.2f, 0, 0.2f); + XMStoreFloat4x4(&sb.g_xTransform, matZ); + sb.g_xColor = state == TRANSLATOR_XZ ? XMFLOAT4(1, 1, 1, 1) : XMFLOAT4(0.2f, 0.2f, 0, 0.2f); device->UpdateBuffer(wiRenderer::constantBuffers[CBTYPE_MISC], &sb, threadID); device->Draw(vertexCount_Plane, 0, threadID); // yz - sb.mTransform = matY; - sb.mColor = state == TRANSLATOR_YZ ? XMFLOAT4(1, 1, 1, 1) : XMFLOAT4(0.2f, 0.2f, 0, 0.2f); + XMStoreFloat4x4(&sb.g_xTransform, matY); + sb.g_xColor = state == TRANSLATOR_YZ ? XMFLOAT4(1, 1, 1, 1) : XMFLOAT4(0.2f, 0.2f, 0, 0.2f); device->UpdateBuffer(wiRenderer::constantBuffers[CBTYPE_MISC], &sb, threadID); device->Draw(vertexCount_Plane, 0, threadID); @@ -499,20 +500,20 @@ void Translator::Draw(const CameraComponent& camera, GRAPHICSTHREAD threadID) } // x - sb.mTransform = matX; - sb.mColor = state == TRANSLATOR_X ? XMFLOAT4(1, 1, 1, 1) : XMFLOAT4(1, 0, 0, 1); + XMStoreFloat4x4(&sb.g_xTransform, matX); + sb.g_xColor = state == TRANSLATOR_X ? XMFLOAT4(1, 1, 1, 1) : XMFLOAT4(1, 0, 0, 1); device->UpdateBuffer(wiRenderer::constantBuffers[CBTYPE_MISC], &sb, threadID); device->Draw(vertexCount_Axis, 0, threadID); // y - sb.mTransform = matY; - sb.mColor = state == TRANSLATOR_Y ? XMFLOAT4(1, 1, 1, 1) : XMFLOAT4(0, 1, 0, 1); + XMStoreFloat4x4(&sb.g_xTransform, matY); + sb.g_xColor = state == TRANSLATOR_Y ? XMFLOAT4(1, 1, 1, 1) : XMFLOAT4(0, 1, 0, 1); device->UpdateBuffer(wiRenderer::constantBuffers[CBTYPE_MISC], &sb, threadID); device->Draw(vertexCount_Axis, 0, threadID); // z - sb.mTransform = matZ; - sb.mColor = state == TRANSLATOR_Z ? XMFLOAT4(1, 1, 1, 1) : XMFLOAT4(0, 0, 1, 1); + XMStoreFloat4x4(&sb.g_xTransform, matZ); + sb.g_xColor = state == TRANSLATOR_Z ? XMFLOAT4(1, 1, 1, 1) : XMFLOAT4(0, 0, 1, 1); device->UpdateBuffer(wiRenderer::constantBuffers[CBTYPE_MISC], &sb, threadID); device->Draw(vertexCount_Axis, 0, threadID); @@ -526,8 +527,8 @@ void Translator::Draw(const CameraComponent& camera, GRAPHICSTHREAD threadID) sizeof(XMFLOAT4) + sizeof(XMFLOAT4), }; device->BindVertexBuffers(vbs, 0, ARRAYSIZE(vbs), strides, nullptr, threadID); - sb.mTransform = XMMatrixTranspose(mat); - sb.mColor = state == TRANSLATOR_XYZ ? XMFLOAT4(1, 1, 1, 1) : XMFLOAT4(0.25f, 0.25f, 0.25f, 1); + XMStoreFloat4x4(&sb.g_xTransform, XMMatrixTranspose(mat)); + sb.g_xColor = state == TRANSLATOR_XYZ ? XMFLOAT4(1, 1, 1, 1) : XMFLOAT4(0.25f, 0.25f, 0.25f, 1); device->UpdateBuffer(wiRenderer::constantBuffers[CBTYPE_MISC], &sb, threadID); device->Draw(vertexCount_Origin, 0, threadID); } diff --git a/Editor/WorldWindow.cpp b/Editor/WorldWindow.cpp index 34d2b6999..e82c8b267 100644 --- a/Editor/WorldWindow.cpp +++ b/Editor/WorldWindow.cpp @@ -29,7 +29,7 @@ WorldWindow::WorldWindow(wiGUI* gui) : GUI(gui) fogStartSlider->SetSize(XMFLOAT2(100, 30)); fogStartSlider->SetPos(XMFLOAT2(x, y += step)); fogStartSlider->OnSlide([&](wiEventArgs args) { - wiRenderer::GetScene().fogStart = args.fValue; + wiRenderer::GetScene().weather.fogStart = args.fValue; }); worldWindow->AddWidget(fogStartSlider); @@ -37,7 +37,7 @@ WorldWindow::WorldWindow(wiGUI* gui) : GUI(gui) fogEndSlider->SetSize(XMFLOAT2(100, 30)); fogEndSlider->SetPos(XMFLOAT2(x, y += step)); fogEndSlider->OnSlide([&](wiEventArgs args) { - wiRenderer::GetScene().fogEnd = args.fValue; + wiRenderer::GetScene().weather.fogEnd = args.fValue; }); worldWindow->AddWidget(fogEndSlider); @@ -45,7 +45,7 @@ WorldWindow::WorldWindow(wiGUI* gui) : GUI(gui) fogHeightSlider->SetSize(XMFLOAT2(100, 30)); fogHeightSlider->SetPos(XMFLOAT2(x, y += step)); fogHeightSlider->OnSlide([&](wiEventArgs args) { - wiRenderer::GetScene().fogHeight = args.fValue; + wiRenderer::GetScene().weather.fogHeight = args.fValue; }); worldWindow->AddWidget(fogHeightSlider); @@ -53,7 +53,7 @@ WorldWindow::WorldWindow(wiGUI* gui) : GUI(gui) cloudinessSlider->SetSize(XMFLOAT2(100, 30)); cloudinessSlider->SetPos(XMFLOAT2(x, y += step)); cloudinessSlider->OnSlide([&](wiEventArgs args) { - wiRenderer::GetScene().cloudiness = args.fValue; + wiRenderer::GetScene().weather.cloudiness = args.fValue; }); worldWindow->AddWidget(cloudinessSlider); @@ -61,7 +61,7 @@ WorldWindow::WorldWindow(wiGUI* gui) : GUI(gui) cloudScaleSlider->SetSize(XMFLOAT2(100, 30)); cloudScaleSlider->SetPos(XMFLOAT2(x, y += step)); cloudScaleSlider->OnSlide([&](wiEventArgs args) { - wiRenderer::GetScene().cloudScale = args.fValue; + wiRenderer::GetScene().weather.cloudScale = args.fValue; }); worldWindow->AddWidget(cloudScaleSlider); @@ -69,7 +69,7 @@ WorldWindow::WorldWindow(wiGUI* gui) : GUI(gui) cloudSpeedSlider->SetSize(XMFLOAT2(100, 30)); cloudSpeedSlider->SetPos(XMFLOAT2(x, y += step)); cloudSpeedSlider->OnSlide([&](wiEventArgs args) { - wiRenderer::GetScene().cloudSpeed = args.fValue; + wiRenderer::GetScene().weather.cloudSpeed = args.fValue; }); worldWindow->AddWidget(cloudSpeedSlider); @@ -77,7 +77,7 @@ WorldWindow::WorldWindow(wiGUI* gui) : GUI(gui) windSpeedSlider->SetSize(XMFLOAT2(100, 30)); windSpeedSlider->SetPos(XMFLOAT2(x, y += step)); windSpeedSlider->OnSlide([&](wiEventArgs args) { - wiRenderer::GetScene().windDirection = XMFLOAT3(args.fValue, 0, 0); + wiRenderer::GetScene().weather.windDirection = XMFLOAT3(args.fValue, 0, 0); }); worldWindow->AddWidget(windSpeedSlider); @@ -143,13 +143,13 @@ WorldWindow::WorldWindow(wiGUI* gui) : GUI(gui) Scene& scene = wiRenderer::GetScene(); - scene.ambient = XMFLOAT3(0.1f, 0.1f, 0.1f); - scene.horizon = XMFLOAT3(0.3f, 0.3f, 0.4f); - scene.zenith = XMFLOAT3(0.05f, 0.05f, 0.5f); - scene.cloudiness = 0.4f; - scene.fogStart = 100; - scene.fogEnd = 1000; - scene.fogHeight = 0; + scene.weather.ambient = XMFLOAT3(0.1f, 0.1f, 0.1f); + scene.weather.horizon = XMFLOAT3(0.3f, 0.3f, 0.4f); + scene.weather.zenith = XMFLOAT3(0.05f, 0.05f, 0.5f); + scene.weather.cloudiness = 0.4f; + scene.weather.fogStart = 100; + scene.weather.fogEnd = 1000; + scene.weather.fogHeight = 0; // Also, we invalidate all environment probes to reflect the sky changes. for (size_t i = 0; i < scene.probes.GetCount(); ++i) @@ -168,13 +168,13 @@ WorldWindow::WorldWindow(wiGUI* gui) : GUI(gui) Scene& scene = wiRenderer::GetScene(); - scene.ambient = XMFLOAT3(0.02f, 0.02f, 0.02f); - scene.horizon = XMFLOAT3(0.2f, 0.05f, 0.15f); - scene.zenith = XMFLOAT3(0.4f, 0.05f, 0.1f); - scene.cloudiness = 0.36f; - scene.fogStart = 50; - scene.fogEnd = 600; - scene.fogHeight = 0; + scene.weather.ambient = XMFLOAT3(0.02f, 0.02f, 0.02f); + scene.weather.horizon = XMFLOAT3(0.2f, 0.05f, 0.15f); + scene.weather.zenith = XMFLOAT3(0.4f, 0.05f, 0.1f); + scene.weather.cloudiness = 0.36f; + scene.weather.fogStart = 50; + scene.weather.fogEnd = 600; + scene.weather.fogHeight = 0; // Also, we invalidate all environment probes to reflect the sky changes. for (size_t i = 0; i < scene.probes.GetCount(); ++i) @@ -193,13 +193,13 @@ WorldWindow::WorldWindow(wiGUI* gui) : GUI(gui) Scene& scene = wiRenderer::GetScene(); - scene.ambient = XMFLOAT3(0.1f, 0.1f, 0.1f); - scene.horizon = XMFLOAT3(0.38f, 0.38f, 0.38f); - scene.zenith = XMFLOAT3(0.42f, 0.42f, 0.42f); - scene.cloudiness = 0.75f; - scene.fogStart = 0; - scene.fogEnd = 500; - scene.fogHeight = 0; + scene.weather.ambient = XMFLOAT3(0.1f, 0.1f, 0.1f); + scene.weather.horizon = XMFLOAT3(0.38f, 0.38f, 0.38f); + scene.weather.zenith = XMFLOAT3(0.42f, 0.42f, 0.42f); + scene.weather.cloudiness = 0.75f; + scene.weather.fogStart = 0; + scene.weather.fogEnd = 500; + scene.weather.fogHeight = 0; // Also, we invalidate all environment probes to reflect the sky changes. for (size_t i = 0; i < scene.probes.GetCount(); ++i) @@ -218,13 +218,13 @@ WorldWindow::WorldWindow(wiGUI* gui) : GUI(gui) Scene& scene = wiRenderer::GetScene(); - scene.ambient = XMFLOAT3(0.01f, 0.01f, 0.02f); - scene.horizon = XMFLOAT3(0.02f, 0.05f, 0.1f); - scene.zenith = XMFLOAT3(0.01f, 0.02f, 0.04f); - scene.cloudiness = 0.28f; - scene.fogStart = 10; - scene.fogEnd = 400; - scene.fogHeight = 0; + scene.weather.ambient = XMFLOAT3(0.01f, 0.01f, 0.02f); + scene.weather.horizon = XMFLOAT3(0.02f, 0.05f, 0.1f); + scene.weather.zenith = XMFLOAT3(0.01f, 0.02f, 0.04f); + scene.weather.cloudiness = 0.28f; + scene.weather.fogStart = 10; + scene.weather.fogEnd = 400; + scene.weather.fogHeight = 0; // Also, we invalidate all environment probes to reflect the sky changes. for (size_t i = 0; i < scene.probes.GetCount(); ++i) @@ -311,7 +311,7 @@ WorldWindow::WorldWindow(wiGUI* gui) : GUI(gui) ambientColorPicker->SetVisible(false); ambientColorPicker->SetEnabled(true); ambientColorPicker->OnColorChanged([&](wiEventArgs args) { - wiRenderer::GetScene().ambient = XMFLOAT3(args.color.x, args.color.y, args.color.z); + wiRenderer::GetScene().weather.ambient = XMFLOAT3(args.color.x, args.color.y, args.color.z); }); worldWindow->AddWidget(ambientColorPicker); @@ -322,7 +322,7 @@ WorldWindow::WorldWindow(wiGUI* gui) : GUI(gui) horizonColorPicker->SetVisible(false); horizonColorPicker->SetEnabled(true); horizonColorPicker->OnColorChanged([&](wiEventArgs args) { - wiRenderer::GetScene().horizon = XMFLOAT3(args.color.x, args.color.y, args.color.z); + wiRenderer::GetScene().weather.horizon = XMFLOAT3(args.color.x, args.color.y, args.color.z); }); worldWindow->AddWidget(horizonColorPicker); @@ -334,7 +334,7 @@ WorldWindow::WorldWindow(wiGUI* gui) : GUI(gui) zenithColorPicker->SetVisible(false); zenithColorPicker->SetEnabled(true); zenithColorPicker->OnColorChanged([&](wiEventArgs args) { - wiRenderer::GetScene().zenith = XMFLOAT3(args.color.x, args.color.y, args.color.z); + wiRenderer::GetScene().weather.zenith = XMFLOAT3(args.color.x, args.color.y, args.color.z); }); worldWindow->AddWidget(zenithColorPicker); @@ -355,9 +355,9 @@ WorldWindow::~WorldWindow() void WorldWindow::UpdateFromRenderer() { - auto& w = wiRenderer::GetScene(); + const Scene& scene = wiRenderer::GetScene(); - fogStartSlider->SetValue(w.fogStart); - fogEndSlider->SetValue(w.fogEnd); - fogHeightSlider->SetValue(w.fogHeight); + fogStartSlider->SetValue(scene.weather.fogStart); + fogEndSlider->SetValue(scene.weather.fogEnd); + fogHeightSlider->SetValue(scene.weather.fogHeight); } diff --git a/WickedEngine/Renderable3DComponent.cpp b/WickedEngine/Renderable3DComponent.cpp index bff78bee8..44242c8c5 100644 --- a/WickedEngine/Renderable3DComponent.cpp +++ b/WickedEngine/Renderable3DComponent.cpp @@ -350,7 +350,7 @@ void Renderable3DComponent::RenderSecondaryScene(wiRenderTarget& mainRT, wiRende } wiProfiler::GetInstance().BeginRange("Secondary Scene", wiProfiler::DOMAIN_GPU, threadID); - XMVECTOR sunDirection = XMLoadFloat3(&wiRenderer::GetScene().sunDirection); + XMVECTOR sunDirection = XMLoadFloat3(&wiRenderer::GetScene().weather.sunDirection); if (getLightShaftsEnabled() && XMVectorGetX(XMVector3Dot(sunDirection, wiRenderer::GetCamera().GetAt())) > 0) { wiRenderer::GetDevice()->EventBegin("Light Shafts", threadID); diff --git a/WickedEngine/ShaderInterop_Renderer.h b/WickedEngine/ShaderInterop_Renderer.h new file mode 100644 index 000000000..3d96e3090 --- /dev/null +++ b/WickedEngine/ShaderInterop_Renderer.h @@ -0,0 +1,176 @@ +#ifndef _SHADERINTEROP_RENDERER_H_ +#define _SHADERINTEROP_RENDERER_H_ +#include "ShaderInterop.h" + +// ---------- Persistent: ----------------- + +CBUFFER(WorldCB, CBSLOT_RENDERER_WORLD) +{ + float2 g_xWorld_ScreenWidthHeight; + float2 g_xWorld_ScreenWidthHeight_Inverse; + + float2 g_xWorld_InternalResolution; + float2 g_xWorld_InternalResolution_Inverse; + + float g_xWorld_Gamma; + float3 g_xWorld_SunColor; + + float3 g_xWorld_SunDirection; float pad0_WorldCB; + + float3 g_xWorld_Horizon; float pad1_WorldCB; + + float3 g_xWorld_Zenith; + float g_xWorld_CloudScale; + + float3 g_xWorld_Ambient; + float g_xWorld_Cloudiness; + + float3 g_xWorld_Fog; // Fog Start,End,Height + float g_xWorld_SpecularAA; + + float g_xWorld_VoxelRadianceDataSize; // voxel half-extent in world space units + float g_xWorld_VoxelRadianceDataSize_Inverse; // 1.0 / voxel-half extent + uint g_xWorld_VoxelRadianceDataRes; // voxel grid resolution + float g_xWorld_VoxelRadianceDataRes_Inverse; // 1.0 / voxel grid resolution + + uint g_xWorld_VoxelRadianceDataMIPs; // voxel grid mipmap count + uint g_xWorld_VoxelRadianceNumCones; // number of diffuse cones to trace + float g_xWorld_VoxelRadianceNumCones_Inverse; // 1.0 / number of diffuse cones to trace + float g_xWorld_VoxelRadianceRayStepSize; // raymarch step size in voxel space units + + uint g_xWorld_VoxelRadianceReflectionsEnabled; // are voxel gi reflections enabled or not + float3 g_xWorld_VoxelRadianceDataCenter; // center of the voxel grid in world space units + + uint g_xWorld_AdvancedRefractions; + uint3 g_xWorld_EntityCullingTileCount; + + uint g_xWorld_TransparentShadowsEnabled; + int g_xWorld_GlobalEnvProbeIndex; + uint g_xWorld_EnvProbeMipCount; + float g_xWorld_EnvProbeMipCount_Inverse; +}; + +CBUFFER(FrameCB, CBSLOT_RENDERER_FRAME) +{ + float g_xFrame_Time; + float g_xFrame_TimePrev; + float g_xFrame_DeltaTime; + uint g_xFrame_FrameCount; + + uint g_xFrame_LightArrayOffset; // indexing into entity array + uint g_xFrame_LightArrayCount; // indexing into entity array + uint g_xFrame_DecalArrayOffset; // indexing into entity array + uint g_xFrame_DecalArrayCount; // indexing into entity array + + uint g_xFrame_ForceFieldArrayOffset; // indexing into entity array + uint g_xFrame_ForceFieldArrayCount; // indexing into entity array + uint g_xFrame_EnvProbeArrayOffset; // indexing into entity array + uint g_xFrame_EnvProbeArrayCount; // indexing into entity array + + float3 g_xFrame_WindDirection; + float g_xFrame_WindWaveSize; + + float g_xFrame_WindRandomness; + float pad0_FrameCB; + uint g_xFrame_VoxelRadianceRetargetted; + uint g_xFrame_TemporalAASampleRotation; + + float2 g_xFrame_TemporalAAJitter; + float2 g_xFrame_TemporalAAJitterPrev; + + // The following are per frame properties for the main camera: + float4x4 g_xFrame_MainCamera_VP; // View*Projection + float4x4 g_xFrame_MainCamera_View; + float4x4 g_xFrame_MainCamera_Proj; + + float3 g_xFrame_MainCamera_CamPos; + float g_xFrame_MainCamera_DistanceFromOrigin; + + float4x4 g_xFrame_MainCamera_PrevV; + float4x4 g_xFrame_MainCamera_PrevP; + float4x4 g_xFrame_MainCamera_PrevVP; // PrevView*PrevProjection + float4x4 g_xFrame_MainCamera_PrevInvVP; // Inverse(PrevView*PrevProjection) + float4x4 g_xFrame_MainCamera_ReflVP; // ReflectionView*ReflectionProjection + float4x4 g_xFrame_MainCamera_InvV; // Inverse View + float4x4 g_xFrame_MainCamera_InvP; // Inverse Projection + float4x4 g_xFrame_MainCamera_InvVP; // Inverse View-Projection + + float3 g_xFrame_MainCamera_At; + float g_xFrame_MainCamera_ZNearP; + + float3 g_xFrame_MainCamera_Up; + float g_xFrame_MainCamera_ZFarP; + + float g_xFrame_MainCamera_ZNearP_Recip; + float g_xFrame_MainCamera_ZFarP_Recip; + float g_xFrame_MainCamera_ZRange; + float g_xFrame_MainCamera_ZRange_Recip; + + float4 g_xFrame_FrustumPlanesWS[6]; // Frustum planes in world space in order: left,right,top,bottom,near,far + + float3 g_xFrame_WorldBoundsMin; float pad0_frameCB; // world enclosing AABB min + float3 g_xFrame_WorldBoundsMax; float pad1_frameCB; // world enclosing AABB max + float3 g_xFrame_WorldBoundsExtents; float pad2_frameCB; // world enclosing AABB abs(max - min) + float3 g_xFrame_WorldBoundsExtents_Inverse; float pad3_frameCB; // world enclosing AABB 1.0f / abs(max - min) +}; +// The following buffer contains properties for a temporary camera (eg. main camera, reflection camera, shadow camera...) +CBUFFER(CameraCB, CBSLOT_RENDERER_CAMERA) +{ + float4x4 g_xCamera_VP; // View*Projection + float4x4 g_xCamera_View; + float4x4 g_xCamera_Proj; + float3 g_xCamera_CamPos; float xPadding0_Camera_CommonCB; +}; +CBUFFER(MiscCB, CBSLOT_RENDERER_MISC) +{ + float4x4 g_xTransform; + float4 g_xColor; +}; + +CBUFFER(APICB, CBSLOT_API) +{ + float4 g_xClipPlane; + float g_xAlphaRef; + float3 g_xPadding0_APICB; +}; + + + + +// ------- On demand: ---------- + +CBUFFER(DecalCB, CBSLOT_RENDERER_DECAL) +{ + float4x4 xDecalVP; + int hasTexNor; + float3 eye; + float opacity; + float3 front; +}; + +CBUFFER(VolumeLightCB, CBSLOT_RENDERER_VOLUMELIGHT) +{ + float4x4 lightWorld; + float4 lightColor; + float4 lightEnerdis; +}; + +CBUFFER(CubemapRenderCB, CBSLOT_RENDERER_CUBEMAPRENDER) +{ + float4x4 xCubeShadowVP[6]; +}; + +CBUFFER(TessellationCB, CBSLOT_RENDERER_TESSELLATION) +{ + float4 g_f4TessFactors; +}; + +CBUFFER(DispatchParamsCB, CBSLOT_RENDERER_DISPATCHPARAMS) +{ + uint3 xDispatchParams_numThreadGroups; + uint xDispatchParams_value0; + uint3 xDispatchParams_numThreads; + uint xDispatchParams_value1; +}; + +#endif // _SHADERINTEROP_RENDERER_H_ diff --git a/WickedEngine/WickedEngine_SHARED.vcxitems b/WickedEngine/WickedEngine_SHARED.vcxitems index f3e80a520..3a6c6f1d8 100644 --- a/WickedEngine/WickedEngine_SHARED.vcxitems +++ b/WickedEngine/WickedEngine_SHARED.vcxitems @@ -235,6 +235,7 @@ + diff --git a/WickedEngine/WickedEngine_SHARED.vcxitems.filters b/WickedEngine/WickedEngine_SHARED.vcxitems.filters index 42a20c67c..1460f8f2c 100644 --- a/WickedEngine/WickedEngine_SHARED.vcxitems.filters +++ b/WickedEngine/WickedEngine_SHARED.vcxitems.filters @@ -1137,6 +1137,9 @@ ENGINE\Scripting\LuaBindings + + ENGINE\Graphics\GPUMapping + diff --git a/WickedEngine/cubeShadowGS.hlsl b/WickedEngine/cubeShadowGS.hlsl index dd5bd8b78..2b5a8fb32 100644 --- a/WickedEngine/cubeShadowGS.hlsl +++ b/WickedEngine/cubeShadowGS.hlsl @@ -12,11 +12,6 @@ struct PS_CUBEMAP_IN }; -CBUFFER(CubemapRenderCB, CBSLOT_RENDERER_CUBEMAPRENDER) -{ - float4x4 xCubeShadowVP[6]; -} - [maxvertexcount(18)] void main( triangle GS_CUBEMAP_IN input[3], inout TriangleStream CubeMapStream ) { diff --git a/WickedEngine/cubeShadowGS_alphatest.hlsl b/WickedEngine/cubeShadowGS_alphatest.hlsl index ca1d39522..23a3d6239 100644 --- a/WickedEngine/cubeShadowGS_alphatest.hlsl +++ b/WickedEngine/cubeShadowGS_alphatest.hlsl @@ -13,12 +13,6 @@ struct PS_CUBEMAP_IN uint RTIndex : SV_RenderTargetArrayIndex; }; - -CBUFFER(CubemapRenderCB, CBSLOT_RENDERER_CUBEMAPRENDER) -{ - float4x4 xCubeShadowVP[6]; -} - [maxvertexcount(18)] void main(triangle GS_CUBEMAP_IN input[3], inout TriangleStream CubeMapStream) { diff --git a/WickedEngine/decalPS.hlsl b/WickedEngine/decalPS.hlsl index e00ef1be2..a9df6816e 100644 --- a/WickedEngine/decalPS.hlsl +++ b/WickedEngine/decalPS.hlsl @@ -1,13 +1,8 @@ +#include "globals.hlsli" #include "reconstructPositionHF.hlsli" #include "tangentComputeHF.hlsli" #include "packHF.hlsli" -//Texture2D xSceneDepthMap:register(t1); -//Texture2D xTexture:register(t2); -//Texture2D xNormal:register(t3); - -// texture_0 : texture map -// texture_1 : normal map struct VertexToPixel{ float4 pos : SV_POSITION; @@ -19,15 +14,6 @@ struct PixelOutputType //float4 nor : SV_TARGET1; }; -CBUFFER(DecalCB, CBSLOT_RENDERER_DECAL) -{ - float4x4 xDecalVP; - int hasTexNor; - float3 eye; - float opacity; - float3 front; -} - PixelOutputType main(VertexToPixel PSIn) { PixelOutputType Out = (PixelOutputType)0; diff --git a/WickedEngine/envMapGS.hlsl b/WickedEngine/envMapGS.hlsl index 78b911f68..76380b221 100644 --- a/WickedEngine/envMapGS.hlsl +++ b/WickedEngine/envMapGS.hlsl @@ -1,10 +1,5 @@ #include "envMapHF.hlsli" -CBUFFER(CubemapRenderCB, CBSLOT_RENDERER_CUBEMAPRENDER) -{ - float4x4 xCubeShadowVP[6]; -} - [maxvertexcount(18)] void main(triangle VSOut_EnvmapRendering input[3], inout TriangleStream CubeMapStream) { diff --git a/WickedEngine/envMap_skyGS.hlsl b/WickedEngine/envMap_skyGS.hlsl index 7a40fabdd..52f9f371d 100644 --- a/WickedEngine/envMap_skyGS.hlsl +++ b/WickedEngine/envMap_skyGS.hlsl @@ -1,10 +1,5 @@ #include "envMapHF.hlsli" -CBUFFER(CubemapRenderCB, CBSLOT_RENDERER_CUBEMAPRENDER) -{ - float4x4 xCubeShadowVP[6]; -} - [maxvertexcount(18)] void main(triangle VSOut_Sky_EnvmapRendering input[3], inout TriangleStream< PSIn_Sky_EnvmapRendering > CubeMapStream) { diff --git a/WickedEngine/globals.hlsli b/WickedEngine/globals.hlsli index 669c852d2..e3e5da95e 100644 --- a/WickedEngine/globals.hlsli +++ b/WickedEngine/globals.hlsli @@ -1,6 +1,7 @@ #ifndef _SHADER_GLOBALS_ #define _SHADER_GLOBALS_ #include "ShaderInterop.h" +#include "ShaderInterop_Renderer.h" TEXTURE2D(texture_depth, float, TEXSLOT_DEPTH) TEXTURE2D(texture_lineardepth, float, TEXSLOT_LINEARDEPTH) @@ -44,108 +45,6 @@ SAMPLERSTATE( sampler_aniso_mirror, SSLOT_ANISO_MIRROR ) SAMPLERCOMPARISONSTATE( sampler_cmp_depth, SSLOT_CMP_DEPTH ) SAMPLERSTATE( sampler_objectshader, SSLOT_OBJECTSHADER ) -CBUFFER(WorldCB, CBSLOT_RENDERER_WORLD) -{ - float2 g_xWorld_ScreenWidthHeight; - float2 g_xWorld_ScreenWidthHeight_Inverse; - float2 g_xWorld_InternalResolution; - float2 g_xWorld_InternalResolution_Inverse; - float g_xWorld_Gamma; - float3 g_xWorld_Horizon; - float3 g_xWorld_Zenith; - float g_xWorld_CloudScale; - float3 g_xWorld_Ambient; - float g_xWorld_Cloudiness; - float3 g_xWorld_Fog; // Fog Start,End,Height - float g_xWorld_SpecularAA; - float g_xWorld_VoxelRadianceDataSize; // voxel half-extent in world space units - float g_xWorld_VoxelRadianceDataSize_Inverse; // 1.0 / voxel-half extent - uint g_xWorld_VoxelRadianceDataRes; // voxel grid resolution - float g_xWorld_VoxelRadianceDataRes_Inverse; // 1.0 / voxel grid resolution - uint g_xWorld_VoxelRadianceDataMIPs; // voxel grid mipmap count - uint g_xWorld_VoxelRadianceNumCones; // number of diffuse cones to trace - float g_xWorld_VoxelRadianceNumCones_Inverse; // 1.0 / number of diffuse cones to trace - float g_xWorld_VoxelRadianceRayStepSize; // raymarch step size in voxel space units - bool g_xWorld_VoxelRadianceReflectionsEnabled; // are voxel gi reflections enabled or not - float3 g_xWorld_VoxelRadianceDataCenter; // center of the voxel grid in world space units - bool g_xWorld_AdvancedRefractions; - uint3 g_xWorld_EntityCullingTileCount; - uint g_xWorld_TransparentShadowsEnabled; - int g_xWorld_GlobalEnvProbeIndex; - uint g_xWorld_EnvProbeMipCount; - float g_xWorld_EnvProbeMipCount_Inverse; -}; -CBUFFER(FrameCB, CBSLOT_RENDERER_FRAME) -{ - float g_xFrame_Time; - float g_xFrame_TimePrev; - float g_xFrame_DeltaTime; - uint g_xFrame_FrameCount; - uint g_xFrame_LightArrayOffset; // indexing into entity array - uint g_xFrame_LightArrayCount; // indexing into entity array - uint g_xFrame_DecalArrayOffset; // indexing into entity array - uint g_xFrame_DecalArrayCount; // indexing into entity array - uint g_xFrame_ForceFieldArrayOffset; // indexing into entity array - uint g_xFrame_ForceFieldArrayCount; // indexing into entity array - uint g_xFrame_EnvProbeArrayOffset; // indexing into entity array - uint g_xFrame_EnvProbeArrayCount; // indexing into entity array - float3 g_xFrame_WindDirection; - float g_xFrame_WindWaveSize; - float g_xFrame_WindRandomness; - int g_xFrame_SunEntityArrayIndex; - bool g_xFrame_VoxelRadianceRetargetted; - uint g_xFrame_TemporalAASampleRotation; - float2 g_xFrame_TemporalAAJitter; - float2 g_xFrame_TemporalAAJitterPrev; - // The following are per frame properties for the main camera: - float4x4 g_xFrame_MainCamera_VP; // View*Projection - float4x4 g_xFrame_MainCamera_View; - float4x4 g_xFrame_MainCamera_Proj; - float3 g_xFrame_MainCamera_CamPos; - float g_xFrame_MainCamera_DistanceFromOrigin; - float4x4 g_xFrame_MainCamera_PrevV; - float4x4 g_xFrame_MainCamera_PrevP; - float4x4 g_xFrame_MainCamera_PrevVP; // PrevView*PrevProjection - float4x4 g_xFrame_MainCamera_PrevInvVP; // Inverse(PrevView*PrevProjection) - float4x4 g_xFrame_MainCamera_ReflVP; // ReflectionView*ReflectionProjection - float4x4 g_xFrame_MainCamera_InvV; // Inverse View - float4x4 g_xFrame_MainCamera_InvP; // Inverse Projection - float4x4 g_xFrame_MainCamera_InvVP; // Inverse View-Projection - float3 g_xFrame_MainCamera_At; - float g_xFrame_MainCamera_ZNearP; - float3 g_xFrame_MainCamera_Up; - float g_xFrame_MainCamera_ZFarP; - float g_xFrame_MainCamera_ZNearP_Recip; - float g_xFrame_MainCamera_ZFarP_Recip; - float g_xFrame_MainCamera_ZRange; - float g_xFrame_MainCamera_ZRange_Recip; - float4 g_xFrame_FrustumPlanesWS[6]; // Frustum planes in world space in order: left,right,top,bottom,near,far - float3 g_xFrame_WorldBoundsMin; float pad0_frameCB; // world enclosing AABB min - float3 g_xFrame_WorldBoundsMax; float pad1_frameCB; // world enclosing AABB max - float3 g_xFrame_WorldBoundsExtents; float pad2_frameCB; // world enclosing AABB abs(max - min) - float3 g_xFrame_WorldBoundsExtents_Inverse; float pad3_frameCB; // world enclosing AABB 1.0f / abs(max - min) -}; -// The following buffer contains properties for a temporary camera (eg. main camera, reflection camera, shadow camera...) -CBUFFER(Camera_CommonCB, CBSLOT_RENDERER_CAMERA) -{ - float4x4 g_xCamera_VP; // View*Projection - float4x4 g_xCamera_View; - float4x4 g_xCamera_Proj; - float3 g_xCamera_CamPos; float xPadding0_Camera_CommonCB; -}; -CBUFFER(MiscCB, CBSLOT_RENDERER_MISC) -{ - float4x4 g_xTransform; - float4 g_xColor; -}; - -CBUFFER(APICB, CBSLOT_API) -{ - float4 g_xClipPlane; - float g_xAlphaRef; - float3 g_xPadding0_APICB; -}; - static const float PI = 3.14159265358979323846; static const float SQRT2 = 1.41421356237309504880; @@ -160,6 +59,8 @@ static const float SQRT2 = 1.41421356237309504880; #define DEGAMMA(x) pow(abs(x),g_xWorld_Gamma) #define GAMMA(x) pow(abs(x),1.0/g_xWorld_Gamma) +inline float3 GetSunColor() { return g_xWorld_SunColor; } +inline float3 GetSunDirection() { return g_xWorld_SunDirection; } inline float3 GetHorizonColor() { return g_xWorld_Horizon.rgb; } inline float3 GetZenithColor() { return g_xWorld_Zenith.rgb; } inline float3 GetAmbientColor() { return g_xWorld_Ambient.rgb; } diff --git a/WickedEngine/lightCullingCS.hlsl b/WickedEngine/lightCullingCS.hlsl index de0eb6369..cca92165b 100644 --- a/WickedEngine/lightCullingCS.hlsl +++ b/WickedEngine/lightCullingCS.hlsl @@ -6,14 +6,6 @@ #define xSSR texture_9 -CBUFFER(DispatchParams, CBSLOT_RENDERER_DISPATCHPARAMS) -{ - uint3 xDispatchParams_numThreadGroups; - uint xDispatchParams_value0; - uint3 xDispatchParams_numThreads; - uint xDispatchParams_value1; -} - #ifdef DEBUG_TILEDLIGHTCULLING RWTEXTURE2D(DebugTexture, unorm float4, UAVSLOT_DEBUGTEXTURE); #endif diff --git a/WickedEngine/lightingHF.hlsli b/WickedEngine/lightingHF.hlsli index 2421f5a04..2c72b3a3f 100644 --- a/WickedEngine/lightingHF.hlsli +++ b/WickedEngine/lightingHF.hlsli @@ -4,15 +4,6 @@ #include "brdf.hlsli" #include "voxelConeTracingHF.hlsli" -inline float3 GetSunColor() -{ - return EntityArray[g_xFrame_SunEntityArrayIndex].GetColor().rgb * EntityArray[g_xFrame_SunEntityArrayIndex].energy; -} -inline float3 GetSunDirection() -{ - return EntityArray[g_xFrame_SunEntityArrayIndex].directionWS; -} - struct LightingResult { float3 diffuse; diff --git a/WickedEngine/objectHS.hlsl b/WickedEngine/objectHS.hlsl index 41d738dde..c6333ecef 100644 --- a/WickedEngine/objectHS.hlsl +++ b/WickedEngine/objectHS.hlsl @@ -2,11 +2,6 @@ #define g_f4Eye g_xCamera_CamPos -CBUFFER(TessellationCB, CBSLOT_RENDERER_TESSELLATION) -{ - float4 g_f4TessFactors; -}; - struct HullInputType { float3 f3Position : POSITION; diff --git a/WickedEngine/tileFrustumsCS.hlsl b/WickedEngine/tileFrustumsCS.hlsl index f88d74396..86b36e76c 100644 --- a/WickedEngine/tileFrustumsCS.hlsl +++ b/WickedEngine/tileFrustumsCS.hlsl @@ -1,14 +1,6 @@ #include "globals.hlsli" #include "cullingShaderHF.hlsli" -CBUFFER(DispatchParams, CBSLOT_RENDERER_DISPATCHPARAMS) -{ - uint3 xDispatchParams_numThreadGroups; - uint xDispatchParams_value0; - uint3 xDispatchParams_numThreads; - uint xDispatchParams_value1; -} - // View space frustums for the grid cells. RWSTRUCTUREDBUFFER(out_Frustums, Frustum, UAVSLOT_TILEFRUSTUMS); diff --git a/WickedEngine/volumeLightHF.hlsli b/WickedEngine/volumeLightHF.hlsli index feb4d26ee..a19d29329 100644 --- a/WickedEngine/volumeLightHF.hlsli +++ b/WickedEngine/volumeLightHF.hlsli @@ -7,11 +7,4 @@ struct VertexToPixel{ float4 col : COLOR; }; -CBUFFER(VolumeLightCB, CBSLOT_RENDERER_VOLUMELIGHT) -{ - float4x4 lightWorld; - float4 lightColor; - float4 lightEnerdis; -}; - #endif // _VOLUMELIGHT_HF_ \ No newline at end of file diff --git a/WickedEngine/wiECS.h b/WickedEngine/wiECS.h index 74aec5b86..c2b6680f2 100644 --- a/WickedEngine/wiECS.h +++ b/WickedEngine/wiECS.h @@ -89,7 +89,8 @@ namespace wiECS // Read/Write everything to an archive depending on the archive state // seed: needed when serializing from disk which might cause discrepancy in entity uniqueness - inline void Serialize(wiArchive& archive, uint32_t seed = 0) + // propagateSeedDeep: Components can have Entity references inside them, should the seed be propageted to those too? + inline void Serialize(wiArchive& archive, uint32_t seed = 0, bool propagateSeedDeep = true) { if (archive.IsReadMode()) { @@ -101,7 +102,7 @@ namespace wiECS components.resize(count); for (size_t i = 0; i < count; ++i) { - components[i].Serialize(archive, seed); + components[i].Serialize(archive, propagateSeedDeep ? seed : 0); } entities.resize(count); diff --git a/WickedEngine/wiFont.cpp b/WickedEngine/wiFont.cpp index 54d7f1316..70c6ec814 100644 --- a/WickedEngine/wiFont.cpp +++ b/WickedEngine/wiFont.cpp @@ -3,6 +3,7 @@ #include "wiResourceManager.h" #include "wiHelper.h" #include "ResourceMapping.h" +#include "ShaderInterop_Renderer.h" #include #include @@ -314,27 +315,27 @@ void wiFont::Draw(GRAPHICSTHREAD threadID) device->BindResource(PS, fontStyles[style].texture, TEXSLOT_ONDEMAND1, threadID); - wiRenderer::MiscCB cb; + MiscCB cb; if (newProps.shadowColor.a > 0) { // font shadow render: - cb.mTransform = XMMatrixTranspose( + XMStoreFloat4x4(&cb.g_xTransform, XMMatrixTranspose( XMMatrixTranslation((float)newProps.posX + 1, (float)newProps.posY + 1, 0) * device->GetScreenProjection() - ); - cb.mColor = XMFLOAT4(newProps.shadowColor.R, newProps.shadowColor.G, newProps.shadowColor.B, newProps.shadowColor.A); + )); + cb.g_xColor = float4(newProps.shadowColor.R, newProps.shadowColor.G, newProps.shadowColor.B, newProps.shadowColor.A); device->UpdateBuffer(wiRenderer::constantBuffers[CBTYPE_MISC], &cb, threadID); device->DrawIndexed((int)text.length() * 6, 0, 0, threadID); } // font base render: - cb.mTransform = XMMatrixTranspose( + XMStoreFloat4x4(&cb.g_xTransform, XMMatrixTranspose( XMMatrixTranslation((float)newProps.posX, (float)newProps.posY, 0) * device->GetScreenProjection() - ); - cb.mColor = XMFLOAT4(newProps.color.R, newProps.color.G, newProps.color.B, newProps.color.A); + )); + cb.g_xColor = float4(newProps.color.R, newProps.color.G, newProps.color.B, newProps.color.A); device->UpdateBuffer(wiRenderer::constantBuffers[CBTYPE_MISC], &cb, threadID); device->DrawIndexed((int)text.length() * 6, 0, 0, threadID); diff --git a/WickedEngine/wiRenderer.cpp b/WickedEngine/wiRenderer.cpp index bca2a2279..75869ce85 100644 --- a/WickedEngine/wiRenderer.cpp +++ b/WickedEngine/wiRenderer.cpp @@ -21,6 +21,7 @@ #include "wiBackLog.h" #include "wiProfiler.h" #include "wiOcean.h" +#include "ShaderInterop_Renderer.h" #include "ShaderInterop_CloudGenerator.h" #include "ShaderInterop_Skinning.h" #include "ShaderInterop_TracedRendering.h" @@ -709,7 +710,7 @@ void wiRenderer::LoadBuffers() bd.ByteWidth = sizeof(DecalCB); GetDevice()->CreateBuffer(&bd, nullptr, constantBuffers[CBTYPE_DECAL]); - bd.ByteWidth = sizeof(CubeMapRenderCB); + bd.ByteWidth = sizeof(CubemapRenderCB); GetDevice()->CreateBuffer(&bd, nullptr, constantBuffers[CBTYPE_CUBEMAPRENDER]); bd.ByteWidth = sizeof(TessellationCB); @@ -3497,7 +3498,7 @@ void wiRenderer::UpdateRenderData(GRAPHICSTHREAD threadID) } // Generate cloud layer: - if(enviroMap == nullptr && GetScene().cloudiness > 0) // generate only when sky is dynamic + if(enviroMap == nullptr && scene.weather.cloudiness > 0) // generate only when sky is dynamic { if (textures[TEXTYPE_2D_CLOUDS] == nullptr) { @@ -3515,7 +3516,7 @@ void wiRenderer::UpdateRenderData(GRAPHICSTHREAD threadID) device->CreateTexture2D(&desc, nullptr, (Texture2D**)&textures[TEXTYPE_2D_CLOUDS]); } - float cloudPhase = renderTime * GetScene().cloudSpeed; + float cloudPhase = renderTime * scene.weather.cloudSpeed; GenerateClouds((Texture2D*)textures[TEXTYPE_2D_CLOUDS], 5, cloudPhase, GRAPHICSTHREAD_IMMEDIATE); } @@ -3582,7 +3583,7 @@ void wiRenderer::OcclusionCulling_Render(GRAPHICSTHREAD threadID) queryID++; // previous frame view*projection because these are drawn against the previous depth buffer: - cb.mTransform = XMMatrixTranspose(aabb.getAsBoxMatrix()*GetPrevCamera().GetViewProjection()); // todo: obb + XMStoreFloat4x4(&cb.g_xTransform, XMMatrixTranspose(aabb.getAsBoxMatrix()*GetPrevCamera().GetViewProjection())); // todo: obb GetDevice()->UpdateBuffer(constantBuffers[CBTYPE_MISC], &cb, threadID); // render bounding box to later read the occlusion status @@ -3699,8 +3700,8 @@ void wiRenderer::DrawDebugWorld(const CameraComponent& camera, GRAPHICSTHREAD th device->BindGraphicsPSO(PSO_debug[DEBUGRENDERING_LINES], threadID); MiscCB sb; - sb.mTransform = XMMatrixTranspose(camera.GetViewProjection()); - sb.mColor = XMFLOAT4(1, 1, 1, 1); + XMStoreFloat4x4(&sb.g_xTransform, XMMatrixTranspose(camera.GetViewProjection())); + sb.g_xColor = XMFLOAT4(1, 1, 1, 1); device->UpdateBuffer(constantBuffers[CBTYPE_MISC], &sb, threadID); for (size_t i = 0; i < scene.armatures.GetCount(); ++i) @@ -3767,8 +3768,8 @@ void wiRenderer::DrawDebugWorld(const CameraComponent& camera, GRAPHICSTHREAD th device->BindGraphicsPSO(PSO_debug[DEBUGRENDERING_LINES], threadID); MiscCB sb; - sb.mTransform = XMMatrixTranspose(camera.GetViewProjection()); - sb.mColor = XMFLOAT4(1, 1, 1, 1); + XMStoreFloat4x4(&sb.g_xTransform, XMMatrixTranspose(camera.GetViewProjection())); + sb.g_xColor = XMFLOAT4(1, 1, 1, 1); device->UpdateBuffer(constantBuffers[CBTYPE_MISC], &sb, threadID); struct LineSegment @@ -3829,8 +3830,8 @@ void wiRenderer::DrawDebugWorld(const CameraComponent& camera, GRAPHICSTHREAD th for (auto& x : renderableBoxes) { - sb.mTransform = XMMatrixTranspose(XMLoadFloat4x4(&x.first)*camera.GetViewProjection()); - sb.mColor = x.second; + XMStoreFloat4x4(&sb.g_xTransform, XMMatrixTranspose(XMLoadFloat4x4(&x.first)*camera.GetViewProjection())); + sb.g_xColor = x.second; device->UpdateBuffer(constantBuffers[CBTYPE_MISC], &sb, threadID); @@ -3854,7 +3855,7 @@ void wiRenderer::DrawDebugWorld(const CameraComponent& camera, GRAPHICSTHREAD th { EnvironmentProbeComponent& probe = scene.probes[i]; - sb.mTransform = XMMatrixTranspose(XMMatrixTranslationFromVector(XMLoadFloat3(&probe.position))); + XMStoreFloat4x4(&sb.g_xTransform, XMMatrixTranspose(XMMatrixTranslationFromVector(XMLoadFloat3(&probe.position)))); device->UpdateBuffer(constantBuffers[CBTYPE_MISC], &sb, threadID); if (probe.textureIndex < 0) @@ -3895,8 +3896,8 @@ void wiRenderer::DrawDebugWorld(const CameraComponent& camera, GRAPHICSTHREAD th Entity entity = scene.probes.GetEntity(i); const TransformComponent& transform = *scene.transforms.GetComponent(entity); - sb.mTransform = XMMatrixTranspose(XMLoadFloat4x4(&transform.world)*camera.GetViewProjection()); - sb.mColor = XMFLOAT4(0, 1, 1, 1); + XMStoreFloat4x4(&sb.g_xTransform , XMMatrixTranspose(XMLoadFloat4x4(&transform.world)*camera.GetViewProjection())); + sb.g_xColor = float4(0, 1, 1, 1); device->UpdateBuffer(constantBuffers[CBTYPE_MISC], &sb, threadID); @@ -3956,8 +3957,8 @@ void wiRenderer::DrawDebugWorld(const CameraComponent& camera, GRAPHICSTHREAD th } MiscCB sb; - sb.mTransform = XMMatrixTranspose(camera.GetViewProjection()); - sb.mColor = XMFLOAT4(1, 1, 1, 1); + XMStoreFloat4x4(&sb.g_xTransform, XMMatrixTranspose(camera.GetViewProjection())); + sb.g_xColor = float4(1, 1, 1, 1); device->UpdateBuffer(constantBuffers[CBTYPE_MISC], &sb, threadID); @@ -3981,8 +3982,8 @@ void wiRenderer::DrawDebugWorld(const CameraComponent& camera, GRAPHICSTHREAD th MiscCB sb; - sb.mTransform = XMMatrixTranspose(XMMatrixTranslationFromVector(XMLoadFloat3(&voxelSceneData.center)) * camera.GetViewProjection()); - sb.mColor = XMFLOAT4(1, 1, 1, 1); + XMStoreFloat4x4(&sb.g_xTransform, XMMatrixTranspose(XMMatrixTranslationFromVector(XMLoadFloat3(&voxelSceneData.center)) * camera.GetViewProjection())); + sb.g_xColor = float4(1, 1, 1, 1); device->UpdateBuffer(constantBuffers[CBTYPE_MISC], &sb, threadID); @@ -4003,8 +4004,8 @@ void wiRenderer::DrawDebugWorld(const CameraComponent& camera, GRAPHICSTHREAD th const TransformComponent& transform = *scene.transforms.GetComponent(entity); const MeshComponent* mesh = scene.meshes.GetComponent(emitter.meshID); - sb.mTransform = XMMatrixTranspose(XMLoadFloat4x4(&transform.world)*camera.GetViewProjection()); - sb.mColor = XMFLOAT4(0, 1, 0, 1); + XMStoreFloat4x4(&sb.g_xTransform, XMMatrixTranspose(XMLoadFloat4x4(&transform.world)*camera.GetViewProjection())); + sb.g_xColor = float4(0, 1, 0, 1); device->UpdateBuffer(constantBuffers[CBTYPE_MISC], &sb, threadID); if (mesh == nullptr) @@ -4051,8 +4052,8 @@ void wiRenderer::DrawDebugWorld(const CameraComponent& camera, GRAPHICSTHREAD th { ForceFieldComponent& force = scene.forces[i]; - sb.mTransform = XMMatrixTranspose(camera.GetViewProjection()); - sb.mColor = XMFLOAT4(camera.Eye.x, camera.Eye.y, camera.Eye.z, (float)i); + XMStoreFloat4x4(&sb.g_xTransform, XMMatrixTranspose(camera.GetViewProjection())); + sb.g_xColor = XMFLOAT4(camera.Eye.x, camera.Eye.y, camera.Eye.z, (float)i); device->UpdateBuffer(constantBuffers[CBTYPE_MISC], &sb, threadID); switch (force.type) @@ -4090,14 +4091,14 @@ void wiRenderer::DrawDebugWorld(const CameraComponent& camera, GRAPHICSTHREAD th device->BindIndexBuffer(&Cube::indexBuffer, INDEXFORMAT_16BIT, 0, threadID); MiscCB sb; - sb.mColor = XMFLOAT4(1, 1, 1, 1); + sb.g_xColor = XMFLOAT4(1, 1, 1, 1); for(size_t i = 0; i < scene.cameras.GetCount(); ++i) { const CameraComponent& cam = scene.cameras[i]; Entity entity = scene.cameras.GetEntity(i); - sb.mTransform = XMMatrixTranspose(cam.GetInvView()*camera.GetViewProjection()); + XMStoreFloat4x4(&sb.g_xTransform, XMMatrixTranspose(cam.GetInvView()*camera.GetViewProjection())); device->UpdateBuffer(constantBuffers[CBTYPE_MISC], &sb, threadID); @@ -4260,7 +4261,7 @@ void wiRenderer::DrawLights(const CameraComponent& camera, GRAPHICSTHREAD thread case LightComponent::TUBE: { MiscCB miscCb; - miscCb.mColor.x = (float)light.entityArray_index; + miscCb.g_xColor.x = (float)light.entityArray_index; GetDevice()->UpdateBuffer(constantBuffers[CBTYPE_MISC], &miscCb, threadID); GetDevice()->Draw(3, 0, threadID); // full screen triangle @@ -4269,9 +4270,9 @@ void wiRenderer::DrawLights(const CameraComponent& camera, GRAPHICSTHREAD thread case LightComponent::POINT: { MiscCB miscCb; - miscCb.mColor.x = (float)light.entityArray_index; + miscCb.g_xColor.x = (float)light.entityArray_index; float sca = light.range + 1; - miscCb.mTransform = XMMatrixTranspose(XMMatrixScaling(sca, sca, sca)*XMMatrixTranslationFromVector(XMLoadFloat3(&light.position)) * camera.GetViewProjection()); + XMStoreFloat4x4(&miscCb.g_xTransform, XMMatrixTranspose(XMMatrixScaling(sca, sca, sca)*XMMatrixTranslationFromVector(XMLoadFloat3(&light.position)) * camera.GetViewProjection())); GetDevice()->UpdateBuffer(constantBuffers[CBTYPE_MISC], &miscCb, threadID); GetDevice()->Draw(240, 0, threadID); // icosphere @@ -4280,14 +4281,14 @@ void wiRenderer::DrawLights(const CameraComponent& camera, GRAPHICSTHREAD thread case LightComponent::SPOT: { MiscCB miscCb; - miscCb.mColor.x = (float)light.entityArray_index; + miscCb.g_xColor.x = (float)light.entityArray_index; const float coneS = (const float)(light.fov / XM_PIDIV4); - miscCb.mTransform = XMMatrixTranspose( + XMStoreFloat4x4(&miscCb.g_xTransform, XMMatrixTranspose( XMMatrixScaling(coneS*light.range, light.range, coneS*light.range)* XMMatrixRotationQuaternion(XMLoadFloat4(&light.rotation))* XMMatrixTranslationFromVector(XMLoadFloat3(&light.position)) * camera.GetViewProjection() - ); + )); GetDevice()->UpdateBuffer(constantBuffers[CBTYPE_MISC], &miscCb, threadID); GetDevice()->Draw(192, 0, threadID); // cone @@ -4326,17 +4327,17 @@ void wiRenderer::DrawLightVisualizers(const CameraComponent& camera, GRAPHICSTHR { VolumeLightCB lcb; - lcb.col = XMFLOAT4(light.color.x, light.color.y, light.color.z, 1); - lcb.enerdis = XMFLOAT4(light.energy, light.range, light.fov, light.energy); + lcb.lightColor = XMFLOAT4(light.color.x, light.color.y, light.color.z, 1); + lcb.lightEnerdis = XMFLOAT4(light.energy, light.range, light.fov, light.energy); if (type == LightComponent::POINT) { - lcb.enerdis.w = light.range*light.energy*0.01f; // scale - lcb.world = XMMatrixTranspose( - XMMatrixScaling(lcb.enerdis.w, lcb.enerdis.w, lcb.enerdis.w)* + lcb.lightEnerdis.w = light.range*light.energy*0.01f; // scale + XMStoreFloat4x4(&lcb.lightWorld, XMMatrixTranspose( + XMMatrixScaling(lcb.lightEnerdis.w, lcb.lightEnerdis.w, lcb.lightEnerdis.w)* camrot* XMMatrixTranslationFromVector(XMLoadFloat3(&light.position)) - ); + )); GetDevice()->UpdateBuffer(constantBuffers[CBTYPE_VOLUMELIGHT], &lcb, threadID); @@ -4345,12 +4346,12 @@ void wiRenderer::DrawLightVisualizers(const CameraComponent& camera, GRAPHICSTHR else if(type == LightComponent::SPOT) { float coneS = (float)(light.fov / 0.7853981852531433); - lcb.enerdis.w = light.range*light.energy*0.03f; // scale - lcb.world = XMMatrixTranspose( - XMMatrixScaling(coneS*lcb.enerdis.w, lcb.enerdis.w, coneS*lcb.enerdis.w)* + lcb.lightEnerdis.w = light.range*light.energy*0.03f; // scale + XMStoreFloat4x4(&lcb.lightWorld, XMMatrixTranspose( + XMMatrixScaling(coneS*lcb.lightEnerdis.w, lcb.lightEnerdis.w, coneS*lcb.lightEnerdis.w)* XMMatrixRotationQuaternion(XMLoadFloat4(&light.rotation))* XMMatrixTranslationFromVector(XMLoadFloat3(&light.position)) - ); + )); GetDevice()->UpdateBuffer(constantBuffers[CBTYPE_VOLUMELIGHT], &lcb, threadID); @@ -4358,12 +4359,12 @@ void wiRenderer::DrawLightVisualizers(const CameraComponent& camera, GRAPHICSTHR } else if (type == LightComponent::SPHERE) { - lcb.world = XMMatrixTranspose( + XMStoreFloat4x4(&lcb.lightWorld, XMMatrixTranspose( XMMatrixScaling(light.radius, light.radius, light.radius)* XMMatrixRotationQuaternion(XMLoadFloat4(&light.rotation))* XMMatrixTranslationFromVector(XMLoadFloat3(&light.position))* camera.GetViewProjection() - ); + )); GetDevice()->UpdateBuffer(constantBuffers[CBTYPE_VOLUMELIGHT], &lcb, threadID); @@ -4371,12 +4372,12 @@ void wiRenderer::DrawLightVisualizers(const CameraComponent& camera, GRAPHICSTHR } else if (type == LightComponent::DISC) { - lcb.world = XMMatrixTranspose( + XMStoreFloat4x4(&lcb.lightWorld, XMMatrixTranspose( XMMatrixScaling(light.radius, light.radius, light.radius)* XMMatrixRotationQuaternion(XMLoadFloat4(&light.rotation))* XMMatrixTranslationFromVector(XMLoadFloat3(&light.position))* camera.GetViewProjection() - ); + )); GetDevice()->UpdateBuffer(constantBuffers[CBTYPE_VOLUMELIGHT], &lcb, threadID); @@ -4384,12 +4385,12 @@ void wiRenderer::DrawLightVisualizers(const CameraComponent& camera, GRAPHICSTHR } else if (type == LightComponent::RECTANGLE) { - lcb.world = XMMatrixTranspose( + XMStoreFloat4x4(&lcb.lightWorld, XMMatrixTranspose( XMMatrixScaling(light.width * 0.5f, light.height * 0.5f, 0.5f)* XMMatrixRotationQuaternion(XMLoadFloat4(&light.rotation))* XMMatrixTranslationFromVector(XMLoadFloat3(&light.position))* camera.GetViewProjection() - ); + )); GetDevice()->UpdateBuffer(constantBuffers[CBTYPE_VOLUMELIGHT], &lcb, threadID); @@ -4397,12 +4398,12 @@ void wiRenderer::DrawLightVisualizers(const CameraComponent& camera, GRAPHICSTHR } else if (type == LightComponent::TUBE) { - lcb.world = XMMatrixTranspose( + XMStoreFloat4x4(&lcb.lightWorld, XMMatrixTranspose( XMMatrixScaling(max(light.width * 0.5f, light.radius), light.radius, light.radius)* XMMatrixRotationQuaternion(XMLoadFloat4(&light.rotation))* XMMatrixTranslationFromVector(XMLoadFloat3(&light.position))* camera.GetViewProjection() - ); + )); GetDevice()->UpdateBuffer(constantBuffers[CBTYPE_VOLUMELIGHT], &lcb, threadID); @@ -4454,7 +4455,7 @@ void wiRenderer::DrawVolumeLights(const CameraComponent& camera, GRAPHICSTHREAD case LightComponent::TUBE: { MiscCB miscCb; - miscCb.mColor.x = (float)light.entityArray_index; + miscCb.g_xColor.x = (float)light.entityArray_index; GetDevice()->UpdateBuffer(constantBuffers[CBTYPE_MISC], &miscCb, threadID); GetDevice()->Draw(3, 0, threadID); // full screen triangle @@ -4463,9 +4464,9 @@ void wiRenderer::DrawVolumeLights(const CameraComponent& camera, GRAPHICSTHREAD case LightComponent::POINT: { MiscCB miscCb; - miscCb.mColor.x = (float)light.entityArray_index; + miscCb.g_xColor.x = (float)light.entityArray_index; float sca = light.range + 1; - miscCb.mTransform = XMMatrixTranspose(XMMatrixScaling(sca, sca, sca)*XMMatrixTranslationFromVector(XMLoadFloat3(&light.position)) * camera.GetViewProjection()); + XMStoreFloat4x4(&miscCb.g_xTransform, XMMatrixTranspose(XMMatrixScaling(sca, sca, sca)*XMMatrixTranslationFromVector(XMLoadFloat3(&light.position)) * camera.GetViewProjection())); GetDevice()->UpdateBuffer(constantBuffers[CBTYPE_MISC], &miscCb, threadID); GetDevice()->Draw(240, 0, threadID); // icosphere @@ -4474,14 +4475,14 @@ void wiRenderer::DrawVolumeLights(const CameraComponent& camera, GRAPHICSTHREAD case LightComponent::SPOT: { MiscCB miscCb; - miscCb.mColor.x = (float)light.entityArray_index; + miscCb.g_xColor.x = (float)light.entityArray_index; const float coneS = (const float)(light.fov / XM_PIDIV4); - miscCb.mTransform = XMMatrixTranspose( + XMStoreFloat4x4(&miscCb.g_xTransform, XMMatrixTranspose( XMMatrixScaling(coneS*light.range, light.range, coneS*light.range)* XMMatrixRotationQuaternion(XMLoadFloat4(&light.rotation))* XMMatrixTranslationFromVector(XMLoadFloat3(&light.position)) * camera.GetViewProjection() - ); + )); GetDevice()->UpdateBuffer(constantBuffers[CBTYPE_MISC], &miscCb, threadID); GetDevice()->Draw(192, 0, threadID); // cone @@ -4659,7 +4660,7 @@ void wiRenderer::DrawForShadowMap(GRAPHICSTHREAD threadID, uint32_t layerMask) vp.MaxDepth = 1.0f; GetDevice()->BindViewports(1, &vp, threadID); - GetDevice()->BindConstantBuffer(GS, constantBuffers[CBTYPE_CUBEMAPRENDER], CB_GETBINDSLOT(CubeMapRenderCB), threadID); + GetDevice()->BindConstantBuffer(GS, constantBuffers[CBTYPE_CUBEMAPRENDER], CB_GETBINDSLOT(CubemapRenderCB), threadID); break; } break; @@ -4717,7 +4718,7 @@ void wiRenderer::DrawForShadowMap(GRAPHICSTHREAD threadID, uint32_t layerMask) if (!culledRenderer.empty()) { CameraCB cb; - cb.mVP = light.shadowCam_dirLight[cascade].getVP(); + XMStoreFloat4x4(&cb.g_xCamera_VP, light.shadowCam_dirLight[cascade].getVP()); GetDevice()->UpdateBuffer(constantBuffers[CBTYPE_CAMERA], &cb, threadID); GetDevice()->ClearDepthStencil(shadowMapArray_2D, CLEAR_DEPTH, 0.0f, 0, threadID, light.shadowMap_index + cascade); @@ -4779,7 +4780,7 @@ void wiRenderer::DrawForShadowMap(GRAPHICSTHREAD threadID, uint32_t layerMask) if (!culledRenderer.empty()) { CameraCB cb; - cb.mVP = light.shadowCam_spotLight[0].getVP(); + XMStoreFloat4x4(&cb.g_xCamera_VP, light.shadowCam_spotLight[0].getVP()); GetDevice()->UpdateBuffer(constantBuffers[CBTYPE_CAMERA], &cb, threadID); GetDevice()->ClearDepthStencil(shadowMapArray_2D, CLEAR_DEPTH, 0.0f, 0, threadID, light.shadowMap_index); @@ -4838,12 +4839,14 @@ void wiRenderer::DrawForShadowMap(GRAPHICSTHREAD threadID, uint32_t layerMask) GetDevice()->ClearDepthStencil(shadowMapArray_Cube, CLEAR_DEPTH, 0.0f, 0, threadID, light.shadowMap_index); MiscCB miscCb; - miscCb.mColor = XMFLOAT4(light.position.x, light.position.y, light.position.z, 1.0f / light.GetRange()); // reciprocal range, to avoid division in shader + miscCb.g_xColor = float4(light.position.x, light.position.y, light.position.z, 1.0f / light.GetRange()); // reciprocal range, to avoid division in shader GetDevice()->UpdateBuffer(constantBuffers[CBTYPE_MISC], &miscCb, threadID); - CubeMapRenderCB cb; + CubemapRenderCB cb; for (unsigned int shcam = 0; shcam < light.shadowCam_pointLight.size(); ++shcam) - cb.mViewProjection[shcam] = light.shadowCam_pointLight[shcam].getVP(); + { + XMStoreFloat4x4(&cb.xCubeShadowVP[shcam], light.shadowCam_pointLight[shcam].getVP()); + } GetDevice()->UpdateBuffer(constantBuffers[CBTYPE_CUBEMAPRENDER], &cb, threadID); @@ -5065,7 +5068,7 @@ void wiRenderer::RenderMeshes(const XMFLOAT3& eye, const CulledCollection& culle if (tessellatorRequested) { TessellationCB tessCB; - tessCB.tessellationFactors = XMFLOAT4(tessF, tessF, tessF, tessF); + tessCB.g_f4TessFactors = XMFLOAT4(tessF, tessF, tessF, tessF); device->UpdateBuffer(constantBuffers[CBTYPE_TESSELLATION], &tessCB, threadID); device->BindConstantBuffer(HS, constantBuffers[CBTYPE_TESSELLATION], CBSLOT_RENDERER_TESSELLATION, threadID); } @@ -5412,7 +5415,7 @@ void wiRenderer::DrawSky(GRAPHICSTHREAD threadID) else { GetDevice()->BindGraphicsPSO(PSO_sky[SKYRENDERING_DYNAMIC], threadID); - if (GetScene().cloudiness > 0) + if (GetScene().weather.cloudiness > 0) { GetDevice()->BindResource(PS, textures[TEXTYPE_2D_CLOUDS], TEXSLOT_ONDEMAND0, threadID); } @@ -5481,11 +5484,11 @@ void wiRenderer::DrawDecals(const CameraComponent& camera, GRAPHICSTHREAD thread XMMATRIX decalWorld = XMLoadFloat4x4(&decal.world); MiscCB dcbvs; - dcbvs.mTransform = XMMatrixTranspose(decalWorld*camera.GetViewProjection()); + XMStoreFloat4x4(&dcbvs.g_xTransform, XMMatrixTranspose(decalWorld*camera.GetViewProjection())); device->UpdateBuffer(constantBuffers[CBTYPE_MISC], &dcbvs, threadID); DecalCB dcbps; - dcbps.mDecalVP = XMMatrixTranspose(XMMatrixInverse(nullptr, decalWorld)); // todo: cache the inverse! + XMStoreFloat4x4(&dcbps.xDecalVP, XMMatrixTranspose(XMMatrixInverse(nullptr, decalWorld))); // todo: cache the inverse! dcbps.hasTexNor = 0; if (decal.texture != nullptr) dcbps.hasTexNor |= 0x0000001; @@ -5637,19 +5640,19 @@ void wiRenderer::RefreshEnvProbes(GRAPHICSTHREAD threadID) XMFLOAT3 center = probe.position; XMVECTOR vCenter = XMLoadFloat3(¢er); - CubeMapRenderCB cb; + CubemapRenderCB cb; for (unsigned int i = 0; i < cameras.size(); ++i) { cameras[i].Update(vCenter); - cb.mViewProjection[i] = cameras[i].getVP(); + XMStoreFloat4x4(&cb.xCubeShadowVP[i], cameras[i].getVP()); } GetDevice()->UpdateBuffer(constantBuffers[CBTYPE_CUBEMAPRENDER], &cb, threadID); - GetDevice()->BindConstantBuffer(GS, constantBuffers[CBTYPE_CUBEMAPRENDER], CB_GETBINDSLOT(CubeMapRenderCB), threadID); + GetDevice()->BindConstantBuffer(GS, constantBuffers[CBTYPE_CUBEMAPRENDER], CB_GETBINDSLOT(CubemapRenderCB), threadID); CameraCB camcb; - camcb.mCamPos = center; // only this will be used by envprobe rendering shaders the rest is read from cubemaprenderCB + camcb.g_xCamera_CamPos = center; // only this will be used by envprobe rendering shaders the rest is read from cubemaprenderCB GetDevice()->UpdateBuffer(constantBuffers[CBTYPE_CAMERA], &camcb, threadID); const LayerComponent& layer = *scene.layers.GetComponent(entity); @@ -5998,16 +6001,16 @@ void wiRenderer::ComputeTiledLightCulling(bool deferred, GRAPHICSTHREAD threadID device->BindComputePSO(CPSO[CSTYPE_TILEFRUSTUMS], threadID); DispatchParamsCB dispatchParams; - dispatchParams.numThreads[0] = tileCount.x; - dispatchParams.numThreads[1] = tileCount.y; - dispatchParams.numThreads[2] = 1; - dispatchParams.numThreadGroups[0] = (UINT)ceilf(dispatchParams.numThreads[0] / (float)TILED_CULLING_BLOCKSIZE); - dispatchParams.numThreadGroups[1] = (UINT)ceilf(dispatchParams.numThreads[1] / (float)TILED_CULLING_BLOCKSIZE); - dispatchParams.numThreadGroups[2] = 1; + dispatchParams.xDispatchParams_numThreads.x = tileCount.x; + dispatchParams.xDispatchParams_numThreads.y = tileCount.y; + dispatchParams.xDispatchParams_numThreads.z = 1; + dispatchParams.xDispatchParams_numThreadGroups.x = (UINT)ceilf(dispatchParams.xDispatchParams_numThreads.x / (float)TILED_CULLING_BLOCKSIZE); + dispatchParams.xDispatchParams_numThreadGroups.y = (UINT)ceilf(dispatchParams.xDispatchParams_numThreads.y / (float)TILED_CULLING_BLOCKSIZE); + dispatchParams.xDispatchParams_numThreadGroups.z = 1; device->UpdateBuffer(constantBuffers[CBTYPE_DISPATCHPARAMS], &dispatchParams, threadID); device->BindConstantBuffer(CS, constantBuffers[CBTYPE_DISPATCHPARAMS], CB_GETBINDSLOT(DispatchParamsCB), threadID); - device->Dispatch(dispatchParams.numThreadGroups[0], dispatchParams.numThreadGroups[1], dispatchParams.numThreadGroups[2], threadID); + device->Dispatch(dispatchParams.xDispatchParams_numThreadGroups.x, dispatchParams.xDispatchParams_numThreadGroups.y, dispatchParams.xDispatchParams_numThreadGroups.z, threadID); device->UnbindUAVs(UAVSLOT_TILEFRUSTUMS, 1, threadID); device->UAVBarrier(uavs, ARRAYSIZE(uavs), threadID); } @@ -6053,13 +6056,13 @@ void wiRenderer::ComputeTiledLightCulling(bool deferred, GRAPHICSTHREAD threadID DispatchParamsCB dispatchParams; - dispatchParams.numThreadGroups[0] = tileCount.x; - dispatchParams.numThreadGroups[1] = tileCount.y; - dispatchParams.numThreadGroups[2] = 1; - dispatchParams.numThreads[0] = dispatchParams.numThreadGroups[0] * TILED_CULLING_BLOCKSIZE; - dispatchParams.numThreads[1] = dispatchParams.numThreadGroups[1] * TILED_CULLING_BLOCKSIZE; - dispatchParams.numThreads[2] = 1; - dispatchParams.value0 = (UINT)(frameCulling.culledLights.size() + frameCulling.culledEnvProbes.size() + frameCulling.culledDecals.size()); + dispatchParams.xDispatchParams_numThreadGroups.x = tileCount.x; + dispatchParams.xDispatchParams_numThreadGroups.y = tileCount.y; + dispatchParams.xDispatchParams_numThreadGroups.z = 1; + dispatchParams.xDispatchParams_numThreads.x = dispatchParams.xDispatchParams_numThreadGroups.x * TILED_CULLING_BLOCKSIZE; + dispatchParams.xDispatchParams_numThreads.y = dispatchParams.xDispatchParams_numThreadGroups.y * TILED_CULLING_BLOCKSIZE; + dispatchParams.xDispatchParams_numThreads.z = 1; + dispatchParams.xDispatchParams_value0 = (UINT)(frameCulling.culledLights.size() + frameCulling.culledEnvProbes.size() + frameCulling.culledDecals.size()); device->UpdateBuffer(constantBuffers[CBTYPE_DISPATCHPARAMS], &dispatchParams, threadID); device->BindConstantBuffer(CS, constantBuffers[CBTYPE_DISPATCHPARAMS], CB_GETBINDSLOT(DispatchParamsCB), threadID); @@ -6076,7 +6079,7 @@ void wiRenderer::ComputeTiledLightCulling(bool deferred, GRAPHICSTHREAD threadID GetDevice()->BindResource(CS, shadowMapArray_Cube, TEXSLOT_SHADOWARRAY_CUBE, threadID); GetDevice()->BindResource(CS, shadowMapArray_Transparent, TEXSLOT_SHADOWARRAY_TRANSPARENT, threadID); - device->Dispatch(dispatchParams.numThreadGroups[0], dispatchParams.numThreadGroups[1], dispatchParams.numThreadGroups[2], threadID); + device->Dispatch(dispatchParams.xDispatchParams_numThreadGroups.x, dispatchParams.xDispatchParams_numThreadGroups.y, dispatchParams.xDispatchParams_numThreadGroups.z, threadID); device->UAVBarrier(uavs, ARRAYSIZE(uavs), threadID); } else @@ -6087,7 +6090,7 @@ void wiRenderer::ComputeTiledLightCulling(bool deferred, GRAPHICSTHREAD threadID }; device->BindUAVs(CS, uavs, UAVSLOT_ENTITYINDEXLIST_OPAQUE, ARRAYSIZE(uavs), threadID); - device->Dispatch(dispatchParams.numThreadGroups[0], dispatchParams.numThreadGroups[1], dispatchParams.numThreadGroups[2], threadID); + device->Dispatch(dispatchParams.xDispatchParams_numThreadGroups.x, dispatchParams.xDispatchParams_numThreadGroups.y, dispatchParams.xDispatchParams_numThreadGroups.z, threadID); device->UAVBarrier(uavs, ARRAYSIZE(uavs), threadID); } @@ -7461,42 +7464,44 @@ void wiRenderer::UpdateWorldCB(GRAPHICSTHREAD threadID) WorldCB value; ZeroMemory(&value, sizeof(value)); - value.mScreenWidthHeight = XMFLOAT2((float)GetDevice()->GetScreenWidth(), (float)GetDevice()->GetScreenHeight()); - value.mScreenWidthHeight_Inverse = XMFLOAT2(1.0f / value.mScreenWidthHeight.x, 1.0f / value.mScreenWidthHeight.y); - value.mInternalResolution = XMFLOAT2((float)GetInternalResolution().x, (float)GetInternalResolution().y); - value.mInternalResolution_Inverse = XMFLOAT2(1.0f / value.mInternalResolution.x, 1.0f / value.mInternalResolution.y); - value.mGamma = GetGamma(); - value.mAmbient = scene.ambient; - value.mCloudiness = scene.cloudiness; - value.mCloudScale = scene.cloudScale; - value.mFog = XMFLOAT3(scene.fogStart, scene.fogEnd, scene.fogHeight); - value.mHorizon = scene.horizon; - value.mZenith = scene.zenith; - value.mSpecularAA = SPECULARAA; - value.mVoxelRadianceDataSize = voxelSceneData.voxelsize; - value.mVoxelRadianceDataSize_Inverse = 1.0f / (float)value.mVoxelRadianceDataSize; - value.mVoxelRadianceDataRes = GetVoxelRadianceEnabled() ? (UINT)voxelSceneData.res : 0; - value.mVoxelRadianceDataRes_Inverse = 1.0f / (float)value.mVoxelRadianceDataRes; - value.mVoxelRadianceDataMIPs = voxelSceneData.mips; - value.mVoxelRadianceDataNumCones = max(min(voxelSceneData.numCones, 16), 1); - value.mVoxelRadianceDataNumCones_Inverse = 1.0f / (float)value.mVoxelRadianceDataNumCones; - value.mVoxelRadianceDataRayStepSize = voxelSceneData.rayStepSize; - value.mVoxelRadianceReflectionsEnabled = voxelSceneData.reflectionsEnabled; - value.mVoxelRadianceDataCenter = voxelSceneData.center; - value.mAdvancedRefractions = GetAdvancedRefractionsEnabled() ? 1 : 0; - value.mEntityCullingTileCount = GetEntityCullingTileCount(); - value.mTransparentShadowsEnabled = TRANSPARENTSHADOWSENABLED; - value.mGlobalEnvProbeIndex = -1; - value.mEnvProbeMipCount = 0; - value.mEnvProbeMipCount_Inverse = 1.0f; + value.g_xWorld_ScreenWidthHeight = float2((float)GetDevice()->GetScreenWidth(), (float)GetDevice()->GetScreenHeight()); + value.g_xWorld_ScreenWidthHeight_Inverse = float2(1.0f / value.g_xWorld_ScreenWidthHeight.x, 1.0f / value.g_xWorld_ScreenWidthHeight.y); + value.g_xWorld_InternalResolution = float2((float)GetInternalResolution().x, (float)GetInternalResolution().y); + value.g_xWorld_InternalResolution_Inverse = float2(1.0f / value.g_xWorld_InternalResolution.x, 1.0f / value.g_xWorld_InternalResolution.y); + value.g_xWorld_Gamma = GetGamma(); + value.g_xWorld_SunColor = scene.weather.sunColor; + value.g_xWorld_SunDirection = scene.weather.sunDirection; + value.g_xWorld_Ambient = scene.weather.ambient; + value.g_xWorld_Cloudiness = scene.weather.cloudiness; + value.g_xWorld_CloudScale = scene.weather.cloudScale; + value.g_xWorld_Fog = float3(scene.weather.fogStart, scene.weather.fogEnd, scene.weather.fogHeight); + value.g_xWorld_Horizon = scene.weather.horizon; + value.g_xWorld_Zenith = scene.weather.zenith; + value.g_xWorld_SpecularAA = SPECULARAA; + value.g_xWorld_VoxelRadianceDataSize = voxelSceneData.voxelsize; + value.g_xWorld_VoxelRadianceDataSize_Inverse = 1.0f / (float)value.g_xWorld_VoxelRadianceDataSize; + value.g_xWorld_VoxelRadianceDataRes = GetVoxelRadianceEnabled() ? (uint)voxelSceneData.res : 0; + value.g_xWorld_VoxelRadianceDataRes_Inverse = 1.0f / (float)value.g_xWorld_VoxelRadianceDataRes; + value.g_xWorld_VoxelRadianceDataMIPs = voxelSceneData.mips; + value.g_xWorld_VoxelRadianceNumCones = max(min(voxelSceneData.numCones, 16), 1); + value.g_xWorld_VoxelRadianceNumCones_Inverse = 1.0f / (float)value.g_xWorld_VoxelRadianceNumCones; + value.g_xWorld_VoxelRadianceRayStepSize = voxelSceneData.rayStepSize; + value.g_xWorld_VoxelRadianceReflectionsEnabled = voxelSceneData.reflectionsEnabled; + value.g_xWorld_VoxelRadianceDataCenter = voxelSceneData.center; + value.g_xWorld_AdvancedRefractions = GetAdvancedRefractionsEnabled() ? 1 : 0; + value.g_xWorld_EntityCullingTileCount = GetEntityCullingTileCount(); + value.g_xWorld_TransparentShadowsEnabled = TRANSPARENTSHADOWSENABLED; + value.g_xWorld_GlobalEnvProbeIndex = -1; + value.g_xWorld_EnvProbeMipCount = 0; + value.g_xWorld_EnvProbeMipCount_Inverse = 1.0f; if (scene.probes.GetCount() > 0) { - value.mGlobalEnvProbeIndex = 0; // for now, the global envprobe will be the first probe in the array. Easy change later on if required... + value.g_xWorld_GlobalEnvProbeIndex = 0; // for now, the global envprobe will be the first probe in the array. Easy change later on if required... } if (textures[TEXTYPE_CUBEARRAY_ENVMAPARRAY] != nullptr) { - value.mEnvProbeMipCount = static_cast(textures[TEXTYPE_CUBEARRAY_ENVMAPARRAY])->GetDesc().MipLevels; - value.mEnvProbeMipCount_Inverse = 1.0f / (float)value.mEnvProbeMipCount; + value.g_xWorld_EnvProbeMipCount = static_cast(textures[TEXTYPE_CUBEARRAY_ENVMAPARRAY])->GetDesc().MipLevels; + value.g_xWorld_EnvProbeMipCount_Inverse = 1.0f / (float)value.g_xWorld_EnvProbeMipCount; } if (memcmp(&prevcb[threadID], &value, sizeof(WorldCB)) != 0) // prevent overcommit @@ -7511,29 +7516,28 @@ void wiRenderer::UpdateFrameCB(GRAPHICSTHREAD threadID) FrameCB cb; - cb.mTime = renderTime; - cb.mTimePrev = renderTime_Prev; - cb.mDeltaTime = deltaTime; - cb.mLightArrayOffset = entityArrayOffset_Lights; - cb.mLightArrayCount = entityArrayCount_Lights; - cb.mDecalArrayOffset = entityArrayOffset_Decals; - cb.mDecalArrayCount = entityArrayCount_Decals; - cb.mForceFieldArrayOffset = entityArrayOffset_ForceFields; - cb.mForceFieldArrayCount = entityArrayCount_ForceFields; - cb.mEnvProbeArrayOffset = entityArrayOffset_EnvProbes; - cb.mEnvProbeArrayCount = entityArrayCount_EnvProbes; - cb.mVoxelRadianceRetargetted = voxelSceneData.centerChangedThisFrame ? 1 : 0; - cb.mWindRandomness = scene.windRandomness; - cb.mWindWaveSize = scene.windWaveSize; - cb.mWindDirection = scene.windDirection; - cb.mFrameCount = (UINT)GetDevice()->GetFrameCount(); - cb.mSunEntityArrayIndex = -1; - cb.mTemporalAASampleRotation = 0; + cb.g_xFrame_Time = renderTime; + cb.g_xFrame_TimePrev = renderTime_Prev; + cb.g_xFrame_DeltaTime = deltaTime; + cb.g_xFrame_LightArrayOffset = entityArrayOffset_Lights; + cb.g_xFrame_LightArrayCount = entityArrayCount_Lights; + cb.g_xFrame_DecalArrayOffset = entityArrayOffset_Decals; + cb.g_xFrame_DecalArrayCount = entityArrayCount_Decals; + cb.g_xFrame_ForceFieldArrayOffset = entityArrayOffset_ForceFields; + cb.g_xFrame_ForceFieldArrayCount = entityArrayCount_ForceFields; + cb.g_xFrame_EnvProbeArrayOffset = entityArrayOffset_EnvProbes; + cb.g_xFrame_EnvProbeArrayCount = entityArrayCount_EnvProbes; + cb.g_xFrame_VoxelRadianceRetargetted = voxelSceneData.centerChangedThisFrame ? 1 : 0; + cb.g_xFrame_WindRandomness = scene.weather.windRandomness; + cb.g_xFrame_WindWaveSize = scene.weather.windWaveSize; + cb.g_xFrame_WindDirection = scene.weather.windDirection; + cb.g_xFrame_FrameCount = (uint)GetDevice()->GetFrameCount(); + cb.g_xFrame_TemporalAASampleRotation = 0; if (GetTemporalAAEnabled()) { - UINT id = cb.mFrameCount % 4; - UINT x = 0; - UINT y = 0; + uint id = cb.g_xFrame_FrameCount % 4; + uint x = 0; + uint y = 0; switch (id) { case 1: @@ -7549,51 +7553,51 @@ void wiRenderer::UpdateFrameCB(GRAPHICSTHREAD threadID) default: break; } - cb.mTemporalAASampleRotation = (x & 0x000000FF) | ((y & 0x000000FF) << 8); + cb.g_xFrame_TemporalAASampleRotation = (x & 0x000000FF) | ((y & 0x000000FF) << 8); } - cb.mTemporalAAJitter = temporalAAJitter; - cb.mTemporalAAJitterPrev = temporalAAJitterPrev; + cb.g_xFrame_TemporalAAJitter = temporalAAJitter; + cb.g_xFrame_TemporalAAJitterPrev = temporalAAJitterPrev; const auto& camera = GetCamera(); const auto& prevCam = GetPrevCamera(); const auto& reflCam = GetRefCamera(); - cb.mVP = XMMatrixTranspose(camera.GetViewProjection()); - cb.mView = XMMatrixTranspose(camera.GetView()); - cb.mProj = XMMatrixTranspose(camera.GetProjection()); - cb.mCamPos = camera.Eye; - cb.mCamDistanceFromOrigin = XMVectorGetX(XMVector3Length(XMLoadFloat3(&cb.mCamPos))); - cb.mPrevV = XMMatrixTranspose(prevCam.GetView()); - cb.mPrevP = XMMatrixTranspose(prevCam.GetProjection()); - cb.mPrevVP = XMMatrixTranspose(prevCam.GetViewProjection()); - cb.mPrevInvVP = XMMatrixTranspose(prevCam.GetInvViewProjection()); - cb.mReflVP = XMMatrixTranspose(reflCam.GetViewProjection()); - cb.mInvV = XMMatrixTranspose(camera.GetInvView()); - cb.mInvP = XMMatrixTranspose(camera.GetInvProjection()); - cb.mInvVP = XMMatrixTranspose(camera.GetInvViewProjection()); - cb.mAt = camera.At; - cb.mUp = camera.Up; - cb.mZNearP = camera.zNearP; - cb.mZFarP = camera.zFarP; - cb.mZNearP_Recip = 1.0f / max(0.0001f, cb.mZNearP); - cb.mZFarP_Recip = 1.0f / max(0.0001f, cb.mZFarP); - cb.mZRange = abs(cb.mZFarP - cb.mZNearP); - cb.mZRange_Recip = 1.0f / max(0.0001f, cb.mZRange); - cb.mFrustumPlanesWS[0] = camera.frustum.getLeftPlane(); - cb.mFrustumPlanesWS[1] = camera.frustum.getRightPlane(); - cb.mFrustumPlanesWS[2] = camera.frustum.getTopPlane(); - cb.mFrustumPlanesWS[3] = camera.frustum.getBottomPlane(); - cb.mFrustumPlanesWS[4] = camera.frustum.getNearPlane(); - cb.mFrustumPlanesWS[5] = camera.frustum.getFarPlane(); + XMStoreFloat4x4(&cb.g_xFrame_MainCamera_VP, XMMatrixTranspose(camera.GetViewProjection())); + XMStoreFloat4x4(&cb.g_xFrame_MainCamera_View, XMMatrixTranspose(camera.GetView())); + XMStoreFloat4x4(&cb.g_xFrame_MainCamera_Proj, XMMatrixTranspose(camera.GetProjection())); + cb.g_xFrame_MainCamera_CamPos = camera.Eye; + cb.g_xFrame_MainCamera_DistanceFromOrigin, XMVectorGetX(XMVector3Length(XMLoadFloat3(&cb.g_xFrame_MainCamera_CamPos))); + XMStoreFloat4x4(&cb.g_xFrame_MainCamera_PrevV, XMMatrixTranspose(prevCam.GetView())); + XMStoreFloat4x4(&cb.g_xFrame_MainCamera_PrevP, XMMatrixTranspose(prevCam.GetProjection())); + XMStoreFloat4x4(&cb.g_xFrame_MainCamera_PrevVP, XMMatrixTranspose(prevCam.GetViewProjection())); + XMStoreFloat4x4(&cb.g_xFrame_MainCamera_PrevInvVP, XMMatrixTranspose(prevCam.GetInvViewProjection())); + XMStoreFloat4x4(&cb.g_xFrame_MainCamera_ReflVP, XMMatrixTranspose(reflCam.GetViewProjection())); + XMStoreFloat4x4(&cb.g_xFrame_MainCamera_InvV, XMMatrixTranspose(camera.GetInvView())); + XMStoreFloat4x4(&cb.g_xFrame_MainCamera_InvP, XMMatrixTranspose(camera.GetInvProjection())); + XMStoreFloat4x4(&cb.g_xFrame_MainCamera_InvVP, XMMatrixTranspose(camera.GetInvViewProjection())); + cb.g_xFrame_MainCamera_At = camera.At; + cb.g_xFrame_MainCamera_Up = camera.Up; + cb.g_xFrame_MainCamera_ZNearP = camera.zNearP; + cb.g_xFrame_MainCamera_ZFarP = camera.zFarP; + cb.g_xFrame_MainCamera_ZNearP_Recip = 1.0f / max(0.0001f, cb.g_xFrame_MainCamera_ZNearP); + cb.g_xFrame_MainCamera_ZFarP_Recip = 1.0f / max(0.0001f, cb.g_xFrame_MainCamera_ZFarP); + cb.g_xFrame_MainCamera_ZRange = abs(cb.g_xFrame_MainCamera_ZFarP - cb.g_xFrame_MainCamera_ZNearP); + cb.g_xFrame_MainCamera_ZRange_Recip = 1.0f / max(0.0001f, cb.g_xFrame_MainCamera_ZRange); + cb.g_xFrame_FrustumPlanesWS[0] = camera.frustum.getLeftPlane(); + cb.g_xFrame_FrustumPlanesWS[1] = camera.frustum.getRightPlane(); + cb.g_xFrame_FrustumPlanesWS[2] = camera.frustum.getTopPlane(); + cb.g_xFrame_FrustumPlanesWS[3] = camera.frustum.getBottomPlane(); + cb.g_xFrame_FrustumPlanesWS[4] = camera.frustum.getNearPlane(); + cb.g_xFrame_FrustumPlanesWS[5] = camera.frustum.getFarPlane(); - cb.mWorldBoundsMin = scene.bounds.getMin(); - cb.mWorldBoundsMax = scene.bounds.getMax(); - cb.mWorldBoundsExtents.x = abs(cb.mWorldBoundsMax.x - cb.mWorldBoundsMin.x); - cb.mWorldBoundsExtents.y = abs(cb.mWorldBoundsMax.y - cb.mWorldBoundsMin.y); - cb.mWorldBoundsExtents.z = abs(cb.mWorldBoundsMax.z - cb.mWorldBoundsMin.z); - cb.mWorldBoundsExtents_Inverse.x = 1.0f / cb.mWorldBoundsExtents.x; - cb.mWorldBoundsExtents_Inverse.y = 1.0f / cb.mWorldBoundsExtents.y; - cb.mWorldBoundsExtents_Inverse.z = 1.0f / cb.mWorldBoundsExtents.z; + cb.g_xFrame_WorldBoundsMin = scene.bounds.getMin(); + cb.g_xFrame_WorldBoundsMax = scene.bounds.getMax(); + cb.g_xFrame_WorldBoundsExtents.x = abs(cb.g_xFrame_WorldBoundsMax.x - cb.g_xFrame_WorldBoundsMin.x); + cb.g_xFrame_WorldBoundsExtents.y = abs(cb.g_xFrame_WorldBoundsMax.y - cb.g_xFrame_WorldBoundsMin.y); + cb.g_xFrame_WorldBoundsExtents.z = abs(cb.g_xFrame_WorldBoundsMax.z - cb.g_xFrame_WorldBoundsMin.z); + cb.g_xFrame_WorldBoundsExtents_Inverse.x = 1.0f / cb.g_xFrame_WorldBoundsExtents.x; + cb.g_xFrame_WorldBoundsExtents_Inverse.y = 1.0f / cb.g_xFrame_WorldBoundsExtents.y; + cb.g_xFrame_WorldBoundsExtents_Inverse.z = 1.0f / cb.g_xFrame_WorldBoundsExtents.z; GetDevice()->UpdateBuffer(constantBuffers[CBTYPE_FRAME], &cb, threadID); } @@ -7601,24 +7605,25 @@ void wiRenderer::UpdateCameraCB(const CameraComponent& camera, GRAPHICSTHREAD th { CameraCB cb; - cb.mVP = XMMatrixTranspose(camera.GetViewProjection()); - cb.mView = XMMatrixTranspose(camera.GetView()); - cb.mProj = XMMatrixTranspose(camera.GetProjection()); - cb.mCamPos = camera.Eye; + XMStoreFloat4x4(&cb.g_xCamera_VP, XMMatrixTranspose(camera.GetViewProjection())); + XMStoreFloat4x4(&cb.g_xCamera_View, XMMatrixTranspose(camera.GetView())); + XMStoreFloat4x4(&cb.g_xCamera_Proj, XMMatrixTranspose(camera.GetProjection())); + cb.g_xCamera_CamPos = camera.Eye; GetDevice()->UpdateBuffer(constantBuffers[CBTYPE_CAMERA], &cb, threadID); } -wiRenderer::APICB apiCB[GRAPHICSTHREAD_COUNT]; + +APICB apiCB[GRAPHICSTHREAD_COUNT]; void wiRenderer::SetClipPlane(const XMFLOAT4& clipPlane, GRAPHICSTHREAD threadID) { - apiCB[threadID].clipPlane = clipPlane; + apiCB[threadID].g_xClipPlane = clipPlane; GetDevice()->UpdateBuffer(constantBuffers[CBTYPE_API], &apiCB[threadID], threadID); } void wiRenderer::SetAlphaRef(float alphaRef, GRAPHICSTHREAD threadID) { - if (alphaRef != apiCB[threadID].alphaRef) + if (alphaRef != apiCB[threadID].g_xAlphaRef) { - apiCB[threadID].alphaRef = alphaRef; + apiCB[threadID].g_xAlphaRef = alphaRef; GetDevice()->UpdateBuffer(constantBuffers[CBTYPE_API], &apiCB[threadID], threadID); } } diff --git a/WickedEngine/wiRenderer.h b/WickedEngine/wiRenderer.h index eeb235108..3acd7e9a7 100644 --- a/WickedEngine/wiRenderer.h +++ b/WickedEngine/wiRenderer.h @@ -87,140 +87,6 @@ public: static void SetShadowProps2D(int resolution, int count, int softShadowQuality); static void SetShadowPropsCube(int resolution, int count); - // Constant Buffers: - // Persistent buffers: - CBUFFER(WorldCB, CBSLOT_RENDERER_WORLD) - { - XMFLOAT2 mScreenWidthHeight; - XMFLOAT2 mScreenWidthHeight_Inverse; - XMFLOAT2 mInternalResolution; - XMFLOAT2 mInternalResolution_Inverse; - float mGamma; - XMFLOAT3 mHorizon; - XMFLOAT3 mZenith; - float mCloudScale; - XMFLOAT3 mAmbient; - float mCloudiness; - XMFLOAT3 mFog; - float mSpecularAA; - float mVoxelRadianceDataSize; - float mVoxelRadianceDataSize_Inverse; - UINT mVoxelRadianceDataRes; - float mVoxelRadianceDataRes_Inverse; - UINT mVoxelRadianceDataMIPs; - UINT mVoxelRadianceDataNumCones; - float mVoxelRadianceDataNumCones_Inverse; - float mVoxelRadianceDataRayStepSize; - BOOL mVoxelRadianceReflectionsEnabled; - XMFLOAT3 mVoxelRadianceDataCenter; - BOOL mAdvancedRefractions; - XMUINT3 mEntityCullingTileCount; - BOOL mTransparentShadowsEnabled; - int mGlobalEnvProbeIndex; - UINT mEnvProbeMipCount; - float mEnvProbeMipCount_Inverse; - }; - CBUFFER(FrameCB, CBSLOT_RENDERER_FRAME) - { - float mTime; - float mTimePrev; - float mDeltaTime; - UINT mFrameCount; - UINT mLightArrayOffset; - UINT mLightArrayCount; - UINT mDecalArrayOffset; - UINT mDecalArrayCount; - UINT mForceFieldArrayOffset; - UINT mForceFieldArrayCount; - UINT mEnvProbeArrayOffset; - UINT mEnvProbeArrayCount; - XMFLOAT3 mWindDirection; - float mWindWaveSize; - float mWindRandomness; - int mSunEntityArrayIndex; - BOOL mVoxelRadianceRetargetted; - UINT mTemporalAASampleRotation; - XMFLOAT2 mTemporalAAJitter; - XMFLOAT2 mTemporalAAJitterPrev; - XMMATRIX mVP; - XMMATRIX mView; - XMMATRIX mProj; - XMFLOAT3 mCamPos; - float mCamDistanceFromOrigin; - XMMATRIX mPrevV; - XMMATRIX mPrevP; - XMMATRIX mPrevVP; - XMMATRIX mPrevInvVP; - XMMATRIX mReflVP; - XMMATRIX mInvV; - XMMATRIX mInvP; - XMMATRIX mInvVP; - XMFLOAT3 mAt; - float mZNearP; - XMFLOAT3 mUp; - float mZFarP; - float mZNearP_Recip; - float mZFarP_Recip; - float mZRange; - float mZRange_Recip; - XMFLOAT4 mFrustumPlanesWS[6]; - XMFLOAT3 mWorldBoundsMin; float pad0; - XMFLOAT3 mWorldBoundsMax; float pad1; - XMFLOAT3 mWorldBoundsExtents; float pad2; - XMFLOAT3 mWorldBoundsExtents_Inverse; float pad3; - }; - CBUFFER(CameraCB, CBSLOT_RENDERER_CAMERA) - { - XMMATRIX mVP; - XMMATRIX mView; - XMMATRIX mProj; - XMFLOAT3 mCamPos; float pad0; - }; - CBUFFER(MiscCB, CBSLOT_RENDERER_MISC) - { - XMMATRIX mTransform; - XMFLOAT4 mColor; - }; - - // On demand buffers: - CBUFFER(VolumeLightCB, CBSLOT_RENDERER_VOLUMELIGHT) - { - XMMATRIX world; - XMFLOAT4 col; - XMFLOAT4 enerdis; - }; - CBUFFER(DecalCB, CBSLOT_RENDERER_DECAL) - { - XMMATRIX mDecalVP; - int hasTexNor; - XMFLOAT3 eye; - float opacity; - XMFLOAT3 front; - }; - CBUFFER(CubeMapRenderCB, CBSLOT_RENDERER_CUBEMAPRENDER) - { - XMMATRIX mViewProjection[6]; - }; - CBUFFER(APICB, CBSLOT_API) - { - XMFLOAT4 clipPlane; - float alphaRef; - float pad[3]; - - APICB(const XMFLOAT4& clipPlane = XMFLOAT4(0, 0, 0, 0), float alphaRef = 0.75f) :clipPlane(clipPlane), alphaRef(alphaRef) {} - }; - CBUFFER(TessellationCB, CBSLOT_RENDERER_TESSELLATION) - { - XMFLOAT4 tessellationFactors; - }; - CBUFFER(DispatchParamsCB, CBSLOT_RENDERER_DISPATCHPARAMS) - { - UINT numThreadGroups[3]; - UINT value0; - UINT numThreads[3]; - UINT value1; - }; - protected: static bool wireRender, debugBoneLines, debugPartitionTree, debugEnvProbes, debugEmitters, debugForceFields, debugCameras, gridHelper, voxelHelper, advancedLightCulling, advancedRefractions; diff --git a/WickedEngine/wiSceneSystem.cpp b/WickedEngine/wiSceneSystem.cpp index a70946711..e2d858f09 100644 --- a/WickedEngine/wiSceneSystem.cpp +++ b/WickedEngine/wiSceneSystem.cpp @@ -805,6 +805,10 @@ namespace wiSceneSystem void Scene::Update(float dt) { + if (weathers.GetCount() > 0) + { + weather = weathers[0]; + } RunPreviousFrameTransformUpdateSystem(transforms, prev_transforms); @@ -830,10 +834,9 @@ namespace wiSceneSystem RunForceUpdateSystem(transforms, forces); - RunLightUpdateSystem(wiRenderer::GetCamera(), transforms, aabb_lights, lights, sunDirection, sunColor); + RunLightUpdateSystem(wiRenderer::GetCamera(), transforms, aabb_lights, lights, &weather); RunParticleUpdateSystem(transforms, meshes, emitters, hairs, dt); - } void Scene::Clear() { @@ -860,27 +863,10 @@ namespace wiSceneSystem animations.Clear(); emitters.Clear(); hairs.Clear(); + weathers.Clear(); } void Scene::Merge(Scene& other) { - if (CountEntities() == 0) - { - sunDirection = other.sunDirection; - sunColor = other.sunColor; - horizon = other.horizon; - zenith = other.zenith; - ambient = other.ambient; - fogStart = other.fogStart; - fogEnd = other.fogEnd; - fogHeight = other.fogHeight; - cloudiness = other.cloudiness; - cloudScale = other.cloudScale; - cloudSpeed = other.cloudSpeed; - windDirection = other.windDirection; - windRandomness = other.windRandomness; - windWaveSize = other.windWaveSize; - } - names.Merge(other.names); layers.Merge(other.layers); transforms.Merge(other.transforms); @@ -963,6 +949,7 @@ namespace wiSceneSystem animations.Remove(entity); emitters.Remove(entity); hairs.Remove(entity); + weathers.Remove(entity); } Entity Scene::Entity_FindByName(const std::string& name) { @@ -986,7 +973,7 @@ namespace wiSceneSystem // Then deserialize with a unique seed: archive.SetReadModeAndResetPos(true); uint32_t seed = wiRandom::getRandom(1, INT_MAX); - return Entity_Serialize(archive, entity, seed); + return Entity_Serialize(archive, entity, seed, false); } Entity Scene::Entity_CreateMaterial( const std::string& name @@ -1735,7 +1722,7 @@ namespace wiSceneSystem const ComponentManager& transforms, ComponentManager& aabb_lights, ComponentManager& lights, - XMFLOAT3& sunDirection, XMFLOAT3& sunColor + WeatherComponent* weather ) { assert(lights.GetCount() == aabb_lights.GetCount()); @@ -1759,8 +1746,11 @@ namespace wiSceneSystem { case LightComponent::DIRECTIONAL: { - sunDirection = light.direction; - sunColor = light.color; + if (weather != nullptr) + { + weather->sunColor = light.color; + weather->sunDirection = light.direction; + } if (light.IsCastingShadow()) { diff --git a/WickedEngine/wiSceneSystem.h b/WickedEngine/wiSceneSystem.h index be355d656..bf3cdd799 100644 --- a/WickedEngine/wiSceneSystem.h +++ b/WickedEngine/wiSceneSystem.h @@ -854,6 +854,26 @@ namespace wiSceneSystem void Serialize(wiArchive& archive, uint32_t seed = 0); }; + struct WeatherComponent + { + XMFLOAT3 sunColor = XMFLOAT3(0, 0, 0); + XMFLOAT3 sunDirection = XMFLOAT3(0, 1, 0); + 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); + float fogStart = 100; + float fogEnd = 1000; + float fogHeight = 0; + float cloudiness = 0.0f; + float cloudScale = 0.0003f; + float cloudSpeed = 0.1f; + XMFLOAT3 windDirection = XMFLOAT3(0, 0, 0); + float windRandomness = 5; + float windWaveSize = 1; + + void Serialize(wiArchive& archive, uint32_t seed = 0); + }; + struct Scene { wiECS::ComponentManager names; @@ -879,31 +899,18 @@ namespace wiSceneSystem wiECS::ComponentManager animations; wiECS::ComponentManager emitters; wiECS::ComponentManager hairs; - - XMFLOAT3 sunDirection = XMFLOAT3(0, 1, 0); - XMFLOAT3 sunColor = XMFLOAT3(0, 0, 0); - 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); - float fogStart = 100; - float fogEnd = 1000; - float fogHeight = 0; - float cloudiness = 0.0f; - float cloudScale = 0.0003f; - float cloudSpeed = 0.1f; - XMFLOAT3 windDirection = XMFLOAT3(0, 0, 0); - float windRandomness = 5; - float windWaveSize = 1; + wiECS::ComponentManager weathers; // Non-serialized attributes: AABB bounds; XMFLOAT4 waterPlane = XMFLOAT4(0, 1, 0, 0); + WeatherComponent weather; // Update all components by a given timestep (in seconds): void Update(float dt); // Remove everything from the scene that it owns: void Clear(); - // Merge with an other scene. Other scene state is non-retained! + // Merge with an other scene. void Merge(Scene& other); // Count how many entities there are in the scene: size_t CountEntities() const; @@ -917,8 +924,9 @@ namespace wiSceneSystem // Serializes entity and all of its components to archive: // You can specify entity = INVALID_ENTITY when the entity needs to be created from archive // You can specify seed = 0 when the archive is guaranteed to be storing persistent and unique entities + // propagateDeepSeed : request that entity references inside components should be seeded as well // Returns either the new entity that was read, or the original entity that was written - wiECS::Entity Entity_Serialize(wiArchive& archive, wiECS::Entity entity = wiECS::INVALID_ENTITY, uint32_t seed = 0); + wiECS::Entity Entity_Serialize(wiArchive& archive, wiECS::Entity entity = wiECS::INVALID_ENTITY, uint32_t seed = 0, bool propagateSeedDeep = true); wiECS::Entity Entity_CreateMaterial( const std::string& name @@ -1033,7 +1041,7 @@ namespace wiSceneSystem const wiECS::ComponentManager& transforms, wiECS::ComponentManager& aabb_lights, wiECS::ComponentManager& lights, - XMFLOAT3& sunDirection, XMFLOAT3& sunColor + WeatherComponent* weather = nullptr ); void RunParticleUpdateSystem( const wiECS::ComponentManager& transforms, diff --git a/WickedEngine/wiSceneSystem_BindLua.cpp b/WickedEngine/wiSceneSystem_BindLua.cpp index ad23f9cbc..ca89226c8 100644 --- a/WickedEngine/wiSceneSystem_BindLua.cpp +++ b/WickedEngine/wiSceneSystem_BindLua.cpp @@ -1,4 +1,5 @@ #include "wiSceneSystem_BindLua.h" +#include "wiSceneSystem.h" #include "Vector_BindLua.h" #include "Matrix_BindLua.h" #include "wiEmittedParticle.h" @@ -18,8 +19,13 @@ void Bind() { initialized = true; - Luna::Register(wiLua::GetGlobal()->GetLuaState()); - Luna::Register(wiLua::GetGlobal()->GetLuaState()); + lua_State* L = wiLua::GetGlobal()->GetLuaState(); + + Luna::Register(L); + Luna::Register(L); + Luna::Register(L); + Luna::Register(L); + Luna::Register(L); } } @@ -31,7 +37,10 @@ Luna::FunctionType Scene_BindLua::methods[] = { lunamethod(Scene_BindLua, Update), lunamethod(Scene_BindLua, Clear), lunamethod(Scene_BindLua, Entity_FindByName), + lunamethod(Scene_BindLua, Component_GetName), + lunamethod(Scene_BindLua, Component_GetLayer), lunamethod(Scene_BindLua, Component_GetTransform), + lunamethod(Scene_BindLua, Component_GetAnimation), lunamethod(Scene_BindLua, Component_Attach), lunamethod(Scene_BindLua, Component_Detach), lunamethod(Scene_BindLua, Component_DetachChildren), @@ -88,6 +97,40 @@ int Scene_BindLua::Entity_FindByName(lua_State* L) return 0; } +int Scene_BindLua::Component_GetName(lua_State* L) +{ + int argc = wiLua::SGetArgCount(L); + if (argc > 0) + { + Entity entity = (Entity)wiLua::SGetInt(L, 1); + + NameComponent* component = scene->names.GetComponent(entity); + Luna::push(L, new NameComponent_BindLua(component)); + return 1; + } + else + { + wiLua::SError(L, "Scene::Component_GetName(Entity entity) not enough arguments!"); + } + return 0; +} +int Scene_BindLua::Component_GetLayer(lua_State* L) +{ + int argc = wiLua::SGetArgCount(L); + if (argc > 0) + { + Entity entity = (Entity)wiLua::SGetInt(L, 1); + + LayerComponent* component = scene->layers.GetComponent(entity); + Luna::push(L, new LayerComponent_BindLua(component)); + return 1; + } + else + { + wiLua::SError(L, "Scene::Component_GetLayer(Entity entity) not enough arguments!"); + } + return 0; +} int Scene_BindLua::Component_GetTransform(lua_State* L) { int argc = wiLua::SGetArgCount(L); @@ -95,8 +138,8 @@ int Scene_BindLua::Component_GetTransform(lua_State* L) { Entity entity = (Entity)wiLua::SGetInt(L, 1); - TransformComponent* transform = scene->transforms.GetComponent(entity); - Luna::push(L, new TransformComponent_BindLua(transform)); + TransformComponent* component = scene->transforms.GetComponent(entity); + Luna::push(L, new TransformComponent_BindLua(component)); return 1; } else @@ -105,6 +148,24 @@ int Scene_BindLua::Component_GetTransform(lua_State* L) } return 0; } +int Scene_BindLua::Component_GetAnimation(lua_State* L) +{ + int argc = wiLua::SGetArgCount(L); + if (argc > 0) + { + Entity entity = (Entity)wiLua::SGetInt(L, 1); + + AnimationComponent* component = scene->animations.GetComponent(entity); + Luna::push(L, new AnimationComponent_BindLua(component)); + return 1; + } + else + { + wiLua::SError(L, "Scene::Component_GetAnimation(Entity entity) not enough arguments!"); + } + return 0; +} + int Scene_BindLua::Component_Attach(lua_State* L) { int argc = wiLua::SGetArgCount(L); @@ -156,6 +217,104 @@ int Scene_BindLua::Component_DetachChildren(lua_State* L) + +const char NameComponent_BindLua::className[] = "NameComponent"; + +Luna::FunctionType NameComponent_BindLua::methods[] = { + lunamethod(NameComponent_BindLua, SetName), + lunamethod(NameComponent_BindLua, GetName), + { NULL, NULL } +}; +Luna::PropertyType NameComponent_BindLua::properties[] = { + { NULL, NULL } +}; + +NameComponent_BindLua::NameComponent_BindLua(lua_State *L) +{ + owning = true; + component = new NameComponent; +} +NameComponent_BindLua::~NameComponent_BindLua() +{ + if (owning) + { + delete component; + } +} + +int NameComponent_BindLua::SetName(lua_State* L) +{ + int argc = wiLua::SGetArgCount(L); + if (argc > 0) + { + string name = wiLua::SGetString(L, 1); + *component = name; + } + else + { + wiLua::SError(L, "SetName(string value) not enough arguments!"); + } + return 0; +} +int NameComponent_BindLua::GetName(lua_State* L) +{ + wiLua::SSetString(L, component->name); + return 1; +} + + + + + +const char LayerComponent_BindLua::className[] = "LayerComponent"; + +Luna::FunctionType LayerComponent_BindLua::methods[] = { + lunamethod(LayerComponent_BindLua, SetLayerMask), + lunamethod(LayerComponent_BindLua, GetLayerMask), + { NULL, NULL } +}; +Luna::PropertyType LayerComponent_BindLua::properties[] = { + { NULL, NULL } +}; + +LayerComponent_BindLua::LayerComponent_BindLua(lua_State *L) +{ + owning = true; + component = new LayerComponent; +} +LayerComponent_BindLua::~LayerComponent_BindLua() +{ + if (owning) + { + delete component; + } +} + +int LayerComponent_BindLua::SetLayerMask(lua_State* L) +{ + int argc = wiLua::SGetArgCount(L); + if (argc > 0) + { + int mask = wiLua::SGetInt(L, 1); + component->layerMask = *reinterpret_cast(&mask); + } + else + { + wiLua::SError(L, "SetLayerMask(int value) not enough arguments!"); + } + return 0; +} +int LayerComponent_BindLua::GetLayerMask(lua_State* L) +{ + wiLua::SSetInt(L, component->GetLayerMask()); + return 1; +} + + + + + + const char TransformComponent_BindLua::className[] = "TransformComponent"; Luna::FunctionType TransformComponent_BindLua::methods[] = { @@ -178,9 +337,15 @@ Luna::PropertyType TransformComponent_BindLua::prope TransformComponent_BindLua::TransformComponent_BindLua(lua_State *L) { + owning = true; + component = new TransformComponent; } TransformComponent_BindLua::~TransformComponent_BindLua() { + if (owning) + { + delete component; + } } int TransformComponent_BindLua::Scale(lua_State* L) @@ -194,7 +359,7 @@ int TransformComponent_BindLua::Scale(lua_State* L) XMFLOAT3 value; XMStoreFloat3(&value, v->vector); - transform->Scale(value); + component->Scale(value); } else { @@ -218,7 +383,7 @@ int TransformComponent_BindLua::Rotate(lua_State* L) XMFLOAT3 rollPitchYaw; XMStoreFloat3(&rollPitchYaw, v->vector); - transform->RotateRollPitchYaw(rollPitchYaw); + component->RotateRollPitchYaw(rollPitchYaw); } else { @@ -242,7 +407,7 @@ int TransformComponent_BindLua::Translate(lua_State* L) XMFLOAT3 value; XMStoreFloat3(&value, v->vector); - transform->Translate(value); + component->Translate(value); } else { @@ -269,21 +434,21 @@ int TransformComponent_BindLua::Lerp(lua_State* L) { float t = wiLua::SGetFloat(L, 3); - transform->Lerp(*a->transform, *b->transform, t); + component->Lerp(*a->component, *b->component, t); } else { - wiLua::SError(L, "Lerp(Transform a,b, float t) argument (b) is not a Transform!"); + wiLua::SError(L, "Lerp(TransformComponent a,b, float t) argument (b) is not a Transform!"); } } else { - wiLua::SError(L, "Lerp(Transform a,b, float t) argument (a) is not a Transform!"); + wiLua::SError(L, "Lerp(TransformComponent a,b, float t) argument (a) is not a Transform!"); } } else { - wiLua::SError(L, "Lerp(Transform a,b, float t) not enough arguments!"); + wiLua::SError(L, "Lerp(TransformComponent a,b, float t) not enough arguments!"); } return 0; } @@ -309,31 +474,31 @@ int TransformComponent_BindLua::CatmullRom(lua_State* L) { float t = wiLua::SGetFloat(L, 5); - transform->CatmullRom(*a->transform, *b->transform, *c->transform, *d->transform, t); + component->CatmullRom(*a->component, *b->component, *c->component, *d->component, t); } else { - wiLua::SError(L, "CatmullRom(Transform a,b,c,d, float t) argument (d) is not a Transform!"); + wiLua::SError(L, "CatmullRom(TransformComponent a,b,c,d, float t) argument (d) is not a Transform!"); } } else { - wiLua::SError(L, "CatmullRom(Transform a,b,c,d, float t) argument (c) is not a Transform!"); + wiLua::SError(L, "CatmullRom(TransformComponent a,b,c,d, float t) argument (c) is not a Transform!"); } } else { - wiLua::SError(L, "CatmullRom(Transform a,b,c,d, float t) argument (b) is not a Transform!"); + wiLua::SError(L, "CatmullRom(TransformComponent a,b,c,d, float t) argument (b) is not a Transform!"); } } else { - wiLua::SError(L, "CatmullRom(Transform a,b,c,d, float t) argument (a) is not a Transform!"); + wiLua::SError(L, "CatmullRom(TransformComponent a,b,c,d, float t) argument (a) is not a Transform!"); } } else { - wiLua::SError(L, "CatmullRom(Transform a,b,c,d, float t) not enough arguments!"); + wiLua::SError(L, "CatmullRom(TransformComponent a,b,c,d, float t) not enough arguments!"); } return 0; } @@ -345,7 +510,7 @@ int TransformComponent_BindLua::MatrixTransform(lua_State* L) Matrix_BindLua* m = Luna::lightcheck(L, 1); if (m != nullptr) { - transform->MatrixTransform(m->matrix); + component->MatrixTransform(m->matrix); } else { @@ -360,33 +525,83 @@ int TransformComponent_BindLua::MatrixTransform(lua_State* L) } int TransformComponent_BindLua::GetMatrix(lua_State* L) { - XMMATRIX M = XMLoadFloat4x4(&transform->world); + XMMATRIX M = XMLoadFloat4x4(&component->world); Luna::push(L, new Matrix_BindLua(M)); return 1; } int TransformComponent_BindLua::ClearTransform(lua_State* L) { - transform->ClearTransform(); + component->ClearTransform(); return 0; } int TransformComponent_BindLua::GetPosition(lua_State* L) { - XMVECTOR V = transform->GetPositionV(); + XMVECTOR V = component->GetPositionV(); Luna::push(L, new Vector_BindLua(V)); return 1; } int TransformComponent_BindLua::GetRotation(lua_State* L) { - XMVECTOR V = transform->GetRotationV(); + XMVECTOR V = component->GetRotationV(); Luna::push(L, new Vector_BindLua(V)); return 1; } int TransformComponent_BindLua::GetScale(lua_State* L) { - XMVECTOR V = transform->GetScaleV(); + XMVECTOR V = component->GetScaleV(); Luna::push(L, new Vector_BindLua(V)); return 1; } + + + + + + + + +const char AnimationComponent_BindLua::className[] = "AnimationComponent"; + +Luna::FunctionType AnimationComponent_BindLua::methods[] = { + lunamethod(AnimationComponent_BindLua, Play), + lunamethod(AnimationComponent_BindLua, Pause), + lunamethod(AnimationComponent_BindLua, Stop), + { NULL, NULL } +}; +Luna::PropertyType AnimationComponent_BindLua::properties[] = { + { NULL, NULL } +}; + +AnimationComponent_BindLua::AnimationComponent_BindLua(lua_State *L) +{ + owning = true; + component = new AnimationComponent; +} +AnimationComponent_BindLua::~AnimationComponent_BindLua() +{ + if (owning) + { + delete component; + } +} + +int AnimationComponent_BindLua::Play(lua_State* L) +{ + component->Play(); + return 0; +} +int AnimationComponent_BindLua::Pause(lua_State* L) +{ + component->Pause(); + return 0; +} +int AnimationComponent_BindLua::Stop(lua_State* L) +{ + component->Stop(); + return 0; +} + + } diff --git a/WickedEngine/wiSceneSystem_BindLua.h b/WickedEngine/wiSceneSystem_BindLua.h index 5d6495613..d59827feb 100644 --- a/WickedEngine/wiSceneSystem_BindLua.h +++ b/WickedEngine/wiSceneSystem_BindLua.h @@ -1,7 +1,7 @@ #pragma once #include "wiLua.h" #include "wiLuna.h" -#include "wiSceneSystem.h" +#include "wiSceneSystem_Decl.h" namespace wiSceneSystem_BindLua { @@ -25,23 +25,63 @@ namespace wiSceneSystem_BindLua int Entity_FindByName(lua_State* L); + int Component_GetName(lua_State* L); + int Component_GetLayer(lua_State* L); int Component_GetTransform(lua_State* L); + int Component_GetAnimation(lua_State* L); int Component_Attach(lua_State* L); int Component_Detach(lua_State* L); int Component_DetachChildren(lua_State* L); }; + class NameComponent_BindLua + { + public: + bool owning = false; + wiSceneSystem::NameComponent* component = nullptr; + + static const char className[]; + static Luna::FunctionType methods[]; + static Luna::PropertyType properties[]; + + NameComponent_BindLua(wiSceneSystem::NameComponent* component) :component(component) {} + NameComponent_BindLua(lua_State *L); + ~NameComponent_BindLua(); + + int SetName(lua_State* L); + int GetName(lua_State* L); + }; + + class LayerComponent_BindLua + { + public: + bool owning = false; + wiSceneSystem::LayerComponent* component = nullptr; + + static const char className[]; + static Luna::FunctionType methods[]; + static Luna::PropertyType properties[]; + + LayerComponent_BindLua(wiSceneSystem::LayerComponent* component) :component(component) {} + LayerComponent_BindLua(lua_State *L); + ~LayerComponent_BindLua(); + + int SetLayerMask(lua_State* L); + int GetLayerMask(lua_State* L); + }; + class TransformComponent_BindLua { public: - wiSceneSystem::TransformComponent* transform = nullptr; + bool owning = false; + wiSceneSystem::TransformComponent* component = nullptr; static const char className[]; static Luna::FunctionType methods[]; static Luna::PropertyType properties[]; - TransformComponent_BindLua(wiSceneSystem::TransformComponent* transform) :transform(transform) {} + TransformComponent_BindLua(wiSceneSystem::TransformComponent* component) :component(component) {} TransformComponent_BindLua(lua_State *L); ~TransformComponent_BindLua(); @@ -58,5 +98,24 @@ namespace wiSceneSystem_BindLua int GetScale(lua_State* L); }; + class AnimationComponent_BindLua + { + public: + bool owning = false; + wiSceneSystem::AnimationComponent* component = nullptr; + + static const char className[]; + static Luna::FunctionType methods[]; + static Luna::PropertyType properties[]; + + AnimationComponent_BindLua(wiSceneSystem::AnimationComponent* component) :component(component) {} + AnimationComponent_BindLua(lua_State *L); + ~AnimationComponent_BindLua(); + + int Play(lua_State* L); + int Pause(lua_State* L); + int Stop(lua_State* L); + }; + } diff --git a/WickedEngine/wiSceneSystem_Decl.h b/WickedEngine/wiSceneSystem_Decl.h index 61de0d8ec..d339822de 100644 --- a/WickedEngine/wiSceneSystem_Decl.h +++ b/WickedEngine/wiSceneSystem_Decl.h @@ -20,6 +20,6 @@ namespace wiSceneSystem struct ForceFieldComponent; struct DecalComponent; struct AnimationComponent; - struct ModelComponent; + struct WeatherComponent; struct Scene; } diff --git a/WickedEngine/wiSceneSystem_Serializers.cpp b/WickedEngine/wiSceneSystem_Serializers.cpp index 049980d19..488665003 100644 --- a/WickedEngine/wiSceneSystem_Serializers.cpp +++ b/WickedEngine/wiSceneSystem_Serializers.cpp @@ -454,6 +454,43 @@ namespace wiSceneSystem } } } + void WeatherComponent::Serialize(wiArchive& archive, uint32_t seed) + { + if (archive.IsReadMode()) + { + archive >> sunDirection; + archive >> sunColor; + archive >> horizon; + archive >> zenith; + archive >> ambient; + archive >> fogStart; + archive >> fogEnd; + archive >> fogHeight; + archive >> cloudiness; + archive >> cloudScale; + archive >> cloudSpeed; + archive >> windDirection; + archive >> windRandomness; + archive >> windWaveSize; + } + else + { + archive << sunDirection; + archive << sunColor; + archive << horizon; + archive << zenith; + archive << ambient; + archive << fogStart; + archive << fogEnd; + archive << fogHeight; + archive << cloudiness; + archive << cloudScale; + archive << cloudSpeed; + archive << windDirection; + archive << windRandomness; + archive << windWaveSize; + } + } void Scene::Serialize(wiArchive& archive) { @@ -493,45 +530,11 @@ namespace wiSceneSystem animations.Serialize(archive, seed); emitters.Serialize(archive, seed); hairs.Serialize(archive, seed); - - if (archive.IsReadMode()) - { - archive >> sunDirection; - archive >> sunColor; - archive >> horizon; - archive >> zenith; - archive >> ambient; - archive >> fogStart; - archive >> fogEnd; - archive >> fogHeight; - archive >> cloudiness; - archive >> cloudScale; - archive >> cloudSpeed; - archive >> windDirection; - archive >> windRandomness; - archive >> windWaveSize; - } - else - { - archive << sunDirection; - archive << sunColor; - archive << horizon; - archive << zenith; - archive << ambient; - archive << fogStart; - archive << fogEnd; - archive << fogHeight; - archive << cloudiness; - archive << cloudScale; - archive << cloudSpeed; - archive << windDirection; - archive << windRandomness; - archive << windWaveSize; - } + weathers.Serialize(archive, seed); } - Entity Scene::Entity_Serialize(wiArchive& archive, Entity entity, uint32_t seed) + Entity Scene::Entity_Serialize(wiArchive& archive, Entity entity, uint32_t seed, bool propagateSeedDeep) { SerializeEntity(archive, entity, seed); @@ -544,7 +547,7 @@ namespace wiSceneSystem if (component_exists) { auto& component = names.Create(entity); - component.Serialize(archive, seed); + component.Serialize(archive, propagateSeedDeep ? seed : 0); } } { @@ -553,7 +556,7 @@ namespace wiSceneSystem if (component_exists) { auto& component = layers.Create(entity); - component.Serialize(archive, seed); + component.Serialize(archive, propagateSeedDeep ? seed : 0); } } { @@ -562,7 +565,7 @@ namespace wiSceneSystem if (component_exists) { auto& component = transforms.Create(entity); - component.Serialize(archive, seed); + component.Serialize(archive, propagateSeedDeep ? seed : 0); } } { @@ -571,7 +574,7 @@ namespace wiSceneSystem if (component_exists) { auto& component = prev_transforms.Create(entity); - component.Serialize(archive, seed); + component.Serialize(archive, propagateSeedDeep ? seed : 0); } } { @@ -580,7 +583,7 @@ namespace wiSceneSystem if (component_exists) { auto& component = hierarchy.Create(entity); - component.Serialize(archive, seed); + component.Serialize(archive, propagateSeedDeep ? seed : 0); } } { @@ -589,7 +592,7 @@ namespace wiSceneSystem if (component_exists) { auto& component = materials.Create(entity); - component.Serialize(archive, seed); + component.Serialize(archive, propagateSeedDeep ? seed : 0); } } { @@ -598,7 +601,7 @@ namespace wiSceneSystem if (component_exists) { auto& component = meshes.Create(entity); - component.Serialize(archive, seed); + component.Serialize(archive, propagateSeedDeep ? seed : 0); } } { @@ -607,7 +610,7 @@ namespace wiSceneSystem if (component_exists) { auto& component = objects.Create(entity); - component.Serialize(archive, seed); + component.Serialize(archive, propagateSeedDeep ? seed : 0); } } { @@ -616,7 +619,7 @@ namespace wiSceneSystem if (component_exists) { auto& component = aabb_objects.Create(entity); - component.Serialize(archive, seed); + component.Serialize(archive, propagateSeedDeep ? seed : 0); } } { @@ -625,7 +628,7 @@ namespace wiSceneSystem if (component_exists) { auto& component = rigidbodies.Create(entity); - component.Serialize(archive, seed); + component.Serialize(archive, propagateSeedDeep ? seed : 0); } } { @@ -634,7 +637,7 @@ namespace wiSceneSystem if (component_exists) { auto& component = softbodies.Create(entity); - component.Serialize(archive, seed); + component.Serialize(archive, propagateSeedDeep ? seed : 0); } } { @@ -643,7 +646,7 @@ namespace wiSceneSystem if (component_exists) { auto& component = armatures.Create(entity); - component.Serialize(archive, seed); + component.Serialize(archive, propagateSeedDeep ? seed : 0); } } { @@ -652,7 +655,7 @@ namespace wiSceneSystem if (component_exists) { auto& component = lights.Create(entity); - component.Serialize(archive, seed); + component.Serialize(archive, propagateSeedDeep ? seed : 0); } } { @@ -661,7 +664,7 @@ namespace wiSceneSystem if (component_exists) { auto& component = aabb_lights.Create(entity); - component.Serialize(archive, seed); + component.Serialize(archive, propagateSeedDeep ? seed : 0); } } { @@ -670,7 +673,7 @@ namespace wiSceneSystem if (component_exists) { auto& component = cameras.Create(entity); - component.Serialize(archive, seed); + component.Serialize(archive, propagateSeedDeep ? seed : 0); } } { @@ -679,7 +682,7 @@ namespace wiSceneSystem if (component_exists) { auto& component = probes.Create(entity); - component.Serialize(archive, seed); + component.Serialize(archive, propagateSeedDeep ? seed : 0); } } { @@ -688,7 +691,7 @@ namespace wiSceneSystem if (component_exists) { auto& component = aabb_probes.Create(entity); - component.Serialize(archive, seed); + component.Serialize(archive, propagateSeedDeep ? seed : 0); } } { @@ -697,7 +700,7 @@ namespace wiSceneSystem if (component_exists) { auto& component = forces.Create(entity); - component.Serialize(archive, seed); + component.Serialize(archive, propagateSeedDeep ? seed : 0); } } { @@ -706,7 +709,7 @@ namespace wiSceneSystem if (component_exists) { auto& component = decals.Create(entity); - component.Serialize(archive, seed); + component.Serialize(archive, propagateSeedDeep ? seed : 0); } } { @@ -715,7 +718,7 @@ namespace wiSceneSystem if (component_exists) { auto& component = aabb_decals.Create(entity); - component.Serialize(archive, seed); + component.Serialize(archive, propagateSeedDeep ? seed : 0); } } { @@ -724,7 +727,7 @@ namespace wiSceneSystem if (component_exists) { auto& component = animations.Create(entity); - component.Serialize(archive, seed); + component.Serialize(archive, propagateSeedDeep ? seed : 0); } } { @@ -733,7 +736,7 @@ namespace wiSceneSystem if (component_exists) { auto& component = emitters.Create(entity); - component.Serialize(archive, seed); + component.Serialize(archive, propagateSeedDeep ? seed : 0); } } { @@ -742,7 +745,16 @@ namespace wiSceneSystem if (component_exists) { auto& component = hairs.Create(entity); - component.Serialize(archive, seed); + component.Serialize(archive, propagateSeedDeep ? seed : 0); + } + } + { + bool component_exists; + archive >> component_exists; + if (component_exists) + { + auto& component = weathers.Create(entity); + component.Serialize(archive, propagateSeedDeep ? seed : 0); } } } @@ -1025,6 +1037,18 @@ namespace wiSceneSystem archive << false; } } + { + auto component = weathers.GetComponent(entity); + if (component != nullptr) + { + archive << true; + component->Serialize(archive, seed); + } + else + { + archive << false; + } + } } diff --git a/WickedEngine/wiWidget.cpp b/WickedEngine/wiWidget.cpp index 894b8ca6e..b750f40e0 100644 --- a/WickedEngine/wiWidget.cpp +++ b/WickedEngine/wiWidget.cpp @@ -6,6 +6,7 @@ #include "wiMath.h" #include "wiHelper.h" #include "wiInputManager.h" +#include "ShaderInterop_Renderer.h" #include @@ -1770,7 +1771,7 @@ void wiColorPicker::Render(wiGUI* gui) wiRenderer::GetDevice()->BindConstantBuffer(VS, wiRenderer::constantBuffers[CBTYPE_MISC], CBSLOT_RENDERER_MISC, threadID); wiRenderer::GetDevice()->BindGraphicsPSO(PSO_colorpicker, threadID); - wiRenderer::MiscCB cb; + MiscCB cb; // render saturation triangle { @@ -1780,12 +1781,12 @@ void wiColorPicker::Render(wiGUI* gui) wiRenderer::GetDevice()->UpdateBuffer(&vb_saturation, vertices_saturation.data(), threadID, vb_saturation.GetDesc().ByteWidth); } - cb.mTransform = XMMatrixTranspose( + XMStoreFloat4x4(&cb.g_xTransform, XMMatrixTranspose( XMMatrixRotationZ(-angle) * XMMatrixTranslation(translation.x + __colorpicker_center, translation.y + __colorpicker_center, 0) * __cam - ); - cb.mColor = XMFLOAT4(1, 1, 1, 1); + )); + cb.g_xColor = XMFLOAT4(1, 1, 1, 1); wiRenderer::GetDevice()->UpdateBuffer(wiRenderer::constantBuffers[CBTYPE_MISC], &cb, threadID); GPUBuffer* vbs[] = { &vb_saturation, @@ -1799,11 +1800,11 @@ void wiColorPicker::Render(wiGUI* gui) // render hue circle { - cb.mTransform = XMMatrixTranspose( + XMStoreFloat4x4(&cb.g_xTransform, XMMatrixTranspose( XMMatrixTranslation(translation.x + __colorpicker_center, translation.y + __colorpicker_center, 0) * __cam - ); - cb.mColor = XMFLOAT4(1, 1, 1, 1); + )); + cb.g_xColor = float4(1, 1, 1, 1); wiRenderer::GetDevice()->UpdateBuffer(wiRenderer::constantBuffers[CBTYPE_MISC], &cb, threadID); GPUBuffer* vbs[] = { &vb_hue, @@ -1817,11 +1818,11 @@ void wiColorPicker::Render(wiGUI* gui) // render hue picker { - cb.mTransform = XMMatrixTranspose( + XMStoreFloat4x4(&cb.g_xTransform, XMMatrixTranspose( XMMatrixTranslation(hue_picker.x, hue_picker.y, 0) * __cam - ); - cb.mColor = XMFLOAT4(1 - hue_color.x, 1 - hue_color.y, 1 - hue_color.z, 1); + )); + cb.g_xColor = float4(1 - hue_color.x, 1 - hue_color.y, 1 - hue_color.z, 1); wiRenderer::GetDevice()->UpdateBuffer(wiRenderer::constantBuffers[CBTYPE_MISC], &cb, threadID); GPUBuffer* vbs[] = { &vb_picker, @@ -1835,11 +1836,11 @@ void wiColorPicker::Render(wiGUI* gui) // render saturation picker { - cb.mTransform = XMMatrixTranspose( + XMStoreFloat4x4(&cb.g_xTransform, XMMatrixTranspose( XMMatrixTranslation(saturation_picker.x, saturation_picker.y, 0) * __cam - ); - cb.mColor = XMFLOAT4(1 - final_color.x, 1 - final_color.y, 1 - final_color.z, 1); + )); + cb.g_xColor = float4(1 - final_color.x, 1 - final_color.y, 1 - final_color.z, 1); wiRenderer::GetDevice()->UpdateBuffer(wiRenderer::constantBuffers[CBTYPE_MISC], &cb, threadID); GPUBuffer* vbs[] = { &vb_picker, @@ -1853,11 +1854,11 @@ void wiColorPicker::Render(wiGUI* gui) // render preview { - cb.mTransform = XMMatrixTranspose( + XMStoreFloat4x4(&cb.g_xTransform, XMMatrixTranspose( XMMatrixTranslation(translation.x + 260, translation.y + 40, 0) * __cam - ); - cb.mColor = GetPickColor(); + )); + cb.g_xColor = GetPickColor(); wiRenderer::GetDevice()->UpdateBuffer(wiRenderer::constantBuffers[CBTYPE_MISC], &cb, threadID); GPUBuffer* vbs[] = { &vb_preview,