From 5efe28fdf9917da221133d8fdd5a0f99460758af Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tur=C3=A1nszki=20J=C3=A1nos?= Date: Mon, 7 Dec 2020 01:32:44 +0100 Subject: [PATCH] 0.51.0 (#200) * large renderer state refactor; added subsurface scattering energy conservation; added emitted particle subsurface scattering; removed area lights; optimizations; * added layerMask support in shaders * fixed incorrect shadow priority for directional light; fix point light shadow disconnect; * fix incorrect shadow assignment --- Content.vcxitems | 20 + Content.vcxitems.filters | 6 + Documentation/ScriptingAPI-Documentation.md | 4 +- Editor/CameraWindow.cpp | 16 +- Editor/Editor.cpp | 38 +- Editor/EnvProbeWindow.cpp | 2 +- Editor/LayerWindow.cpp | 20 + Editor/LightWindow.cpp | 112 +-- Editor/ModelImporter_GLTF.cpp | 6 +- Editor/PaintToolWindow.cpp | 2 +- Editor/RendererWindow.cpp | 12 +- Editor/Translator.cpp | 2 +- Tests/Tests.cpp | 2 +- WickedEngine/ArchiveVersionHistory.txt | 1 + WickedEngine/RenderPath2D.cpp | 23 +- WickedEngine/RenderPath2D.h | 7 +- WickedEngine/RenderPath3D.cpp | 102 +-- WickedEngine/RenderPath3D.h | 8 +- WickedEngine/RenderPath3D_PathTracing.cpp | 12 +- WickedEngine/ShaderInterop_Ocean.h | 2 +- WickedEngine/ShaderInterop_Postprocess.h | 2 - WickedEngine/ShaderInterop_Renderer.h | 142 ++-- WickedEngine/Shaders_SOURCE.vcxitems | 40 - WickedEngine/Shaders_SOURCE.vcxitems.filters | 12 - WickedEngine/brdf.hlsli | 2 + WickedEngine/emittedparticlePS_soft.hlsl | 10 +- WickedEngine/emittedparticle_simulateCS.hlsl | 4 +- WickedEngine/forceFieldPlaneVisualizerVS.hlsl | 2 +- WickedEngine/forceFieldPointVisualizerVS.hlsl | 2 +- WickedEngine/forceFieldVisualizerPS.hlsl | 8 +- WickedEngine/hairparticle_simulateCS.hlsl | 4 +- WickedEngine/lightCullingCS.hlsl | 14 +- WickedEngine/lightingHF.hlsli | 19 +- WickedEngine/objectHF.hlsli | 70 +- WickedEngine/objectPS_voxelizer.hlsl | 8 +- WickedEngine/oceanSimulatorCS.hlsl | 5 +- WickedEngine/raytrace_shadeCS.hlsl | 24 +- WickedEngine/renderlightmapPS.hlsl | 24 +- WickedEngine/rtaoLIB.hlsl | 2 +- WickedEngine/rtreflectionLIB.hlsl | 22 +- WickedEngine/shaders/CMakeLists.txt | 4 - WickedEngine/vDiscLightVS.hlsl | 13 - WickedEngine/vRectangleLightVS.hlsl | 13 - WickedEngine/vSphereLightVS.hlsl | 13 - WickedEngine/vTubeLightVS.hlsl | 13 - .../volumetricLight_DirectionalPS.hlsl | 4 +- WickedEngine/volumetricLight_PointPS.hlsl | 8 +- WickedEngine/volumetricLight_SpotPS.hlsl | 6 +- WickedEngine/wiArchive.cpp | 14 +- WickedEngine/wiEmittedParticle.cpp | 1 + WickedEngine/wiEnums.h | 4 - WickedEngine/wiEvent.h | 1 - WickedEngine/wiFont.cpp | 6 +- WickedEngine/wiImage.cpp | 59 +- WickedEngine/wiImage.h | 13 +- WickedEngine/wiOcean.cpp | 6 +- WickedEngine/wiOcean.h | 4 +- WickedEngine/wiRenderer.cpp | 733 +++++++----------- WickedEngine/wiRenderer.h | 36 +- WickedEngine/wiRenderer_BindLua.cpp | 37 - WickedEngine/wiScene.cpp | 30 +- WickedEngine/wiScene.h | 22 +- WickedEngine/wiScene_BindLua.cpp | 6 + WickedEngine/wiScene_Serializers.cpp | 48 +- WickedEngine/wiVersion.cpp | 6 +- WickedEngine/wiWidget.cpp | 14 +- models/shadowspriority_spot_test.wiscene | Bin 12162 -> 12030 bytes 67 files changed, 776 insertions(+), 1151 deletions(-) delete mode 100644 WickedEngine/vDiscLightVS.hlsl delete mode 100644 WickedEngine/vRectangleLightVS.hlsl delete mode 100644 WickedEngine/vSphereLightVS.hlsl delete mode 100644 WickedEngine/vTubeLightVS.hlsl diff --git a/Content.vcxitems b/Content.vcxitems index 307edfff3..5a0f46e18 100644 --- a/Content.vcxitems +++ b/Content.vcxitems @@ -374,6 +374,26 @@ true true + + true + true + true + true + true + true + true + true + + + true + true + true + true + true + true + true + true + true true diff --git a/Content.vcxitems.filters b/Content.vcxitems.filters index 475a6a80e..aeb18a349 100644 --- a/Content.vcxitems.filters +++ b/Content.vcxitems.filters @@ -192,6 +192,12 @@ models + + models + + + models + diff --git a/Documentation/ScriptingAPI-Documentation.md b/Documentation/ScriptingAPI-Documentation.md index 86eb04775..b397021b1 100644 --- a/Documentation/ScriptingAPI-Documentation.md +++ b/Documentation/ScriptingAPI-Documentation.md @@ -100,15 +100,12 @@ This is the graphics renderer, which is also responsible for managing the scene parent-child relationships between the scene hierarchy, updating the world, animating armatures. You can use the Renderer with the following functions, all of which are in the global scope: - GetGameSpeed() : float result -- SetResolutionScale(float scale) - SetGamma(float gamma) - SetGameSpeed(float speed) - GetScreenWidth() : float result - GetScreenHeight() : float result - GetRenderWidth() : float result - GetRenderHeight(): float result -- GetCamera() : Camera result -- returns the main camera -- AttachCamera(Entity entity) -- attaches camera to an entity in the current frame - HairParticleSettings(opt int lod0, opt int lod1, opt int lod2) - SetShadowProps2D(int resolution, int count) - SetShadowPropsCube(int resolution, int count) @@ -417,6 +414,7 @@ An entity is just an int value (int in LUA and uint32 in C++) and works as a han The scene holds components. Entity handles can be used to retrieve associated components through the scene. - [constructor]Scene() : Scene result -- creates a custom scene - [outer]GetScene() : Scene result -- returns the global scene +- [outer]GetCamera() : Camera result -- returns the global camera - [outer]LoadModel(string fileName, opt Matrix transform) : int rootEntity -- Load Model from file. returns a root entity that everything in this model is attached to - [outer]LoadModel(Scene scene, string fileName, opt Matrix transform) : int rootEntity -- Load Model from file into specified scene. returns a root entity that everything in this model is attached to - [outer]Pick(Ray ray, opt PICKTYPE pickType, opt uint layerMask, opt Scene scene) : int entity, Vector position,normal, float distance -- Perform ray-picking in the scene. pickType is a bitmask specifying object types to check against. layerMask is a bitmask specifying which layers to check against. Scene parameter is optional and will use the global scene if not specified. diff --git a/Editor/CameraWindow.cpp b/Editor/CameraWindow.cpp index db7b19551..f4d4fc345 100644 --- a/Editor/CameraWindow.cpp +++ b/Editor/CameraWindow.cpp @@ -12,7 +12,7 @@ void CameraWindow::ResetCam() camera_transform.ClearTransform(); camera_transform.Translate(XMFLOAT3(0, 2, -10)); camera_transform.UpdateTransform(); - wiRenderer::GetCamera().TransformCamera(camera_transform); + wiScene::GetCamera().TransformCamera(camera_transform); camera_target.ClearTransform(); camera_target.UpdateTransform(); @@ -21,7 +21,7 @@ void CameraWindow::ResetCam() void CameraWindow::Create(EditorComponent* editor) { wiWindow::Create("Camera Window"); - camera_transform.MatrixTransform(wiRenderer::GetCamera().GetInvView()); + camera_transform.MatrixTransform(wiScene::GetCamera().GetInvView()); camera_transform.UpdateTransform(); SetSize(XMFLOAT2(380, 260)); @@ -34,10 +34,10 @@ void CameraWindow::Create(EditorComponent* editor) farPlaneSlider.Create(1, 5000, 1000, 100000, "Far Plane: "); farPlaneSlider.SetSize(XMFLOAT2(100, hei)); farPlaneSlider.SetPos(XMFLOAT2(x, y += step)); - farPlaneSlider.SetValue(wiRenderer::GetCamera().zFarP); + farPlaneSlider.SetValue(wiScene::GetCamera().zFarP); farPlaneSlider.OnSlide([&](wiEventArgs args) { Scene& scene = wiScene::GetScene(); - CameraComponent& camera = wiRenderer::GetCamera(); + CameraComponent& camera = wiScene::GetCamera(); camera.zFarP = args.fValue; camera.UpdateCamera(); }); @@ -46,10 +46,10 @@ void CameraWindow::Create(EditorComponent* editor) nearPlaneSlider.Create(0.01f, 10, 0.1f, 10000, "Near Plane: "); nearPlaneSlider.SetSize(XMFLOAT2(100, hei)); nearPlaneSlider.SetPos(XMFLOAT2(x, y += step)); - nearPlaneSlider.SetValue(wiRenderer::GetCamera().zNearP); + nearPlaneSlider.SetValue(wiScene::GetCamera().zNearP); nearPlaneSlider.OnSlide([&](wiEventArgs args) { Scene& scene = wiScene::GetScene(); - CameraComponent& camera = wiRenderer::GetCamera(); + CameraComponent& camera = wiScene::GetCamera(); camera.zNearP = args.fValue; camera.UpdateCamera(); }); @@ -60,7 +60,7 @@ void CameraWindow::Create(EditorComponent* editor) fovSlider.SetPos(XMFLOAT2(x, y += step)); fovSlider.OnSlide([&](wiEventArgs args) { Scene& scene = wiScene::GetScene(); - CameraComponent& camera = wiRenderer::GetCamera(); + CameraComponent& camera = wiScene::GetCamera(); camera.fov = args.fValue / 180.f * XM_PI; camera.UpdateCamera(); }); @@ -98,7 +98,7 @@ void CameraWindow::Create(EditorComponent* editor) proxyButton.SetPos(XMFLOAT2(x, y += step * 2)); proxyButton.OnClick([=](wiEventArgs args) { - const CameraComponent& camera = wiRenderer::GetCamera(); + const CameraComponent& camera = wiScene::GetCamera(); Scene& scene = wiScene::GetScene(); diff --git a/Editor/Editor.cpp b/Editor/Editor.cpp index 98b93c275..75623303c 100644 --- a/Editor/Editor.cpp +++ b/Editor/Editor.cpp @@ -119,6 +119,8 @@ void EditorComponent::ChangeRenderPath(RENDERPATH path) break; } + renderPath->resolutionScale = resolutionScale; + renderPath->setShadowsEnabled(true); renderPath->setReflectionsEnabled(true); renderPath->setAO(RenderPath3D::AO_DISABLED); @@ -159,8 +161,8 @@ void EditorComponent::ResizeBuffers() if(renderPath != nullptr && renderPath->GetDepthStencil() != nullptr) { TextureDesc desc; - desc.Width = wiRenderer::GetInternalResolution().x; - desc.Height = wiRenderer::GetInternalResolution().y; + desc.Width = GetInternalResolution().x; + desc.Height = GetInternalResolution().y; desc.Format = FORMAT_R8_UNORM; desc.BindFlags = BIND_RENDER_TARGET | BIND_SHADER_RESOURCE; @@ -1003,7 +1005,7 @@ void EditorComponent::Update(float dt) wiProfiler::range_id profrange = wiProfiler::BeginRangeCPU("Editor Update"); Scene& scene = wiScene::GetScene(); - CameraComponent& camera = wiRenderer::GetCamera(); + CameraComponent& camera = wiScene::GetCamera(); animWnd.Update(); weatherWnd.Update(); @@ -1904,7 +1906,7 @@ void EditorComponent::Compose(CommandList cmd) const device->EventEnd(cmd); } - const CameraComponent& camera = wiRenderer::GetCamera(); + const CameraComponent& camera = wiScene::GetCamera(); Scene& scene = wiScene::GetScene(); @@ -1913,6 +1915,18 @@ void EditorComponent::Compose(CommandList cmd) const const XMFLOAT4 glow = wiMath::Lerp(wiMath::Lerp(XMFLOAT4(1, 1, 1, 1), selectionColor, 0.4f), selectionColor, selectionColorIntensity); const wiColor selectedEntityColor = wiColor::fromFloat4(glow); + // remove camera jittering + CameraComponent cam = *renderPath->camera; + cam.jitter = XMFLOAT2(0, 0); + cam.UpdateCamera(); + const XMMATRIX VP = cam.GetViewProjection(); + + const XMMATRIX R = XMLoadFloat3x3(&cam.rotationMatrix); + + wiImageParams fx; + fx.customRotation = &R; + fx.customProjection = &VP; + if (rendererWnd.GetPickType() & PICK_LIGHT) { for (size_t i = 0; i < scene.lights.GetCount(); ++i) @@ -1923,10 +1937,8 @@ void EditorComponent::Compose(CommandList cmd) const float dist = wiMath::Distance(transform.GetPosition(), camera.Eye) * 0.08f; - wiImageParams fx; fx.pos = transform.GetPosition(); fx.siz = XMFLOAT2(dist, dist); - fx.typeFlag = ImageType::WORLD; fx.pivot = XMFLOAT2(0.5f, 0.5f); fx.color = inactiveEntityColor; @@ -1971,10 +1983,8 @@ void EditorComponent::Compose(CommandList cmd) const float dist = wiMath::Distance(transform.GetPosition(), camera.Eye) * 0.08f; - wiImageParams fx; fx.pos = transform.GetPosition(); fx.siz = XMFLOAT2(dist, dist); - fx.typeFlag = ImageType::WORLD; fx.pivot = XMFLOAT2(0.5f, 0.5f); fx.color = inactiveEntityColor; @@ -2006,10 +2016,8 @@ void EditorComponent::Compose(CommandList cmd) const float dist = wiMath::Distance(transform.GetPosition(), camera.Eye) * 0.08f; - wiImageParams fx; fx.pos = transform.GetPosition(); fx.siz = XMFLOAT2(dist, dist); - fx.typeFlag = ImageType::WORLD; fx.pivot = XMFLOAT2(0.5f, 0.5f); fx.color = inactiveEntityColor; @@ -2041,10 +2049,8 @@ void EditorComponent::Compose(CommandList cmd) const float dist = wiMath::Distance(transform.GetPosition(), camera.Eye) * 0.08f; - wiImageParams fx; fx.pos = transform.GetPosition(); fx.siz = XMFLOAT2(dist, dist); - fx.typeFlag = ImageType::WORLD; fx.pivot = XMFLOAT2(0.5f, 0.5f); fx.color = inactiveEntityColor; @@ -2075,10 +2081,8 @@ void EditorComponent::Compose(CommandList cmd) const float dist = wiMath::Distance(transform.GetPosition(), camera.Eye) * 0.08f; - wiImageParams fx; fx.pos = transform.GetPosition(); fx.siz = XMFLOAT2(dist, dist); - fx.typeFlag = ImageType::WORLD; fx.pivot = XMFLOAT2(0.5f, 0.5f); fx.color = inactiveEntityColor; @@ -2109,10 +2113,8 @@ void EditorComponent::Compose(CommandList cmd) const float dist = wiMath::Distance(transform.GetPosition(), camera.Eye) * 0.08f; - wiImageParams fx; fx.pos = transform.GetPosition(); fx.siz = XMFLOAT2(dist, dist); - fx.typeFlag = ImageType::WORLD; fx.pivot = XMFLOAT2(0.5f, 0.5f); fx.color = inactiveEntityColor; @@ -2143,10 +2145,8 @@ void EditorComponent::Compose(CommandList cmd) const float dist = wiMath::Distance(transform.GetPosition(), camera.Eye) * 0.08f; - wiImageParams fx; fx.pos = transform.GetPosition(); fx.siz = XMFLOAT2(dist, dist); - fx.typeFlag = ImageType::WORLD; fx.pivot = XMFLOAT2(0.5f, 0.5f); fx.color = inactiveEntityColor; @@ -2177,10 +2177,8 @@ void EditorComponent::Compose(CommandList cmd) const float dist = wiMath::Distance(transform.GetPosition(), camera.Eye) * 0.08f; - wiImageParams fx; fx.pos = transform.GetPosition(); fx.siz = XMFLOAT2(dist, dist); - fx.typeFlag = ImageType::WORLD; fx.pivot = XMFLOAT2(0.5f, 0.5f); fx.color = inactiveEntityColor; diff --git a/Editor/EnvProbeWindow.cpp b/Editor/EnvProbeWindow.cpp index a4d97fc99..3759354bf 100644 --- a/Editor/EnvProbeWindow.cpp +++ b/Editor/EnvProbeWindow.cpp @@ -29,7 +29,7 @@ void EnvProbeWindow::Create(EditorComponent* editor) generateButton.SetPos(XMFLOAT2(x, y += step)); generateButton.OnClick([=](wiEventArgs args) { XMFLOAT3 pos; - XMStoreFloat3(&pos, XMVectorAdd(wiRenderer::GetCamera().GetEye(), wiRenderer::GetCamera().GetAt() * 4)); + XMStoreFloat3(&pos, XMVectorAdd(wiScene::GetCamera().GetEye(), wiScene::GetCamera().GetAt() * 4)); Entity entity = wiScene::GetScene().Entity_CreateEnvironmentProbe("editorProbe", pos); editor->ClearSelected(); editor->AddSelected(entity); diff --git a/Editor/LayerWindow.cpp b/Editor/LayerWindow.cpp index b7b5fbae9..a25bb4324 100644 --- a/Editor/LayerWindow.cpp +++ b/Editor/LayerWindow.cpp @@ -48,6 +48,10 @@ void LayerWindow::Create(EditorComponent* editor) enableAllButton.SetPos(XMFLOAT2(x, y)); enableAllButton.OnClick([this](wiEventArgs args) { LayerComponent* layer = wiScene::GetScene().layers.GetComponent(entity); + if (layer == nullptr) + { + layer = &wiScene::GetScene().layers.Create(entity); + } if (layer == nullptr) return; layer->layerMask = ~0; @@ -58,6 +62,10 @@ void LayerWindow::Create(EditorComponent* editor) enableNoneButton.SetPos(XMFLOAT2(x + 120, y)); enableNoneButton.OnClick([this](wiEventArgs args) { LayerComponent* layer = wiScene::GetScene().layers.GetComponent(entity); + if (layer == nullptr) + { + layer = &wiScene::GetScene().layers.Create(entity); + } if (layer == nullptr) return; layer->layerMask = 0; @@ -92,6 +100,18 @@ void LayerWindow::SetEntity(Entity entity) { layers[i].SetCheck(layer->GetLayerMask() & 1 << i); } + + HierarchyComponent* hier = wiScene::GetScene().hierarchy.GetComponent(entity); + if (hier != nullptr) + { + hier->layerMask_bind = layer->layerMask; + } + + MaterialComponent* material = wiScene::GetScene().materials.GetComponent(entity); + if (material != nullptr) + { + material->SetDirty(); + } } } else diff --git a/Editor/LightWindow.cpp b/Editor/LightWindow.cpp index 6ef4ecf99..07785ee47 100644 --- a/Editor/LightWindow.cpp +++ b/Editor/LightWindow.cpp @@ -15,7 +15,7 @@ void LightWindow::Create(EditorComponent* editor) SetSize(XMFLOAT2(650, 500)); float x = 450; - float y = 0; + float y = 20; float hei = 18; float step = hei + 2; @@ -47,47 +47,47 @@ void LightWindow::Create(EditorComponent* editor) rangeSlider.SetTooltip("Adjust the maximum range the light can affect."); AddWidget(&rangeSlider); - radiusSlider.Create(0.01f, 10, 0, 100000, "Radius: "); - radiusSlider.SetSize(XMFLOAT2(100, hei)); - radiusSlider.SetPos(XMFLOAT2(x, y += step)); - radiusSlider.OnSlide([&](wiEventArgs args) { - LightComponent* light = wiScene::GetScene().lights.GetComponent(entity); - if (light != nullptr) - { - light->radius = args.fValue; - } - }); - radiusSlider.SetEnabled(false); - radiusSlider.SetTooltip("Adjust the radius of an area light."); - AddWidget(&radiusSlider); + //radiusSlider.Create(0.01f, 10, 0, 100000, "Radius: "); + //radiusSlider.SetSize(XMFLOAT2(100, hei)); + //radiusSlider.SetPos(XMFLOAT2(x, y += step)); + //radiusSlider.OnSlide([&](wiEventArgs args) { + // LightComponent* light = wiScene::GetScene().lights.GetComponent(entity); + // if (light != nullptr) + // { + // light->radius = args.fValue; + // } + //}); + //radiusSlider.SetEnabled(false); + //radiusSlider.SetTooltip("Adjust the radius of an area light."); + //AddWidget(&radiusSlider); - widthSlider.Create(1, 10, 0, 100000, "Width: "); - widthSlider.SetSize(XMFLOAT2(100, hei)); - widthSlider.SetPos(XMFLOAT2(x, y += step)); - widthSlider.OnSlide([&](wiEventArgs args) { - LightComponent* light = wiScene::GetScene().lights.GetComponent(entity); - if (light != nullptr) - { - light->width = args.fValue; - } - }); - widthSlider.SetEnabled(false); - widthSlider.SetTooltip("Adjust the width of an area light."); - AddWidget(&widthSlider); + //widthSlider.Create(1, 10, 0, 100000, "Width: "); + //widthSlider.SetSize(XMFLOAT2(100, hei)); + //widthSlider.SetPos(XMFLOAT2(x, y += step)); + //widthSlider.OnSlide([&](wiEventArgs args) { + // LightComponent* light = wiScene::GetScene().lights.GetComponent(entity); + // if (light != nullptr) + // { + // light->width = args.fValue; + // } + //}); + //widthSlider.SetEnabled(false); + //widthSlider.SetTooltip("Adjust the width of an area light."); + //AddWidget(&widthSlider); - heightSlider.Create(1, 10, 0, 100000, "Height: "); - heightSlider.SetSize(XMFLOAT2(100, hei)); - heightSlider.SetPos(XMFLOAT2(x, y += step)); - heightSlider.OnSlide([&](wiEventArgs args) { - LightComponent* light = wiScene::GetScene().lights.GetComponent(entity); - if (light != nullptr) - { - light->height = args.fValue; - } - }); - heightSlider.SetEnabled(false); - heightSlider.SetTooltip("Adjust the height of an area light."); - AddWidget(&heightSlider); + //heightSlider.Create(1, 10, 0, 100000, "Height: "); + //heightSlider.SetSize(XMFLOAT2(100, hei)); + //heightSlider.SetPos(XMFLOAT2(x, y += step)); + //heightSlider.OnSlide([&](wiEventArgs args) { + // LightComponent* light = wiScene::GetScene().lights.GetComponent(entity); + // if (light != nullptr) + // { + // light->height = args.fValue; + // } + //}); + //heightSlider.SetEnabled(false); + //heightSlider.SetTooltip("Adjust the height of an area light."); + //AddWidget(&heightSlider); fovSlider.Create(0.1f, XM_PI - 0.01f, 0, 100000, "FOV: "); fovSlider.SetSize(XMFLOAT2(100, hei)); @@ -209,10 +209,10 @@ void LightWindow::Create(EditorComponent* editor) typeSelectorComboBox.AddItem("Directional"); typeSelectorComboBox.AddItem("Point"); typeSelectorComboBox.AddItem("Spot"); - typeSelectorComboBox.AddItem("Sphere"); - typeSelectorComboBox.AddItem("Disc"); - typeSelectorComboBox.AddItem("Rectangle"); - typeSelectorComboBox.AddItem("Tube"); + //typeSelectorComboBox.AddItem("Sphere"); + //typeSelectorComboBox.AddItem("Disc"); + //typeSelectorComboBox.AddItem("Rectangle"); + //typeSelectorComboBox.AddItem("Tube"); typeSelectorComboBox.SetTooltip("Choose the light source type..."); typeSelectorComboBox.SetSelected((int)LightComponent::POINT); AddWidget(&typeSelectorComboBox); @@ -292,9 +292,9 @@ void LightWindow::SetEntity(Entity entity) energySlider.SetEnabled(true); energySlider.SetValue(light->energy); rangeSlider.SetValue(light->range_local); - radiusSlider.SetValue(light->radius); - widthSlider.SetValue(light->width); - heightSlider.SetValue(light->height); + //radiusSlider.SetValue(light->radius); + //widthSlider.SetValue(light->width); + //heightSlider.SetValue(light->height); fovSlider.SetValue(light->fov); shadowCheckBox.SetEnabled(true); shadowCheckBox.SetCheck(light->IsCastingShadow()); @@ -352,15 +352,15 @@ void LightWindow::SetLightType(LightComponent::LightType type) } else { - if (type == LightComponent::SPHERE || type == LightComponent::DISC || type == LightComponent::RECTANGLE || type == LightComponent::TUBE) - { - rangeSlider.SetEnabled(false); - radiusSlider.SetEnabled(true); - widthSlider.SetEnabled(true); - heightSlider.SetEnabled(true); - fovSlider.SetEnabled(false); - } - else + //if (type == LightComponent::SPHERE || type == LightComponent::DISC || type == LightComponent::RECTANGLE || type == LightComponent::TUBE) + //{ + // rangeSlider.SetEnabled(false); + // radiusSlider.SetEnabled(true); + // widthSlider.SetEnabled(true); + // heightSlider.SetEnabled(true); + // fovSlider.SetEnabled(false); + //} + //else { rangeSlider.SetEnabled(true); radiusSlider.SetEnabled(false); diff --git a/Editor/ModelImporter_GLTF.cpp b/Editor/ModelImporter_GLTF.cpp index be40c8a57..f602a288b 100644 --- a/Editor/ModelImporter_GLTF.cpp +++ b/Editor/ModelImporter_GLTF.cpp @@ -283,12 +283,10 @@ void LoadNode(int nodeIndex, Entity parent, LoaderState& state) if (node.name.empty()) { static int camID = 0; - stringstream ss(""); - ss << "cam" << camID++; - node.name = ss.str(); + node.name = "cam" + std::to_string(camID++); } - entity = scene.Entity_CreateCamera(node.name, (float)wiRenderer::GetInternalResolution().x, (float)wiRenderer::GetInternalResolution().y, 0.1f, 800); + entity = scene.Entity_CreateCamera(node.name, wiScene::GetCamera().width, wiScene::GetCamera().height, 0.1f, 800); } if (entity == INVALID_ENTITY) diff --git a/Editor/PaintToolWindow.cpp b/Editor/PaintToolWindow.cpp index ec078a294..679dee6e2 100644 --- a/Editor/PaintToolWindow.cpp +++ b/Editor/PaintToolWindow.cpp @@ -255,7 +255,7 @@ void PaintToolWindow::Update(float dt) const bool wireframe = wireCheckBox.GetCheck(); Scene& scene = wiScene::GetScene(); - const CameraComponent& camera = wiRenderer::GetCamera(); + const CameraComponent& camera = wiScene::GetCamera(); const XMVECTOR C = XMLoadFloat2(&pos); const XMMATRIX VP = camera.GetViewProjection(); const XMVECTOR MUL = XMVectorSet(0.5f, -0.5f, 1, 1); diff --git a/Editor/RendererWindow.cpp b/Editor/RendererWindow.cpp index 24113070b..441e94ea8 100644 --- a/Editor/RendererWindow.cpp +++ b/Editor/RendererWindow.cpp @@ -42,9 +42,15 @@ void RendererWindow::Create(EditorComponent* editor) resolutionScaleSlider.SetTooltip("Adjust the internal rendering resolution."); resolutionScaleSlider.SetSize(XMFLOAT2(100, itemheight)); resolutionScaleSlider.SetPos(XMFLOAT2(x, y += step)); - resolutionScaleSlider.SetValue(wiRenderer::GetResolutionScale()); - resolutionScaleSlider.OnSlide([&](wiEventArgs args) { - wiRenderer::SetResolutionScale(args.fValue); + resolutionScaleSlider.SetValue(editor->resolutionScale); + resolutionScaleSlider.OnSlide([editor](wiEventArgs args) { + if (editor->resolutionScale != args.fValue) + { + editor->resolutionScale = args.fValue; + editor->ResizeBuffers(); + editor->renderPath->resolutionScale = args.fValue; + editor->renderPath->ResizeBuffers(); + } }); AddWidget(&resolutionScaleSlider); diff --git a/Editor/Translator.cpp b/Editor/Translator.cpp index cddcbaf31..225a1eca4 100644 --- a/Editor/Translator.cpp +++ b/Editor/Translator.cpp @@ -176,7 +176,7 @@ void Translator::Update() dragEnded = false; XMFLOAT4 pointer = wiInput::GetPointer(); - const CameraComponent& cam = wiRenderer::GetCamera(); + const CameraComponent& cam = wiScene::GetCamera(); XMVECTOR pos = transform.GetPositionV(); if (enabled) diff --git a/Tests/Tests.cpp b/Tests/Tests.cpp index 271c10769..6f33a14f5 100644 --- a/Tests/Tests.cpp +++ b/Tests/Tests.cpp @@ -138,7 +138,7 @@ void TestsRenderer::Load() TransformComponent transform; transform.Translate(XMFLOAT3(0, 2.f, -4.5f)); transform.UpdateTransform(); - wiRenderer::GetCamera().TransformCamera(transform); + wiScene::GetCamera().TransformCamera(transform); float screenW = wiRenderer::GetDevice()->GetScreenWidth(); float screenH = wiRenderer::GetDevice()->GetScreenHeight(); diff --git a/WickedEngine/ArchiveVersionHistory.txt b/WickedEngine/ArchiveVersionHistory.txt index 1a15f9195..7ee18a30e 100644 --- a/WickedEngine/ArchiveVersionHistory.txt +++ b/WickedEngine/ArchiveVersionHistory.txt @@ -1,5 +1,6 @@ This file contains changelog of wiArchive versions +55: removed area lights 54: MaterialComponent::subsurfaceScattering color instead of profile 53: Support Morph Target 52: Serialized MaterialComponent::subsurfaceProfile diff --git a/WickedEngine/RenderPath2D.cpp b/WickedEngine/RenderPath2D.cpp index 637a3cf66..59b170f73 100644 --- a/WickedEngine/RenderPath2D.cpp +++ b/WickedEngine/RenderPath2D.cpp @@ -14,7 +14,7 @@ void RenderPath2D::ResizeBuffers() FORMAT defaultTextureFormat = device->GetBackBufferFormat(); const Texture* dsv = GetDepthStencil(); - if(dsv != nullptr && (wiRenderer::GetResolutionScale() != 1.0f || dsv->GetDesc().SampleCount > 1)) + if(dsv != nullptr && (resolutionScale != 1.0f || dsv->GetDesc().SampleCount > 1)) { TextureDesc desc = GetDepthStencil()->GetDesc(); desc.BindFlags = BIND_RENDER_TARGET | BIND_SHADER_RESOURCE; @@ -98,12 +98,6 @@ void RenderPath2D::Load() ResizeLayout(); }); } - if (!resolutionScaleChange_handle.IsValid()) - { - resolutionScaleChange_handle = wiEvent::Subscribe(SYSTEM_EVENT_CHANGE_RESOLUTION_SCALE, [this](uint64_t userdata) { - ResizeBuffers(); - }); - } if (!dpiChange_handle.IsValid()) { ResizeLayout(); @@ -129,12 +123,6 @@ void RenderPath2D::Update(float dt) ResizeLayout(); }); } - if (!resolutionScaleChange_handle.IsValid()) - { - resolutionScaleChange_handle = wiEvent::Subscribe(SYSTEM_EVENT_CHANGE_RESOLUTION_SCALE, [this](uint64_t userdata) { - ResizeBuffers(); - }); - } if (!dpiChange_handle.IsValid()) { ResizeLayout(); @@ -548,3 +536,12 @@ void RenderPath2D::CleanLayers() } } + +XMUINT2 RenderPath2D::GetInternalResolution() const +{ + GraphicsDevice* device = wiRenderer::GetDevice(); + return XMUINT2( + (uint32_t)ceilf(device->GetResolutionWidth() * resolutionScale), + (uint32_t)ceilf(device->GetResolutionHeight() * resolutionScale) + ); +} diff --git a/WickedEngine/RenderPath2D.h b/WickedEngine/RenderPath2D.h index 64431608b..39daa1ff6 100644 --- a/WickedEngine/RenderPath2D.h +++ b/WickedEngine/RenderPath2D.h @@ -42,15 +42,13 @@ private: wiGUI GUI; wiEvent::Handle resolutionChange_handle; - wiEvent::Handle resolutionScaleChange_handle; wiEvent::Handle dpiChange_handle; -protected: +public: // create resolution dependant resources, such as render targets virtual void ResizeBuffers(); // update resolution dependent elements, such as elements dependent on current monitor DPI virtual void ResizeLayout() {} -public: void Load() override; void Start() override; @@ -83,5 +81,8 @@ public: const wiGUI& GetGUI() const { return GUI; } wiGUI& GetGUI() { return GUI; } + + float resolutionScale = 1.0f; + virtual XMUINT2 GetInternalResolution() const; }; diff --git a/WickedEngine/RenderPath3D.cpp b/WickedEngine/RenderPath3D.cpp index aed2923f3..a3c99138e 100644 --- a/WickedEngine/RenderPath3D.cpp +++ b/WickedEngine/RenderPath3D.cpp @@ -14,7 +14,8 @@ void RenderPath3D::ResizeBuffers() FORMAT defaultTextureFormat = device->GetBackBufferFormat(); - + camera->CreatePerspective((float)GetInternalResolution().x, (float)GetInternalResolution().y, camera->zNearP, camera->zFarP); + // Render targets: { @@ -24,8 +25,8 @@ void RenderPath3D::ResizeBuffers() { desc.BindFlags |= BIND_UNORDERED_ACCESS; } - desc.Width = wiRenderer::GetInternalResolution().x; - desc.Height = wiRenderer::GetInternalResolution().y; + desc.Width = GetInternalResolution().x; + desc.Height = GetInternalResolution().y; desc.SampleCount = getMSAASampleCount(); desc.Format = FORMAT_R16G16B16A16_FLOAT; @@ -52,8 +53,8 @@ void RenderPath3D::ResizeBuffers() TextureDesc desc; desc.BindFlags = BIND_SHADER_RESOURCE | BIND_UNORDERED_ACCESS; desc.Format = FORMAT_R16G16B16A16_FLOAT; - desc.Width = wiRenderer::GetInternalResolution().x; - desc.Height = wiRenderer::GetInternalResolution().y; + desc.Width = GetInternalResolution().x; + desc.Height = GetInternalResolution().y; device->CreateTexture(&desc, nullptr, &rtSSR); device->SetName(&rtSSR, "rtSSR"); } @@ -61,8 +62,8 @@ void RenderPath3D::ResizeBuffers() TextureDesc desc; desc.BindFlags = BIND_RENDER_TARGET | BIND_SHADER_RESOURCE; desc.Format = FORMAT_R16G16B16A16_FLOAT; - desc.Width = wiRenderer::GetInternalResolution().x; - desc.Height = wiRenderer::GetInternalResolution().y; + desc.Width = GetInternalResolution().x; + desc.Height = GetInternalResolution().y; desc.SampleCount = getMSAASampleCount(); device->CreateTexture(&desc, nullptr, &rtParticleDistortion); device->SetName(&rtParticleDistortion, "rtParticleDistortion"); @@ -77,8 +78,8 @@ void RenderPath3D::ResizeBuffers() TextureDesc desc; desc.Format = FORMAT_R16G16B16A16_FLOAT; desc.BindFlags = BIND_RENDER_TARGET | BIND_SHADER_RESOURCE | BIND_UNORDERED_ACCESS; - desc.Width = wiRenderer::GetInternalResolution().x / 4; - desc.Height = wiRenderer::GetInternalResolution().y / 4; + desc.Width = GetInternalResolution().x / 4; + desc.Height = GetInternalResolution().y / 4; device->CreateTexture(&desc, nullptr, &rtVolumetricLights[0]); device->SetName(&rtVolumetricLights[0], "rtVolumetricLights[0]"); device->CreateTexture(&desc, nullptr, &rtVolumetricLights[1]); @@ -88,8 +89,8 @@ void RenderPath3D::ResizeBuffers() TextureDesc desc; desc.BindFlags = BIND_RENDER_TARGET | BIND_SHADER_RESOURCE; desc.Format = FORMAT_R8G8B8A8_SNORM; - desc.Width = wiRenderer::GetInternalResolution().x; - desc.Height = wiRenderer::GetInternalResolution().y; + desc.Width = GetInternalResolution().x; + desc.Height = GetInternalResolution().y; device->CreateTexture(&desc, nullptr, &rtWaterRipple); device->SetName(&rtWaterRipple, "rtWaterRipple"); } @@ -97,8 +98,8 @@ void RenderPath3D::ResizeBuffers() TextureDesc desc; desc.BindFlags = BIND_SHADER_RESOURCE | BIND_UNORDERED_ACCESS | BIND_RENDER_TARGET; desc.Format = FORMAT_R11G11B10_FLOAT; - desc.Width = wiRenderer::GetInternalResolution().x / 2; - desc.Height = wiRenderer::GetInternalResolution().y / 2; + desc.Width = GetInternalResolution().x / 2; + desc.Height = GetInternalResolution().y / 2; desc.MipLevels = std::min(8u, (uint32_t)std::log2(std::max(desc.Width, desc.Height))); device->CreateTexture(&desc, nullptr, &rtSceneCopy); device->SetName(&rtSceneCopy, "rtSceneCopy"); @@ -123,8 +124,8 @@ void RenderPath3D::ResizeBuffers() TextureDesc desc; desc.BindFlags = BIND_RENDER_TARGET | BIND_SHADER_RESOURCE; desc.Format = FORMAT_R11G11B10_FLOAT; - desc.Width = wiRenderer::GetInternalResolution().x / 4; - desc.Height = wiRenderer::GetInternalResolution().y / 4; + desc.Width = GetInternalResolution().x / 4; + desc.Height = GetInternalResolution().y / 4; desc.layout = IMAGE_LAYOUT_SHADER_RESOURCE; device->CreateTexture(&desc, nullptr, &rtReflection); device->SetName(&rtReflection, "rtReflection"); @@ -133,8 +134,8 @@ void RenderPath3D::ResizeBuffers() TextureDesc desc; desc.BindFlags = BIND_SHADER_RESOURCE | BIND_UNORDERED_ACCESS; desc.Format = FORMAT_R8_UNORM; - desc.Width = wiRenderer::GetInternalResolution().x; - desc.Height = wiRenderer::GetInternalResolution().y; + desc.Width = GetInternalResolution().x; + desc.Height = GetInternalResolution().y; device->CreateTexture(&desc, nullptr, &rtAO); device->SetName(&rtAO, "rtAO"); } @@ -142,23 +143,23 @@ void RenderPath3D::ResizeBuffers() TextureDesc desc; desc.BindFlags = BIND_RENDER_TARGET | BIND_SHADER_RESOURCE; desc.Format = defaultTextureFormat; - desc.Width = wiRenderer::GetInternalResolution().x; - desc.Height = wiRenderer::GetInternalResolution().y; + desc.Width = GetInternalResolution().x; + desc.Height = GetInternalResolution().y; desc.SampleCount = getMSAASampleCount(); device->CreateTexture(&desc, nullptr, &rtSun[0]); device->SetName(&rtSun[0], "rtSun[0]"); desc.BindFlags = BIND_SHADER_RESOURCE | BIND_UNORDERED_ACCESS; desc.SampleCount = 1; - desc.Width = wiRenderer::GetInternalResolution().x / 2; - desc.Height = wiRenderer::GetInternalResolution().y / 2; + desc.Width = GetInternalResolution().x / 2; + desc.Height = GetInternalResolution().y / 2; device->CreateTexture(&desc, nullptr, &rtSun[1]); device->SetName(&rtSun[1], "rtSun[1]"); if (getMSAASampleCount() > 1) { - desc.Width = wiRenderer::GetInternalResolution().x; - desc.Height = wiRenderer::GetInternalResolution().y; + desc.Width = GetInternalResolution().x; + desc.Height = GetInternalResolution().y; desc.SampleCount = 1; device->CreateTexture(&desc, nullptr, &rtSun_resolved); device->SetName(&rtSun_resolved, "rtSun_resolved"); @@ -168,8 +169,8 @@ void RenderPath3D::ResizeBuffers() TextureDesc desc; desc.BindFlags = BIND_RENDER_TARGET | BIND_SHADER_RESOURCE | BIND_UNORDERED_ACCESS; desc.Format = FORMAT_R11G11B10_FLOAT; - desc.Width = wiRenderer::GetInternalResolution().x / 4; - desc.Height = wiRenderer::GetInternalResolution().y / 4; + desc.Width = GetInternalResolution().x / 4; + desc.Height = GetInternalResolution().y / 4; desc.MipLevels = std::min(5u, (uint32_t)std::log2(std::max(desc.Width, desc.Height))); device->CreateTexture(&desc, nullptr, &rtBloom); device->SetName(&rtBloom, "rtBloom"); @@ -193,8 +194,8 @@ void RenderPath3D::ResizeBuffers() TextureDesc desc; desc.BindFlags = BIND_SHADER_RESOURCE | BIND_UNORDERED_ACCESS; desc.Format = FORMAT_R11G11B10_FLOAT; - desc.Width = wiRenderer::GetInternalResolution().x; - desc.Height = wiRenderer::GetInternalResolution().y; + desc.Width = GetInternalResolution().x; + desc.Height = GetInternalResolution().y; device->CreateTexture(&desc, nullptr, &rtTemporalAA[0]); device->SetName(&rtTemporalAA[0], "rtTemporalAA[0]"); device->CreateTexture(&desc, nullptr, &rtTemporalAA[1]); @@ -204,8 +205,8 @@ void RenderPath3D::ResizeBuffers() TextureDesc desc; desc.BindFlags = BIND_RENDER_TARGET | BIND_SHADER_RESOURCE | BIND_UNORDERED_ACCESS; desc.Format = FORMAT_R11G11B10_FLOAT; - desc.Width = wiRenderer::GetInternalResolution().x; - desc.Height = wiRenderer::GetInternalResolution().y; + desc.Width = GetInternalResolution().x; + desc.Height = GetInternalResolution().y; device->CreateTexture(&desc, nullptr, &rtPostprocess_HDR); device->SetName(&rtPostprocess_HDR, "rtPostprocess_HDR"); } @@ -213,8 +214,8 @@ void RenderPath3D::ResizeBuffers() TextureDesc desc; desc.BindFlags = BIND_RENDER_TARGET | BIND_SHADER_RESOURCE | BIND_UNORDERED_ACCESS; desc.Format = defaultTextureFormat; - desc.Width = wiRenderer::GetInternalResolution().x; - desc.Height = wiRenderer::GetInternalResolution().y; + desc.Width = GetInternalResolution().x; + desc.Height = GetInternalResolution().y; device->CreateTexture(&desc, nullptr, &rtPostprocess_LDR[0]); device->SetName(&rtPostprocess_LDR[0], "rtPostprocess_LDR[0]"); device->CreateTexture(&desc, nullptr, &rtPostprocess_LDR[1]); @@ -241,8 +242,8 @@ void RenderPath3D::ResizeBuffers() TextureDesc desc; desc.BindFlags = BIND_UNORDERED_ACCESS; desc.Format = FORMAT_R8_UINT; - desc.Width = (wiRenderer::GetInternalResolution().x + tileSize - 1) / tileSize; - desc.Height = (wiRenderer::GetInternalResolution().y + tileSize - 1) / tileSize; + desc.Width = (GetInternalResolution().x + tileSize - 1) / tileSize; + desc.Height = (GetInternalResolution().y + tileSize - 1) / tileSize; device->CreateTexture(&desc, nullptr, &rtShadingRate); device->SetName(&rtShadingRate, "rtShadingRate"); } @@ -250,8 +251,8 @@ void RenderPath3D::ResizeBuffers() // Depth buffers: { TextureDesc desc; - desc.Width = wiRenderer::GetInternalResolution().x; - desc.Height = wiRenderer::GetInternalResolution().y; + desc.Width = GetInternalResolution().x; + desc.Height = GetInternalResolution().y; desc.Format = FORMAT_R32G8X24_TYPELESS; desc.BindFlags = BIND_DEPTH_STENCIL | BIND_SHADER_RESOURCE; @@ -280,8 +281,8 @@ void RenderPath3D::ResizeBuffers() TextureDesc desc; desc.BindFlags = BIND_DEPTH_STENCIL; desc.Format = FORMAT_D16_UNORM; - desc.Width = wiRenderer::GetInternalResolution().x / 4; - desc.Height = wiRenderer::GetInternalResolution().y / 4; + desc.Width = GetInternalResolution().x / 4; + desc.Height = GetInternalResolution().y / 4; desc.layout = IMAGE_LAYOUT_DEPTHSTENCIL; device->CreateTexture(&desc, nullptr, &depthBuffer_Reflection); device->SetName(&depthBuffer_Reflection, "depthBuffer_Reflection"); @@ -290,8 +291,8 @@ void RenderPath3D::ResizeBuffers() TextureDesc desc; desc.BindFlags = BIND_SHADER_RESOURCE | BIND_UNORDERED_ACCESS; desc.Format = FORMAT_R32_FLOAT; - desc.Width = wiRenderer::GetInternalResolution().x; - desc.Height = wiRenderer::GetInternalResolution().y; + desc.Width = GetInternalResolution().x; + desc.Height = GetInternalResolution().y; desc.MipLevels = 6; device->CreateTexture(&desc, nullptr, &rtLinearDepth); device->SetName(&rtLinearDepth, "rtLinearDepth"); @@ -309,8 +310,8 @@ void RenderPath3D::ResizeBuffers() TextureDesc desc; desc.BindFlags = BIND_DEPTH_STENCIL; desc.Format = FORMAT_D16_UNORM; - desc.Width = wiRenderer::GetInternalResolution().x / 4; - desc.Height = wiRenderer::GetInternalResolution().y / 4; + desc.Width = GetInternalResolution().x / 4; + desc.Height = GetInternalResolution().y / 4; desc.layout = IMAGE_LAYOUT_DEPTHSTENCIL_READONLY; device->CreateTexture(&desc, nullptr, &smallDepth); device->SetName(&smallDepth, "smallDepth"); @@ -520,7 +521,19 @@ void RenderPath3D::Update(float dt) } wiRenderer::OcclusionCulling_Read(*scene, visibility_main); - wiRenderer::UpdatePerFrameData(*scene, visibility_main, dt); + wiRenderer::UpdatePerFrameData(*scene, visibility_main, frameCB, GetInternalResolution(), dt); + + if (wiRenderer::GetTemporalAAEnabled()) + { + const XMFLOAT4& halton = wiMath::GetHaltonSequence(wiRenderer::GetDevice()->GetFrameCount() % 256); + camera->jitter.x = (halton.x * 2 - 1) / (float)GetInternalResolution().x; + camera->jitter.y = (halton.y * 2 - 1) / (float)GetInternalResolution().y; + } + else + { + camera->jitter = XMFLOAT2(0, 0); + } + camera->UpdateCamera(); std::swap(depthBuffer_Copy, depthBuffer_Copy1); } @@ -751,7 +764,7 @@ void RenderPath3D::RenderFrameSetUp(CommandList cmd) const GraphicsDevice* device = wiRenderer::GetDevice(); device->BindResource(CS, &depthBuffer_Copy1, TEXSLOT_DEPTH, cmd); - wiRenderer::UpdateRenderData(visibility_main, cmd); + wiRenderer::UpdateRenderData(visibility_main, frameCB, cmd); if (getAO() == AO_RTAO || wiRenderer::GetRaytracedShadowsEnabled() || getRaytracedReflectionEnabled()) { @@ -1016,7 +1029,7 @@ void RenderPath3D::RenderTransparents(CommandList cmd) const vp.Height = (float)rtWaterRipple.GetDesc().Height; device->BindViewports(1, &vp, cmd); - wiRenderer::DrawWaterRipples(cmd); + wiRenderer::DrawWaterRipples(visibility_main, cmd); device->RenderPassEnd(cmd); } @@ -1223,3 +1236,4 @@ void RenderPath3D::RenderPostprocessChain(CommandList cmd) const } } } + diff --git a/WickedEngine/RenderPath3D.h b/WickedEngine/RenderPath3D.h index 653a92bf0..ff26410de 100644 --- a/WickedEngine/RenderPath3D.h +++ b/WickedEngine/RenderPath3D.h @@ -136,8 +136,6 @@ protected: return &rtPostprocess_LDR[rt_index]; } - void ResizeBuffers() override; - virtual void RenderFrameSetUp(wiGraphics::CommandList cmd) const; virtual void RenderReflections(wiGraphics::CommandList cmd) const; @@ -154,7 +152,9 @@ protected: public: - wiScene::CameraComponent* camera = &wiRenderer::GetCamera(); + void ResizeBuffers() override; + + wiScene::CameraComponent* camera = &wiScene::GetCamera(); wiScene::CameraComponent camera_previous; wiScene::CameraComponent camera_reflection; @@ -162,6 +162,8 @@ public: wiRenderer::Visibility visibility_main; wiRenderer::Visibility visibility_reflection; + FrameCB frameCB = {}; + const wiGraphics::Texture* GetDepthStencil() const override { return &depthBuffer; } const wiGraphics::Texture* GetGUIBlurredBackground() const override { return &rtGUIBlurredBackground[2]; } diff --git a/WickedEngine/RenderPath3D_PathTracing.cpp b/WickedEngine/RenderPath3D_PathTracing.cpp index ff1919d19..02c318aef 100644 --- a/WickedEngine/RenderPath3D_PathTracing.cpp +++ b/WickedEngine/RenderPath3D_PathTracing.cpp @@ -24,8 +24,8 @@ void RenderPath3D_PathTracing::ResizeBuffers() TextureDesc desc; desc.BindFlags = BIND_UNORDERED_ACCESS | BIND_SHADER_RESOURCE | BIND_RENDER_TARGET; desc.Format = FORMAT_R32G32B32A32_FLOAT; - desc.Width = wiRenderer::GetInternalResolution().x; - desc.Height = wiRenderer::GetInternalResolution().y; + desc.Width = GetInternalResolution().x; + desc.Height = GetInternalResolution().y; device->CreateTexture(&desc, nullptr, &traceResult); device->SetName(&traceResult, "traceResult"); } @@ -33,8 +33,8 @@ void RenderPath3D_PathTracing::ResizeBuffers() TextureDesc desc; desc.BindFlags = BIND_SHADER_RESOURCE | BIND_UNORDERED_ACCESS; desc.Format = defaultTextureFormat; - desc.Width = wiRenderer::GetInternalResolution().x; - desc.Height = wiRenderer::GetInternalResolution().y; + desc.Width = GetInternalResolution().x; + desc.Height = GetInternalResolution().y; device->CreateTexture(&desc, nullptr, &rtPostprocess_LDR[0]); device->SetName(&rtPostprocess_LDR[0], "rtPostprocess_LDR[0]"); @@ -115,7 +115,7 @@ void RenderPath3D_PathTracing::Render() const cmd = device->BeginCommandList(); wiJobSystem::Execute(ctx, [this, cmd](wiJobArgs args) { - wiRenderer::UpdateRenderData(visibility_main, cmd); + wiRenderer::UpdateRenderData(visibility_main, frameCB, cmd); if (sam == 0) { @@ -154,7 +154,7 @@ void RenderPath3D_PathTracing::Render() const { auto range = wiProfiler::BeginRangeGPU("Traced Scene", cmd); - wiRenderer::RayBuffers* rayBuffers = wiRenderer::GenerateScreenRayBuffers(*camera, cmd); + wiRenderer::RayBuffers* rayBuffers = wiRenderer::GenerateScreenRayBuffers(*camera, GetInternalResolution().x, GetInternalResolution().y, cmd); wiRenderer::RayTraceScene(*scene, rayBuffers, &traceResult, sam, cmd); diff --git a/WickedEngine/ShaderInterop_Ocean.h b/WickedEngine/ShaderInterop_Ocean.h index 430f7cb29..371354540 100644 --- a/WickedEngine/ShaderInterop_Ocean.h +++ b/WickedEngine/ShaderInterop_Ocean.h @@ -19,7 +19,7 @@ CBUFFER(Ocean_Simulation_ImmutableCB, CBSLOT_OTHER_OCEAN_SIMULATION_IMMUTABLE) CBUFFER(Ocean_Simulation_PerFrameCB, CBSLOT_OTHER_OCEAN_SIMULATION_PERFRAME) { - float g_Time; + float g_TimeScale; float g_ChoppyScale; float g_GridLen; float Ocean_Simulation_PerFrameCB_padding; diff --git a/WickedEngine/ShaderInterop_Postprocess.h b/WickedEngine/ShaderInterop_Postprocess.h index 93bf922a5..57a824f57 100644 --- a/WickedEngine/ShaderInterop_Postprocess.h +++ b/WickedEngine/ShaderInterop_Postprocess.h @@ -27,10 +27,8 @@ CBUFFER(PostProcessCB, CBSLOT_RENDERER_POSTPROCESS) #define rtao_range ssao_range #define rtao_samplecount ssao_samplecount #define rtao_power ssao_power -#define rtao_seed xPPParams0.w #define rtreflection_range ssao_range -#define rtreflection_seed xPPParams0.w static const uint POSTPROCESS_HBAO_THREADCOUNT = 320; #define hbao_direction xPPParams0.xy diff --git a/WickedEngine/ShaderInterop_Renderer.h b/WickedEngine/ShaderInterop_Renderer.h index ba437f593..fc7c5030b 100644 --- a/WickedEngine/ShaderInterop_Renderer.h +++ b/WickedEngine/ShaderInterop_Renderer.h @@ -27,7 +27,7 @@ struct ShaderMaterial float alphaTest; float displacementMapping; - int padding0; + uint layerMask; int uvset_baseColorMap; int uvset_surfaceMap; int uvset_normalMap; @@ -52,60 +52,58 @@ struct ShaderMaterial // Warning: the size of this structure directly affects shader performance. // Try to reduce it as much as possible! // Keep it aligned to 16 bytes for best performance! -// Right now, this is 64 bytes total +// Right now, this is 48 bytes total struct ShaderEntity { - uint3 positionVS16_directionVS16; - uint type8_flags8_coneAngleCos16; + float3 position; + uint type8_flags8_range16; - float3 positionWS; - uint range16_energy16; - - uint2 directionWS16; // 16 bits free + uint2 direction16_coneAngleCos16; + uint energy16_X16; // 16 bits free uint color; - uint indices; - uint2 texMulAdd16; uint layerMask; + uint indices; + uint cubeRemap; uint userdata; #ifndef __cplusplus // Shader-side: - inline float3 GetPositionVS() - { - return f16tof32(positionVS16_directionVS16 & 0xFFFF); - } - inline float3 GetDirectionVS() - { - return f16tof32((positionVS16_directionVS16 >> 16) & 0xFFFF); - } inline uint GetType() { - return type8_flags8_coneAngleCos16 & 0xFF; + return type8_flags8_range16 & 0xFF; } inline uint GetFlags() { - return (type8_flags8_coneAngleCos16 >> 8) & 0xFF; - } - inline float GetConeAngleCos() - { - return f16tof32((type8_flags8_coneAngleCos16 >> 16) & 0xFFFF); + return (type8_flags8_range16 >> 8) & 0xFF; } inline float GetRange() { - return f16tof32(range16_energy16 & 0xFFFF); + return f16tof32((type8_flags8_range16 >> 16) & 0xFFFF); + } + inline float3 GetDirection() + { + return float3( + f16tof32(direction16_coneAngleCos16.x & 0xFFFF), + f16tof32((direction16_coneAngleCos16.x >> 16) & 0xFFFF), + f16tof32(direction16_coneAngleCos16.y & 0xFFFF) + ); + } + inline float GetConeAngleCos() + { + return f16tof32((direction16_coneAngleCos16.y >> 16) & 0xFFFF); } inline float GetEnergy() { - return f16tof32((range16_energy16 >> 16) & 0xFFFF); + return f16tof32(energy16_X16 & 0xFFFF); } - inline float3 GetDirectionWS() + inline float GetCubemapDepthRemapNear() { - return float3( - f16tof32(directionWS16.x & 0xFFFF), - f16tof32((directionWS16.x >> 16) & 0xFFFF), - f16tof32(directionWS16.y & 0xFFFF) - ); + return f16tof32(cubeRemap & 0xFFFF); + } + inline float GetCubemapDepthRemapFar() + { + return f16tof32((cubeRemap >> 16) & 0xFFFF); } inline float4 GetColor() { @@ -130,83 +128,51 @@ struct ShaderEntity { return indices != ~0; } - inline float4 GetTexMulAdd() - { - return float4( - f16tof32(texMulAdd16.x & 0xFFFF), - f16tof32((texMulAdd16.x >> 16) & 0xFFFF), - f16tof32(texMulAdd16.y & 0xFFFF), - f16tof32((texMulAdd16.y >> 16) & 0xFFFF) - ); - } - - // Load area light props: - inline float3 GetRight() { return GetDirectionWS(); } - inline float3 GetUp() { return GetDirectionVS(); } - inline float3 GetFront() { return GetPositionVS(); } - inline float GetRadius() { return GetTexMulAdd().x; } - inline float GetWidth() { return GetTexMulAdd().y; } - inline float GetHeight() { return GetTexMulAdd().z; } - - // Load cubemap depth remap props: - inline float GetCubemapDepthRemapNear() { return GetTexMulAdd().w; } - inline float GetCubemapDepthRemapFar() { return GetConeAngleCos(); } // Load decal props: inline float GetEmissive() { return GetEnergy(); } #else // Application-side: - inline void SetPositionVS(float3 value) - { - positionVS16_directionVS16.x |= XMConvertFloatToHalf(value.x); - positionVS16_directionVS16.y |= XMConvertFloatToHalf(value.y); - positionVS16_directionVS16.z |= XMConvertFloatToHalf(value.z); - } - inline void SetDirectionVS(float3 value) - { - positionVS16_directionVS16.x |= XMConvertFloatToHalf(value.x) << 16; - positionVS16_directionVS16.y |= XMConvertFloatToHalf(value.y) << 16; - positionVS16_directionVS16.z |= XMConvertFloatToHalf(value.z) << 16; - } inline void SetType(uint type) { - type8_flags8_coneAngleCos16 |= type & 0xFF; + type8_flags8_range16 |= type & 0xFF; } inline void SetFlags(uint flags) { - type8_flags8_coneAngleCos16 |= (flags & 0xFF) << 8; - } - inline void SetConeAngleCos(float value) - { - type8_flags8_coneAngleCos16 |= XMConvertFloatToHalf(value) << 16; + type8_flags8_range16 |= (flags & 0xFF) << 8; } inline void SetRange(float value) { - range16_energy16 |= XMConvertFloatToHalf(value); + type8_flags8_range16 |= XMConvertFloatToHalf(value) << 16; + } + inline void SetDirection(float3 value) + { + direction16_coneAngleCos16.x |= XMConvertFloatToHalf(value.x); + direction16_coneAngleCos16.x |= XMConvertFloatToHalf(value.y) << 16; + direction16_coneAngleCos16.y |= XMConvertFloatToHalf(value.z); + } + inline void SetConeAngleCos(float value) + { + direction16_coneAngleCos16.y |= XMConvertFloatToHalf(value) << 16; } inline void SetEnergy(float value) { - range16_energy16 |= XMConvertFloatToHalf(value) << 16; + energy16_X16 |= XMConvertFloatToHalf(value); } - inline void SetDirectionWS(float3 value) + inline void SetCubeRemapNear(float value) { - directionWS16.x |= XMConvertFloatToHalf(value.x); - directionWS16.x |= XMConvertFloatToHalf(value.y) << 16; - directionWS16.y |= XMConvertFloatToHalf(value.z); + cubeRemap |= XMConvertFloatToHalf(value); + } + inline void SetCubeRemapFar(float value) + { + cubeRemap |= XMConvertFloatToHalf(value) << 16; } inline void SetIndices(uint matrixIndex, uint textureIndex) { indices = matrixIndex & 0xFFFF; indices |= (textureIndex & 0xFFFF) << 16; } - inline void SetTexMulAdd(float4 value) - { - texMulAdd16.x |= XMConvertFloatToHalf(value.x); - texMulAdd16.x |= XMConvertFloatToHalf(value.y) << 16; - texMulAdd16.y |= XMConvertFloatToHalf(value.z); - texMulAdd16.y |= XMConvertFloatToHalf(value.w) << 16; - } #endif // __cplusplus }; @@ -214,10 +180,10 @@ struct ShaderEntity static const uint ENTITY_TYPE_DIRECTIONALLIGHT = 0; static const uint ENTITY_TYPE_POINTLIGHT = 1; static const uint ENTITY_TYPE_SPOTLIGHT = 2; -static const uint ENTITY_TYPE_SPHERELIGHT = 3; -static const uint ENTITY_TYPE_DISCLIGHT = 4; -static const uint ENTITY_TYPE_RECTANGLELIGHT = 5; -static const uint ENTITY_TYPE_TUBELIGHT = 6; +//static const uint ENTITY_TYPE_SPHERELIGHT = 3; +//static const uint ENTITY_TYPE_DISCLIGHT = 4; +//static const uint ENTITY_TYPE_RECTANGLELIGHT = 5; +//static const uint ENTITY_TYPE_TUBELIGHT = 6; static const uint ENTITY_TYPE_DECAL = 100; static const uint ENTITY_TYPE_ENVMAP = 101; static const uint ENTITY_TYPE_FORCEFIELD_POINT = 200; diff --git a/WickedEngine/Shaders_SOURCE.vcxitems b/WickedEngine/Shaders_SOURCE.vcxitems index aae28b18e..0c6a298f3 100644 --- a/WickedEngine/Shaders_SOURCE.vcxitems +++ b/WickedEngine/Shaders_SOURCE.vcxitems @@ -2626,16 +2626,6 @@ Compute Compute - - Vertex - Vertex - Vertex - Vertex - Vertex - Vertex - Vertex - Vertex - Pixel Pixel @@ -2766,26 +2756,6 @@ Vertex Vertex - - Vertex - Vertex - Vertex - Vertex - Vertex - Vertex - Vertex - Vertex - - - Vertex - Vertex - Vertex - Vertex - Vertex - Vertex - Vertex - Vertex - Vertex Vertex @@ -2796,15 +2766,5 @@ Vertex Vertex - - Vertex - Vertex - Vertex - Vertex - Vertex - Vertex - Vertex - Vertex - \ No newline at end of file diff --git a/WickedEngine/Shaders_SOURCE.vcxitems.filters b/WickedEngine/Shaders_SOURCE.vcxitems.filters index cd9c01e52..3f387bfb9 100644 --- a/WickedEngine/Shaders_SOURCE.vcxitems.filters +++ b/WickedEngine/Shaders_SOURCE.vcxitems.filters @@ -701,21 +701,9 @@ VS - - VS - - - VS - VS - - VS - - - VS - VS diff --git a/WickedEngine/brdf.hlsli b/WickedEngine/brdf.hlsli index 912e1385d..f63beab4b 100644 --- a/WickedEngine/brdf.hlsli +++ b/WickedEngine/brdf.hlsli @@ -44,6 +44,7 @@ struct Surface float anisotropy; // anisotropy factor [0 -> 1] float4 sss; // subsurface scattering color * amount float4 sss_inv; // 1 / (1 + sss) + uint layerMask; float alphaRoughness; // roughness remapped from perceptual to a "more linear change in roughness" float alphaRoughnessSq; // roughness input to brdf functions @@ -117,6 +118,7 @@ inline Surface CreateSurface( surface.sss_inv = 1; surface.T = T; surface.B = B; + surface.layerMask = ~0; surface.Update(); diff --git a/WickedEngine/emittedparticlePS_soft.hlsl b/WickedEngine/emittedparticlePS_soft.hlsl index a802bc4ff..9431b4e6b 100644 --- a/WickedEngine/emittedparticlePS_soft.hlsl +++ b/WickedEngine/emittedparticlePS_soft.hlsl @@ -25,10 +25,10 @@ float4 main(VertextoPixel input) : SV_TARGET float fade = saturate(1.0 / input.size*(max(max(depthScene.x, depthScene.y), max(depthScene.z, depthScene.w)) - depthFragment)); float4 inputColor; - inputColor.r = ((input.color >> 0) & 0x000000FF) / 255.0f; - inputColor.g = ((input.color >> 8) & 0x000000FF) / 255.0f; - inputColor.b = ((input.color >> 16) & 0x000000FF) / 255.0f; - inputColor.a = ((input.color >> 24) & 0x000000FF) / 255.0f; + inputColor.r = ((input.color >> 0) & 0xFF) / 255.0f; + inputColor.g = ((input.color >> 8) & 0xFF) / 255.0f; + inputColor.b = ((input.color >> 16) & 0xFF) / 255.0f; + inputColor.a = ((input.color >> 24) & 0xFF) / 255.0f; float opacity = saturate(color.a * inputColor.a * fade); @@ -52,6 +52,8 @@ float4 main(VertextoPixel input) : SV_TARGET Lighting lighting = CreateLighting(0, 0, GetAmbient(N), 0); Surface surface = CreateSurface(input.P, N, 0, color, 1, 1, 0, 0); surface.pixel = pixel; + surface.sss = g_xMaterial.subsurfaceScattering; + surface.sss_inv = g_xMaterial.subsurfaceScattering_inv; TiledLighting(surface, lighting); diff --git a/WickedEngine/emittedparticle_simulateCS.hlsl b/WickedEngine/emittedparticle_simulateCS.hlsl index cdcec16f7..a5dedfbba 100644 --- a/WickedEngine/emittedparticle_simulateCS.hlsl +++ b/WickedEngine/emittedparticle_simulateCS.hlsl @@ -37,10 +37,10 @@ void main(uint3 DTid : SV_DispatchThreadID, uint Gid : SV_GroupIndex) ShaderEntity forceField = EntityArray[forceFieldID]; forceFields[Gid].type = (uint)forceField.GetType(); - forceFields[Gid].position = forceField.positionWS; + forceFields[Gid].position = forceField.position; forceFields[Gid].gravity = forceField.GetEnergy(); forceFields[Gid].range_rcp = forceField.GetRange(); // it is actually uploaded from CPU as 1.0f / range - forceFields[Gid].normal = forceField.GetDirectionWS(); + forceFields[Gid].normal = forceField.GetDirection(); } GroupMemoryBarrierWithGroupSync(); diff --git a/WickedEngine/forceFieldPlaneVisualizerVS.hlsl b/WickedEngine/forceFieldPlaneVisualizerVS.hlsl index 19ac78c97..b9c77aa9e 100644 --- a/WickedEngine/forceFieldPlaneVisualizerVS.hlsl +++ b/WickedEngine/forceFieldPlaneVisualizerVS.hlsl @@ -17,7 +17,7 @@ PSIn main(uint vID : SV_VERTEXID) ShaderEntity forceField = EntityArray[forceFieldID]; Out.pos.xyz *= forceField.GetConeAngleCos(); // range... - Out.pos.xyz += forceField.positionWS; + Out.pos.xyz += forceField.position; Out.pos3D = Out.pos; diff --git a/WickedEngine/forceFieldPointVisualizerVS.hlsl b/WickedEngine/forceFieldPointVisualizerVS.hlsl index bdb0c284e..6914e581e 100644 --- a/WickedEngine/forceFieldPointVisualizerVS.hlsl +++ b/WickedEngine/forceFieldPointVisualizerVS.hlsl @@ -19,7 +19,7 @@ PSIn main(uint vID : SV_VERTEXID) ShaderEntity forceField = EntityArray[forceFieldID]; Out.pos.xyz *= forceField.GetConeAngleCos(); // range... - Out.pos.xyz += forceField.positionWS; + Out.pos.xyz += forceField.position; Out.pos3D = Out.pos; diff --git a/WickedEngine/forceFieldVisualizerPS.hlsl b/WickedEngine/forceFieldVisualizerPS.hlsl index 8fb432002..f343319ea 100644 --- a/WickedEngine/forceFieldVisualizerPS.hlsl +++ b/WickedEngine/forceFieldVisualizerPS.hlsl @@ -17,15 +17,15 @@ float4 main(PSIn input) : SV_TARGET if (forceField.GetType() == ENTITY_TYPE_FORCEFIELD_POINT) { // point-like forcefield: - float3 centerToPos = normalize(input.pos3D.xyz - forceField.positionWS.xyz); - float3 eyeToCenter = normalize(forceField.positionWS.xyz - g_xColor.xyz); + float3 centerToPos = normalize(input.pos3D.xyz - forceField.position.xyz); + float3 eyeToCenter = normalize(forceField.position.xyz - g_xColor.xyz); color.a *= pow(saturate(dot(centerToPos, eyeToCenter)), 1.0f / max(0.0001f, abs(forceField.GetEnergy()))); } else { // planar forcefield: - float3 dir = forceField.positionWS - input.pos3D.xyz; - float dist = dot(forceField.GetDirectionWS(), dir); + float3 dir = forceField.position - input.pos3D.xyz; + float dist = dot(forceField.GetDirection(), dir); color.a *= pow(1 - saturate(dist * forceField.GetRange()), 1.0f / max(0.0001f, abs(forceField.GetEnergy()))); } diff --git a/WickedEngine/hairparticle_simulateCS.hlsl b/WickedEngine/hairparticle_simulateCS.hlsl index 8715a1bf8..b7273a03b 100644 --- a/WickedEngine/hairparticle_simulateCS.hlsl +++ b/WickedEngine/hairparticle_simulateCS.hlsl @@ -32,10 +32,10 @@ void main(uint3 DTid : SV_DispatchThreadID, uint3 Gid : SV_GroupID, uint groupIn ShaderEntity forceField = EntityArray[forceFieldID]; forceFields[groupIndex].type = (uint)forceField.GetType(); - forceFields[groupIndex].position = forceField.positionWS; + forceFields[groupIndex].position = forceField.position; forceFields[groupIndex].gravity = forceField.GetEnergy(); forceFields[groupIndex].range_rcp = forceField.GetRange(); // it is actually uploaded from CPU as 1.0f / range - forceFields[groupIndex].normal = forceField.GetDirectionWS(); + forceFields[groupIndex].normal = forceField.GetDirection(); } GroupMemoryBarrierWithGroupSync(); diff --git a/WickedEngine/lightCullingCS.hlsl b/WickedEngine/lightCullingCS.hlsl index dc2852964..2b005f90c 100644 --- a/WickedEngine/lightCullingCS.hlsl +++ b/WickedEngine/lightCullingCS.hlsl @@ -221,7 +221,8 @@ void main(uint3 Gid : SV_GroupID, uint3 DTid : SV_DispatchThreadID, uint3 GTid : { case ENTITY_TYPE_POINTLIGHT: { - Sphere sphere = { entity.GetPositionVS().xyz, entity.GetRange() }; + float3 positionVS = mul(g_xCamera_View, float4(entity.position, 1)).xyz; + Sphere sphere = { positionVS.xyz, entity.GetRange() }; if (SphereInsideFrustum(sphere, GroupFrustum, nearClipVS, maxDepthVS)) { AppendEntity_Transparent(i); @@ -240,9 +241,11 @@ void main(uint3 Gid : SV_GroupID, uint3 DTid : SV_DispatchThreadID, uint3 GTid : break; case ENTITY_TYPE_SPOTLIGHT: { + float3 positionVS = mul(g_xCamera_View, float4(entity.position, 1)).xyz; + float3 directionVS = mul((float3x3)g_xCamera_View, entity.GetDirection()); // Construct a tight fitting sphere around the spotlight cone: const float r = entity.GetRange() * 0.5f / (entity.GetConeAngleCos() * entity.GetConeAngleCos()); - Sphere sphere = { entity.GetPositionVS().xyz - entity.GetDirectionVS() * r, r }; + Sphere sphere = { positionVS - directionVS * r, r }; if (SphereInsideFrustum(sphere, GroupFrustum, nearClipVS, maxDepthVS)) { AppendEntity_Transparent(i); @@ -261,10 +264,6 @@ void main(uint3 Gid : SV_GroupID, uint3 DTid : SV_DispatchThreadID, uint3 GTid : } break; case ENTITY_TYPE_DIRECTIONALLIGHT: - case ENTITY_TYPE_SPHERELIGHT: - case ENTITY_TYPE_DISCLIGHT: - case ENTITY_TYPE_RECTANGLELIGHT: - case ENTITY_TYPE_TUBELIGHT: { AppendEntity_Transparent(i); AppendEntity_Opaque(i); @@ -273,7 +272,8 @@ void main(uint3 Gid : SV_GroupID, uint3 DTid : SV_DispatchThreadID, uint3 GTid : case ENTITY_TYPE_DECAL: case ENTITY_TYPE_ENVMAP: { - Sphere sphere = { entity.GetPositionVS().xyz, entity.GetRange() }; + float3 positionVS = mul(g_xCamera_View, float4(entity.position, 1)).xyz; + Sphere sphere = { positionVS.xyz, entity.GetRange() }; if (SphereInsideFrustum(sphere, GroupFrustum, nearClipVS, maxDepthVS)) { AppendEntity_Transparent(i); diff --git a/WickedEngine/lightingHF.hlsli b/WickedEngine/lightingHF.hlsli index eadc05c1d..84e92e1aa 100644 --- a/WickedEngine/lightingHF.hlsli +++ b/WickedEngine/lightingHF.hlsli @@ -10,8 +10,6 @@ #define DISABLE_SOFT_RTSHADOW #endif // BRDF_CARTOON -//#define DISABLE_AREALIGHT - struct LightingPart { float3 diffuse; @@ -81,8 +79,8 @@ inline float3 shadowCascade(in ShaderEntity light, in float3 shadowPos, in float inline float shadowCube(in ShaderEntity light, in float3 L, in float3 Lunnormalized) { const float slice = light.GetTextureIndex(); - float remappedDistance = light.GetCubemapDepthRemapNear() + light.GetCubemapDepthRemapFar() / max(max(abs(Lunnormalized.x), abs(Lunnormalized.y)), abs(Lunnormalized.z)); - remappedDistance += 0.0005; // removes the border sampling artifact + float remappedDistance = light.GetCubemapDepthRemapNear() + + light.GetCubemapDepthRemapFar() / (max(max(abs(Lunnormalized.x), abs(Lunnormalized.y)), abs(Lunnormalized.z)) * 0.989); // little bias to avoid border sampling artifact float shadow = 0; #ifndef DISABLE_SOFT_SHADOWMAP // sample along a cube pattern around center: @@ -140,7 +138,7 @@ inline float shadowTrace(in Surface surface, in float3 L, in float dist) inline void DirectionalLight(in ShaderEntity light, in Surface surface, inout Lighting lighting) { - float3 L = light.GetDirectionWS().xyz; + float3 L = light.GetDirection().xyz; SurfaceToLight surfaceToLight = CreateSurfaceToLight(surface, L); [branch] @@ -218,7 +216,7 @@ inline void DirectionalLight(in ShaderEntity light, in Surface surface, inout Li } inline void PointLight(in ShaderEntity light, in Surface surface, inout Lighting lighting) { - float3 L = light.positionWS - surface.P; + float3 L = light.position - surface.P; const float dist2 = dot(L, L); const float range2 = light.GetRange() * light.GetRange(); @@ -270,7 +268,7 @@ inline void PointLight(in ShaderEntity light, in Surface surface, inout Lighting } inline void SpotLight(in ShaderEntity light, in Surface surface, inout Lighting lighting) { - float3 L = light.positionWS - surface.P; + float3 L = light.position - surface.P; const float dist2 = dot(L, L); const float range2 = light.GetRange() * light.GetRange(); @@ -285,7 +283,7 @@ inline void SpotLight(in ShaderEntity light, in Surface surface, inout Lighting [branch] if (any(surfaceToLight.NdotL_sss)) { - const float SpotFactor = dot(L, light.GetDirectionWS()); + const float SpotFactor = dot(L, light.GetDirection()); const float spotCutOff = light.GetConeAngleCos(); [branch] @@ -337,7 +335,7 @@ inline void SpotLight(in ShaderEntity light, in Surface surface, inout Lighting - +#if 0 // Currently area lights are disabled // AREA LIGHTS // Based on the Frostbite presentation: @@ -773,6 +771,7 @@ inline void TubeLight(in ShaderEntity light, in Surface surface, inout Lighting } #endif // DISABLE_AREALIGHT } +#endif // AREA LIGHTS // VOXEL RADIANCE @@ -876,7 +875,7 @@ inline float4 EnvironmentReflection_Local(in Surface surface, in ShaderEntity pr float3 FurthestPlane = max(FirstPlaneIntersect, SecondPlaneIntersect); float Distance = min(FurthestPlane.x, min(FurthestPlane.y, FurthestPlane.z)); float3 IntersectPositionWS = surface.P + surface.R * Distance; - float3 R_parallaxCorrected = IntersectPositionWS - probe.positionWS; + float3 R_parallaxCorrected = IntersectPositionWS - probe.position; // Sample cubemap texture: float3 envmapColor = texture_envmaparray.SampleLevel(sampler_linear_clamp, float4(R_parallaxCorrected, probe.GetTextureIndex()), MIP).rgb; // GetFlags() stores textureIndex here... diff --git a/WickedEngine/objectHF.hlsli b/WickedEngine/objectHF.hlsli index 658208b15..6e4d1d8fc 100644 --- a/WickedEngine/objectHF.hlsli +++ b/WickedEngine/objectHF.hlsli @@ -220,17 +220,21 @@ inline void ForwardLighting(inout Surface surface, inout Lighting lighting) if (decalAccumulation.a < 1) { ShaderEntity decal = EntityArray[g_xFrame_DecalArrayOffset + entity_index]; + if ((decal.layerMask & g_xMaterial.layerMask) == 0) + continue; - const float4x4 decalProjection = MatrixArray[decal.GetMatrixIndex()]; + float4x4 decalProjection = MatrixArray[decal.GetMatrixIndex()]; + float4 texMulAdd = decalProjection[3]; + decalProjection[3] = float4(0, 0, 0, 1); const float3 clipSpacePos = mul(decalProjection, float4(surface.P, 1)).xyz; const float3 uvw = clipSpacePos.xyz * float3(0.5, -0.5, 0.5) + 0.5; [branch] if (is_saturated(uvw)) { // mipmapping needs to be performed by hand: - const float2 decalDX = mul(P_dx, (float3x3)decalProjection).xy * decal.GetTexMulAdd().xy; - const float2 decalDY = mul(P_dy, (float3x3)decalProjection).xy * decal.GetTexMulAdd().xy; - float4 decalColor = texture_decalatlas.SampleGrad(sampler_linear_clamp, uvw.xy*decal.GetTexMulAdd().xy + decal.GetTexMulAdd().zw, decalDX, decalDY); + const float2 decalDX = mul(P_dx, (float3x3)decalProjection).xy * texMulAdd.xy; + const float2 decalDY = mul(P_dy, (float3x3)decalProjection).xy * texMulAdd.xy; + float4 decalColor = texture_decalatlas.SampleGrad(sampler_linear_clamp, uvw.xy * texMulAdd.xy + texMulAdd.zw, decalDX, decalDY); // blend out if close to cube Z: float edgeBlend = 1 - pow(saturate(abs(clipSpacePos.z)), 8); decalColor.a *= edgeBlend; @@ -286,6 +290,8 @@ inline void ForwardLighting(inout Surface surface, inout Lighting lighting) if (envmapAccumulation.a < 1) { ShaderEntity probe = EntityArray[g_xFrame_EnvProbeArrayOffset + entity_index]; + if ((probe.layerMask & g_xMaterial.layerMask) == 0) + continue; const float4x4 probeProjection = MatrixArray[probe.GetMatrixIndex()]; const float3 clipSpacePos = mul(probeProjection, float4(surface.P, 1)).xyz; @@ -375,26 +381,6 @@ inline void ForwardLighting(inout Surface surface, inout Lighting lighting) SpotLight(light, surface, lighting); } break; - case ENTITY_TYPE_SPHERELIGHT: - { - SphereLight(light, surface, lighting); - } - break; - case ENTITY_TYPE_DISCLIGHT: - { - DiscLight(light, surface, lighting); - } - break; - case ENTITY_TYPE_RECTANGLELIGHT: - { - RectangleLight(light, surface, lighting); - } - break; - case ENTITY_TYPE_TUBELIGHT: - { - TubeLight(light, surface, lighting); - } - break; } } } @@ -442,17 +428,21 @@ inline void TiledLighting(inout Surface surface, inout Lighting lighting) if (entity_index >= first_item && entity_index <= last_item && decalAccumulation.a < 1) { ShaderEntity decal = EntityArray[entity_index]; + if ((decal.layerMask & g_xMaterial.layerMask) == 0) + continue; - const float4x4 decalProjection = MatrixArray[decal.GetMatrixIndex()]; + float4x4 decalProjection = MatrixArray[decal.GetMatrixIndex()]; + float4 texMulAdd = decalProjection[3]; + decalProjection[3] = float4(0, 0, 0, 1); const float3 clipSpacePos = mul(decalProjection, float4(surface.P, 1)).xyz; const float3 uvw = clipSpacePos.xyz * float3(0.5, -0.5, 0.5) + 0.5; [branch] if (is_saturated(uvw)) { // mipmapping needs to be performed by hand: - const float2 decalDX = mul(P_dx, (float3x3)decalProjection).xy * decal.GetTexMulAdd().xy; - const float2 decalDY = mul(P_dy, (float3x3)decalProjection).xy * decal.GetTexMulAdd().xy; - float4 decalColor = texture_decalatlas.SampleGrad(sampler_linear_clamp, uvw.xy*decal.GetTexMulAdd().xy + decal.GetTexMulAdd().zw, decalDX, decalDY); + const float2 decalDX = mul(P_dx, (float3x3)decalProjection).xy * texMulAdd.xy; + const float2 decalDY = mul(P_dy, (float3x3)decalProjection).xy * texMulAdd.xy; + float4 decalColor = texture_decalatlas.SampleGrad(sampler_linear_clamp, uvw.xy * texMulAdd.xy + texMulAdd.zw, decalDX, decalDY); // blend out if close to cube Z: float edgeBlend = 1 - pow(saturate(abs(clipSpacePos.z)), 8); decalColor.a *= edgeBlend; @@ -521,6 +511,8 @@ inline void TiledLighting(inout Surface surface, inout Lighting lighting) if (entity_index >= first_item && entity_index <= last_item && envmapAccumulation.a < 1) { ShaderEntity probe = EntityArray[entity_index]; + if ((probe.layerMask & g_xMaterial.layerMask) == 0) + continue; const float4x4 probeProjection = MatrixArray[probe.GetMatrixIndex()]; const float3 clipSpacePos = mul(probeProjection, float4(surface.P, 1)).xyz; @@ -619,26 +611,6 @@ inline void TiledLighting(inout Surface surface, inout Lighting lighting) SpotLight(light, surface, lighting); } break; - case ENTITY_TYPE_SPHERELIGHT: - { - SphereLight(light, surface, lighting); - } - break; - case ENTITY_TYPE_DISCLIGHT: - { - DiscLight(light, surface, lighting); - } - break; - case ENTITY_TYPE_RECTANGLELIGHT: - { - RectangleLight(light, surface, lighting); - } - break; - case ENTITY_TYPE_TUBELIGHT: - { - TubeLight(light, surface, lighting); - } - break; } } else if (entity_index > last_item) @@ -1060,6 +1032,8 @@ GBUFFEROutputType main(PIXELINPUT input) surface.pixel = pixel; surface.screenUV = ScreenCoord; + surface.layerMask = g_xMaterial.layerMask; + float3 ambient = GetAmbient(surface.N); ambient = lerp(ambient, ambient * surface.sss.rgb, saturate(surface.sss.a)); diff --git a/WickedEngine/objectPS_voxelizer.hlsl b/WickedEngine/objectPS_voxelizer.hlsl index d58e5ffbd..c1b0f0d2a 100644 --- a/WickedEngine/objectPS_voxelizer.hlsl +++ b/WickedEngine/objectPS_voxelizer.hlsl @@ -272,7 +272,7 @@ void main(PSInput input) { case ENTITY_TYPE_DIRECTIONALLIGHT: { - float3 L = light.GetDirectionWS(); + float3 L = light.GetDirection(); const float NdotL = saturate(dot(L, N)); [branch] @@ -299,7 +299,7 @@ void main(PSInput input) break; case ENTITY_TYPE_POINTLIGHT: { - float3 L = light.positionWS - P; + float3 L = light.position - P; const float dist2 = dot(L, L); const float range2 = light.GetRange() * light.GetRange(); @@ -331,7 +331,7 @@ void main(PSInput input) break; case ENTITY_TYPE_SPOTLIGHT: { - float3 L = light.positionWS - P; + float3 L = light.position - P; const float dist2 = dot(L, L); const float range2 = light.GetRange() * light.GetRange(); @@ -345,7 +345,7 @@ void main(PSInput input) [branch] if (NdotL > 0) { - const float SpotFactor = dot(L, light.GetDirectionWS()); + const float SpotFactor = dot(L, light.GetDirection()); const float spotCutOff = light.GetConeAngleCos(); [branch] diff --git a/WickedEngine/oceanSimulatorCS.hlsl b/WickedEngine/oceanSimulatorCS.hlsl index c42e4c508..061d2a55a 100644 --- a/WickedEngine/oceanSimulatorCS.hlsl +++ b/WickedEngine/oceanSimulatorCS.hlsl @@ -1,7 +1,6 @@ +#include "globals.hlsli" #include "ShaderInterop_Ocean.h" -#define PI 3.1415926536f - STRUCTUREDBUFFER(g_InputH0, float2, TEXSLOT_ONDEMAND0); STRUCTUREDBUFFER(g_InputOmega, float, TEXSLOT_ONDEMAND1); RWSTRUCTUREDBUFFER(g_OutputHt, float2, 0); @@ -18,7 +17,7 @@ void main(uint3 DTid : SV_DispatchThreadID) float2 h0_k = g_InputH0[in_index]; float2 h0_mk = g_InputH0[in_mindex]; float sin_v, cos_v; - sincos(g_InputOmega[in_index] * g_Time, sin_v, cos_v); + sincos(g_InputOmega[in_index] * g_xFrame_Time * g_TimeScale, sin_v, cos_v); float2 ht; ht.x = (h0_k.x + h0_mk.x) * cos_v - (h0_k.y + h0_mk.y) * sin_v; diff --git a/WickedEngine/raytrace_shadeCS.hlsl b/WickedEngine/raytrace_shadeCS.hlsl index a9b756e26..37818e4e6 100644 --- a/WickedEngine/raytrace_shadeCS.hlsl +++ b/WickedEngine/raytrace_shadeCS.hlsl @@ -164,7 +164,7 @@ void main(uint3 DTid : SV_DispatchThreadID, uint groupIndex : SV_GroupIndex) { dist = FLT_MAX; - L = light.GetDirectionWS().xyz; + L = light.GetDirection().xyz; SurfaceToLight surfaceToLight = CreateSurfaceToLight(surface, L); NdotL = surfaceToLight.NdotL; @@ -187,7 +187,7 @@ void main(uint3 DTid : SV_DispatchThreadID, uint groupIndex : SV_GroupIndex) break; case ENTITY_TYPE_POINTLIGHT: { - L = light.positionWS - P; + L = light.position - P; const float dist2 = dot(L, L); const float range2 = light.GetRange() * light.GetRange(); @@ -220,7 +220,7 @@ void main(uint3 DTid : SV_DispatchThreadID, uint groupIndex : SV_GroupIndex) break; case ENTITY_TYPE_SPOTLIGHT: { - L = light.positionWS - surface.P; + L = light.position - surface.P; const float dist2 = dot(L, L); const float range2 = light.GetRange() * light.GetRange(); @@ -236,7 +236,7 @@ void main(uint3 DTid : SV_DispatchThreadID, uint groupIndex : SV_GroupIndex) [branch] if (NdotL > 0) { - const float SpotFactor = dot(L, light.GetDirectionWS()); + const float SpotFactor = dot(L, light.GetDirection()); const float spotCutOff = light.GetConeAngleCos(); [branch] @@ -259,22 +259,6 @@ void main(uint3 DTid : SV_DispatchThreadID, uint groupIndex : SV_GroupIndex) } } break; - case ENTITY_TYPE_SPHERELIGHT: - { - } - break; - case ENTITY_TYPE_DISCLIGHT: - { - } - break; - case ENTITY_TYPE_RECTANGLELIGHT: - { - } - break; - case ENTITY_TYPE_TUBELIGHT: - { - } - break; } if (NdotL > 0 && dist > 0) diff --git a/WickedEngine/renderlightmapPS.hlsl b/WickedEngine/renderlightmapPS.hlsl index 85b7ebad2..568443deb 100644 --- a/WickedEngine/renderlightmapPS.hlsl +++ b/WickedEngine/renderlightmapPS.hlsl @@ -46,7 +46,7 @@ float4 main(Input input) : SV_TARGET { dist = FLT_MAX; - L = light.GetDirectionWS().xyz; + L = light.GetDirection().xyz; NdotL = saturate(dot(L, N)); [branch] @@ -67,7 +67,7 @@ float4 main(Input input) : SV_TARGET break; case ENTITY_TYPE_POINTLIGHT: { - L = light.positionWS - P; + L = light.position - P; const float dist2 = dot(L, L); const float range2 = light.GetRange() * light.GetRange(); @@ -96,7 +96,7 @@ float4 main(Input input) : SV_TARGET break; case ENTITY_TYPE_SPOTLIGHT: { - L = light.positionWS - P; + L = light.position - P; const float dist2 = dot(L, L); const float range2 = light.GetRange() * light.GetRange(); @@ -110,7 +110,7 @@ float4 main(Input input) : SV_TARGET [branch] if (NdotL > 0) { - const float SpotFactor = dot(L, light.GetDirectionWS()); + const float SpotFactor = dot(L, light.GetDirection()); const float spotCutOff = light.GetConeAngleCos(); [branch] @@ -131,22 +131,6 @@ float4 main(Input input) : SV_TARGET } } break; - case ENTITY_TYPE_SPHERELIGHT: - { - } - break; - case ENTITY_TYPE_DISCLIGHT: - { - } - break; - case ENTITY_TYPE_RECTANGLELIGHT: - { - } - break; - case ENTITY_TYPE_TUBELIGHT: - { - } - break; } if (NdotL > 0 && dist > 0) diff --git a/WickedEngine/rtaoLIB.hlsl b/WickedEngine/rtaoLIB.hlsl index c77a27c8e..88775feba 100644 --- a/WickedEngine/rtaoLIB.hlsl +++ b/WickedEngine/rtaoLIB.hlsl @@ -33,7 +33,7 @@ void RTAO_Raygen() const float3 P = reconstructPosition(uv, depth); float3 N = normalize(texture_normals.SampleLevel(sampler_point_clamp, uv, 0) * 2 - 1); - float seed = rtao_seed; + float seed = g_xFrame_Time; RayDesc ray; ray.TMin = 0.001; diff --git a/WickedEngine/rtreflectionLIB.hlsl b/WickedEngine/rtreflectionLIB.hlsl index 724aeac33..845ec9ad9 100644 --- a/WickedEngine/rtreflectionLIB.hlsl +++ b/WickedEngine/rtreflectionLIB.hlsl @@ -76,7 +76,7 @@ void RTReflection_Raygen() const float3 R = -reflect(V, H.xyz); - float seed = rtreflection_seed; + float seed = g_xFrame_Time; RayDesc ray; ray.TMin = 0.001; @@ -189,26 +189,6 @@ void RTReflection_ClosestHit(inout RayPayload payload, in MyAttributes attr) SpotLight(light, surface, lighting); } break; - case ENTITY_TYPE_SPHERELIGHT: - { - SphereLight(light, surface, lighting); - } - break; - case ENTITY_TYPE_DISCLIGHT: - { - DiscLight(light, surface, lighting); - } - break; - case ENTITY_TYPE_RECTANGLELIGHT: - { - RectangleLight(light, surface, lighting); - } - break; - case ENTITY_TYPE_TUBELIGHT: - { - TubeLight(light, surface, lighting); - } - break; } } diff --git a/WickedEngine/shaders/CMakeLists.txt b/WickedEngine/shaders/CMakeLists.txt index 5cfeebce3..bb2705bcb 100644 --- a/WickedEngine/shaders/CMakeLists.txt +++ b/WickedEngine/shaders/CMakeLists.txt @@ -235,11 +235,7 @@ set(SHADERS_VS "volumetriclight_pointVS.hlsl" "volumetriclight_spotVS.hlsl" "vSpotLightVS.hlsl" - "vTubeLightVS.hlsl" - "vDiscLightVS.hlsl" "vPointLightVS.hlsl" - "vRectangleLightVS.hlsl" - "vSphereLightVS.hlsl" "sphereVS.hlsl" "skyVS.hlsl" "shadowVS_transparent.hlsl" diff --git a/WickedEngine/vDiscLightVS.hlsl b/WickedEngine/vDiscLightVS.hlsl deleted file mode 100644 index 06869dd76..000000000 --- a/WickedEngine/vDiscLightVS.hlsl +++ /dev/null @@ -1,13 +0,0 @@ -#include "volumeLightHF.hlsli" -#include "circle.hlsli" - -VertexToPixel main(uint vID : SV_VertexID) -{ - VertexToPixel Out = (VertexToPixel)0; - - float4 pos = CIRCLE[vID]; - Out.pos = mul(lightWorld, pos); - Out.col = float4(lightColor.rgb * lightEnerdis.x, 1); - - return Out; -} \ No newline at end of file diff --git a/WickedEngine/vRectangleLightVS.hlsl b/WickedEngine/vRectangleLightVS.hlsl deleted file mode 100644 index 8e3267b64..000000000 --- a/WickedEngine/vRectangleLightVS.hlsl +++ /dev/null @@ -1,13 +0,0 @@ -#include "volumeLightHF.hlsli" -#include "quad.hlsli" - -VertexToPixel main(uint vID : SV_VertexID) -{ - VertexToPixel Out = (VertexToPixel)0; - - float4 pos = QUAD[vID]; - Out.pos = mul(lightWorld, pos); - Out.col = float4(lightColor.rgb * lightEnerdis.x, 1); - - return Out; -} \ No newline at end of file diff --git a/WickedEngine/vSphereLightVS.hlsl b/WickedEngine/vSphereLightVS.hlsl deleted file mode 100644 index 537e89640..000000000 --- a/WickedEngine/vSphereLightVS.hlsl +++ /dev/null @@ -1,13 +0,0 @@ -#include "volumeLightHF.hlsli" -#include "uvsphere.hlsli" - -VertexToPixel main(uint vID : SV_VertexID) -{ - VertexToPixel Out = (VertexToPixel)0; - - float4 pos = UVSPHERE[vID]; - Out.pos = mul(lightWorld, pos); - Out.col = float4(lightColor.rgb * lightEnerdis.x, 1); - - return Out; -} \ No newline at end of file diff --git a/WickedEngine/vTubeLightVS.hlsl b/WickedEngine/vTubeLightVS.hlsl deleted file mode 100644 index cc3074236..000000000 --- a/WickedEngine/vTubeLightVS.hlsl +++ /dev/null @@ -1,13 +0,0 @@ -#include "volumeLightHF.hlsli" -#include "cylinder.hlsli" - -VertexToPixel main(uint vID : SV_VertexID) -{ - VertexToPixel Out = (VertexToPixel)0; - - float4 pos = CYLINDER[vID]; - Out.pos = mul(lightWorld, pos); - Out.col = float4(lightColor.rgb * lightEnerdis.x, 1); - - return Out; -} \ No newline at end of file diff --git a/WickedEngine/volumetricLight_DirectionalPS.hlsl b/WickedEngine/volumetricLight_DirectionalPS.hlsl index c7eccb82a..40909dd0d 100644 --- a/WickedEngine/volumetricLight_DirectionalPS.hlsl +++ b/WickedEngine/volumetricLight_DirectionalPS.hlsl @@ -4,7 +4,7 @@ float4 main(VertexToPixel input) : SV_TARGET { - ShaderEntity light = EntityArray[(uint)g_xColor.x]; + ShaderEntity light = EntityArray[g_xFrame_LightArrayOffset + (uint)g_xColor.x]; if (!light.IsCastingShadow()) { @@ -22,7 +22,7 @@ float4 main(VertexToPixel input) : SV_TARGET float marchedDistance = 0; float3 accumulation = 0; - const float3 L = light.GetDirectionWS(); + const float3 L = light.GetDirection(); float3 rayEnd = g_xCamera_CamPos; diff --git a/WickedEngine/volumetricLight_PointPS.hlsl b/WickedEngine/volumetricLight_PointPS.hlsl index 60c4020f5..48bf1316a 100644 --- a/WickedEngine/volumetricLight_PointPS.hlsl +++ b/WickedEngine/volumetricLight_PointPS.hlsl @@ -4,7 +4,7 @@ float4 main(VertexToPixel input) : SV_TARGET { - ShaderEntity light = EntityArray[(uint)g_xColor.x]; + ShaderEntity light = EntityArray[g_xFrame_LightArrayOffset + (uint)g_xColor.x]; float2 ScreenCoord = input.pos2D.xy / input.pos2D.w * float2(0.5f, -0.5f) + 0.5f; float depth = max(input.pos.z, texture_depth.SampleLevel(sampler_linear_clamp, ScreenCoord, 0)); @@ -17,10 +17,10 @@ float4 main(VertexToPixel input) : SV_TARGET float accumulation = 0; float3 rayEnd = g_xCamera_CamPos; - if (length(rayEnd - light.positionWS) > light.GetRange()) + if (length(rayEnd - light.position) > light.GetRange()) { // if we are outside the light volume, then rayEnd will be the traced sphere frontface: - float t = Trace_sphere(rayEnd, -V, light.positionWS, light.GetRange()); + float t = Trace_sphere(rayEnd, -V, light.position, light.GetRange()); rayEnd = rayEnd - t * V; } @@ -34,7 +34,7 @@ float4 main(VertexToPixel input) : SV_TARGET [loop] for(uint i = 0; i < sampleCount; ++i) { - float3 L = light.positionWS - P; + float3 L = light.position - P; const float3 Lunnormalized = L; const float dist2 = dot(L, L); const float dist = sqrt(dist2); diff --git a/WickedEngine/volumetricLight_SpotPS.hlsl b/WickedEngine/volumetricLight_SpotPS.hlsl index bd7fd1b0e..894851e30 100644 --- a/WickedEngine/volumetricLight_SpotPS.hlsl +++ b/WickedEngine/volumetricLight_SpotPS.hlsl @@ -3,7 +3,7 @@ float4 main(VertexToPixel input) : SV_TARGET { - ShaderEntity light = EntityArray[(uint)g_xColor.x]; + ShaderEntity light = EntityArray[g_xFrame_LightArrayOffset + (uint)g_xColor.x]; float2 ScreenCoord = input.pos2D.xy / input.pos2D.w * float2(0.5f, -0.5f) + 0.5f; float depth = max(input.pos.z, texture_depth.SampleLevel(sampler_linear_clamp, ScreenCoord, 0)); @@ -28,12 +28,12 @@ float4 main(VertexToPixel input) : SV_TARGET [loop] for (uint i = 0; i < sampleCount; ++i) { - float3 L = light.positionWS - P; + float3 L = light.position - P; const float dist2 = dot(L, L); const float dist = sqrt(dist2); L /= dist; - float SpotFactor = dot(L, light.GetDirectionWS()); + float SpotFactor = dot(L, light.GetDirection()); float spotCutOff = light.GetConeAngleCos(); [branch] diff --git a/WickedEngine/wiArchive.cpp b/WickedEngine/wiArchive.cpp index ededac4b0..41d2ed40f 100644 --- a/WickedEngine/wiArchive.cpp +++ b/WickedEngine/wiArchive.cpp @@ -2,12 +2,11 @@ #include "wiHelper.h" #include -#include using namespace std; // this should always be only INCREMENTED and only if a new serialization is implemeted somewhere! -uint64_t __archiveVersion = 54; +uint64_t __archiveVersion = 55; // this is the version number of which below the archive is not compatible with the current version uint64_t __archiveVersionBarrier = 22; @@ -29,17 +28,14 @@ wiArchive::wiArchive(const std::string& fileName, bool readMode) : fileName(file (*this) >> version; if (version < __archiveVersionBarrier) { - stringstream ss(""); - ss << "The archive version (" << version << ") is no longer supported!"; - wiHelper::messageBox(ss.str(), "Error!"); + string ss = "The archive version (" + std::to_string(version) + ") is no longer supported!"; + wiHelper::messageBox(ss.c_str(), "Error!"); Close(); } if (version > __archiveVersion) { - stringstream ss(""); - - ss << "The archive version (" << version << ") is higher than the program's ("<<__archiveVersion<<")!"; - wiHelper::messageBox(ss.str(), "Error!"); + string ss = "The archive version (" + std::to_string(version) + ") is higher than the program's (" + std::to_string(__archiveVersion) + ")!"; + wiHelper::messageBox(ss.c_str(), "Error!"); Close(); } } diff --git a/WickedEngine/wiEmittedParticle.cpp b/WickedEngine/wiEmittedParticle.cpp index c8c42a633..bae5e3fcb 100644 --- a/WickedEngine/wiEmittedParticle.cpp +++ b/WickedEngine/wiEmittedParticle.cpp @@ -545,6 +545,7 @@ void wiEmittedParticle::Draw(const CameraComponent& camera, const MaterialCompon device->BindConstantBuffer(VS, &constantBuffer, CB_GETBINDSLOT(EmittedParticleCB), cmd); device->BindConstantBuffer(PS, &constantBuffer, CB_GETBINDSLOT(EmittedParticleCB), cmd); + device->BindConstantBuffer(PS, &material.constantBuffer, CB_GETBINDSLOT(MaterialCB), cmd); if (device->CheckCapability(GRAPHICSDEVICE_CAPABILITY_MESH_SHADER)) { diff --git a/WickedEngine/wiEnums.h b/WickedEngine/wiEnums.h index a03b37806..d5e793267 100644 --- a/WickedEngine/wiEnums.h +++ b/WickedEngine/wiEnums.h @@ -129,10 +129,6 @@ enum SHADERTYPE VSTYPE_VOLUMETRICLIGHT_SPOT, VSTYPE_LIGHTVISUALIZER_SPOTLIGHT, VSTYPE_LIGHTVISUALIZER_POINTLIGHT, - VSTYPE_LIGHTVISUALIZER_SPHERELIGHT, - VSTYPE_LIGHTVISUALIZER_DISCLIGHT, - VSTYPE_LIGHTVISUALIZER_RECTANGLELIGHT, - VSTYPE_LIGHTVISUALIZER_TUBELIGHT, VSTYPE_SKY, VSTYPE_ENVMAP, VSTYPE_ENVMAP_SKY, diff --git a/WickedEngine/wiEvent.h b/WickedEngine/wiEvent.h index 403cd2c8f..eeb36c147 100644 --- a/WickedEngine/wiEvent.h +++ b/WickedEngine/wiEvent.h @@ -6,7 +6,6 @@ static const int SYSTEM_EVENT_RELOAD_SHADERS = -1; static const int SYSTEM_EVENT_CHANGE_RESOLUTION = -2; -static const int SYSTEM_EVENT_CHANGE_RESOLUTION_SCALE = -3; static const int SYSTEM_EVENT_CHANGE_DPI = -4; static const int SYSTEM_EVENT_THREAD_SAFE_POINT = -5; diff --git a/WickedEngine/wiFont.cpp b/WickedEngine/wiFont.cpp index c1558e44e..608f160d9 100644 --- a/WickedEngine/wiFont.cpp +++ b/WickedEngine/wiFont.cpp @@ -14,7 +14,6 @@ #include "Utility/stb_truetype.h" #include -#include #include #include #include @@ -86,9 +85,8 @@ namespace wiFont_Internal if (!stbtt_InitFont(&fontInfo, fontBuffer.data(), offset)) { - stringstream ss(""); - ss << "Failed to load font: " << name; - wiHelper::messageBox(ss.str()); + string ss = "Failed to load font: " + name; + wiHelper::messageBox(ss.c_str()); } stbtt_GetFontVMetrics(&fontInfo, &ascent, &descent, &lineGap); diff --git a/WickedEngine/wiImage.cpp b/WickedEngine/wiImage.cpp index 92ecbefc1..3cb3b1df3 100644 --- a/WickedEngine/wiImage.cpp +++ b/WickedEngine/wiImage.cpp @@ -4,7 +4,6 @@ #include "wiHelper.h" #include "SamplerMapping.h" #include "ResourceMapping.h" -#include "wiScene.h" #include "ShaderInterop_Image.h" #include "wiBackLog.h" #include "wiEvent.h" @@ -105,54 +104,30 @@ namespace wiImage return; } - XMMATRIX M; - if (params.typeFlag == SCREEN) + XMMATRIX M = XMMatrixScaling(params.scale.x * params.siz.x, params.scale.y * params.siz.y, 1); + M = M * XMMatrixRotationZ(params.rotation); + + if (params.customRotation != nullptr) { - M = - XMMatrixScaling(params.scale.x*params.siz.x, params.scale.y*params.siz.y, 1) - * XMMatrixRotationZ(params.rotation) - * XMMatrixTranslation(params.pos.x, params.pos.y, 0) - * device->GetScreenProjection() - ; + M = M * (*params.customRotation); } - else if (params.typeFlag == WORLD) + + M = M * XMMatrixTranslation(params.pos.x, params.pos.y, params.pos.z); + + if (params.customProjection != nullptr) { - XMMATRIX faceRot = XMMatrixIdentity(); - if (params.lookAt.w) - { - XMVECTOR vvv = (params.lookAt.x == 1 && !params.lookAt.y && !params.lookAt.z) ? XMVectorSet(0, 1, 0, 0) : XMVectorSet(1, 0, 0, 0); - faceRot = - XMMatrixLookAtLH(XMVectorSet(0, 0, 0, 0) - , XMLoadFloat4(¶ms.lookAt) - , XMVector3Cross( - vvv, XMLoadFloat4(¶ms.lookAt) - ) - ); - } - else - { - faceRot = XMLoadFloat3x3(&wiRenderer::GetCamera().rotationMatrix); - } - - XMMATRIX view = wiRenderer::GetCamera().GetView(); - XMMATRIX projection = wiRenderer::GetCamera().GetProjection(); - // Remove possible jittering from temporal camera: - projection.r[2] = XMVectorSetX(projection.r[2], 0); - projection.r[2] = XMVectorSetY(projection.r[2], 0); - - M = - XMMatrixScaling(params.scale.x*params.siz.x, -1 * params.scale.y*params.siz.y, 1) - *XMMatrixRotationZ(params.rotation) - *faceRot - *XMMatrixTranslation(params.pos.x, params.pos.y, params.pos.z) - *view * projection - ; + M = XMMatrixScaling(1, -1, 1) * M; // reason: screen projection is Y down (like UV-space) and that is the common case for image rendering. But custom projections will use the "world space" + M = M * (*params.customProjection); + } + else + { + M = M * device->GetScreenProjection(); } for (int i = 0; i < 4; ++i) { XMVECTOR V = XMVectorSet(params.corners[i].x - params.pivot.x, params.corners[i].y - params.pivot.y, 0, 1); - V = XMVector2Transform(V, M); + V = XMVector2Transform(V, M); // division by w will happen on GPU XMStoreFloat4(&cb.xCorners[i], V); } @@ -313,7 +288,7 @@ namespace wiImage rs.DepthBias = 0; rs.DepthBiasClamp = 0; rs.SlopeScaledDepthBias = 0; - rs.DepthClipEnable = false; + rs.DepthClipEnable = true; rs.MultisampleEnable = false; rs.AntialiasedLineEnable = false; device->CreateRasterizerState(&rs, &rasterizerState); diff --git a/WickedEngine/wiImage.h b/WickedEngine/wiImage.h index 8cf3c6ede..266be8049 100644 --- a/WickedEngine/wiImage.h +++ b/WickedEngine/wiImage.h @@ -47,11 +47,6 @@ enum QUALITY QUALITY_ANISOTROPIC, QUALITY_COUNT }; -enum ImageType -{ - SCREEN, - WORLD, -}; struct wiImageParams { @@ -73,7 +68,6 @@ struct wiImageParams XMFLOAT4 color; XMFLOAT4 drawRect; XMFLOAT4 drawRect2; - XMFLOAT4 lookAt; //(x,y,z) : direction, (w) :isenabled? XMFLOAT2 texOffset; XMFLOAT2 texOffset2; XMFLOAT2 pivot; // (0,0) : upperleft, (0.5,0.5) : center, (1,1) : bottomright @@ -81,12 +75,13 @@ struct wiImageParams float fade; float opacity; XMFLOAT2 corners[4]; // you can deform the image by its corners (0: top left, 1: top right, 2: bottom left, 3: bottom right) + const XMMATRIX* customRotation = nullptr; + const XMMATRIX* customProjection = nullptr; uint8_t stencilRef; STENCILMODE stencilComp; STENCILREFMODE stencilRefMode; BLENDMODE blendFlag; - ImageType typeFlag; SAMPLEMODE sampleFlag; QUALITY quality; @@ -105,7 +100,6 @@ struct wiImageParams drawRect2 = XMFLOAT4(0, 0, 0, 0); texOffset = XMFLOAT2(0, 0); texOffset2 = XMFLOAT2(0, 0); - lookAt = XMFLOAT4(0, 0, 0, 0); pivot = XMFLOAT2(0, 0); fade = 0; rotation = 0; @@ -114,7 +108,6 @@ struct wiImageParams stencilComp = STENCILMODE_DISABLED; stencilRefMode = STENCILREFMODE_ALL; blendFlag = BLENDMODE_ALPHA; - typeFlag = SCREEN; sampleFlag = SAMPLEMODE_MIRROR; quality = QUALITY_LINEAR; maskMap = nullptr; @@ -122,6 +115,8 @@ struct wiImageParams corners[1] = XMFLOAT2(1, 0); corners[2] = XMFLOAT2(0, 1); corners[3] = XMFLOAT2(1, 1); + customRotation = nullptr; + customProjection = nullptr; } constexpr bool isDrawRectEnabled() const { return _flags & DRAWRECT; } diff --git a/WickedEngine/wiOcean.cpp b/WickedEngine/wiOcean.cpp index bef2c542b..c9735a963 100644 --- a/WickedEngine/wiOcean.cpp +++ b/WickedEngine/wiOcean.cpp @@ -267,7 +267,7 @@ void wiOcean::initHeightMap(const WeatherComponent& weather, XMFLOAT2* out_h0, f } } -void wiOcean::UpdateDisplacementMap(const WeatherComponent& weather, float time, CommandList cmd) const +void wiOcean::UpdateDisplacementMap(const WeatherComponent& weather, CommandList cmd) const { auto& params = weather.oceanParameters; @@ -290,7 +290,7 @@ void wiOcean::UpdateDisplacementMap(const WeatherComponent& weather, float time, device->BindUAVs(CS, cs0_uavs, 0, arraysize(cs0_uavs), cmd); Ocean_Simulation_PerFrameCB perFrameData; - perFrameData.g_Time = time * params.time_scale; + perFrameData.g_TimeScale = params.time_scale; perFrameData.g_ChoppyScale = params.choppy_scale; perFrameData.g_GridLen = params.dmap_dim / params.patch_length; device->UpdateBuffer(&perFrameCB, &perFrameData, cmd); @@ -349,7 +349,7 @@ void wiOcean::UpdateDisplacementMap(const WeatherComponent& weather, float time, } -void wiOcean::Render(const CameraComponent& camera, const WeatherComponent& weather, float time, CommandList cmd) const +void wiOcean::Render(const CameraComponent& camera, const WeatherComponent& weather, CommandList cmd) const { auto& params = weather.oceanParameters; diff --git a/WickedEngine/wiOcean.h b/WickedEngine/wiOcean.h index 1307929c8..05f4fe50d 100644 --- a/WickedEngine/wiOcean.h +++ b/WickedEngine/wiOcean.h @@ -11,8 +11,8 @@ class wiOcean public: wiOcean(const wiScene::WeatherComponent& weather); - void UpdateDisplacementMap(const wiScene::WeatherComponent& weather, float time, wiGraphics::CommandList cmd) const; - void Render(const wiScene::CameraComponent& camera, const wiScene::WeatherComponent& weather, float time, wiGraphics::CommandList cmd) const; + void UpdateDisplacementMap(const wiScene::WeatherComponent& weather, wiGraphics::CommandList cmd) const; + void Render(const wiScene::CameraComponent& camera, const wiScene::WeatherComponent& weather, wiGraphics::CommandList cmd) const; const wiGraphics::Texture* getDisplacementMap() const; const wiGraphics::Texture* getGradientMap() const; diff --git a/WickedEngine/wiRenderer.cpp b/WickedEngine/wiRenderer.cpp index 8ec31bc17..7a1a8cbe1 100644 --- a/WickedEngine/wiRenderer.cpp +++ b/WickedEngine/wiRenderer.cpp @@ -12,7 +12,6 @@ #include "wiBackLog.h" #include "wiProfiler.h" #include "wiOcean.h" -#include "ShaderInterop_Renderer.h" #include "ShaderInterop_Postprocess.h" #include "ShaderInterop_Skinning.h" #include "ShaderInterop_Raytracing.h" @@ -86,18 +85,6 @@ bool variableRateShadingClassification = false; bool variableRateShadingClassificationDebug = false; bool ldsSkinningEnabled = true; bool scene_bvh_invalid = true; -float renderTime = 0; -float renderTime_Prev = 0; -float deltaTime = 0; -float RESOLUTIONSCALE = 1.0f; -uint32_t entityArrayOffset_Lights = 0; -uint32_t entityArrayCount_Lights = 0; -uint32_t entityArrayOffset_Decals = 0; -uint32_t entityArrayCount_Decals = 0; -uint32_t entityArrayOffset_ForceFields = 0; -uint32_t entityArrayCount_ForceFields = 0; -uint32_t entityArrayOffset_EnvProbes = 0; -uint32_t entityArrayCount_EnvProbes = 0; float GameSpeed = 1; bool debugLightCulling = false; bool occlusionCulling = false; @@ -107,7 +94,6 @@ uint32_t raytraceBounceCount = 2; bool raytraceDebugVisualizer = false; bool raytracedShadows = false; bool tessellationEnabled = false; -Entity cameraTransform = INVALID_ENTITY; struct VoxelizedSceneData @@ -147,8 +133,6 @@ std::vector renderableTriangles_solid; std::vector renderableTriangles_wireframe; std::vector paintrads; -XMFLOAT4 waterPlane = XMFLOAT4(0, 1, 0, 0); - wiSpinLock deferredMIPGenLock; std::vector, bool>> deferredMIPGens; @@ -809,6 +793,15 @@ enum DEBUGRENDERING }; PipelineState PSO_debug[DEBUGRENDERING_COUNT]; +XMUINT3 GetEntityCullingTileCount(XMUINT2 internalResolution) +{ + return XMUINT3( + (internalResolution.x + TILED_CULLING_BLOCKSIZE - 1) / TILED_CULLING_BLOCKSIZE, + (internalResolution.y + TILED_CULLING_BLOCKSIZE - 1) / TILED_CULLING_BLOCKSIZE, + 1 + ); +} + bool LoadShader(SHADERSTAGE stage, Shader& shader, const std::string& filename) { @@ -957,10 +950,6 @@ void LoadShaders() wiJobSystem::Execute(ctx, [](wiJobArgs args) { LoadShader(VS, shaders[VSTYPE_VOLUMETRICLIGHT_SPOT], "volumetriclight_spotVS.cso"); }); wiJobSystem::Execute(ctx, [](wiJobArgs args) { LoadShader(VS, shaders[VSTYPE_LIGHTVISUALIZER_SPOTLIGHT], "vSpotLightVS.cso"); }); wiJobSystem::Execute(ctx, [](wiJobArgs args) { LoadShader(VS, shaders[VSTYPE_LIGHTVISUALIZER_POINTLIGHT], "vPointLightVS.cso"); }); - wiJobSystem::Execute(ctx, [](wiJobArgs args) { LoadShader(VS, shaders[VSTYPE_LIGHTVISUALIZER_SPHERELIGHT], "vSphereLightVS.cso"); }); - wiJobSystem::Execute(ctx, [](wiJobArgs args) { LoadShader(VS, shaders[VSTYPE_LIGHTVISUALIZER_DISCLIGHT], "vDiscLightVS.cso"); }); - wiJobSystem::Execute(ctx, [](wiJobArgs args) { LoadShader(VS, shaders[VSTYPE_LIGHTVISUALIZER_RECTANGLELIGHT], "vRectangleLightVS.cso"); }); - wiJobSystem::Execute(ctx, [](wiJobArgs args) { LoadShader(VS, shaders[VSTYPE_LIGHTVISUALIZER_TUBELIGHT], "vTubeLightVS.cso"); }); wiJobSystem::Execute(ctx, [](wiJobArgs args) { LoadShader(VS, shaders[VSTYPE_SPHERE], "sphereVS.cso"); }); wiJobSystem::Execute(ctx, [](wiJobArgs args) { LoadShader(VS, shaders[VSTYPE_CUBE], "cubeVS.cso"); }); wiJobSystem::Execute(ctx, [](wiJobArgs args) { LoadShader(VS, shaders[VSTYPE_SKY], "skyVS.cso"); }); @@ -1495,26 +1484,6 @@ void LoadShaders() desc.vs = &shaders[VSTYPE_LIGHTVISUALIZER_SPOTLIGHT]; desc.rs = &rasterizers[RSTYPE_DOUBLESIDED]; break; - case LightComponent::SPHERE: - desc.bs = &blendStates[BSTYPE_OPAQUE]; - desc.vs = &shaders[VSTYPE_LIGHTVISUALIZER_SPHERELIGHT]; - desc.rs = &rasterizers[RSTYPE_FRONT]; - break; - case LightComponent::DISC: - desc.bs = &blendStates[BSTYPE_OPAQUE]; - desc.vs = &shaders[VSTYPE_LIGHTVISUALIZER_DISCLIGHT]; - desc.rs = &rasterizers[RSTYPE_FRONT]; - break; - case LightComponent::RECTANGLE: - desc.bs = &blendStates[BSTYPE_OPAQUE]; - desc.vs = &shaders[VSTYPE_LIGHTVISUALIZER_RECTANGLELIGHT]; - desc.rs = &rasterizers[RSTYPE_BACK]; - break; - case LightComponent::TUBE: - desc.bs = &blendStates[BSTYPE_OPAQUE]; - desc.vs = &shaders[VSTYPE_LIGHTVISUALIZER_TUBELIGHT]; - desc.rs = &rasterizers[RSTYPE_FRONT]; - break; } device->CreatePipelineState(&desc, &PSO_lightvisualizer[args.jobIndex]); @@ -2279,24 +2248,9 @@ void ReloadShaders() wiEvent::FireEvent(SYSTEM_EVENT_RELOAD_SHADERS, 0); } -CameraComponent& GetCamera() -{ - static CameraComponent camera; - return camera; -} -void AttachCamera(wiECS::Entity entity) -{ - cameraTransform = entity; -} void Initialize() { - auto camera_setup = [](uint64_t userdata) { - GetCamera().CreatePerspective((float)GetInternalResolution().x, (float)GetInternalResolution().y, 0.1f, 800); - }; - camera_setup(0); - static wiEvent::Handle handle1 = wiEvent::Subscribe(SYSTEM_EVENT_CHANGE_RESOLUTION, [=](uint64_t userdata) { camera_setup(userdata); }); - SetUpStates(); LoadBuffers(); @@ -3166,7 +3120,11 @@ void UpdateVisibility(Visibility& vis) assert(args.jobIndex < 0xFFFF); group_list[group_count].index = (uint16_t)args.jobIndex; const LightComponent& lightcomponent = vis.scene->lights[args.jobIndex]; - float distance = wiMath::DistanceEstimated(lightcomponent.position, vis.camera->Eye); + float distance = 0; + if (lightcomponent.type != LightComponent::DIRECTIONAL) + { + distance = wiMath::DistanceEstimated(lightcomponent.position, vis.camera->Eye); + } group_list[group_count].distance = uint16_t(distance * 10); group_count++; if (lightcomponent.IsVolumetricsEnabled()) @@ -3381,46 +3339,21 @@ void UpdateVisibility(Visibility& vis) wiProfiler::EndRange(range); // Frustum Culling } -void UpdatePerFrameData(Scene& scene, const Visibility& vis, float dt) +void UpdatePerFrameData( + Scene& scene, + const Visibility& vis, + FrameCB& frameCB, + XMUINT2 internalResolution, + float dt +) { for (int i = 0; i < COMMANDLIST_COUNT; ++i) { renderFrameAllocators[i].reset(); } - renderTime_Prev = renderTime; - deltaTime = dt * GetGameSpeed(); - renderTime += deltaTime; - wiJobSystem::context ctx; - // Because main camera is not part of the scene, update it if it is attached to an entity here: - if (cameraTransform != INVALID_ENTITY) - { - const TransformComponent* transform = scene.transforms.GetComponent(cameraTransform); - if (transform != nullptr) - { - GetCamera().TransformCamera(*transform); - GetCamera().UpdateCamera(); - } - cameraTransform = INVALID_ENTITY; // but this is only active for the current frame - } - - if (GetTemporalAAEnabled()) - { - const XMFLOAT4& halton = wiMath::GetHaltonSequence(device->GetFrameCount() % 256); - GetCamera().jitter.x = (halton.x * 2 - 1) / (float)GetInternalResolution().x; - GetCamera().jitter.y = (halton.y * 2 - 1) / (float)GetInternalResolution().y; - } - else - { - GetCamera().jitter = XMFLOAT2(0, 0); - } - - GetCamera().UpdateCamera(); - - waterPlane = vis.reflectionPlane; - // Need to swap prev and current vertex buffers for any dynamic meshes BEFORE render threads are kicked // and also create skinning bone buffers: wiJobSystem::Execute(ctx, [&](wiJobArgs args) { @@ -3571,9 +3504,152 @@ void UpdatePerFrameData(Scene& scene, const Visibility& vis, float dt) }); wiJobSystem::Wait(ctx); + + + // Update CPU-side frame constant buffer: + frameCB.g_xFrame_ConstantOne = 1; + frameCB.g_xFrame_ScreenWidthHeight = float2((float)device->GetScreenWidth(), (float)device->GetScreenHeight()); + frameCB.g_xFrame_ScreenWidthHeight_rcp = float2(1.0f / frameCB.g_xFrame_ScreenWidthHeight.x, 1.0f / frameCB.g_xFrame_ScreenWidthHeight.y); + frameCB.g_xFrame_InternalResolution = float2((float)internalResolution.x, (float)internalResolution.y); + frameCB.g_xFrame_InternalResolution_rcp = float2(1.0f / frameCB.g_xFrame_InternalResolution.x, 1.0f / frameCB.g_xFrame_InternalResolution.y); + frameCB.g_xFrame_Gamma = GetGamma(); + frameCB.g_xFrame_SunColor = vis.scene->weather.sunColor; + frameCB.g_xFrame_SunDirection = vis.scene->weather.sunDirection; + frameCB.g_xFrame_SunEnergy = vis.scene->weather.sunEnergy; + frameCB.g_xFrame_ShadowCascadeCount = CASCADE_COUNT; + frameCB.g_xFrame_Ambient = vis.scene->weather.ambient; + frameCB.g_xFrame_Cloudiness = vis.scene->weather.cloudiness; + frameCB.g_xFrame_CloudScale = vis.scene->weather.cloudScale; + frameCB.g_xFrame_CloudSpeed = vis.scene->weather.cloudSpeed; + frameCB.g_xFrame_Fog = float3(vis.scene->weather.fogStart, vis.scene->weather.fogEnd, vis.scene->weather.fogHeight); + frameCB.g_xFrame_Horizon = vis.scene->weather.horizon; + frameCB.g_xFrame_Zenith = vis.scene->weather.zenith; + frameCB.g_xFrame_VoxelRadianceMaxDistance = voxelSceneData.maxDistance; + frameCB.g_xFrame_VoxelRadianceDataSize = voxelSceneData.voxelsize; + frameCB.g_xFrame_VoxelRadianceDataSize_rcp = 1.0f / (float)frameCB.g_xFrame_VoxelRadianceDataSize; + frameCB.g_xFrame_VoxelRadianceDataRes = GetVoxelRadianceEnabled() ? (uint)voxelSceneData.res : 0; + frameCB.g_xFrame_VoxelRadianceDataRes_rcp = 1.0f / (float)frameCB.g_xFrame_VoxelRadianceDataRes; + frameCB.g_xFrame_VoxelRadianceDataMIPs = voxelSceneData.mips; + frameCB.g_xFrame_VoxelRadianceNumCones = std::max(std::min(voxelSceneData.numCones, 16u), 1u); + frameCB.g_xFrame_VoxelRadianceNumCones_rcp = 1.0f / (float)frameCB.g_xFrame_VoxelRadianceNumCones; + frameCB.g_xFrame_VoxelRadianceRayStepSize = voxelSceneData.rayStepSize; + frameCB.g_xFrame_VoxelRadianceDataCenter = voxelSceneData.center; + frameCB.g_xFrame_EntityCullingTileCount = GetEntityCullingTileCount(internalResolution); + + // The order is very important here: + frameCB.g_xFrame_DecalArrayOffset = 0; + frameCB.g_xFrame_DecalArrayCount = (uint)vis.visibleDecals.size(); + frameCB.g_xFrame_EnvProbeArrayOffset = frameCB.g_xFrame_DecalArrayCount; + frameCB.g_xFrame_EnvProbeArrayCount = (uint)vis.visibleEnvProbes.size(); + frameCB.g_xFrame_LightArrayOffset = frameCB.g_xFrame_EnvProbeArrayOffset + frameCB.g_xFrame_EnvProbeArrayCount; + frameCB.g_xFrame_LightArrayCount = (uint)vis.visibleLights.size(); + frameCB.g_xFrame_ForceFieldArrayOffset = frameCB.g_xFrame_LightArrayOffset + frameCB.g_xFrame_LightArrayCount; + frameCB.g_xFrame_ForceFieldArrayCount = (uint)vis.scene->forces.GetCount(); + + frameCB.g_xFrame_GlobalEnvProbeIndex = -1; + frameCB.g_xFrame_EnvProbeMipCount = 0; + frameCB.g_xFrame_EnvProbeMipCount_rcp = 1.0f; + if (vis.scene->probes.GetCount() > 0) + { + frameCB.g_xFrame_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].IsValid()) + { + frameCB.g_xFrame_EnvProbeMipCount = textures[TEXTYPE_CUBEARRAY_ENVMAPARRAY].GetDesc().MipLevels; + frameCB.g_xFrame_EnvProbeMipCount_rcp = 1.0f / (float)frameCB.g_xFrame_EnvProbeMipCount; + } + + frameCB.g_xFrame_DeltaTime = dt * GetGameSpeed(); + frameCB.g_xFrame_TimePrev = frameCB.g_xFrame_Time; + frameCB.g_xFrame_Time += frameCB.g_xFrame_DeltaTime; + frameCB.g_xFrame_WindSpeed = vis.scene->weather.windSpeed; + frameCB.g_xFrame_WindRandomness = vis.scene->weather.windRandomness; + frameCB.g_xFrame_WindWaveSize = vis.scene->weather.windWaveSize; + frameCB.g_xFrame_WindDirection = vis.scene->weather.windDirection; + frameCB.g_xFrame_StaticSkyGamma = 0.0f; + if (vis.scene->weather.skyMap != nullptr) + { + bool hdr = !device->IsFormatUnorm(vis.scene->weather.skyMap->texture->GetDesc().Format); + frameCB.g_xFrame_StaticSkyGamma = hdr ? 1.0f : frameCB.g_xFrame_Gamma; + } + frameCB.g_xFrame_FrameCount = (uint)device->GetFrameCount(); + frameCB.g_xFrame_TemporalAASampleRotation = 0; + if (GetTemporalAAEnabled()) + { + uint id = frameCB.g_xFrame_FrameCount % 4; + uint x = 0; + uint y = 0; + switch (id) + { + case 1: + x = 1; + break; + case 2: + y = 1; + break; + case 3: + x = 1; + y = 1; + break; + default: + break; + } + frameCB.g_xFrame_TemporalAASampleRotation = (x & 0x000000FF) | ((y & 0x000000FF) << 8); + } + frameCB.g_xFrame_ShadowKernel2D = 1.0f / SHADOWRES_2D; + frameCB.g_xFrame_ShadowKernelCube = 1.0f / SHADOWRES_CUBE; + + frameCB.g_xFrame_WorldBoundsMin = vis.scene->bounds.getMin(); + frameCB.g_xFrame_WorldBoundsMax = vis.scene->bounds.getMax(); + frameCB.g_xFrame_WorldBoundsExtents.x = abs(frameCB.g_xFrame_WorldBoundsMax.x - frameCB.g_xFrame_WorldBoundsMin.x); + frameCB.g_xFrame_WorldBoundsExtents.y = abs(frameCB.g_xFrame_WorldBoundsMax.y - frameCB.g_xFrame_WorldBoundsMin.y); + frameCB.g_xFrame_WorldBoundsExtents.z = abs(frameCB.g_xFrame_WorldBoundsMax.z - frameCB.g_xFrame_WorldBoundsMin.z); + frameCB.g_xFrame_WorldBoundsExtents_rcp.x = 1.0f / frameCB.g_xFrame_WorldBoundsExtents.x; + frameCB.g_xFrame_WorldBoundsExtents_rcp.y = 1.0f / frameCB.g_xFrame_WorldBoundsExtents.y; + frameCB.g_xFrame_WorldBoundsExtents_rcp.z = 1.0f / frameCB.g_xFrame_WorldBoundsExtents.z; + + frameCB.g_xFrame_Options = 0; + if (GetTemporalAAEnabled()) + { + frameCB.g_xFrame_Options |= OPTION_BIT_TEMPORALAA_ENABLED; + } + if (GetTransparentShadowsEnabled()) + { + frameCB.g_xFrame_Options |= OPTION_BIT_TRANSPARENTSHADOWS_ENABLED; + } + if (GetVoxelRadianceEnabled()) + { + frameCB.g_xFrame_Options |= OPTION_BIT_VOXELGI_ENABLED; + } + if (GetVoxelRadianceReflectionsEnabled()) + { + frameCB.g_xFrame_Options |= OPTION_BIT_VOXELGI_REFLECTIONS_ENABLED; + } + if (voxelSceneData.centerChangedThisFrame) + { + frameCB.g_xFrame_Options |= OPTION_BIT_VOXELGI_RETARGETTED; + } + if (vis.scene->weather.IsSimpleSky()) + { + frameCB.g_xFrame_Options |= OPTION_BIT_SIMPLE_SKY; + } + if (vis.scene->weather.IsRealisticSky()) + { + frameCB.g_xFrame_Options |= OPTION_BIT_REALISTIC_SKY; + } + if (device->CheckCapability(GRAPHICSDEVICE_CAPABILITY_RAYTRACING) && GetRaytracedShadowsEnabled()) + { + frameCB.g_xFrame_Options |= OPTION_BIT_RAYTRACED_SHADOWS; + } } -void UpdateRenderData(const Visibility& vis, CommandList cmd) +void UpdateRenderData( + const Visibility& vis, + const FrameCB& frameCB, + CommandList cmd +) { + device->UpdateBuffer(&constantBuffers[CBTYPE_FRAME], &frameCB, cmd); + BindCommonResources(cmd); // Update material constant buffers: @@ -3600,13 +3676,6 @@ void UpdateRenderData(const Visibility& vis, CommandList cmd) } pendingMorphUpdates.clear(); - - if (vis.scene->weather.IsRealisticSky()) - { - // Render Atmospheric Scattering textures for lighting and sky - RenderAtmosphericScatteringTextures(cmd); - } - // Fill Entity Array with decals + envprobes + lights in the frustum: { // Reserve temporary entity array for GPU data upload: @@ -3618,17 +3687,7 @@ void UpdateRenderData(const Visibility& vis, CommandList cmd) uint32_t entityCounter = 0; uint32_t matrixCounter = 0; - entityArrayOffset_Lights = 0; - entityArrayCount_Lights = 0; - entityArrayOffset_Decals = 0; - entityArrayCount_Decals = 0; - entityArrayOffset_ForceFields = 0; - entityArrayCount_ForceFields = 0; - entityArrayOffset_EnvProbes = 0; - entityArrayCount_EnvProbes = 0; - // Write decals into entity array: - entityArrayOffset_Decals = entityCounter; for (size_t i = 0; i < vis.visibleDecals.size(); ++i) { if (entityCounter == SHADER_ENTITY_COUNT) @@ -3647,27 +3706,33 @@ void UpdateRenderData(const Visibility& vis, CommandList cmd) const DecalComponent& decal = vis.scene->decals[decalIndex]; entityArray[entityCounter] = {}; // zero out! + entityArray[entityCounter].layerMask = ~0u; + + Entity entity = vis.scene->decals.GetEntity(decalIndex); + const LayerComponent* layer = vis.scene->layers.GetComponent(entity); + if (layer != nullptr) + { + entityArray[entityCounter].layerMask = layer->layerMask; + } entityArray[entityCounter].SetType(ENTITY_TYPE_DECAL); - entityArray[entityCounter].positionWS = decal.position; - float3 positionVS; - XMStoreFloat3(&positionVS, XMVector3TransformCoord(XMLoadFloat3(&decal.position), viewMatrix)); - entityArray[entityCounter].SetPositionVS(positionVS); + entityArray[entityCounter].position = decal.position; entityArray[entityCounter].SetRange(decal.range); - entityArray[entityCounter].SetTexMulAdd(decal.atlasMulAdd); entityArray[entityCounter].color = wiMath::CompressColor(XMFLOAT4(decal.color.x, decal.color.y, decal.color.z, decal.GetOpacity())); entityArray[entityCounter].SetEnergy(decal.emissive); entityArray[entityCounter].SetIndices(matrixCounter, 0); matrixArray[matrixCounter] = XMMatrixInverse(nullptr, XMLoadFloat4x4(&decal.world)); + matrixArray[matrixCounter].r[0] = XMVectorSetW(matrixArray[matrixCounter].r[0], decal.atlasMulAdd.x); + matrixArray[matrixCounter].r[1] = XMVectorSetW(matrixArray[matrixCounter].r[1], decal.atlasMulAdd.y); + matrixArray[matrixCounter].r[2] = XMVectorSetW(matrixArray[matrixCounter].r[2], decal.atlasMulAdd.z); + matrixArray[matrixCounter].r[3] = XMVectorSetW(matrixArray[matrixCounter].r[3], decal.atlasMulAdd.w); matrixCounter++; entityCounter++; } - entityArrayCount_Decals = entityCounter - entityArrayOffset_Decals; // Write environment probes into entity array: - entityArrayOffset_EnvProbes = entityCounter; for (size_t i = 0; i < vis.visibleEnvProbes.size(); ++i) { if (entityCounter == SHADER_ENTITY_COUNT) @@ -3691,12 +3756,17 @@ void UpdateRenderData(const Visibility& vis, CommandList cmd) } entityArray[entityCounter] = {}; // zero out! + entityArray[entityCounter].layerMask = ~0u; + + Entity entity = vis.scene->probes.GetEntity(probeIndex); + const LayerComponent* layer = vis.scene->layers.GetComponent(entity); + if (layer != nullptr) + { + entityArray[entityCounter].layerMask = layer->layerMask; + } entityArray[entityCounter].SetType(ENTITY_TYPE_ENVMAP); - entityArray[entityCounter].positionWS = probe.position; - float3 positionVS; - XMStoreFloat3(&positionVS, XMVector3TransformCoord(XMLoadFloat3(&probe.position), viewMatrix)); - entityArray[entityCounter].SetPositionVS(positionVS); + entityArray[entityCounter].position = probe.position; entityArray[entityCounter].SetRange(probe.range); entityArray[entityCounter].SetIndices(matrixCounter, (uint32_t)probe.textureIndex); @@ -3705,10 +3775,8 @@ void UpdateRenderData(const Visibility& vis, CommandList cmd) entityCounter++; } - entityArrayCount_EnvProbes = entityCounter - entityArrayOffset_EnvProbes; // Write lights into entity array: - entityArrayOffset_Lights = entityCounter; uint32_t shadowCounter_2D = 0; uint32_t shadowCounter_Cube = 0; for (auto visibleLight : vis.visibleLights) @@ -3724,53 +3792,67 @@ void UpdateRenderData(const Visibility& vis, CommandList cmd) const LightComponent& light = vis.scene->lights[lightIndex]; entityArray[entityCounter] = {}; // zero out! + entityArray[entityCounter].layerMask = ~0u; + + Entity entity = vis.scene->lights.GetEntity(lightIndex); + const LayerComponent* layer = vis.scene->layers.GetComponent(entity); + if (layer != nullptr) + { + entityArray[entityCounter].layerMask = layer->layerMask; + } entityArray[entityCounter].SetType(light.GetType()); - entityArray[entityCounter].positionWS = light.position; - float3 positionVS; - XMStoreFloat3(&positionVS, XMVector3TransformCoord(XMLoadFloat3(&entityArray[entityCounter].positionWS), viewMatrix)); - entityArray[entityCounter].SetPositionVS(positionVS); + entityArray[entityCounter].position = light.position; entityArray[entityCounter].SetRange(light.GetRange()); entityArray[entityCounter].color = wiMath::CompressColor(light.color); entityArray[entityCounter].SetEnergy(light.energy); + + // mark as no shadow by default: entityArray[entityCounter].indices = ~0; bool shadow = light.IsCastingShadow() && !light.IsStatic(); - if (shadow) + + if (GetRaytracedShadowsEnabled() && shadow) { - switch (light.GetType()) + entityArray[entityCounter].SetIndices(matrixCounter, 0); + } + else if(shadow) + { + shadow = light.IsCastingShadow() && !light.IsStatic(); + if (shadow) { - case LightComponent::DIRECTIONAL: - if (shadowCounter_2D < SHADOWCOUNT_2D - CASCADE_COUNT + 1) + switch (light.GetType()) { - entityArray[entityCounter].SetIndices(matrixCounter, shadowCounter_2D); - shadowCounter_2D += CASCADE_COUNT; + case LightComponent::DIRECTIONAL: + if (shadowCounter_2D < SHADOWCOUNT_2D - CASCADE_COUNT + 1) + { + entityArray[entityCounter].SetIndices(matrixCounter, shadowCounter_2D); + shadowCounter_2D += CASCADE_COUNT; + } + break; + case LightComponent::SPOT: + if (shadowCounter_2D < SHADOWCOUNT_2D) + { + entityArray[entityCounter].SetIndices(matrixCounter, shadowCounter_2D); + shadowCounter_2D += 1; + } + break; + default: + if (shadowCounter_Cube < SHADOWCOUNT_CUBE) + { + entityArray[entityCounter].SetIndices(matrixCounter, shadowCounter_Cube); + shadowCounter_Cube += 1; + } + break; } - break; - case LightComponent::SPOT: - if (shadowCounter_2D < SHADOWCOUNT_2D) - { - entityArray[entityCounter].SetIndices(matrixCounter, shadowCounter_2D); - shadowCounter_2D += 1; - } - break; - default: - if (shadowCounter_Cube < SHADOWCOUNT_CUBE) - { - entityArray[entityCounter].SetIndices(matrixCounter, shadowCounter_Cube); - shadowCounter_Cube += 1; - } - break; } } - float4 texMulAdd = {}; - switch (light.GetType()) { case LightComponent::DIRECTIONAL: { - entityArray[entityCounter].SetDirectionWS(light.direction); + entityArray[entityCounter].SetDirection(light.direction); if (shadow) { @@ -3782,13 +3864,24 @@ void UpdateRenderData(const Visibility& vis, CommandList cmd) } } break; + case LightComponent::POINT: + { + if (shadow) + { + const float FarZ = 0.1f; // watch out: reversed depth buffer! Also, light near plane is constant for simplicity, this should match on cpu side! + const float NearZ = std::max(1.0f, light.GetRange()); // watch out: reversed depth buffer! + const float fRange = FarZ / (FarZ - NearZ); + const float cubemapDepthRemapNear = fRange; + const float cubemapDepthRemapFar = -fRange * NearZ; + entityArray[entityCounter].SetCubeRemapNear(cubemapDepthRemapNear); + entityArray[entityCounter].SetCubeRemapFar(cubemapDepthRemapFar); + } + } + break; case LightComponent::SPOT: { entityArray[entityCounter].SetConeAngleCos(cosf(light.fov * 0.5f)); - entityArray[entityCounter].SetDirectionWS(light.direction); - float3 directionVS; - XMStoreFloat3(&directionVS, XMVector3TransformNormal(XMLoadFloat3(&light.direction), viewMatrix)); - entityArray[entityCounter].SetDirectionVS(directionVS); + entityArray[entityCounter].SetDirection(light.direction); if (shadow) { @@ -3798,40 +3891,7 @@ void UpdateRenderData(const Visibility& vis, CommandList cmd) } } break; - case LightComponent::SPHERE: - case LightComponent::DISC: - case LightComponent::RECTANGLE: - case LightComponent::TUBE: - { - // Note: area lights are facing back by default - entityArray[entityCounter].SetDirectionWS(light.right); - entityArray[entityCounter].SetDirectionVS(light.direction); - entityArray[entityCounter].SetPositionVS(light.front); - texMulAdd = float4(light.radius, light.width, light.height, 0); } - break; - } - - switch (light.GetType()) - { - case LightComponent::POINT: - case LightComponent::SPHERE: - case LightComponent::DISC: - case LightComponent::RECTANGLE: - case LightComponent::TUBE: - { - const float FarZ = 0.1f; // watch out: reversed depth buffer! Also, light near plane is constant for simplicity, this should match on cpu side! - const float NearZ = std::max(1.0f, light.GetRange()); // watch out: reversed depth buffer! - const float fRange = FarZ / (FarZ - NearZ); - const float cubemapDepthRemapNear = fRange; - const float cubemapDepthRemapFar = -fRange * NearZ; - texMulAdd.w = cubemapDepthRemapNear; - entityArray[entityCounter].SetConeAngleCos(cubemapDepthRemapFar); - } - break; - } - - entityArray[entityCounter].SetTexMulAdd(texMulAdd); if (light.IsStatic()) { @@ -3840,10 +3900,8 @@ void UpdateRenderData(const Visibility& vis, CommandList cmd) entityCounter++; } - entityArrayCount_Lights = entityCounter - entityArrayOffset_Lights; // Write force fields into entity array: - entityArrayOffset_ForceFields = entityCounter; for (size_t i = 0; i < vis.scene->forces.GetCount(); ++i) { if (entityCounter == SHADER_ENTITY_COUNT) @@ -3856,18 +3914,25 @@ void UpdateRenderData(const Visibility& vis, CommandList cmd) const ForceFieldComponent& force = vis.scene->forces[i]; entityArray[entityCounter] = {}; // zero out! + entityArray[entityCounter].layerMask = ~0u; + + Entity entity = vis.scene->forces.GetEntity(i); + const LayerComponent* layer = vis.scene->layers.GetComponent(entity); + if (layer != nullptr) + { + entityArray[entityCounter].layerMask = layer->layerMask; + } entityArray[entityCounter].SetType(force.type); - entityArray[entityCounter].positionWS = force.position; + entityArray[entityCounter].position = force.position; entityArray[entityCounter].SetEnergy(force.gravity); entityArray[entityCounter].SetRange(1.0f / std::max(0.0001f, force.GetRange())); // avoid division in shader entityArray[entityCounter].SetConeAngleCos(force.GetRange()); // this will be the real range in the less common shaders... // The default planar force field is facing upwards, and thus the pull direction is downwards: - entityArray[entityCounter].SetDirectionWS(force.direction); + entityArray[entityCounter].SetDirection(force.direction); entityCounter++; } - entityArrayCount_ForceFields = entityCounter - entityArrayOffset_ForceFields; // Issue GPU entity array update: device->UpdateBuffer(&resourceBuffers[RBTYPE_ENTITYARRAY], entityArray, cmd, sizeof(ShaderEntity)*entityCounter); @@ -3878,8 +3943,6 @@ void UpdateRenderData(const Visibility& vis, CommandList cmd) GetRenderFrameAllocator(cmd).free(sizeof(XMMATRIX)*MATRIXARRAY_COUNT); } - UpdateFrameCB(*vis.scene, cmd); - auto range = wiProfiler::BeginRangeGPU("Skinning", cmd); device->EventBegin("Skinning", cmd); { @@ -4029,9 +4092,15 @@ void UpdateRenderData(const Visibility& vis, CommandList cmd) if (vis.scene->weather.IsOceanEnabled() && ocean != nullptr) { range = wiProfiler::BeginRangeGPU("Ocean - Simulate", cmd); - ocean->UpdateDisplacementMap(vis.scene->weather, renderTime, cmd); + ocean->UpdateDisplacementMap(vis.scene->weather, cmd); wiProfiler::EndRange(range); } + + if (vis.scene->weather.IsRealisticSky()) + { + // Render Atmospheric Scattering textures for lighting and sky + RenderAtmosphericScatteringTextures(cmd); + } } void UpdateRaytracingAccelerationStructures(const Scene& scene, CommandList cmd) { @@ -4244,11 +4313,8 @@ void PutWaterRipple(const std::string& image, const XMFLOAT3& pos) img.params.pos = pos; img.params.rotation = (wiRandom::getRandom(0, 1000)*0.001f) * 2 * 3.1415f; img.params.siz = XMFLOAT2(1, 1); - img.params.typeFlag = WORLD; img.params.quality = QUALITY_ANISOTROPIC; img.params.pivot = XMFLOAT2(0.5f, 0.5f); - img.params.lookAt = waterPlane; - img.params.lookAt.w = 1; waterRipples.push_back(img); } void ManageWaterRipples(){ @@ -4260,11 +4326,23 @@ void ManageWaterRipples(){ waterRipples.pop_front(); } } -void DrawWaterRipples(CommandList cmd) +void DrawWaterRipples(const Visibility& vis, CommandList cmd) { + // remove camera jittering + CameraComponent cam = *vis.camera; + cam.jitter = XMFLOAT2(0, 0); + cam.UpdateCamera(); + const XMMATRIX VP = cam.GetViewProjection(); + + XMVECTOR vvv = abs(vis.reflectionPlane.x) > 0.99f ? XMVectorSet(0, 1, 0, 0) : XMVectorSet(1, 0, 0, 0); + XMVECTOR dir = XMLoadFloat4(&vis.reflectionPlane); + XMMATRIX R = XMMatrixLookToLH(XMVectorZero(), dir, XMVector3Cross(vvv, dir)); + device->EventBegin("Water Ripples", cmd); for(auto& x : waterRipples) { + x.params.customRotation = &R; + x.params.customProjection = &VP; x.Draw(cmd); } device->EventEnd(cmd); @@ -4379,58 +4457,6 @@ void DrawLightVisualizers( device->Draw(192, 0, cmd); // cone } - else if (type == LightComponent::SPHERE) - { - XMStoreFloat4x4(&lcb.lightWorld, - XMMatrixScaling(light.radius, light.radius, light.radius)* - XMMatrixRotationQuaternion(XMLoadFloat4(&light.rotation))* - XMMatrixTranslationFromVector(XMLoadFloat3(&light.position))* - VP - ); - - device->UpdateBuffer(&constantBuffers[CBTYPE_VOLUMELIGHT], &lcb, cmd); - - device->Draw(2880, 0, cmd); // uv-sphere - } - else if (type == LightComponent::DISC) - { - XMStoreFloat4x4(&lcb.lightWorld, - XMMatrixScaling(light.radius, light.radius, light.radius)* - XMMatrixRotationQuaternion(XMLoadFloat4(&light.rotation))* - XMMatrixTranslationFromVector(XMLoadFloat3(&light.position))* - VP - ); - - device->UpdateBuffer(&constantBuffers[CBTYPE_VOLUMELIGHT], &lcb, cmd); - - device->Draw(108, 0, cmd); // circle - } - else if (type == LightComponent::RECTANGLE) - { - XMStoreFloat4x4(&lcb.lightWorld, - XMMatrixScaling(light.width * 0.5f * light.scale.x, light.height * 0.5f * light.scale.y, 0.5f)* - XMMatrixRotationQuaternion(XMLoadFloat4(&light.rotation))* - XMMatrixTranslationFromVector(XMLoadFloat3(&light.position))* - VP - ); - - device->UpdateBuffer(&constantBuffers[CBTYPE_VOLUMELIGHT], &lcb, cmd); - - device->Draw(6, 0, cmd); // quad - } - else if (type == LightComponent::TUBE) - { - XMStoreFloat4x4(&lcb.lightWorld, - XMMatrixScaling(std::max(light.width * 0.5f, light.radius) * light.scale.x, light.radius, light.radius)* - XMMatrixRotationQuaternion(XMLoadFloat4(&light.rotation))* - XMMatrixTranslationFromVector(XMLoadFloat3(&light.position))* - VP - ); - - device->UpdateBuffer(&constantBuffers[CBTYPE_VOLUMELIGHT], &lcb, cmd); - - device->Draw(384, 0, cmd); // cylinder - } } } @@ -4478,13 +4504,9 @@ void DrawVolumeLights( switch (type) { case LightComponent::DIRECTIONAL: - case LightComponent::SPHERE: - case LightComponent::DISC: - case LightComponent::RECTANGLE: - case LightComponent::TUBE: { MiscCB miscCb; - miscCb.g_xColor.x = float(entityArrayOffset_Lights + i); + miscCb.g_xColor.x = float(i); device->UpdateBuffer(&constantBuffers[CBTYPE_MISC], &miscCb, cmd); device->BindConstantBuffer(VS, &constantBuffers[CBTYPE_MISC], CB_GETBINDSLOT(MiscCB), cmd); device->BindConstantBuffer(PS, &constantBuffers[CBTYPE_MISC], CB_GETBINDSLOT(MiscCB), cmd); @@ -4495,7 +4517,7 @@ void DrawVolumeLights( case LightComponent::POINT: { MiscCB miscCb; - miscCb.g_xColor.x = float(entityArrayOffset_Lights + i); + miscCb.g_xColor.x = float(i); float sca = light.GetRange() + 1; XMStoreFloat4x4(&miscCb.g_xTransform, XMMatrixScaling(sca, sca, sca)*XMMatrixTranslationFromVector(XMLoadFloat3(&light.position)) * VP); device->UpdateBuffer(&constantBuffers[CBTYPE_MISC], &miscCb, cmd); @@ -4508,7 +4530,7 @@ void DrawVolumeLights( case LightComponent::SPOT: { MiscCB miscCb; - miscCb.g_xColor.x = float(entityArrayOffset_Lights + i); + miscCb.g_xColor.x = float(i); const float coneS = (const float)(light.fov / XM_PIDIV4); XMStoreFloat4x4(&miscCb.g_xTransform, XMMatrixScaling(coneS*light.GetRange(), light.GetRange(), coneS*light.GetRange())* @@ -4578,7 +4600,7 @@ void DrawLensFlares( XMVECTOR flarePos = XMVector3Project(POS, 0, 0, 1, 1, 1, 0, vis.camera->GetProjection(), vis.camera->GetView(), XMMatrixIdentity()); LensFlareCB cb; XMStoreFloat4(&cb.xSunPos, flarePos); - cb.xScreen = XMFLOAT4((float)wiRenderer::GetInternalResolution().x, (float)wiRenderer::GetInternalResolution().y, 0, 0); + cb.xScreen = XMFLOAT4((float)depthbuffer.desc.Width, (float)depthbuffer.desc.Height, 0, 0); device->UpdateBuffer(&constantBuffers[CBTYPE_LENSFLARE], &cb, cmd); device->BindConstantBuffer(GS, &constantBuffers[CBTYPE_LENSFLARE], CB_GETBINDSLOT(LensFlareCB), cmd); @@ -4942,10 +4964,6 @@ void DrawShadowmaps( } break; case LightComponent::POINT: - case LightComponent::SPHERE: - case LightComponent::DISC: - case LightComponent::RECTANGLE: - case LightComponent::TUBE: { if (shadowCounter_Cube >= SHADOWCOUNT_CUBE) { @@ -5095,7 +5113,7 @@ void DrawScene( } if (ocean != nullptr) { - ocean->Render(*vis.camera, vis.scene->weather, renderTime, cmd); + ocean->Render(*vis.camera, vis.scene->weather, cmd); } } else @@ -7082,13 +7100,6 @@ void VoxelRadiance(const Visibility& vis, CommandList cmd) -inline XMUINT3 GetEntityCullingTileCount() -{ - return XMUINT3( - (GetInternalResolution().x + TILED_CULLING_BLOCKSIZE - 1) / TILED_CULLING_BLOCKSIZE, - (GetInternalResolution().y + TILED_CULLING_BLOCKSIZE - 1) / TILED_CULLING_BLOCKSIZE, - 1); -} void ComputeTiledLightCulling( const CameraComponent& camera, const Texture& depthbuffer, @@ -7097,10 +7108,10 @@ void ComputeTiledLightCulling( { auto range = wiProfiler::BeginRangeGPU("Entity Culling", cmd); - int _width = GetInternalResolution().x; - int _height = GetInternalResolution().y; + int _width = (int)depthbuffer.desc.Width; + int _height = (int)depthbuffer.desc.Height; - const XMUINT3 tileCount = GetEntityCullingTileCount(); + const XMUINT3 tileCount = GetEntityCullingTileCount(XMUINT2(depthbuffer.desc.Width, depthbuffer.desc.Height)); static int _savedWidth = 0; static int _savedHeight = 0; @@ -7645,19 +7656,17 @@ void RayBuffers::Create(uint32_t newRayCapacity) device->SetName(&rayCountBuffer[1], "rayCountBuffer[1]"); } -RayBuffers* GenerateScreenRayBuffers(const CameraComponent& camera, CommandList cmd) +RayBuffers* GenerateScreenRayBuffers(const CameraComponent& camera, uint32_t width, uint32_t height, CommandList cmd) { - uint _width = GetInternalResolution().x; - uint _height = GetInternalResolution().y; static uint RayCountPrev = 0; - const uint _raycount = _width * _height; + const uint raycount = width * height; static RayBuffers screenRayBuffers; - if (RayCountPrev != _raycount) + if (RayCountPrev != raycount) { - RayCountPrev = _raycount; - screenRayBuffers.Create(_raycount); + RayCountPrev = raycount; + screenRayBuffers.Create(raycount); } @@ -7668,8 +7677,8 @@ RayBuffers* GenerateScreenRayBuffers(const CameraComponent& camera, CommandList const XMFLOAT4& halton = wiMath::GetHaltonSequence((int)device->GetFrameCount()); RaytracingCB cb; cb.xTracePixelOffset = XMFLOAT2(halton.x, halton.y); - cb.xTraceResolution.x = _width; - cb.xTraceResolution.y = _height; + cb.xTraceResolution.x = width; + cb.xTraceResolution.y = height; cb.xTraceResolution_rcp.x = 1.0f / cb.xTraceResolution.x; cb.xTraceResolution_rcp.y = 1.0f / cb.xTraceResolution.y; device->UpdateBuffer(&constantBuffers[CBTYPE_RAYTRACE], &cb, cmd); @@ -7682,8 +7691,8 @@ RayBuffers* GenerateScreenRayBuffers(const CameraComponent& camera, CommandList device->BindUAVs(CS, uavs, 0, arraysize(uavs), cmd); device->Dispatch( - (_width + RAYTRACING_LAUNCH_BLOCKSIZE - 1) / RAYTRACING_LAUNCH_BLOCKSIZE, - (_height + RAYTRACING_LAUNCH_BLOCKSIZE - 1) / RAYTRACING_LAUNCH_BLOCKSIZE, + (width + RAYTRACING_LAUNCH_BLOCKSIZE - 1) / RAYTRACING_LAUNCH_BLOCKSIZE, + (height + RAYTRACING_LAUNCH_BLOCKSIZE - 1) / RAYTRACING_LAUNCH_BLOCKSIZE, 1, cmd); @@ -7762,7 +7771,7 @@ void RayTraceScene( cb.xTraceUserData.x = (bounce == 1 && accumulation_sample == 0) ? 1 : 0; // pre-clear result texture? cb.xTraceUserData.y = bounce == raytraceBounceCount ? 1 : 0; // accumulation step? - cb.xTraceRandomSeed = renderTime * (float)(bounce + 1); + cb.xTraceRandomSeed = (float)accumulation_sample * (float)(bounce + 1); device->UpdateBuffer(&constantBuffers[CBTYPE_RAYTRACE], &cb, cmd); device->BindConstantBuffer(CS, &constantBuffers[CBTYPE_RAYTRACE], CB_GETBINDSLOT(RaytracingCB), cmd); @@ -7951,7 +7960,7 @@ void ManageDecalAtlas(Scene& scene) { const DecalComponent& decal = scene.decals[i]; - if (decal.texture != nullptr) + if (decal.texture != nullptr && decal.texture->texture != nullptr) { if (packedDecals.find(decal.texture) == packedDecals.end()) { @@ -8393,144 +8402,6 @@ void BindCommonResources(CommandList cmd) device->BindResources(CS, resources, SBSLOT_ENTITYARRAY, arraysize(resources), cmd); } -void UpdateFrameCB(const Scene& scene, CommandList cmd) -{ - FrameCB cb; - - cb.g_xFrame_ConstantOne = 1; - cb.g_xFrame_ScreenWidthHeight = float2((float)device->GetScreenWidth(), (float)device->GetScreenHeight()); - cb.g_xFrame_ScreenWidthHeight_rcp = float2(1.0f / cb.g_xFrame_ScreenWidthHeight.x, 1.0f / cb.g_xFrame_ScreenWidthHeight.y); - cb.g_xFrame_InternalResolution = float2((float)GetInternalResolution().x, (float)GetInternalResolution().y); - cb.g_xFrame_InternalResolution_rcp = float2(1.0f / cb.g_xFrame_InternalResolution.x, 1.0f / cb.g_xFrame_InternalResolution.y); - cb.g_xFrame_Gamma = GetGamma(); - cb.g_xFrame_SunColor = scene.weather.sunColor; - cb.g_xFrame_SunDirection = scene.weather.sunDirection; - cb.g_xFrame_SunEnergy = scene.weather.sunEnergy; - cb.g_xFrame_ShadowCascadeCount = CASCADE_COUNT; - cb.g_xFrame_Ambient = scene.weather.ambient; - cb.g_xFrame_Cloudiness = scene.weather.cloudiness; - cb.g_xFrame_CloudScale = scene.weather.cloudScale; - cb.g_xFrame_CloudSpeed = scene.weather.cloudSpeed; - cb.g_xFrame_Fog = float3(scene.weather.fogStart, scene.weather.fogEnd, scene.weather.fogHeight); - cb.g_xFrame_Horizon = scene.weather.horizon; - cb.g_xFrame_Zenith = scene.weather.zenith; - cb.g_xFrame_VoxelRadianceMaxDistance = voxelSceneData.maxDistance; - cb.g_xFrame_VoxelRadianceDataSize = voxelSceneData.voxelsize; - cb.g_xFrame_VoxelRadianceDataSize_rcp = 1.0f / (float)cb.g_xFrame_VoxelRadianceDataSize; - cb.g_xFrame_VoxelRadianceDataRes = GetVoxelRadianceEnabled() ? (uint)voxelSceneData.res : 0; - cb.g_xFrame_VoxelRadianceDataRes_rcp = 1.0f / (float)cb.g_xFrame_VoxelRadianceDataRes; - cb.g_xFrame_VoxelRadianceDataMIPs = voxelSceneData.mips; - cb.g_xFrame_VoxelRadianceNumCones = std::max(std::min(voxelSceneData.numCones, 16u), 1u); - cb.g_xFrame_VoxelRadianceNumCones_rcp = 1.0f / (float)cb.g_xFrame_VoxelRadianceNumCones; - cb.g_xFrame_VoxelRadianceRayStepSize = voxelSceneData.rayStepSize; - cb.g_xFrame_VoxelRadianceDataCenter = voxelSceneData.center; - cb.g_xFrame_EntityCullingTileCount = GetEntityCullingTileCount(); - cb.g_xFrame_GlobalEnvProbeIndex = -1; - cb.g_xFrame_EnvProbeMipCount = 0; - cb.g_xFrame_EnvProbeMipCount_rcp = 1.0f; - if (scene.probes.GetCount() > 0) - { - cb.g_xFrame_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].IsValid()) - { - cb.g_xFrame_EnvProbeMipCount = textures[TEXTYPE_CUBEARRAY_ENVMAPARRAY].GetDesc().MipLevels; - cb.g_xFrame_EnvProbeMipCount_rcp = 1.0f / (float)cb.g_xFrame_EnvProbeMipCount; - } - - 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_WindSpeed = scene.weather.windSpeed; - cb.g_xFrame_WindRandomness = scene.weather.windRandomness; - cb.g_xFrame_WindWaveSize = scene.weather.windWaveSize; - cb.g_xFrame_WindDirection = scene.weather.windDirection; - cb.g_xFrame_StaticSkyGamma = 0.0f; - if (scene.weather.skyMap != nullptr) - { - bool hdr = !device->IsFormatUnorm(scene.weather.skyMap->texture->GetDesc().Format); - cb.g_xFrame_StaticSkyGamma = hdr ? 1.0f : cb.g_xFrame_Gamma; - } - cb.g_xFrame_FrameCount = (uint)device->GetFrameCount(); - cb.g_xFrame_TemporalAASampleRotation = 0; - if (GetTemporalAAEnabled()) - { - uint id = cb.g_xFrame_FrameCount % 4; - uint x = 0; - uint y = 0; - switch (id) - { - case 1: - x = 1; - break; - case 2: - y = 1; - break; - case 3: - x = 1; - y = 1; - break; - default: - break; - } - cb.g_xFrame_TemporalAASampleRotation = (x & 0x000000FF) | ((y & 0x000000FF) << 8); - } - cb.g_xFrame_ShadowKernel2D = 1.0f / SHADOWRES_2D; - cb.g_xFrame_ShadowKernelCube = 1.0f / SHADOWRES_CUBE; - - 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_rcp.x = 1.0f / cb.g_xFrame_WorldBoundsExtents.x; - cb.g_xFrame_WorldBoundsExtents_rcp.y = 1.0f / cb.g_xFrame_WorldBoundsExtents.y; - cb.g_xFrame_WorldBoundsExtents_rcp.z = 1.0f / cb.g_xFrame_WorldBoundsExtents.z; - - cb.g_xFrame_Options = 0; - if (GetTemporalAAEnabled()) - { - cb.g_xFrame_Options |= OPTION_BIT_TEMPORALAA_ENABLED; - } - if (GetTransparentShadowsEnabled()) - { - cb.g_xFrame_Options |= OPTION_BIT_TRANSPARENTSHADOWS_ENABLED; - } - if (GetVoxelRadianceEnabled()) - { - cb.g_xFrame_Options |= OPTION_BIT_VOXELGI_ENABLED; - } - if (GetVoxelRadianceReflectionsEnabled()) - { - cb.g_xFrame_Options |= OPTION_BIT_VOXELGI_REFLECTIONS_ENABLED; - } - if (voxelSceneData.centerChangedThisFrame) - { - cb.g_xFrame_Options |= OPTION_BIT_VOXELGI_RETARGETTED; - } - if (scene.weather.IsSimpleSky()) - { - cb.g_xFrame_Options |= OPTION_BIT_SIMPLE_SKY; - } - if (scene.weather.IsRealisticSky()) - { - cb.g_xFrame_Options |= OPTION_BIT_REALISTIC_SKY; - } - if (device->CheckCapability(GRAPHICSDEVICE_CAPABILITY_RAYTRACING) && GetRaytracedShadowsEnabled()) - { - cb.g_xFrame_Options |= OPTION_BIT_RAYTRACED_SHADOWS; - } - - device->UpdateBuffer(&constantBuffers[CBTYPE_FRAME], &cb, cmd); -} void UpdateCameraCB( const CameraComponent& camera, const CameraComponent& camera_previous, @@ -9727,7 +9598,6 @@ void Postprocess_RTAO( cb.rtao_range = range; cb.rtao_samplecount = (float)samplecount; cb.rtao_power = power; - cb.rtao_seed = renderTime; GraphicsDevice::GPUAllocation cb_alloc = device->AllocateGPU(sizeof(cb), cmd); memcpy(cb_alloc.data, &cb, sizeof(cb)); @@ -10030,7 +9900,6 @@ void Postprocess_RTReflection( cb.xPPResolution_rcp.x = 1.0f / cb.xPPResolution.x; cb.xPPResolution_rcp.y = 1.0f / cb.xPPResolution.y; cb.rtreflection_range = range; - cb.rtreflection_seed = renderTime; GraphicsDevice::GPUAllocation cb_alloc = device->AllocateGPU(sizeof(cb), cmd); memcpy(cb_alloc.data, &cb, sizeof(cb)); @@ -12020,26 +11889,10 @@ void AddDeferredMorphUpdate(size_t index) -void SetResolutionScale(float value) -{ - if (RESOLUTIONSCALE != value) - { - RESOLUTIONSCALE = value; - union UserData - { - float fValue; - uint64_t ullValue; - } data; - data.fValue = value; - wiEvent::FireEvent(SYSTEM_EVENT_CHANGE_RESOLUTION_SCALE, data.ullValue); - } -} -float GetResolutionScale() { return RESOLUTIONSCALE; } int GetShadowRes2D() { return SHADOWRES_2D; } int GetShadowResCube() { return SHADOWRES_CUBE; } void SetTransparentShadowsEnabled(float value) { TRANSPARENTSHADOWSENABLED = value; } float GetTransparentShadowsEnabled() { return TRANSPARENTSHADOWSENABLED; } -XMUINT2 GetInternalResolution() { return XMUINT2((uint32_t)ceilf(device->GetResolutionWidth()*GetResolutionScale()), (uint32_t)ceilf(device->GetResolutionHeight()*GetResolutionScale())); } void SetGamma(float value) { GAMMA = value; } float GetGamma() { return GAMMA; } void SetWireRender(bool value) { wireRender = value; } diff --git a/WickedEngine/wiRenderer.h b/WickedEngine/wiRenderer.h index 660bd741d..d46df7b4a 100644 --- a/WickedEngine/wiRenderer.h +++ b/WickedEngine/wiRenderer.h @@ -5,6 +5,7 @@ #include "wiScene.h" #include "wiECS.h" #include "wiIntersect.h" +#include "ShaderInterop_Renderer.h" #include @@ -49,11 +50,6 @@ namespace wiRenderer bool LoadShader(wiGraphics::SHADERSTAGE stage, wiGraphics::Shader& shader, const std::string& filename); - // Returns the main camera that is currently being used in rendering (and also for post processing) - wiScene::CameraComponent& GetCamera(); - // Attach camera to entity for the current frame - void AttachCamera(wiECS::Entity entity); - struct Visibility { @@ -135,16 +131,27 @@ namespace wiRenderer // Performs frustum culling. void UpdateVisibility(Visibility& vis); // Prepares the scene for rendering - void UpdatePerFrameData(wiScene::Scene& scene, const Visibility& vis, float dt); + void UpdatePerFrameData( + wiScene::Scene& scene, + const Visibility& vis, + FrameCB& frameCB, + XMUINT2 internalResolution, + float dt + ); // Updates the GPU state according to the previously called UpdatePerFrameData() - void UpdateRenderData(const Visibility& vis, wiGraphics::CommandList cmd); + void UpdateRenderData( + const Visibility& vis, + const FrameCB& frameCB, + wiGraphics::CommandList cmd + ); // Updates all acceleration structures for raytracing API - void UpdateRaytracingAccelerationStructures(const wiScene::Scene& scene, wiGraphics::CommandList cmd); + void UpdateRaytracingAccelerationStructures( + const wiScene::Scene& scene, + wiGraphics::CommandList cmd + ); // Binds all common constant buffers and samplers that may be used in all shaders void BindCommonResources(wiGraphics::CommandList cmd); - // Updates the per frame constant buffer (need to call at least once per frame) - void UpdateFrameCB(const wiScene::Scene& scene, wiGraphics::CommandList cmd); // Updates the per camera constant buffer need to call for each different camera that is used when calling DrawScene() and the like // camera_previous : camera from previous frame, used for reprojection effects. // camera_reflection : camera that renders planar reflection @@ -438,7 +445,7 @@ namespace wiRenderer void Create(uint32_t newRayCapacity); }; // Generate rays for every pixel of the internal resolution - RayBuffers* GenerateScreenRayBuffers(const wiScene::CameraComponent& camera, wiGraphics::CommandList cmd); + RayBuffers* GenerateScreenRayBuffers(const wiScene::CameraComponent& camera, uint32_t width, uint32_t height, wiGraphics::CommandList cmd); // Render the scene with ray tracing. You provide the ray buffer, where each ray maps to one pixel of the result testure void RayTraceScene( const wiScene::Scene& scene, @@ -496,7 +503,7 @@ namespace wiRenderer void PutWaterRipple(const std::string& image, const XMFLOAT3& pos); void ManageWaterRipples(); - void DrawWaterRipples(wiGraphics::CommandList cmd); + void DrawWaterRipples(const Visibility& vis, wiGraphics::CommandList cmd); @@ -512,11 +519,8 @@ namespace wiRenderer - void SetResolutionScale(float value); - float GetResolutionScale(); void SetTransparentShadowsEnabled(float value); float GetTransparentShadowsEnabled(); - XMUINT2 GetInternalResolution(); void SetGamma(float value); float GetGamma(); void SetWireRender(bool value); @@ -587,7 +591,7 @@ namespace wiRenderer const wiGraphics::Texture* GetGlobalLightmap(); // Gets pick ray according to the current screen resolution and pointer coordinates. Can be used as input into RayIntersectWorld() - RAY GetPickRay(long cursorX, long cursorY, const wiScene::CameraComponent& camera = GetCamera()); + RAY GetPickRay(long cursorX, long cursorY, const wiScene::CameraComponent& camera = wiScene::GetCamera()); // Add box to render in next frame. It will be rendered in DrawDebugWorld() diff --git a/WickedEngine/wiRenderer_BindLua.cpp b/WickedEngine/wiRenderer_BindLua.cpp index 71692c574..0e19277ae 100644 --- a/WickedEngine/wiRenderer_BindLua.cpp +++ b/WickedEngine/wiRenderer_BindLua.cpp @@ -19,19 +19,6 @@ using namespace wiIntersect_BindLua; namespace wiRenderer_BindLua { - int SetResolutionScale(lua_State* L) - { - int argc = wiLua::SGetArgCount(L); - if (argc > 0) - { - wiRenderer::SetResolutionScale(wiLua::SGetFloat(L, 1)); - } - else - { - wiLua::SError(L, "SetResolutionScale(float) not enough arguments!"); - } - return 0; - } int SetGamma(lua_State* L) { int argc = wiLua::SGetArgCount(L); @@ -75,26 +62,6 @@ namespace wiRenderer_BindLua return 1; } - int GetCamera(lua_State* L) - { - Luna::push(L, new CameraComponent_BindLua(&wiRenderer::GetCamera())); - return 1; - } - int AttachCamera(lua_State* L) - { - int argc = wiLua::SGetArgCount(L); - if (argc > 0) - { - Entity entity = (Entity)wiLua::SGetLongLong(L, 1); - wiRenderer::AttachCamera(entity); - } - else - { - wiLua::SError(L, "AttachCamera(Entity entity) not enough arguments!"); - } - return 0; - } - int SetShadowProps2D(lua_State* L) { int argc = wiLua::SGetArgCount(L); @@ -410,7 +377,6 @@ namespace wiRenderer_BindLua { initialized = true; - wiLua::RegisterFunc("SetResolutionScale", SetResolutionScale); wiLua::RegisterFunc("SetGamma", SetGamma); wiLua::RegisterFunc("SetGameSpeed", SetGameSpeed); wiLua::RegisterFunc("GetGameSpeed", GetGameSpeed); @@ -418,9 +384,6 @@ namespace wiRenderer_BindLua wiLua::RegisterFunc("GetScreenWidth", GetScreenWidth); wiLua::RegisterFunc("GetScreenHeight", GetScreenHeight); - wiLua::RegisterFunc("GetCamera", GetCamera); - wiLua::RegisterFunc("AttachCamera", AttachCamera); - wiLua::RegisterFunc("SetShadowProps2D", SetShadowProps2D); wiLua::RegisterFunc("SetShadowPropsCube", SetShadowPropsCube); wiLua::RegisterFunc("SetDebugBoxesEnabled", SetDebugBoxesEnabled); diff --git a/WickedEngine/wiScene.cpp b/WickedEngine/wiScene.cpp index f2cabdec1..6ab3bda69 100644 --- a/WickedEngine/wiScene.cpp +++ b/WickedEngine/wiScene.cpp @@ -288,10 +288,10 @@ namespace wiScene dest->subsurfaceScattering.x *= dest->subsurfaceScattering.w; dest->subsurfaceScattering.y *= dest->subsurfaceScattering.w; dest->subsurfaceScattering.z *= dest->subsurfaceScattering.w; - dest->subsurfaceScattering_inv.x = 1.0f / (1 + dest->subsurfaceScattering.x); - dest->subsurfaceScattering_inv.y = 1.0f / (1 + dest->subsurfaceScattering.y); - dest->subsurfaceScattering_inv.z = 1.0f / (1 + dest->subsurfaceScattering.z); - dest->subsurfaceScattering_inv.w = 1.0f / (1 + dest->subsurfaceScattering.w); + dest->subsurfaceScattering_inv.x = 1.0f / ((1 + dest->subsurfaceScattering.x) * (1 + dest->subsurfaceScattering.x)); + dest->subsurfaceScattering_inv.y = 1.0f / ((1 + dest->subsurfaceScattering.y) * (1 + dest->subsurfaceScattering.y)); + dest->subsurfaceScattering_inv.z = 1.0f / ((1 + dest->subsurfaceScattering.z) * (1 + dest->subsurfaceScattering.z)); + dest->subsurfaceScattering_inv.w = 1.0f / ((1 + dest->subsurfaceScattering.w) * (1 + dest->subsurfaceScattering.w)); dest->uvset_baseColorMap = baseColorMap == nullptr ? -1 : (int)uvset_baseColorMap; dest->uvset_surfaceMap = surfaceMap == nullptr ? -1 : (int)uvset_surfaceMap; dest->uvset_normalMap = normalMap == nullptr ? -1 : (int)uvset_normalMap; @@ -299,6 +299,7 @@ namespace wiScene dest->uvset_emissiveMap = emissiveMap == nullptr ? -1 : (int)uvset_emissiveMap; dest->uvset_occlusionMap = occlusionMap == nullptr ? -1 : (int)uvset_occlusionMap; dest->alphaTest = 1 - alphaRef + 1.0f / 256.0f; // 256 so that it is just about smaller than 1 unorm unit (1.0/255.0) + dest->layerMask = layerMask; dest->options = 0; if (IsUsingVertexColors()) { @@ -2121,7 +2122,7 @@ namespace wiScene LayerComponent* layer_parent = layers.GetComponent(parentcomponent.parentID); if (layer_child != nullptr && layer_parent != nullptr) { - layer_child->layerMask = parentcomponent.layerMask_bind & layer_parent->GetLayerMask(); + layer_child->layerMask &= layer_parent->GetLayerMask(); } } @@ -2491,6 +2492,12 @@ namespace wiScene wiJobSystem::Dispatch(ctx, (uint32_t)materials.GetCount(), small_subtask_groupsize, [&](wiJobArgs args) { MaterialComponent& material = materials[args.jobIndex]; + Entity entity = materials.GetEntity(args.jobIndex); + const LayerComponent* layer = layers.GetComponent(entity); + if (layer != nullptr) + { + material.layerMask = layer->layerMask; + } if (!material.constantBuffer.IsValid()) { @@ -2781,7 +2788,7 @@ namespace wiScene { default: case LightComponent::DIRECTIONAL: - aabb.createFromHalfWidth(wiRenderer::GetCamera().Eye, XMFLOAT3(10000, 10000, 10000)); + aabb.createFromHalfWidth(XMFLOAT3(0, 0, 0), XMFLOAT3(FLT_MAX, FLT_MAX, FLT_MAX)); locker.lock(); if (args.jobIndex < weather.most_important_light_index) { @@ -2798,15 +2805,6 @@ namespace wiScene case LightComponent::POINT: aabb.createFromHalfWidth(light.position, XMFLOAT3(light.GetRange(), light.GetRange(), light.GetRange())); break; - case LightComponent::SPHERE: - case LightComponent::DISC: - case LightComponent::RECTANGLE: - case LightComponent::TUBE: - XMStoreFloat3(&light.right, XMVector3TransformNormal(XMVectorSet(-1, 0, 0, 0), W)); - XMStoreFloat3(&light.front, XMVector3TransformNormal(XMVectorSet(0, 0, -1, 0), W)); - // area lights have no bounds, just like directional lights (todo: but they should have real bounds) - aabb.createFromHalfWidth(wiRenderer::GetCamera().Eye, XMFLOAT3(10000, 10000, 10000)); - break; } }); @@ -2850,7 +2848,7 @@ namespace wiScene } void Scene::RunSoundUpdateSystem(wiJobSystem::context& ctx) { - const CameraComponent& camera = wiRenderer::GetCamera(); + const CameraComponent& camera = GetCamera(); wiAudio::SoundInstance3D instance3D; instance3D.listenerPos = camera.Eye; instance3D.listenerUp = camera.Up; diff --git a/WickedEngine/wiScene.h b/WickedEngine/wiScene.h index 35f791bd3..9c6230eb7 100644 --- a/WickedEngine/wiScene.h +++ b/WickedEngine/wiScene.h @@ -188,6 +188,7 @@ namespace wiScene std::shared_ptr emissiveMap; std::shared_ptr occlusionMap; wiGraphics::GPUBuffer constantBuffer; + uint32_t layerMask = ~0u; // User stencil value can be in range [0, 15] inline void SetUserStencilRef(uint8_t value) @@ -766,10 +767,10 @@ namespace wiScene DIRECTIONAL = ENTITY_TYPE_DIRECTIONALLIGHT, POINT = ENTITY_TYPE_POINTLIGHT, SPOT = ENTITY_TYPE_SPOTLIGHT, - SPHERE = ENTITY_TYPE_SPHERELIGHT, - DISC = ENTITY_TYPE_DISCLIGHT, - RECTANGLE = ENTITY_TYPE_RECTANGLELIGHT, - TUBE = ENTITY_TYPE_TUBELIGHT, + //SPHERE = ENTITY_TYPE_SPHERELIGHT, + //DISC = ENTITY_TYPE_DISCLIGHT, + //RECTANGLE = ENTITY_TYPE_RECTANGLELIGHT, + //TUBE = ENTITY_TYPE_TUBELIGHT, LIGHTTYPE_COUNT, ENUM_FORCE_UINT32 = 0xFFFFFFFF, }; @@ -777,10 +778,6 @@ namespace wiScene float energy = 1.0f; float range_local = 10.0f; float fov = XM_PIDIV4; - float shadowBias = 0.0001f; // deprecated! - float radius = 1.0f; // area light only - float width = 1.0f; // area light only - float height = 1.0f; // area light only std::vector lensFlareNames; @@ -825,7 +822,7 @@ namespace wiScene float width = 0.0f; float height = 0.0f; - float zNearP = 0.001f; + float zNearP = 0.1f; float zFarP = 800.0f; float fov = XM_PI / 3.0f; @@ -1339,6 +1336,13 @@ namespace wiScene return scene; } + // Helper that manages a global camera + inline CameraComponent& GetCamera() + { + static CameraComponent camera; + return camera; + } + // Helper function to open a wiscene file and add the contents to the global scene // fileName : file path // transformMatrix : everything will be transformed by this matrix (optional) diff --git a/WickedEngine/wiScene_BindLua.cpp b/WickedEngine/wiScene_BindLua.cpp index 74fee3852..0c3a709be 100644 --- a/WickedEngine/wiScene_BindLua.cpp +++ b/WickedEngine/wiScene_BindLua.cpp @@ -21,6 +21,11 @@ int CreateEntity_BindLua(lua_State* L) return 1; } +int GetCamera(lua_State* L) +{ + Luna::push(L, new CameraComponent_BindLua(&wiScene::GetCamera())); + return 1; +} int GetScene(lua_State* L) { Luna::push(L, new Scene_BindLua(&wiScene::GetScene())); @@ -266,6 +271,7 @@ void Bind() wiLua::RunText("STENCILREF_SKIN = 3"); wiLua::RunText("STENCILREF_SNOW = 4"); + wiLua::RegisterFunc("GetCamera", GetCamera); wiLua::RegisterFunc("GetScene", GetScene); wiLua::RegisterFunc("LoadModel", LoadModel); wiLua::RegisterFunc("Pick", Pick); diff --git a/WickedEngine/wiScene_Serializers.cpp b/WickedEngine/wiScene_Serializers.cpp index 5819ea8af..8f8d8fb15 100644 --- a/WickedEngine/wiScene_Serializers.cpp +++ b/WickedEngine/wiScene_Serializers.cpp @@ -573,30 +573,27 @@ namespace wiScene archive >> _flags; archive >> color; archive >> (uint32_t&)type; + if (type > SPOT) + { + type = POINT; // fallback from old area light + } archive >> energy; archive >> range_local; archive >> fov; - archive >> shadowBias; - archive >> radius; - archive >> width; - archive >> height; + if (archive.GetVersion() < 55) + { + float shadowBias; + float radius; + float width; + float height; + archive >> shadowBias; + archive >> radius; + archive >> width; + archive >> height; + } archive >> lensFlareNames; - if (archive.GetVersion() < 33) - { - switch (GetType()) - { - case LightComponent::POINT: - case LightComponent::SPHERE: - case LightComponent::DISC: - case LightComponent::RECTANGLE: - case LightComponent::TUBE: - shadowBias = 0.0001f; - break; - } - } - wiJobSystem::Execute(seri.ctx, [&](wiJobArgs args) { lensFlareRimTextures.resize(lensFlareNames.size()); for (size_t i = 0; i < lensFlareNames.size(); ++i) @@ -616,10 +613,17 @@ namespace wiScene archive << energy; archive << range_local; archive << fov; - archive << shadowBias; - archive << radius; - archive << width; - archive << height; + if (archive.GetVersion() < 55) + { + float shadowBias = 0; + float radius = 0; + float width = 0; + float height = 0; + archive << shadowBias; + archive << radius; + archive << width; + archive << height; + } // If detecting an absolute path in textures, remove it and convert to relative: if (!dir.empty()) diff --git a/WickedEngine/wiVersion.cpp b/WickedEngine/wiVersion.cpp index f0433aa91..685b61142 100644 --- a/WickedEngine/wiVersion.cpp +++ b/WickedEngine/wiVersion.cpp @@ -6,10 +6,10 @@ namespace wiVersion { // main engine core const int major = 0; - // minor features, major updates, breaking API changes - const int minor = 50; + // minor features, major updates, breaking compatibility changes + const int minor = 51; // minor bug fixes, alterations, refactors, updates - const int revision = 15; + const int revision = 0; const std::string version_string = std::to_string(major) + "." + std::to_string(minor) + "." + std::to_string(revision); diff --git a/WickedEngine/wiWidget.cpp b/WickedEngine/wiWidget.cpp index 7deb40667..fc7276f89 100644 --- a/WickedEngine/wiWidget.cpp +++ b/WickedEngine/wiWidget.cpp @@ -10,8 +10,6 @@ #include "wiEvent.h" #include "wiBackLog.h" -#include - using namespace std; using namespace wiGraphics; using namespace wiScene; @@ -154,9 +152,7 @@ void wiWidget::SetName(const std::string& value) if (value.length() <= 0) { static atomic widgetID{ 0 }; - stringstream ss(""); - ss << "widget_" << widgetID.fetch_add(1); - name = ss.str(); + name = "widget_" + std::to_string(widgetID.fetch_add(1)); } else { @@ -529,15 +525,11 @@ void wiTextInputField::SetValue(const std::string& newValue) } void wiTextInputField::SetValue(int newValue) { - stringstream ss(""); - ss << newValue; - font.SetText(ss.str()); + font.SetText(std::to_string(newValue)); } void wiTextInputField::SetValue(float newValue) { - stringstream ss(""); - ss << newValue; - font.SetText(ss.str()); + font.SetText(std::to_string(newValue)); } const std::string wiTextInputField::GetValue() { diff --git a/models/shadowspriority_spot_test.wiscene b/models/shadowspriority_spot_test.wiscene index 543902683b6dc62af367954b79d02830eeaeff98..e0ecec12e845a8614d6fa0535b06ea1e8600d25a 100644 GIT binary patch literal 12030 zcmeHNeN0tl7(apobx;n=N!R%jvI;FJ=;0I_x(M; z_j%v#-bu)Q_dF0 zdigjrE-qe(?4Mu1*-?}$_;x!2nH523g+ol#A%4r5oaLAAU=&4i#QW;7GfMCt=t5xKZ7_M zaSq~K#CeGG5uZg|fVdFxImG7?7a>{^ZHS48cElva7Z4XCCL_LxxCAi;F%@ws;xfeL zh-rxFh#8105LY5*BCbNrLR^DL@w_8#K>2ZS<3RaN`R&hZB@qWJuQAPq=-GcH(JpZ! z@)C-)gpncup7y)-Z7o}M?MN&8ll;n?gmPT~{gmEPn?l3Ux4v_mK$jC?|D94R?C4Jf z5A78Z)=^@H^?GlIYx1slY&EHAblEZFKfie)`!_P4$9hUl>AjUlOzES`+Dz%Y-2tZN zd#tw51#we0-|?>w4s(;*NPLRC8%*gNPk(GmA5!i%rEiV>+myb(CEP>vHIi==_vdo_ zKap}1c71+^sPZ$js?3!BqZ_+T>Hn-gU`oHTqt28*|G0#m2C%Ya7CS4cr%BDFD+ z&vjRwru4fj>&@v`Ut_(I@tQX9=5jT7p0`zmFN0?G1bwXH3sN=vjv*0#a;;b9}`Hr3eTK z0Gp;PajdcSwUc$A7omi0MY*W>(Uk9Qr%pDdm678}orrRa=0|3#2O>c_iVNw~{#Fx- zNOe7uOf@GPaoX4cE62{4U2aZer0b3nQ#u!Nyx<%Sw8MFl_a5ap1a!nvxdCm~AU?+$ z|5mUMpkW^{2AxJ@^D#!ylHRJ)LRsF)w@L?k*uhR{?TZt~S(F1QYd9|@eZOVN7xO;K z(679S${2i=Wxt@MzI~KgCpk7!miq@Sjq9FeU7VygN}RRr)jo%^oyK`LKB=QBA0ugfP%ia_MN{&}$R8sqA^evS{3+2a4yEE>BEFZ%RE*m|?>>k6vl{w+mfjuC>5_@NW&2WxlEB67!wg#wHTKr8x%5 zvOd3gDf8od@|l14#xCZ)l?R#kR(`{LR9Q3g(PfvIKmYb^=DXb^?bPqO75iM&@3Gnh zD9hvA8$8KP{IqZ{^GL(0ErzAg42=38SgGhg2l z?V*0_Tf(3$`)@A^gE7nTX)lT9@fWqtV7{m=f%$A#3iH{n70kyU&0#+NXdd%jQ@1mJ zJ^U@^(?a3Bl+tfnXchC0;u_{1#fO-$==_rTiq1Ow!@drL0k%lwhq0ahSBTaC&a7p=Fm*KZODZlhKmA%b^A~a>?c`_vOB0!YGpmBfS^LHB z-0#5j>Jt?^@q|vQv@tU>BcOD z(BwmGRSvgFlc)IJO0+aakLElwPcJs0@@#lkJUbWbJX@Z%O}n~5r^z7`sBf!uuF72B51C~MjadHHAGc`q%Y5t%xV4?Cv N7g?FEYCF_W