diff --git a/Editor/Editor.cpp b/Editor/Editor.cpp
index f5fe61448..67ca06d64 100644
--- a/Editor/Editor.cpp
+++ b/Editor/Editor.cpp
@@ -118,9 +118,6 @@ void EditorComponent::ChangeRenderPath(RENDERPATH path)
case EditorComponent::RENDERPATH_PATHTRACING:
renderPath = new RenderPath3D_PathTracing;
break;
- case EditorComponent::RENDERPATH_STEREOGRAM:
- renderPath = new RenderPath3D_Stereogram;
- break;
default:
assert(0);
break;
@@ -652,7 +649,6 @@ void EditorComponent::Load()
renderPathComboBox->AddItem("Tiled Forward");
renderPathComboBox->AddItem("Tiled Deferred");
renderPathComboBox->AddItem("Path Tracing");
- renderPathComboBox->AddItem("Stereogram");
renderPathComboBox->OnSelect([&](wiEventArgs args) {
switch (args.iValue)
{
@@ -671,9 +667,6 @@ void EditorComponent::Load()
case 4:
ChangeRenderPath(RENDERPATH_PATHTRACING);
break;
- case 5:
- ChangeRenderPath(RENDERPATH_STEREOGRAM);
- break;
default:
break;
}
diff --git a/Editor/Editor.h b/Editor/Editor.h
index 1b2eb5db8..7dcd0e23d 100644
--- a/Editor/Editor.h
+++ b/Editor/Editor.h
@@ -64,7 +64,6 @@ public:
RENDERPATH_TILEDFORWARD,
RENDERPATH_TILEDDEFERRED,
RENDERPATH_PATHTRACING,
- RENDERPATH_STEREOGRAM,
};
void ChangeRenderPath(RENDERPATH path);
diff --git a/Editor/MaterialWindow.cpp b/Editor/MaterialWindow.cpp
index b97cc4f6f..45af97809 100644
--- a/Editor/MaterialWindow.cpp
+++ b/Editor/MaterialWindow.cpp
@@ -78,6 +78,16 @@ MaterialWindow::MaterialWindow(wiGUI* gui) : GUI(gui)
});
materialWindow->AddWidget(flipNormalMapCheckBox);
+ useVertexColorsCheckBox = new wiCheckBox("Use vertex colors: ");
+ useVertexColorsCheckBox->SetTooltip("Enable if you want to render the mesh with vertex colors (must have appropriate vertex buffer)");
+ useVertexColorsCheckBox->SetPos(XMFLOAT2(570, y += step));
+ useVertexColorsCheckBox->OnClick([&](wiEventArgs args) {
+ MaterialComponent* material = wiRenderer::GetScene().materials.GetComponent(entity);
+ if (material != nullptr)
+ material->SetUseVertexColors(args.bValue);
+ });
+ materialWindow->AddWidget(useVertexColorsCheckBox);
+
normalMapSlider = new wiSlider(0, 4, 1, 4000, "Normalmap: ");
normalMapSlider->SetTooltip("How much the normal map should distort the face normals (bumpiness).");
normalMapSlider->SetSize(XMFLOAT2(100, 30));
@@ -635,6 +645,7 @@ void MaterialWindow::SetEntity(Entity entity)
planarReflCheckBox->SetCheck(material->HasPlanarReflection());
shadowCasterCheckBox->SetCheck(material->IsCastingShadow());
flipNormalMapCheckBox->SetCheck(material->IsFlipNormalMap());
+ useVertexColorsCheckBox->SetCheck(material->IsUsingVertexColors());
normalMapSlider->SetValue(material->normalMapStrength);
roughnessSlider->SetValue(material->roughness);
reflectanceSlider->SetValue(material->reflectance);
diff --git a/Editor/MaterialWindow.h b/Editor/MaterialWindow.h
index 79991c1c7..b4179ac5a 100644
--- a/Editor/MaterialWindow.h
+++ b/Editor/MaterialWindow.h
@@ -27,6 +27,7 @@ public:
wiCheckBox* planarReflCheckBox;
wiCheckBox* shadowCasterCheckBox;
wiCheckBox* flipNormalMapCheckBox;
+ wiCheckBox* useVertexColorsCheckBox;
wiSlider* normalMapSlider;
wiSlider* roughnessSlider;
wiSlider* reflectanceSlider;
diff --git a/Editor/MeshWindow.cpp b/Editor/MeshWindow.cpp
index be8266092..67cc10e8f 100644
--- a/Editor/MeshWindow.cpp
+++ b/Editor/MeshWindow.cpp
@@ -255,6 +255,14 @@ void MeshWindow::SetEntity(Entity entity)
ss << "Vertex count: " << mesh->vertex_positions.size() << endl;
ss << "Index count: " << mesh->indices.size() << endl;
ss << "Subset count: " << mesh->subsets.size() << endl;
+ ss << endl << "Vertex buffers: ";
+ if (mesh->vertexBuffer_POS != nullptr) ss << "position; ";
+ if (mesh->vertexBuffer_TEX != nullptr) ss << "texcoord; ";
+ if (mesh->vertexBuffer_ATL != nullptr) ss << "atlas; ";
+ if (mesh->vertexBuffer_COL != nullptr) ss << "color; ";
+ if (mesh->vertexBuffer_PRE != nullptr) ss << "prevPos; ";
+ if (mesh->vertexBuffer_BON != nullptr) ss << "bone; ";
+ if (mesh->streamoutBuffer_POS != nullptr) ss << "streamout; ";
meshInfoLabel->SetText(ss.str());
doubleSidedCheckBox->SetCheck(mesh->IsDoubleSided());
diff --git a/WickedEngine/RenderPath2D.cpp b/WickedEngine/RenderPath2D.cpp
index 1cfacebbb..4adae56bf 100644
--- a/WickedEngine/RenderPath2D.cpp
+++ b/WickedEngine/RenderPath2D.cpp
@@ -28,6 +28,7 @@ void RenderPath2D::ResizeBuffers()
desc.Width = device->GetScreenWidth();
desc.Height = device->GetScreenHeight();
device->CreateTexture2D(&desc, nullptr, &rtFinal);
+ device->SetName(&rtFinal, "rtFinal");
}
}
diff --git a/WickedEngine/RenderPath3D.cpp b/WickedEngine/RenderPath3D.cpp
index 4907b3096..d70074c34 100644
--- a/WickedEngine/RenderPath3D.cpp
+++ b/WickedEngine/RenderPath3D.cpp
@@ -26,6 +26,7 @@ void RenderPath3D::ResizeBuffers()
desc.Width = wiRenderer::GetInternalResolution().x;
desc.Height = wiRenderer::GetInternalResolution().y;
device->CreateTexture2D(&desc, nullptr, &rtSSR);
+ device->SetName(&rtSSR, "rtSSR");
}
{
TextureDesc desc;
@@ -34,6 +35,7 @@ void RenderPath3D::ResizeBuffers()
desc.Width = (UINT)(wiRenderer::GetInternalResolution().x*getParticleDownSample());
desc.Height = (UINT)(wiRenderer::GetInternalResolution().y*getParticleDownSample());
device->CreateTexture2D(&desc, nullptr, &rtParticle);
+ device->SetName(&rtParticle, "rtParticle");
}
{
TextureDesc desc;
@@ -42,6 +44,7 @@ void RenderPath3D::ResizeBuffers()
desc.Width = (UINT)(wiRenderer::GetInternalResolution().x * 0.25f);
desc.Height = (UINT)(wiRenderer::GetInternalResolution().y * 0.25f);
device->CreateTexture2D(&desc, nullptr, &rtVolumetricLights);
+ device->SetName(&rtVolumetricLights, "rtVolumetricLights");
}
{
TextureDesc desc;
@@ -50,6 +53,7 @@ void RenderPath3D::ResizeBuffers()
desc.Width = wiRenderer::GetInternalResolution().x;
desc.Height = wiRenderer::GetInternalResolution().y;
device->CreateTexture2D(&desc, nullptr, &rtWaterRipple);
+ device->SetName(&rtWaterRipple, "rtWaterRipple");
}
{
TextureDesc desc;
@@ -61,6 +65,7 @@ void RenderPath3D::ResizeBuffers()
rtSceneCopy.RequestIndependentShaderResourcesForMIPs(true);
rtSceneCopy.RequestIndependentUnorderedAccessResourcesForMIPs(true);
device->CreateTexture2D(&desc, nullptr, &rtSceneCopy);
+ device->SetName(&rtSceneCopy, "rtSceneCopy");
}
{
TextureDesc desc;
@@ -69,6 +74,7 @@ void RenderPath3D::ResizeBuffers()
desc.Width = (UINT)(wiRenderer::GetInternalResolution().x * getReflectionQuality());
desc.Height = (UINT)(wiRenderer::GetInternalResolution().y * getReflectionQuality());
device->CreateTexture2D(&desc, nullptr, &rtReflection);
+ device->SetName(&rtReflection, "rtReflection");
}
{
TextureDesc desc;
@@ -77,7 +83,9 @@ void RenderPath3D::ResizeBuffers()
desc.Width = (UINT)(wiRenderer::GetInternalResolution().x / 2);
desc.Height = (UINT)(wiRenderer::GetInternalResolution().y / 2);
device->CreateTexture2D(&desc, nullptr, &rtDof[0]);
+ device->SetName(&rtDof[0], "rtDof[0]");
device->CreateTexture2D(&desc, nullptr, &rtDof[1]);
+ device->SetName(&rtDof[1], "rtDof[1]");
}
{
TextureDesc desc;
@@ -86,7 +94,9 @@ void RenderPath3D::ResizeBuffers()
desc.Width = (UINT)(wiRenderer::GetInternalResolution().x*getSSAOQuality());
desc.Height = (UINT)(wiRenderer::GetInternalResolution().y*getSSAOQuality());
device->CreateTexture2D(&desc, nullptr, &rtSSAO[0]);
+ device->SetName(&rtSSAO[0], "rtSSAO[0]");
device->CreateTexture2D(&desc, nullptr, &rtSSAO[1]);
+ device->SetName(&rtSSAO[1], "rtSSAO[1]");
}
{
TextureDesc desc;
@@ -96,11 +106,13 @@ void RenderPath3D::ResizeBuffers()
desc.Height = wiRenderer::GetInternalResolution().y;
desc.SampleDesc.Count = getMSAASampleCount();
device->CreateTexture2D(&desc, nullptr, &rtSun[0]);
+ device->SetName(&rtSun[0], "rtSun[0]");
desc.SampleDesc.Count = 1;
desc.Width = (UINT)(wiRenderer::GetInternalResolution().x*getLightShaftQuality());
desc.Height = (UINT)(wiRenderer::GetInternalResolution().y*getLightShaftQuality());
device->CreateTexture2D(&desc, nullptr, &rtSun[1]);
+ device->SetName(&rtSun[1], "rtSun[1]");
if (getMSAASampleCount() > 1)
{
@@ -108,6 +120,7 @@ void RenderPath3D::ResizeBuffers()
desc.Height = wiRenderer::GetInternalResolution().y;
desc.SampleDesc.Count = 1;
device->CreateTexture2D(&desc, nullptr, &rtSun_resolved);
+ device->SetName(&rtSun_resolved, "rtSun_resolved");
}
}
{
@@ -120,6 +133,7 @@ void RenderPath3D::ResizeBuffers()
rtBloom.RequestIndependentShaderResourcesForMIPs(true);
rtBloom.RequestIndependentUnorderedAccessResourcesForMIPs(true);
device->CreateTexture2D(&desc, nullptr, &rtBloom);
+ device->SetName(&rtBloom, "rtBloom");
}
{
TextureDesc desc;
@@ -128,7 +142,9 @@ void RenderPath3D::ResizeBuffers()
desc.Width = wiRenderer::GetInternalResolution().x;
desc.Height = wiRenderer::GetInternalResolution().y;
device->CreateTexture2D(&desc, nullptr, &rtTemporalAA[0]);
+ device->SetName(&rtTemporalAA[0], "rtTemporalAA[0]");
device->CreateTexture2D(&desc, nullptr, &rtTemporalAA[1]);
+ device->SetName(&rtTemporalAA[1], "rtTemporalAA[1]");
}
{
TextureDesc desc;
@@ -137,6 +153,7 @@ void RenderPath3D::ResizeBuffers()
desc.Width = wiRenderer::GetInternalResolution().x;
desc.Height = wiRenderer::GetInternalResolution().y;
device->CreateTexture2D(&desc, nullptr, &rtPostprocess_HDR);
+ device->SetName(&rtPostprocess_HDR, "rtPostprocess_HDR");
}
{
TextureDesc desc;
@@ -145,7 +162,9 @@ void RenderPath3D::ResizeBuffers()
desc.Width = wiRenderer::GetInternalResolution().x;
desc.Height = wiRenderer::GetInternalResolution().y;
device->CreateTexture2D(&desc, nullptr, &rtPostprocess_LDR[0]);
+ device->SetName(&rtPostprocess_LDR[0], "rtPostprocess_LDR[0]");
device->CreateTexture2D(&desc, nullptr, &rtPostprocess_LDR[1]);
+ device->SetName(&rtPostprocess_LDR[1], "rtPostprocess_LDR[1]");
}
// Depth buffers:
@@ -158,6 +177,7 @@ void RenderPath3D::ResizeBuffers()
desc.BindFlags = BIND_DEPTH_STENCIL | BIND_SHADER_RESOURCE;
desc.SampleDesc.Count = getMSAASampleCount();
device->CreateTexture2D(&desc, nullptr, &depthBuffer);
+ device->SetName(&depthBuffer, "depthBuffer");
if (getMSAASampleCount() > 1)
{
@@ -171,6 +191,7 @@ void RenderPath3D::ResizeBuffers()
}
desc.SampleDesc.Count = 1;
device->CreateTexture2D(&desc, nullptr, &depthBuffer_Copy);
+ device->SetName(&depthBuffer_Copy, "depthBuffer_Copy");
}
{
TextureDesc desc;
@@ -179,6 +200,7 @@ void RenderPath3D::ResizeBuffers()
desc.Width = wiRenderer::GetInternalResolution().x;
desc.Height = wiRenderer::GetInternalResolution().y;
device->CreateTexture2D(&desc, nullptr, &rtLinearDepth);
+ device->SetName(&rtLinearDepth, "rtLinearDepth");
}
{
TextureDesc desc;
@@ -187,6 +209,7 @@ void RenderPath3D::ResizeBuffers()
desc.Width = wiRenderer::GetInternalResolution().x / 4;
desc.Height = wiRenderer::GetInternalResolution().y / 4;
device->CreateTexture2D(&desc, nullptr, &smallDepth);
+ device->SetName(&smallDepth, "smallDepth");
}
{
TextureDesc desc;
@@ -195,6 +218,7 @@ void RenderPath3D::ResizeBuffers()
desc.Width = (UINT)(wiRenderer::GetInternalResolution().x * getReflectionQuality());
desc.Height = (UINT)(wiRenderer::GetInternalResolution().y * getReflectionQuality());
device->CreateTexture2D(&desc, nullptr, &depthBuffer_reflection);
+ device->SetName(&depthBuffer_reflection, "depthBuffer_reflection");
}
}
diff --git a/WickedEngine/RenderPath3D_Deferred.cpp b/WickedEngine/RenderPath3D_Deferred.cpp
index 04f458808..c09737b92 100644
--- a/WickedEngine/RenderPath3D_Deferred.cpp
+++ b/WickedEngine/RenderPath3D_Deferred.cpp
@@ -26,12 +26,15 @@ void RenderPath3D_Deferred::ResizeBuffers()
desc.Format = wiRenderer::RTFormat_gbuffer_0;
device->CreateTexture2D(&desc, nullptr, &rtGBuffer[0]);
+ device->SetName(&rtGBuffer[0], "rtGBuffer[0]");
desc.Format = wiRenderer::RTFormat_gbuffer_1;
device->CreateTexture2D(&desc, nullptr, &rtGBuffer[1]);
+ device->SetName(&rtGBuffer[1], "rtGBuffer[1]");
desc.Format = wiRenderer::RTFormat_gbuffer_2;
device->CreateTexture2D(&desc, nullptr, &rtGBuffer[2]);
+ device->SetName(&rtGBuffer[2], "rtGBuffer[2]");
}
{
TextureDesc desc;
@@ -40,6 +43,7 @@ void RenderPath3D_Deferred::ResizeBuffers()
desc.Width = wiRenderer::GetInternalResolution().x;
desc.Height = wiRenderer::GetInternalResolution().y;
device->CreateTexture2D(&desc, nullptr, &rtDeferred);
+ device->SetName(&rtDeferred, "rtDeferred");
}
{
TextureDesc desc;
@@ -48,7 +52,9 @@ void RenderPath3D_Deferred::ResizeBuffers()
desc.Width = wiRenderer::GetInternalResolution().x;
desc.Height = wiRenderer::GetInternalResolution().y;
device->CreateTexture2D(&desc, nullptr, &lightbuffer_diffuse);
+ device->SetName(&lightbuffer_diffuse, "lightbuffer_diffuse");
device->CreateTexture2D(&desc, nullptr, &lightbuffer_specular);
+ device->SetName(&lightbuffer_specular, "lightbuffer_specular");
}
{
TextureDesc desc;
@@ -57,7 +63,9 @@ void RenderPath3D_Deferred::ResizeBuffers()
desc.Width = wiRenderer::GetInternalResolution().x;
desc.Height = wiRenderer::GetInternalResolution().y;
device->CreateTexture2D(&desc, nullptr, &rtSSS[0]);
+ device->SetName(&rtSSS[0], "rtSSS[0]");
device->CreateTexture2D(&desc, nullptr, &rtSSS[1]);
+ device->SetName(&rtSSS[1], "rtSSS[1]");
}
}
diff --git a/WickedEngine/RenderPath3D_Forward.cpp b/WickedEngine/RenderPath3D_Forward.cpp
index f7de24b9c..c9c69cad2 100644
--- a/WickedEngine/RenderPath3D_Forward.cpp
+++ b/WickedEngine/RenderPath3D_Forward.cpp
@@ -25,9 +25,11 @@ void RenderPath3D_Forward::ResizeBuffers()
desc.Format = wiRenderer::RTFormat_hdr;
device->CreateTexture2D(&desc, nullptr, &rtMain[0]);
+ device->SetName(&rtMain[0], "rtMain[0]");
desc.Format = wiRenderer::RTFormat_gbuffer_1;
device->CreateTexture2D(&desc, nullptr, &rtMain[1]);
+ device->SetName(&rtMain[1], "rtMain[1]");
if (getMSAASampleCount() > 1)
{
@@ -35,9 +37,11 @@ void RenderPath3D_Forward::ResizeBuffers()
desc.Format = wiRenderer::RTFormat_hdr;
device->CreateTexture2D(&desc, nullptr, &rtMain_resolved[0]);
+ device->SetName(&rtMain_resolved[0], "rtMain_resolved[0]");
desc.Format = wiRenderer::RTFormat_gbuffer_1;
device->CreateTexture2D(&desc, nullptr, &rtMain_resolved[1]);
+ device->SetName(&rtMain_resolved[1], "rtMain_resolved[1]");
}
}
}
diff --git a/WickedEngine/RenderPath3D_PathTracing.cpp b/WickedEngine/RenderPath3D_PathTracing.cpp
index 801a8c3bc..a0ad13aa0 100644
--- a/WickedEngine/RenderPath3D_PathTracing.cpp
+++ b/WickedEngine/RenderPath3D_PathTracing.cpp
@@ -27,6 +27,7 @@ void RenderPath3D_PathTracing::ResizeBuffers()
desc.Width = wiRenderer::GetInternalResolution().x;
desc.Height = wiRenderer::GetInternalResolution().y;
device->CreateTexture2D(&desc, nullptr, &traceResult);
+ device->SetName(&traceResult, "traceResult");
}
{
TextureDesc desc;
@@ -35,6 +36,7 @@ void RenderPath3D_PathTracing::ResizeBuffers()
desc.Width = wiRenderer::GetInternalResolution().x;
desc.Height = wiRenderer::GetInternalResolution().y;
device->CreateTexture2D(&desc, nullptr, &rtAccumulation);
+ device->SetName(&rtAccumulation, "rtAccumulation");
}
// also reset accumulation buffer state:
diff --git a/WickedEngine/RenderPath3D_Stereogram.h b/WickedEngine/RenderPath3D_Stereogram.h
deleted file mode 100644
index 91fcc01a2..000000000
--- a/WickedEngine/RenderPath3D_Stereogram.h
+++ /dev/null
@@ -1,14 +0,0 @@
-#pragma once
-#include "RenderPath3D.h"
-
-
-class RenderPath3D_Stereogram :
- public RenderPath3D
-{
-public:
- void setMSAASampleCount(UINT value) override { /*disable MSAA*/ }
-
- void Render() const override;
- void Compose() const override;
-};
-
diff --git a/WickedEngine/ShaderInterop_BVH.h b/WickedEngine/ShaderInterop_BVH.h
index 599f249a6..54aabab1c 100644
--- a/WickedEngine/ShaderInterop_BVH.h
+++ b/WickedEngine/ShaderInterop_BVH.h
@@ -13,6 +13,7 @@ static const uint ARGUMENTBUFFER_OFFSET_CLUSTERPROCESSOR = ARGUMENTBUFFER_OFFSET
CBUFFER(BVHCB, CBSLOT_RENDERER_BVH)
{
float4x4 xTraceBVHWorld;
+ float4 xTraceBVHInstanceColor;
uint xTraceBVHMaterialOffset;
uint xTraceBVHMeshTriangleOffset;
uint xTraceBVHMeshTriangleCount;
@@ -21,9 +22,10 @@ CBUFFER(BVHCB, CBSLOT_RENDERER_BVH)
struct BVHMeshTriangle
{
- float3 v0, v1, v2;
- float3 n0, n1, n2;
- float2 t0, t1, t2;
+ float3 v0, v1, v2; // positions
+ float3 n0, n1, n2; // normals
+ float2 t0, t1, t2; // texcoords
+ float4 c0, c1, c2; // vertex colors
uint materialIndex;
};
struct BVHAABB
diff --git a/WickedEngine/ShaderInterop_Renderer.h b/WickedEngine/ShaderInterop_Renderer.h
index 732699219..7fb6e7a38 100644
--- a/WickedEngine/ShaderInterop_Renderer.h
+++ b/WickedEngine/ShaderInterop_Renderer.h
@@ -238,6 +238,9 @@ CBUFFER(MaterialCB, CBSLOT_RENDERER_MATERIAL)
float g_xMat_normalMapStrength;
float g_xMat_normalMapFlip;
float g_xMat_parallaxOcclusionMapping;
+
+ uint g_xMat_useVertexColors;
+ uint3 g_xMat_padding;
};
CBUFFER(MiscCB, CBSLOT_RENDERER_MISC)
diff --git a/WickedEngine/ShaderInterop_TracedRendering.h b/WickedEngine/ShaderInterop_TracedRendering.h
index f12fae4ce..6a4d26a49 100644
--- a/WickedEngine/ShaderInterop_TracedRendering.h
+++ b/WickedEngine/ShaderInterop_TracedRendering.h
@@ -44,6 +44,9 @@ struct TracedRenderingMaterial
float4 baseColorAtlasMulAdd;
float4 surfaceMapAtlasMulAdd;
float4 emissiveMapAtlasMulAdd;
+
+ uint g_xMat_useVertexColors;
+ uint3 g_xMat_padding;
};
diff --git a/WickedEngine/WickedEngine.h b/WickedEngine/WickedEngine.h
index cb43ecda1..f802b516a 100644
--- a/WickedEngine/WickedEngine.h
+++ b/WickedEngine/WickedEngine.h
@@ -17,7 +17,6 @@
#include "RenderPath3D_TiledForward.h"
#include "RenderPath3D_TiledDeferred.h"
#include "RenderPath3D_PathTracing.h"
-#include "RenderPath3D_Stereogram.h"
#include "LoadingScreen.h"
#include "MainComponent.h"
diff --git a/WickedEngine/WickedEngine_SHADERS.vcxproj b/WickedEngine/WickedEngine_SHADERS.vcxproj
index 30b29acaa..320263d60 100644
--- a/WickedEngine/WickedEngine_SHADERS.vcxproj
+++ b/WickedEngine/WickedEngine_SHADERS.vcxproj
@@ -786,9 +786,6 @@
Pixel
-
- Pixel
-
Pixel
diff --git a/WickedEngine/WickedEngine_SHADERS.vcxproj.filters b/WickedEngine/WickedEngine_SHADERS.vcxproj.filters
index de4de997f..add1605e6 100644
--- a/WickedEngine/WickedEngine_SHADERS.vcxproj.filters
+++ b/WickedEngine/WickedEngine_SHADERS.vcxproj.filters
@@ -225,9 +225,6 @@
PS
-
- PS
-
PS
diff --git a/WickedEngine/WickedEngine_SHARED.vcxitems b/WickedEngine/WickedEngine_SHARED.vcxitems
index d8e941ec6..af5d71d6c 100644
--- a/WickedEngine/WickedEngine_SHARED.vcxitems
+++ b/WickedEngine/WickedEngine_SHARED.vcxitems
@@ -233,7 +233,6 @@
-
@@ -518,7 +517,6 @@
-
diff --git a/WickedEngine/WickedEngine_SHARED.vcxitems.filters b/WickedEngine/WickedEngine_SHARED.vcxitems.filters
index 93ca5d10c..e9e78e1ac 100644
--- a/WickedEngine/WickedEngine_SHARED.vcxitems.filters
+++ b/WickedEngine/WickedEngine_SHARED.vcxitems.filters
@@ -1134,9 +1134,6 @@
ENGINE\Scripting\LuaBindings
-
- ENGINE\High level interface
-
@@ -1913,9 +1910,6 @@
ENGINE\Scripting\LuaBindings
-
- ENGINE\High level interface
-
diff --git a/WickedEngine/bvh_classificationCS.hlsl b/WickedEngine/bvh_classificationCS.hlsl
index 3e3fac0c8..d2b0a2722 100644
--- a/WickedEngine/bvh_classificationCS.hlsl
+++ b/WickedEngine/bvh_classificationCS.hlsl
@@ -1,5 +1,6 @@
#include "globals.hlsli"
#include "ShaderInterop_BVH.h"
+#include "tracedRenderingHF.hlsli"
// This shader builds scene triangle data and performs BVH classification:
// - This shader is run per object.
@@ -9,9 +10,11 @@
// - Because we are calling this shader per object, clusters will not span across different objects
// - Clusters will be sorted later based on morton code
-TYPEDBUFFER(meshIndexBuffer, uint, TEXSLOT_ONDEMAND0);
-RAWBUFFER(meshVertexBuffer_POS, TEXSLOT_ONDEMAND1);
-TYPEDBUFFER(meshVertexBuffer_TEX, float2, TEXSLOT_ONDEMAND2);
+STRUCTUREDBUFFER(materialBuffer, TracedRenderingMaterial, TEXSLOT_ONDEMAND0);
+TYPEDBUFFER(meshIndexBuffer, uint, TEXSLOT_ONDEMAND1);
+RAWBUFFER(meshVertexBuffer_POS, TEXSLOT_ONDEMAND2);
+TYPEDBUFFER(meshVertexBuffer_TEX, float2, TEXSLOT_ONDEMAND3);
+TYPEDBUFFER(meshVertexBuffer_COL, float4, TEXSLOT_ONDEMAND4);
RWSTRUCTUREDBUFFER(triangleBuffer, BVHMeshTriangle, 0);
RWRAWBUFFER(clusterCounterBuffer, 1);
@@ -131,6 +134,21 @@ void main(uint3 DTid : SV_DispatchThreadID, uint groupIndex : SV_GroupIndex)
prim.t2 = meshVertexBuffer_TEX[i2];
prim.materialIndex = xTraceBVHMaterialOffset + materialIndex;
+ TracedRenderingMaterial mat = materialBuffer[prim.materialIndex];
+
+ float4 color = xTraceBVHInstanceColor * mat.baseColor;
+ prim.c0 = color;
+ prim.c1 = color;
+ prim.c2 = color;
+
+ [branch]
+ if (mat.g_xMat_useVertexColors)
+ {
+ prim.c0 *= meshVertexBuffer_COL[i0];
+ prim.c1 *= meshVertexBuffer_COL[i1];
+ prim.c2 *= meshVertexBuffer_COL[i2];
+ }
+
triangleBuffer[globalTriangleID] = prim;
// Compute triangle AABB:
diff --git a/WickedEngine/captureImpostorPS_albedo.hlsl b/WickedEngine/captureImpostorPS_albedo.hlsl
index 0504ac597..80a0d2b1d 100644
--- a/WickedEngine/captureImpostorPS_albedo.hlsl
+++ b/WickedEngine/captureImpostorPS_albedo.hlsl
@@ -6,7 +6,7 @@ float4 main(PixelInputType input) : SV_Target0
float4 color = xBaseColorMap.Sample(sampler_objectshader, UV);
color.rgb = DEGAMMA(color.rgb);
- color *= g_xMat_baseColor;
+ color *= input.color;
ALPHATEST(color.a);
color.a = 1;
diff --git a/WickedEngine/envMapGS.hlsl b/WickedEngine/envMapGS.hlsl
index b689dea41..26a6c6141 100644
--- a/WickedEngine/envMapGS.hlsl
+++ b/WickedEngine/envMapGS.hlsl
@@ -12,12 +12,11 @@ void main(triangle VSOut_EnvmapRendering input[3], inout TriangleStream I)
{
- ConstantOutputType O = (ConstantOutputType)0;
+ ConstantOutputType Out;
const float MODIFIER = 0.6f;
float fDistance;
float3 f3MidPoint;
// Edge 0
- f3MidPoint = ( I[2].f3Position + I[0].f3Position ) / 2.0f;
+ f3MidPoint = ( I[2].pos.xyz + I[0].pos.xyz) / 2.0f;
fDistance = distance( f3MidPoint, g_f4Eye.xyz )*MODIFIER - g_f4TessFactors.z;
- O.fTessFactor[0] = g_f4TessFactors.x * ( 1.0f - clamp( ( fDistance / g_f4TessFactors.w ), 0.0f, 1.0f - ( 1.0f / g_f4TessFactors.x ) ) );
+ Out.fTessFactor[0] = g_f4TessFactors.x * ( 1.0f - clamp( ( fDistance / g_f4TessFactors.w ), 0.0f, 1.0f - ( 1.0f / g_f4TessFactors.x ) ) );
// Edge 1
- f3MidPoint = ( I[0].f3Position + I[1].f3Position ) / 2.0f;
+ f3MidPoint = ( I[0].pos.xyz + I[1].pos.xyz) / 2.0f;
fDistance = distance( f3MidPoint, g_f4Eye.xyz )*MODIFIER - g_f4TessFactors.z;
- O.fTessFactor[1] = g_f4TessFactors.x * ( 1.0f - clamp( ( fDistance / g_f4TessFactors.w ), 0.0f, 1.0f - ( 1.0f / g_f4TessFactors.x ) ) );
+ Out.fTessFactor[1] = g_f4TessFactors.x * ( 1.0f - clamp( ( fDistance / g_f4TessFactors.w ), 0.0f, 1.0f - ( 1.0f / g_f4TessFactors.x ) ) );
// Edge 2
- f3MidPoint = ( I[1].f3Position + I[2].f3Position ) / 2.0f;
+ f3MidPoint = ( I[1].pos.xyz + I[2].pos.xyz) / 2.0f;
fDistance = distance( f3MidPoint, g_f4Eye.xyz )*MODIFIER - g_f4TessFactors.z;
- O.fTessFactor[2] = g_f4TessFactors.x * ( 1.0f - clamp( ( fDistance / g_f4TessFactors.w ), 0.0f, 1.0f - ( 1.0f / g_f4TessFactors.x ) ) );
+ Out.fTessFactor[2] = g_f4TessFactors.x * ( 1.0f - clamp( ( fDistance / g_f4TessFactors.w ), 0.0f, 1.0f - ( 1.0f / g_f4TessFactors.x ) ) );
// Inside
- O.fInsideTessFactor = ( O.fTessFactor[0] + O.fTessFactor[1] + O.fTessFactor[2] ) / 3.0f;
-
-
- O.f3B0 = I[0].f3Position;
- O.f3B1 = I[1].f3Position;
- O.f3B2 = I[2].f3Position;
+ Out.fInsideTessFactor = ( Out.fTessFactor[0] + Out.fTessFactor[1] + Out.fTessFactor[2] ) / 3.0f;
- O.f3PrevB0 = I[0].f3PositionPrev;
- O.f3PrevB1 = I[1].f3PositionPrev;
- O.f3PrevB2 = I[2].f3PositionPrev;
+ Out.pos0 = I[0].pos;
+ Out.pos1 = I[1].pos;
+ Out.pos2 = I[2].pos;
+
+ Out.color0 = I[0].color;
+ Out.color1 = I[1].color;
+ Out.color2 = I[2].color;
+
+ Out.tex0 = I[0].tex;
+ Out.tex1 = I[1].tex;
+ Out.tex2 = I[2].tex;
- O.f4N0 = I[0].f4Normal;
- O.f4N1 = I[1].f4Normal;
- O.f4N2 = I[2].f4Normal;
+ Out.nor0 = I[0].nor;
+ Out.nor1 = I[1].nor;
+ Out.nor2 = I[2].nor;
+
+ Out.posPrev0 = I[0].posPrev;
+ Out.posPrev1 = I[1].posPrev;
+ Out.posPrev2 = I[2].posPrev;
- return O;
+ return Out;
}
////////////////////////////////////////////////////////////////////////////////
@@ -125,14 +138,13 @@ ConstantOutputType PatchConstantFunction(InputPatch I)
[patchconstantfunc("PatchConstantFunction")]
HullOutputType main(InputPatch patch, uint pointId : SV_OutputControlPointID, uint patchId : SV_PrimitiveID)
{
- HullOutputType Out = (HullOutputType)0;
+ HullOutputType Out;
- Out.pos = patch[pointId].f3Position.xyz;
- Out.posPrev = patch[pointId].f3PositionPrev.xyz;
+ Out.pos = patch[pointId].pos;
+ Out.color = patch[pointId].color;
Out.tex = patch[pointId].tex;
- Out.nor = patch[pointId].f4Normal;
- Out.instanceColor = patch[pointId].instanceColor.rgb;
- Out.dither = patch[pointId].dither;
+ Out.nor = patch[pointId].nor;
+ Out.posPrev = patch[pointId].posPrev;
return Out;
}
\ No newline at end of file
diff --git a/WickedEngine/objectInputLayoutHF.hlsli b/WickedEngine/objectInputLayoutHF.hlsli
index 054ad3597..e25b1cdd5 100644
--- a/WickedEngine/objectInputLayoutHF.hlsli
+++ b/WickedEngine/objectInputLayoutHF.hlsli
@@ -1,18 +1,19 @@
#ifndef _MESH_INPUT_LAYOUT_HF_
#define _MESH_INPUT_LAYOUT_HF_
+#include "ShaderInterop_Renderer.h"
struct Input_Instance
{
- float4 wi0 : MATI0;
- float4 wi1 : MATI1;
- float4 wi2 : MATI2;
- float4 color_dither : COLOR_DITHER;
+ float4 mat0 : INSTANCEMATRIX0;
+ float4 mat1 : INSTANCEMATRIX1;
+ float4 mat2 : INSTANCEMATRIX2;
+ float4 color : INSTANCECOLOR;
};
struct Input_InstancePrev
{
- float4 wiPrev0 : MATIPREV0;
- float4 wiPrev1 : MATIPREV1;
- float4 wiPrev2 : MATIPREV2;
+ float4 matPrev0 : INSTANCEMATRIXPREV0;
+ float4 matPrev1 : INSTANCEMATRIXPREV1;
+ float4 matPrev2 : INSTANCEMATRIXPREV2;
};
struct Input_InstanceAtlas
{
@@ -35,6 +36,7 @@ struct Input_Object_ALL
float4 pos : POSITION_NORMAL_SUBSETINDEX;
float2 tex : TEXCOORD;
float2 atl : ATLAS;
+ float4 col : COLOR;
float4 pre : PREVPOS;
Input_Instance inst;
Input_InstancePrev instPrev;
@@ -44,29 +46,30 @@ struct Input_Object_ALL
inline float4x4 MakeWorldMatrixFromInstance(in Input_Instance input)
{
return float4x4(
- float4(input.wi0.x, input.wi1.x, input.wi2.x, 0)
- , float4(input.wi0.y, input.wi1.y, input.wi2.y, 0)
- , float4(input.wi0.z, input.wi1.z, input.wi2.z, 0)
- , float4(input.wi0.w, input.wi1.w, input.wi2.w, 1)
+ float4(input.mat0.x, input.mat1.x, input.mat2.x, 0)
+ , float4(input.mat0.y, input.mat1.y, input.mat2.y, 0)
+ , float4(input.mat0.z, input.mat1.z, input.mat2.z, 0)
+ , float4(input.mat0.w, input.mat1.w, input.mat2.w, 1)
);
}
inline float4x4 MakeWorldMatrixFromInstance(in Input_InstancePrev input)
{
return float4x4(
- float4(input.wiPrev0.x, input.wiPrev1.x, input.wiPrev2.x, 0)
- , float4(input.wiPrev0.y, input.wiPrev1.y, input.wiPrev2.y, 0)
- , float4(input.wiPrev0.z, input.wiPrev1.z, input.wiPrev2.z, 0)
- , float4(input.wiPrev0.w, input.wiPrev1.w, input.wiPrev2.w, 1)
+ float4(input.matPrev0.x, input.matPrev1.x, input.matPrev2.x, 0)
+ , float4(input.matPrev0.y, input.matPrev1.y, input.matPrev2.y, 0)
+ , float4(input.matPrev0.z, input.matPrev1.z, input.matPrev2.z, 0)
+ , float4(input.matPrev0.w, input.matPrev1.w, input.matPrev2.w, 1)
);
}
struct VertexSurface
{
float4 position;
- float3 normal;
- uint materialIndex;
float2 uv;
float2 atlas;
+ float4 color;
+ float3 normal;
+ uint materialIndex;
float4 prevPos;
};
inline VertexSurface MakeVertexSurfaceFromInput(Input_Object_POS input)
@@ -75,6 +78,8 @@ inline VertexSurface MakeVertexSurfaceFromInput(Input_Object_POS input)
surface.position = float4(input.pos.xyz, 1);
+ surface.color = g_xMat_baseColor * input.inst.color;
+
uint normal_wind_matID = asuint(input.pos.w);
surface.normal.x = (float)((normal_wind_matID >> 0) & 0x000000FF) / 255.0f * 2.0f - 1.0f;
surface.normal.y = (float)((normal_wind_matID >> 8) & 0x000000FF) / 255.0f * 2.0f - 1.0f;
@@ -89,6 +94,8 @@ inline VertexSurface MakeVertexSurfaceFromInput(Input_Object_POS_TEX input)
surface.position = float4(input.pos.xyz, 1);
+ surface.color = g_xMat_baseColor * input.inst.color;
+
uint normal_wind_matID = asuint(input.pos.w);
surface.normal.x = (float)((normal_wind_matID >> 0) & 0x000000FF) / 255.0f * 2.0f - 1.0f;
surface.normal.y = (float)((normal_wind_matID >> 8) & 0x000000FF) / 255.0f * 2.0f - 1.0f;
@@ -105,6 +112,13 @@ inline VertexSurface MakeVertexSurfaceFromInput(Input_Object_ALL input)
surface.position = float4(input.pos.xyz, 1);
+ surface.color = g_xMat_baseColor * input.inst.color;
+
+ if (g_xMat_useVertexColors)
+ {
+ surface.color *= input.col;
+ }
+
uint normal_wind_matID = asuint(input.pos.w);
surface.normal.x = (float)((normal_wind_matID >> 0) & 0x000000FF) / 255.0f * 2.0f - 1.0f;
surface.normal.y = (float)((normal_wind_matID >> 8) & 0x000000FF) / 255.0f * 2.0f - 1.0f;
diff --git a/WickedEngine/objectPS_hologram.hlsl b/WickedEngine/objectPS_hologram.hlsl
index 325497db8..ca949d417 100644
--- a/WickedEngine/objectPS_hologram.hlsl
+++ b/WickedEngine/objectPS_hologram.hlsl
@@ -7,7 +7,7 @@ float4 main(PixelInputType input) : SV_TARGET
float4 color = xBaseColorMap.Sample(sampler_objectshader, UV);
color.rgb = DEGAMMA(color.rgb);
color.rgb = max(color.r, max(color.g, color.b));
- color *= g_xMat_baseColor * float4(input.instanceColor, 1);
+ color *= input.color;
float time = g_xFrame_Time;
diff --git a/WickedEngine/objectPS_simplest.hlsl b/WickedEngine/objectPS_simplest.hlsl
index 8fd81bbc7..0941bbc79 100644
--- a/WickedEngine/objectPS_simplest.hlsl
+++ b/WickedEngine/objectPS_simplest.hlsl
@@ -1,10 +1,7 @@
#include "objectHF.hlsli"
-
-
-
float4 main(PixelInputType_Simple PSIn) : SV_TARGET
{
- return g_xMat_baseColor * float4(PSIn.instanceColor,1);
+ return PSIn.color;
}
diff --git a/WickedEngine/objectPS_voxelizer.hlsl b/WickedEngine/objectPS_voxelizer.hlsl
index 932afb108..a3204f972 100644
--- a/WickedEngine/objectPS_voxelizer.hlsl
+++ b/WickedEngine/objectPS_voxelizer.hlsl
@@ -3,23 +3,35 @@
RWSTRUCTUREDBUFFER(output, VoxelType, 0);
-void main(float4 pos : SV_POSITION, float3 N : NORMAL, float2 tex : TEXCOORD, float3 P : POSITION3D, nointerpolation float3 instanceColor : COLOR)
+struct PSInput
{
+ float4 pos : SV_POSITION;
+ float4 color : COLOR;
+ float2 tex : TEXCOORD;
+ float3 N : NORMAL;
+ float3 P : POSITION3D;
+};
+
+void main(PSInput input)
+{
+ float3 N = input.N;
+ float3 P = input.P;
+
float3 diff = (P - g_xFrame_VoxelRadianceDataCenter) * g_xFrame_VoxelRadianceDataRes_Inverse * g_xFrame_VoxelRadianceDataSize_Inverse;
float3 uvw = diff * float3(0.5f, -0.5f, 0.5f) + 0.5f;
[branch]
if (is_saturated(uvw))
{
- float4 baseColor = xBaseColorMap.Sample(sampler_linear_wrap, tex);
+ float4 baseColor = xBaseColorMap.Sample(sampler_linear_wrap, input.tex);
baseColor.rgb = DEGAMMA(baseColor.rgb);
- baseColor *= g_xMat_baseColor * float4(instanceColor, 1);
+ baseColor *= input.color;
float4 color = baseColor;
float4 emissiveColor;
[branch]
if (g_xMat_emissiveColor.a > 0)
{
- emissiveColor = xEmissiveMap.Sample(sampler_linear_wrap, tex);
+ emissiveColor = xEmissiveMap.Sample(sampler_linear_wrap, input.tex);
emissiveColor.rgb = DEGAMMA(emissiveColor.rgb);
emissiveColor *= g_xMat_emissiveColor;
}
diff --git a/WickedEngine/objectVS_common.hlsl b/WickedEngine/objectVS_common.hlsl
index fe63066c3..6a8c67ca8 100644
--- a/WickedEngine/objectVS_common.hlsl
+++ b/WickedEngine/objectVS_common.hlsl
@@ -10,9 +10,6 @@ PixelInputType main(Input_Object_ALL input)
float4x4 WORLDPREV = MakeWorldMatrixFromInstance(input.instPrev);
VertexSurface surface = MakeVertexSurfaceFromInput(input);
- Out.instanceColor = input.inst.color_dither.rgb;
- Out.dither = input.inst.color_dither.a;
-
surface.position = mul(surface.position, WORLD);
surface.prevPos = mul(surface.prevPos, WORLDPREV);
surface.normal = normalize(mul(surface.normal, (float3x3)WORLD));
@@ -22,10 +19,11 @@ PixelInputType main(Input_Object_ALL input)
Out.pos = Out.pos2D = mul(surface.position, g_xCamera_VP);
Out.pos2DPrev = mul(surface.prevPos, g_xFrame_MainCamera_PrevVP);
Out.pos3D = surface.position.xyz;
+ Out.color = surface.color;
Out.tex = surface.uv;
+ Out.atl = surface.atlas;
Out.nor = surface.normal;
Out.nor2D = mul(Out.nor.xyz, (float3x3)g_xCamera_View).xy;
- Out.atl = surface.atlas;
Out.ReflectionMapSamplingPos = mul(surface.position, g_xFrame_MainCamera_ReflVP);
diff --git a/WickedEngine/objectVS_common_tessellation.hlsl b/WickedEngine/objectVS_common_tessellation.hlsl
index bc18ba636..22a05af24 100644
--- a/WickedEngine/objectVS_common_tessellation.hlsl
+++ b/WickedEngine/objectVS_common_tessellation.hlsl
@@ -3,37 +3,31 @@
struct HullInputType
{
- float3 pos : POSITION;
- float3 posPrev : POSITIONPREV;
+ float4 pos : POSITION;
+ float4 color : COLOR;
float4 tex : TEXCOORD0;
float4 nor : NORMAL;
- nointerpolation float3 instanceColor : INSTANCECOLOR;
- nointerpolation float dither : DITHER;
+ float4 posPrev : POSITIONPREV;
};
HullInputType main(Input_Object_ALL input)
{
HullInputType Out;
-
float4x4 WORLD = MakeWorldMatrixFromInstance(input.inst);
float4x4 WORLDPREV = MakeWorldMatrixFromInstance(input.instPrev);
VertexSurface surface = MakeVertexSurfaceFromInput(input);
-
surface.position = mul(surface.position, WORLD);
surface.prevPos = mul(surface.prevPos, WORLDPREV);
surface.normal = normalize(mul(surface.normal, (float3x3)WORLD));
-
- Out.pos = surface.position.xyz;
- Out.posPrev = surface.prevPos.xyz;
+ Out.pos = surface.position;
+ Out.color = surface.color;
Out.tex = float4(surface.uv, surface.atlas);
Out.nor = float4(surface.normal, 1);
-
- Out.instanceColor = input.inst.color_dither.rgb;
- Out.dither = input.inst.color_dither.a;
+ Out.posPrev = surface.prevPos;
return Out;
}
\ No newline at end of file
diff --git a/WickedEngine/objectVS_simple.hlsl b/WickedEngine/objectVS_simple.hlsl
index 68725172c..86d6e3751 100644
--- a/WickedEngine/objectVS_simple.hlsl
+++ b/WickedEngine/objectVS_simple.hlsl
@@ -3,18 +3,16 @@
PixelInputType_Simple main(Input_Object_POS_TEX input)
{
PixelInputType_Simple Out;
-
+
float4x4 WORLD = MakeWorldMatrixFromInstance(input.inst);
VertexSurface surface = MakeVertexSurfaceFromInput(input);
- Out.instanceColor = input.inst.color_dither.rgb;
- Out.dither = input.inst.color_dither.a;
-
surface.position = mul(surface.position, WORLD);
Out.clip = dot(surface.position, g_xClipPlane);
Out.pos = mul(surface.position, g_xCamera_VP);
+ Out.color = surface.color;
Out.tex = surface.uv;
return Out;
diff --git a/WickedEngine/objectVS_simple_tessellation.hlsl b/WickedEngine/objectVS_simple_tessellation.hlsl
index 5957b816d..22cb9f410 100644
--- a/WickedEngine/objectVS_simple_tessellation.hlsl
+++ b/WickedEngine/objectVS_simple_tessellation.hlsl
@@ -3,12 +3,11 @@
struct HullInputType
{
- float3 pos : POSITION;
- float3 posPrev : POSITIONPREV;
+ float4 pos : POSITION;
+ float4 color : COLOR;
float4 tex : TEXCOORD0;
float4 nor : NORMAL;
- nointerpolation float3 instanceColor : INSTANCECOLOR;
- nointerpolation float dither : DITHER;
+ float4 posPrev : POSITIONPREV;
};
@@ -22,15 +21,13 @@ HullInputType main(Input_Object_ALL input)
surface.position = mul(surface.position, WORLD);
surface.normal = normalize(mul(surface.normal, (float3x3)WORLD));
- Out.pos = surface.position.xyz;
+ Out.pos = surface.position;
+ Out.color = surface.color;
Out.tex = surface.uv.xyxy;
-
Out.nor = float4(surface.normal, 1);
// todo: leave these but I'm lazy to create appropriate hull/domain shaders now...
Out.posPrev = 0;
- Out.instanceColor = 0;
- Out.dither = 0;
return Out;
}
\ No newline at end of file
diff --git a/WickedEngine/objectVS_voxelizer.hlsl b/WickedEngine/objectVS_voxelizer.hlsl
index 77b98201d..b2336719f 100644
--- a/WickedEngine/objectVS_voxelizer.hlsl
+++ b/WickedEngine/objectVS_voxelizer.hlsl
@@ -3,12 +3,12 @@
struct VSOut
{
float4 pos : SV_POSITION;
- float3 nor : NORMAL;
+ float4 color : COLOR;
float2 tex : TEXCOORD;
- float3 instanceColor : COLOR;
+ float3 nor : NORMAL;
};
-VSOut main(Input_Object_POS_TEX input, uint instanceID : SV_INSTANCEID)
+VSOut main(Input_Object_POS_TEX input)
{
VSOut Out;
@@ -16,9 +16,9 @@ VSOut main(Input_Object_POS_TEX input, uint instanceID : SV_INSTANCEID)
VertexSurface surface = MakeVertexSurfaceFromInput(input);
Out.pos = mul(surface.position, WORLD);
- Out.nor = normalize(mul(surface.normal, (float3x3)WORLD));
+ Out.color = surface.color;
Out.tex = surface.uv;
- Out.instanceColor = input.inst.color_dither.rgb;
+ Out.nor = normalize(mul(surface.normal, (float3x3)WORLD));
return Out;
}
\ No newline at end of file
diff --git a/WickedEngine/raySceneIntersectHF.hlsli b/WickedEngine/raySceneIntersectHF.hlsli
index 03212ae29..1b040119f 100644
--- a/WickedEngine/raySceneIntersectHF.hlsli
+++ b/WickedEngine/raySceneIntersectHF.hlsli
@@ -8,15 +8,15 @@
#endif // RAYTRACE_STACKSIZE
STRUCTUREDBUFFER(materialBuffer, TracedRenderingMaterial, TEXSLOT_ONDEMAND0);
-STRUCTUREDBUFFER(triangleBuffer, BVHMeshTriangle, TEXSLOT_ONDEMAND1);
-RAWBUFFER(clusterCounterBuffer, TEXSLOT_ONDEMAND2);
-STRUCTUREDBUFFER(clusterIndexBuffer, uint, TEXSLOT_ONDEMAND3);
-STRUCTUREDBUFFER(clusterOffsetBuffer, uint2, TEXSLOT_ONDEMAND4);
-STRUCTUREDBUFFER(clusterConeBuffer, ClusterCone, TEXSLOT_ONDEMAND5);
-STRUCTUREDBUFFER(bvhNodeBuffer, BVHNode, TEXSLOT_ONDEMAND6);
-STRUCTUREDBUFFER(bvhAABBBuffer, BVHAABB, TEXSLOT_ONDEMAND7);
+TEXTURE2D(materialTextureAtlas, float4, TEXSLOT_ONDEMAND1);
+STRUCTUREDBUFFER(triangleBuffer, BVHMeshTriangle, TEXSLOT_ONDEMAND2);
+RAWBUFFER(clusterCounterBuffer, TEXSLOT_ONDEMAND3);
+STRUCTUREDBUFFER(clusterIndexBuffer, uint, TEXSLOT_ONDEMAND4);
+STRUCTUREDBUFFER(clusterOffsetBuffer, uint2, TEXSLOT_ONDEMAND5);
+STRUCTUREDBUFFER(clusterConeBuffer, ClusterCone, TEXSLOT_ONDEMAND6);
+STRUCTUREDBUFFER(bvhNodeBuffer, BVHNode, TEXSLOT_ONDEMAND7);
+STRUCTUREDBUFFER(bvhAABBBuffer, BVHAABB, TEXSLOT_ONDEMAND8);
-TEXTURE2D(materialTextureAtlas, float4, TEXSLOT_ONDEMAND8);
inline RayHit TraceScene(Ray ray)
{
@@ -291,6 +291,7 @@ inline float3 Shade(inout Ray ray, inout RayHit hit, inout float seed, in float2
hit.N = normalize(tri.n0 * w + tri.n1 * u + tri.n2 * v);
hit.UV = tri.t0 * w + tri.t1 * u + tri.t2 * v;
+ hit.color = tri.c0 * w + tri.c1 * u + tri.c2 * v;
hit.materialIndex = tri.materialIndex;
TracedRenderingMaterial mat = materialBuffer[hit.materialIndex];
@@ -301,7 +302,7 @@ inline float3 Shade(inout Ray ray, inout RayHit hit, inout float seed, in float2
float4 baseColor = baseColorMap;
baseColor.rgb = DEGAMMA(baseColor.rgb);
- baseColor *= mat.baseColor;
+ baseColor *= hit.color;
float roughness = mat.roughness * surfaceMap.g;
float metalness = mat.metalness * surfaceMap.b;
float reflectance = mat.reflectance * surfaceMap.a;
diff --git a/WickedEngine/shadowPS_transparent.hlsl b/WickedEngine/shadowPS_transparent.hlsl
index ddf011ac9..29dc9b036 100644
--- a/WickedEngine/shadowPS_transparent.hlsl
+++ b/WickedEngine/shadowPS_transparent.hlsl
@@ -4,22 +4,19 @@
struct VertextoPixel
{
float4 pos : SV_POSITION;
+ float4 color : COLOR;
float2 tex : TEXCOORD0;
- nointerpolation float dither : DITHER;
- nointerpolation float3 instanceColor : INSTANCECOLOR;
};
float4 main(VertextoPixel input) : SV_TARGET
{
float2 pixel = input.pos.xy;
- clip(dither(pixel) - input.dither);
-
float2 UV = input.tex * g_xMat_texMulAdd.xy + g_xMat_texMulAdd.zw;
float4 color = xBaseColorMap.Sample(sampler_objectshader, UV);
color.rgb = DEGAMMA(color.rgb);
- color *= g_xMat_baseColor * float4(input.instanceColor, 1);
+ color *= input.color;
ALPHATEST(color.a);
float opacity = color.a;
diff --git a/WickedEngine/shadowPS_water.hlsl b/WickedEngine/shadowPS_water.hlsl
index 38356d235..b6aa00f1c 100644
--- a/WickedEngine/shadowPS_water.hlsl
+++ b/WickedEngine/shadowPS_water.hlsl
@@ -4,22 +4,19 @@
struct VertextoPixel
{
float4 pos : SV_POSITION;
+ float4 color : COLOR;
float2 tex : TEXCOORD0;
- nointerpolation float dither : DITHER;
- nointerpolation float3 instanceColor : INSTANCECOLOR;
};
float4 main(VertextoPixel input) : SV_TARGET
{
float2 pixel = input.pos.xy;
- clip(dither(pixel) - input.dither);
-
float2 UV = input.tex * g_xMat_texMulAdd.xy + g_xMat_texMulAdd.zw;
float4 color = xBaseColorMap.Sample(sampler_objectshader, UV);
color.rgb = DEGAMMA(color.rgb);
- color *= g_xMat_baseColor * float4(input.instanceColor, 1);
+ color *= input.color;
ALPHATEST(color.a);
float opacity = color.a;
diff --git a/WickedEngine/shadowVS_transparent.hlsl b/WickedEngine/shadowVS_transparent.hlsl
index e9448f810..6b2b1fa84 100644
--- a/WickedEngine/shadowVS_transparent.hlsl
+++ b/WickedEngine/shadowVS_transparent.hlsl
@@ -3,9 +3,8 @@
struct VertexOut
{
float4 pos : SV_POSITION;
+ float4 color : COLOR;
float2 tex : TEXCOORD0;
- nointerpolation float dither : DITHER;
- nointerpolation float3 instanceColor : INSTANCECOLOR;
};
VertexOut main(Input_Object_POS_TEX input)
@@ -15,12 +14,10 @@ VertexOut main(Input_Object_POS_TEX input)
float4x4 WORLD = MakeWorldMatrixFromInstance(input.inst);
VertexSurface surface = MakeVertexSurfaceFromInput(input);
- Out.instanceColor = input.inst.color_dither.rgb;
- Out.dither = input.inst.color_dither.a;
-
surface.position = mul(surface.position, WORLD);
Out.pos = mul(surface.position, g_xCamera_VP);
+ Out.color = surface.color;
Out.tex = surface.uv;
return Out;
diff --git a/WickedEngine/stereogramPS.hlsl b/WickedEngine/stereogramPS.hlsl
deleted file mode 100644
index 63d961efc..000000000
--- a/WickedEngine/stereogramPS.hlsl
+++ /dev/null
@@ -1,30 +0,0 @@
-#include "postProcessHF.hlsli"
-
-static const float pWid = 100;
-static const float pHei = 100;
-
-float4 main(VertexToPixelPostProcess PSIn) : SV_TARGET
-{
- float maxStep = 32.;
- float d = 0.;
-
- float2 uv = PSIn.pos.xy;
-
- for (int count = 0; count < 100; count++) {
- if (uv.x < pWid)
- break;
-
- float d = 1.0 - saturate(texture_lineardepth.SampleLevel(sampler_linear_clamp, uv / g_xFrame_ScreenWidthHeight.xy, 0).r * 100);
-
- uv.x -= pWid - (d * maxStep);
- }
-
- float x = (uv.x % pWid) / pWid;
- float y = (uv.y % pHei) / pHei;
- float3 rgb = xTexture.SampleLevel(sampler_linear_wrap, float2(x, y), 0).yxz;
-
- float4 fragColor = float4(rgb, 1.0);
-
-
- return fragColor;
-}
\ No newline at end of file
diff --git a/WickedEngine/tracedRenderingHF.hlsli b/WickedEngine/tracedRenderingHF.hlsli
index ee73e31ac..bd79fbda8 100644
--- a/WickedEngine/tracedRenderingHF.hlsli
+++ b/WickedEngine/tracedRenderingHF.hlsli
@@ -103,6 +103,7 @@ struct RayHit
float3 N;
float2 UV;
uint materialIndex;
+ float4 color;
};
inline RayHit CreateRayHit()
@@ -116,6 +117,7 @@ inline RayHit CreateRayHit()
hit.N = 0;
hit.UV = 0;
hit.materialIndex = 0;
+ hit.color = 0;
return hit;
}
diff --git a/WickedEngine/waterVS.hlsl b/WickedEngine/waterVS.hlsl
index 1d51717b1..11c8662c2 100644
--- a/WickedEngine/waterVS.hlsl
+++ b/WickedEngine/waterVS.hlsl
@@ -11,14 +11,12 @@ PixelInputType main(Input_Object_POS_TEX input)
Out.pos3D = surface.position.xyz;
Out.pos = Out.pos2D = mul(surface.position, g_xCamera_VP);
+ Out.color = surface.color;
Out.tex = surface.uv;
Out.nor = normalize(mul(surface.normal, (float3x3)WORLD));
Out.nor2D = mul(Out.nor.xyz, (float3x3)g_xCamera_View).xy;
Out.ReflectionMapSamplingPos = mul(surface.position, g_xFrame_MainCamera_ReflVP);
- Out.instanceColor = input.inst.color_dither.rgb;
- Out.dither = input.inst.color_dither.a;
-
return Out;
}
\ No newline at end of file
diff --git a/WickedEngine/wiGPUBVH.cpp b/WickedEngine/wiGPUBVH.cpp
index 280e40adc..56a20e0b7 100644
--- a/WickedEngine/wiGPUBVH.cpp
+++ b/WickedEngine/wiGPUBVH.cpp
@@ -5,10 +5,8 @@
#include "wiProfiler.h"
#include "wiResourceManager.h"
#include "wiGPUSortLib.h"
-
-#include
-#include
-#include
+#include "wiTextureHelper.h"
+#include "wiBackLog.h"
using namespace std;
using namespace wiGraphics;
@@ -30,6 +28,220 @@ static ComputePSO CPSO[CSTYPE_BVH_COUNT];
static GPUBuffer constantBuffer;
+
+void wiGPUBVH::UpdateGlobalMaterialResources(const Scene& scene, GRAPHICSTHREAD threadID)
+{
+ GraphicsDevice* device = wiRenderer::GetDevice();
+
+ using namespace wiRectPacker;
+
+ if (sceneTextures.empty())
+ {
+ sceneTextures.insert(wiTextureHelper::getWhite());
+ sceneTextures.insert(wiTextureHelper::getNormalMapDefault());
+ }
+
+ for (size_t i = 0; i < scene.objects.GetCount(); ++i)
+ {
+ const ObjectComponent& object = scene.objects[i];
+
+ if (object.meshID != INVALID_ENTITY)
+ {
+ const MeshComponent& mesh = *scene.meshes.GetComponent(object.meshID);
+
+ for (auto& subset : mesh.subsets)
+ {
+ const MaterialComponent& material = *scene.materials.GetComponent(subset.materialID);
+
+ sceneTextures.insert(material.GetBaseColorMap());
+ sceneTextures.insert(material.GetSurfaceMap());
+ sceneTextures.insert(material.GetEmissiveMap());
+ }
+ }
+
+ }
+
+ bool repackAtlas = false;
+ const int atlasWrapBorder = 1;
+ for (const Texture2D* tex : sceneTextures)
+ {
+ if (tex == nullptr)
+ {
+ continue;
+ }
+
+ if (storedTextures.find(tex) == storedTextures.end())
+ {
+ // we need to pack this texture into the atlas
+ rect_xywh newRect = rect_xywh(0, 0, tex->GetDesc().Width + atlasWrapBorder * 2, tex->GetDesc().Height + atlasWrapBorder * 2);
+ storedTextures[tex] = newRect;
+
+ repackAtlas = true;
+ }
+
+ }
+
+ if (repackAtlas)
+ {
+ vector out_rects(storedTextures.size());
+ int i = 0;
+ for (auto& it : storedTextures)
+ {
+ out_rects[i] = &it.second;
+ i++;
+ }
+
+ std::vector bins;
+ if (pack(out_rects.data(), (int)storedTextures.size(), 16384, bins))
+ {
+ assert(bins.size() == 1 && "The regions won't fit into the texture!");
+
+ TextureDesc desc;
+ desc.Width = (UINT)bins[0].size.w;
+ desc.Height = (UINT)bins[0].size.h;
+ desc.MipLevels = 1;
+ desc.ArraySize = 1;
+ desc.Format = FORMAT_R8G8B8A8_UNORM;
+ desc.SampleDesc.Count = 1;
+ desc.SampleDesc.Quality = 0;
+ desc.Usage = USAGE_DEFAULT;
+ desc.BindFlags = BIND_SHADER_RESOURCE | BIND_UNORDERED_ACCESS;
+ desc.CPUAccessFlags = 0;
+ desc.MiscFlags = 0;
+
+ device->CreateTexture2D(&desc, nullptr, &globalMaterialAtlas);
+ device->SetName(&globalMaterialAtlas, "globalMaterialAtlas");
+
+ for (auto& it : storedTextures)
+ {
+ wiRenderer::CopyTexture2D(&globalMaterialAtlas, 0, it.second.x + atlasWrapBorder, it.second.y + atlasWrapBorder, it.first, 0, threadID, wiRenderer::BORDEREXPAND_WRAP);
+ }
+ }
+ else
+ {
+ wiBackLog::post("Tracing atlas packing failed!");
+ }
+ }
+
+ materialArray.clear();
+
+ // Pre-gather scene properties:
+ for (size_t i = 0; i < scene.objects.GetCount(); ++i)
+ {
+ const ObjectComponent& object = scene.objects[i];
+
+ if (object.meshID != INVALID_ENTITY)
+ {
+ const MeshComponent& mesh = *scene.meshes.GetComponent(object.meshID);
+
+ for (auto& subset : mesh.subsets)
+ {
+ const MaterialComponent& material = *scene.materials.GetComponent(subset.materialID);
+
+ TracedRenderingMaterial global_material;
+
+ // Copy base params:
+ global_material.baseColor = material.baseColor;
+ global_material.emissiveColor = material.emissiveColor;
+ global_material.texMulAdd = material.texMulAdd;
+ global_material.roughness = material.roughness;
+ global_material.reflectance = material.reflectance;
+ global_material.metalness = material.metalness;
+ global_material.refractionIndex = material.refractionIndex;
+ global_material.subsurfaceScattering = material.subsurfaceScattering;
+ global_material.normalMapStrength = material.normalMapStrength;
+ global_material.normalMapFlip = (material._flags & MaterialComponent::FLIP_NORMALMAP ? -1.0f : 1.0f);
+ global_material.parallaxOcclusionMapping = material.parallaxOcclusionMapping;
+ global_material.g_xMat_useVertexColors = material.IsUsingVertexColors() ? 1 : 0;
+
+ // Add extended properties:
+ const TextureDesc& desc = globalMaterialAtlas.GetDesc();
+ rect_xywh rect;
+
+
+ if (material.GetBaseColorMap() != nullptr)
+ {
+ rect = storedTextures[material.GetBaseColorMap()];
+ }
+ else
+ {
+ rect = storedTextures[wiTextureHelper::getWhite()];
+ }
+ // eliminate border expansion:
+ rect.x += atlasWrapBorder;
+ rect.y += atlasWrapBorder;
+ rect.w -= atlasWrapBorder * 2;
+ rect.h -= atlasWrapBorder * 2;
+ global_material.baseColorAtlasMulAdd = XMFLOAT4((float)rect.w / (float)desc.Width, (float)rect.h / (float)desc.Height,
+ (float)rect.x / (float)desc.Width, (float)rect.y / (float)desc.Height);
+
+
+
+ if (material.GetSurfaceMap() != nullptr)
+ {
+ rect = storedTextures[material.GetSurfaceMap()];
+ }
+ else
+ {
+ rect = storedTextures[wiTextureHelper::getWhite()];
+ }
+ // eliminate border expansion:
+ rect.x += atlasWrapBorder;
+ rect.y += atlasWrapBorder;
+ rect.w -= atlasWrapBorder * 2;
+ rect.h -= atlasWrapBorder * 2;
+ global_material.surfaceMapAtlasMulAdd = XMFLOAT4((float)rect.w / (float)desc.Width, (float)rect.h / (float)desc.Height,
+ (float)rect.x / (float)desc.Width, (float)rect.y / (float)desc.Height);
+
+
+
+ if (material.GetEmissiveMap() != nullptr)
+ {
+ rect = storedTextures[material.GetEmissiveMap()];
+ }
+ else
+ {
+
+ rect = storedTextures[wiTextureHelper::getWhite()];
+ }
+ // eliminate border expansion:
+ rect.x += atlasWrapBorder;
+ rect.y += atlasWrapBorder;
+ rect.w -= atlasWrapBorder * 2;
+ rect.h -= atlasWrapBorder * 2;
+ global_material.emissiveMapAtlasMulAdd = XMFLOAT4((float)rect.w / (float)desc.Width, (float)rect.h / (float)desc.Height,
+ (float)rect.x / (float)desc.Width, (float)rect.y / (float)desc.Height);
+
+ materialArray.push_back(global_material);
+ }
+ }
+ }
+
+ if (materialArray.empty())
+ {
+ return;
+ }
+
+ if (globalMaterialBuffer.GetDesc().ByteWidth != sizeof(TracedRenderingMaterial) * materialArray.size())
+ {
+ GPUBufferDesc desc;
+ HRESULT hr;
+
+ desc.BindFlags = BIND_SHADER_RESOURCE;
+ desc.StructureByteStride = sizeof(TracedRenderingMaterial);
+ desc.ByteWidth = desc.StructureByteStride * (UINT)materialArray.size();
+ desc.CPUAccessFlags = 0;
+ desc.Format = FORMAT_UNKNOWN;
+ desc.MiscFlags = RESOURCE_MISC_BUFFER_STRUCTURED;
+ desc.Usage = USAGE_DEFAULT;
+
+ hr = device->CreateBuffer(&desc, nullptr, &globalMaterialBuffer);
+ assert(SUCCEEDED(hr));
+ }
+ device->UpdateBuffer(&globalMaterialBuffer, materialArray.data(), threadID, sizeof(TracedRenderingMaterial) * (int)materialArray.size());
+
+}
+
//#define BVH_VALIDATE // slow but great for debug!
void wiGPUBVH::Build(const Scene& scene, GRAPHICSTHREAD threadID)
{
@@ -205,6 +417,8 @@ void wiGPUBVH::Build(const Scene& scene, GRAPHICSTHREAD threadID)
wiProfiler::BeginRange("BVH Rebuild", wiProfiler::DOMAIN_GPU, threadID);
+ UpdateGlobalMaterialResources(scene, threadID);
+
device->EventBegin("BVH - Reset", threadID);
{
device->BindComputePSO(&CPSO[CSTYPE_BVH_RESET], threadID);
@@ -247,6 +461,7 @@ void wiGPUBVH::Build(const Scene& scene, GRAPHICSTHREAD threadID)
BVHCB cb;
cb.xTraceBVHWorld = object.transform_index >= 0 ? scene.transforms[object.transform_index].world : IDENTITYMATRIX;
+ cb.xTraceBVHInstanceColor = object.color;
cb.xTraceBVHMaterialOffset = materialCount;
cb.xTraceBVHMeshTriangleOffset = triangleCount;
cb.xTraceBVHMeshTriangleCount = (uint)mesh.indices.size() / 3;
@@ -259,9 +474,11 @@ void wiGPUBVH::Build(const Scene& scene, GRAPHICSTHREAD threadID)
device->BindConstantBuffer(CS, &constantBuffer, CB_GETBINDSLOT(BVHCB), threadID);
GPUResource* res[] = {
+ &globalMaterialBuffer,
mesh.indexBuffer.get(),
mesh.vertexBuffer_POS.get(),
mesh.vertexBuffer_TEX.get(),
+ mesh.vertexBuffer_COL.get(),
};
device->BindResources(CS, res, TEXSLOT_ONDEMAND0, ARRAYSIZE(res), threadID);
@@ -472,6 +689,8 @@ void wiGPUBVH::Bind(SHADERSTAGE stage, GRAPHICSTHREAD threadID) const
GraphicsDevice* device = wiRenderer::GetDevice();
const GPUResource* res[] = {
+ &globalMaterialBuffer,
+ (globalMaterialAtlas.IsValid() ? &globalMaterialAtlas : wiTextureHelper::getWhite()),
&triangleBuffer,
&clusterCounterBuffer,
&clusterIndexBuffer,
@@ -480,7 +699,7 @@ void wiGPUBVH::Bind(SHADERSTAGE stage, GRAPHICSTHREAD threadID) const
&bvhNodeBuffer,
&bvhAABBBuffer,
};
- device->BindResources(stage, res, TEXSLOT_ONDEMAND1, ARRAYSIZE(res), threadID);
+ device->BindResources(stage, res, TEXSLOT_ONDEMAND0, ARRAYSIZE(res), threadID);
}
diff --git a/WickedEngine/wiGPUBVH.h b/WickedEngine/wiGPUBVH.h
index 3cac56c2d..e6664c3f9 100644
--- a/WickedEngine/wiGPUBVH.h
+++ b/WickedEngine/wiGPUBVH.h
@@ -4,12 +4,17 @@
#include "CommonInclude.h"
#include "wiGraphicsDevice.h"
#include "wiSceneSystem_Decl.h"
+#include "wiRectPacker.h"
+#include "ShaderInterop_TracedRendering.h"
-#include
+#include
+#include
+#include
class wiGPUBVH
{
private:
+ // Scene BVH intersection resources:
wiGraphics::GPUBuffer bvhNodeBuffer;
wiGraphics::GPUBuffer bvhAABBBuffer;
wiGraphics::GPUBuffer bvhFlagBuffer;
@@ -24,6 +29,14 @@ private:
uint32_t maxTriangleCount = 0;
uint32_t maxClusterCount = 0;
+ // Scene material resources:
+ wiGraphics::GPUBuffer globalMaterialBuffer;
+ wiGraphics::Texture2D globalMaterialAtlas;
+ std::vector materialArray;
+ std::unordered_map storedTextures;
+ std::unordered_set sceneTextures;
+ void UpdateGlobalMaterialResources(const wiSceneSystem::Scene& scene, GRAPHICSTHREAD threadID);
+
public:
void Build(const wiSceneSystem::Scene& scene, GRAPHICSTHREAD threadID);
void Bind(wiGraphics::SHADERSTAGE stage, GRAPHICSTHREAD threadID) const;
diff --git a/WickedEngine/wiGraphicsDevice_DX11.cpp b/WickedEngine/wiGraphicsDevice_DX11.cpp
index 65ecf395d..100252f82 100644
--- a/WickedEngine/wiGraphicsDevice_DX11.cpp
+++ b/WickedEngine/wiGraphicsDevice_DX11.cpp
@@ -3345,8 +3345,8 @@ void GraphicsDevice_DX11::BindResource(SHADERSTAGE stage, const GPUResource* res
}
void GraphicsDevice_DX11::BindResources(SHADERSTAGE stage, const GPUResource *const* resources, UINT slot, UINT count, GRAPHICSTHREAD threadID)
{
- assert(count <= 8);
- ID3D11ShaderResourceView* srvs[8];
+ assert(count <= 16);
+ ID3D11ShaderResourceView* srvs[16];
for (UINT i = 0; i < count; ++i)
{
srvs[i] = resources[i] != nullptr ? (ID3D11ShaderResourceView*)resources[i]->SRV : nullptr;
diff --git a/WickedEngine/wiImage.cpp b/WickedEngine/wiImage.cpp
index ba9c1c063..bbed377cd 100644
--- a/WickedEngine/wiImage.cpp
+++ b/WickedEngine/wiImage.cpp
@@ -293,8 +293,6 @@ namespace wiImage
break;
case wiImageParams::PostProcess::COLORGRADE:
break;
- case wiImageParams::PostProcess::STEREOGRAM:
- break;
case wiImageParams::PostProcess::TONEMAP:
prcb.xPPParams0.x = params.process.params.exposure;
device->UpdateBuffer(&processCb, &prcb, threadID);
@@ -389,7 +387,6 @@ namespace wiImage
postprocessPS[wiImageParams::PostProcess::LINEARDEPTH] = static_cast(wiResourceManager::GetShaderManager().add(path + "linDepthPS.cso", wiResourceManager::PIXELSHADER));
postprocessPS[wiImageParams::PostProcess::COLORGRADE] = static_cast(wiResourceManager::GetShaderManager().add(path + "colorGradePS.cso", wiResourceManager::PIXELSHADER));
postprocessPS[wiImageParams::PostProcess::SSR] = static_cast(wiResourceManager::GetShaderManager().add(path + "ssr.cso", wiResourceManager::PIXELSHADER));
- postprocessPS[wiImageParams::PostProcess::STEREOGRAM] = static_cast(wiResourceManager::GetShaderManager().add(path + "stereogramPS.cso", wiResourceManager::PIXELSHADER));
postprocessPS[wiImageParams::PostProcess::TONEMAP] = static_cast(wiResourceManager::GetShaderManager().add(path + "toneMapPS.cso", wiResourceManager::PIXELSHADER));
postprocessPS[wiImageParams::PostProcess::REPROJECTDEPTHBUFFER] = static_cast(wiResourceManager::GetShaderManager().add(path + "reprojectDepthBufferPS.cso", wiResourceManager::PIXELSHADER));
postprocessPS[wiImageParams::PostProcess::DOWNSAMPLEDEPTHBUFFER] = static_cast(wiResourceManager::GetShaderManager().add(path + "downsampleDepthBuffer4xPS.cso", wiResourceManager::PIXELSHADER));
diff --git a/WickedEngine/wiImage.h b/WickedEngine/wiImage.h
index 713af1a38..f436b8f85 100644
--- a/WickedEngine/wiImage.h
+++ b/WickedEngine/wiImage.h
@@ -112,7 +112,6 @@ struct wiImageParams
SSSS,
SSR,
COLORGRADE,
- STEREOGRAM,
TONEMAP,
REPROJECTDEPTHBUFFER,
DOWNSAMPLEDEPTHBUFFER,
@@ -171,7 +170,6 @@ struct wiImageParams
void setColorGrade() { type = COLORGRADE; }
void setSSSS(const XMFLOAT2& value) { type = SSSS; params.ssss.x = value.x; params.ssss.y = value.y; }
void setSSR() { type = SSR; }
- void setStereogram() { type = STEREOGRAM; }
void setToneMap(float exposure) { type = TONEMAP; params.exposure = exposure; }
void setDepthBufferReprojection() { type = REPROJECTDEPTHBUFFER; }
void setDepthBufferDownsampling() { type = DOWNSAMPLEDEPTHBUFFER; }
diff --git a/WickedEngine/wiRenderer.cpp b/WickedEngine/wiRenderer.cpp
index adcbd945d..5052c9207 100644
--- a/WickedEngine/wiRenderer.cpp
+++ b/WickedEngine/wiRenderer.cpp
@@ -282,13 +282,13 @@ GFX_STRUCT Instance
XMFLOAT4A mat0;
XMFLOAT4A mat1;
XMFLOAT4A mat2;
- XMFLOAT4A color_dither; //rgb:color, a:dither
+ XMFLOAT4A color;
Instance(){}
- Instance(const XMFLOAT4X4& matIn, const XMFLOAT4& color = XMFLOAT4(1, 1, 1, 1), float dither = 0){
- Create(matIn, color, dither);
+ Instance(const XMFLOAT4X4& matIn, const XMFLOAT4& colorIn = XMFLOAT4(1, 1, 1, 1), float dither = 0){
+ Create(matIn, colorIn, dither);
}
- inline void Create(const XMFLOAT4X4& matIn, const XMFLOAT4& color = XMFLOAT4(1, 1, 1, 1), float dither = 0) volatile
+ inline void Create(const XMFLOAT4X4& matIn, const XMFLOAT4& colorIn = XMFLOAT4(1, 1, 1, 1), float dither = 0) volatile
{
mat0.x = matIn._11;
mat0.y = matIn._21;
@@ -305,10 +305,12 @@ GFX_STRUCT Instance
mat2.z = matIn._33;
mat2.w = matIn._43;
- color_dither.x = color.x;
- color_dither.y = color.y;
- color_dither.z = color.z;
- color_dither.w = dither;
+ color.x = colorIn.x;
+ color.y = colorIn.y;
+ color.z = colorIn.z;
+ color.w = colorIn.w;
+
+ color.w *= 1 - dither;
}
ALIGN_16
@@ -1664,6 +1666,7 @@ void RenderMeshes(const RenderQueue& renderQueue, RENDERPASS renderPass, UINT re
mesh.streamoutBuffer_POS.get() != nullptr ? mesh.streamoutBuffer_POS.get() : mesh.vertexBuffer_POS.get(),
mesh.vertexBuffer_TEX.get(),
mesh.vertexBuffer_ATL.get(),
+ mesh.vertexBuffer_COL.get(),
mesh.vertexBuffer_PRE.get() != nullptr ? mesh.vertexBuffer_PRE.get() : mesh.vertexBuffer_POS.get(),
instances.buffer
};
@@ -1671,6 +1674,7 @@ void RenderMeshes(const RenderQueue& renderQueue, RENDERPASS renderPass, UINT re
sizeof(MeshComponent::Vertex_POS),
sizeof(MeshComponent::Vertex_TEX),
sizeof(MeshComponent::Vertex_TEX),
+ sizeof(MeshComponent::Vertex_COL),
sizeof(MeshComponent::Vertex_POS),
instanceDataSize
};
@@ -1679,6 +1683,7 @@ void RenderMeshes(const RenderQueue& renderQueue, RENDERPASS renderPass, UINT re
0,
0,
0,
+ 0,
instancedBatch.dataOffset
};
device->BindVertexBuffers(vbs, 0, ARRAYSIZE(vbs), strides, offsets, threadID);
@@ -1694,6 +1699,7 @@ void RenderMeshes(const RenderQueue& renderQueue, RENDERPASS renderPass, UINT re
device->BindStencilRef(material.GetStencilRef(), threadID);
device->BindGraphicsPSO(pso, threadID);
+ device->BindConstantBuffer(VS, material.constantBuffer.get(), CB_GETBINDSLOT(MaterialCB), threadID);
device->BindConstantBuffer(PS, material.constantBuffer.get(), CB_GETBINDSLOT(MaterialCB), threadID);
const GPUResource* res[] = {
@@ -1818,16 +1824,17 @@ void LoadShaders()
{ "POSITION_NORMAL_SUBSETINDEX", 0, MeshComponent::Vertex_POS::FORMAT, 0, VertexLayoutDesc::APPEND_ALIGNED_ELEMENT, INPUT_PER_VERTEX_DATA, 0 },
{ "TEXCOORD", 0, MeshComponent::Vertex_TEX::FORMAT, 1, VertexLayoutDesc::APPEND_ALIGNED_ELEMENT, INPUT_PER_VERTEX_DATA, 0 },
{ "ATLAS", 0, MeshComponent::Vertex_TEX::FORMAT, 2, VertexLayoutDesc::APPEND_ALIGNED_ELEMENT, INPUT_PER_VERTEX_DATA, 0 },
- { "PREVPOS", 0, MeshComponent::Vertex_POS::FORMAT, 3, VertexLayoutDesc::APPEND_ALIGNED_ELEMENT, INPUT_PER_VERTEX_DATA, 0 },
+ { "COLOR", 0, MeshComponent::Vertex_COL::FORMAT, 3, VertexLayoutDesc::APPEND_ALIGNED_ELEMENT, INPUT_PER_VERTEX_DATA, 0 },
+ { "PREVPOS", 0, MeshComponent::Vertex_POS::FORMAT, 4, VertexLayoutDesc::APPEND_ALIGNED_ELEMENT, INPUT_PER_VERTEX_DATA, 0 },
- { "MATI", 0, FORMAT_R32G32B32A32_FLOAT, 4, VertexLayoutDesc::APPEND_ALIGNED_ELEMENT, INPUT_PER_INSTANCE_DATA, 1 },
- { "MATI", 1, FORMAT_R32G32B32A32_FLOAT, 4, VertexLayoutDesc::APPEND_ALIGNED_ELEMENT, INPUT_PER_INSTANCE_DATA, 1 },
- { "MATI", 2, FORMAT_R32G32B32A32_FLOAT, 4, VertexLayoutDesc::APPEND_ALIGNED_ELEMENT, INPUT_PER_INSTANCE_DATA, 1 },
- { "COLOR_DITHER", 0, FORMAT_R32G32B32A32_FLOAT, 4, VertexLayoutDesc::APPEND_ALIGNED_ELEMENT, INPUT_PER_INSTANCE_DATA, 1 },
- { "MATIPREV", 0, FORMAT_R32G32B32A32_FLOAT, 4, VertexLayoutDesc::APPEND_ALIGNED_ELEMENT, INPUT_PER_INSTANCE_DATA, 1 },
- { "MATIPREV", 1, FORMAT_R32G32B32A32_FLOAT, 4, VertexLayoutDesc::APPEND_ALIGNED_ELEMENT, INPUT_PER_INSTANCE_DATA, 1 },
- { "MATIPREV", 2, FORMAT_R32G32B32A32_FLOAT, 4, VertexLayoutDesc::APPEND_ALIGNED_ELEMENT, INPUT_PER_INSTANCE_DATA, 1 },
- { "INSTANCEATLAS", 0, FORMAT_R32G32B32A32_FLOAT, 4, VertexLayoutDesc::APPEND_ALIGNED_ELEMENT, INPUT_PER_INSTANCE_DATA, 1 },
+ { "INSTANCEMATRIX", 0, FORMAT_R32G32B32A32_FLOAT, 5, VertexLayoutDesc::APPEND_ALIGNED_ELEMENT, INPUT_PER_INSTANCE_DATA, 1 },
+ { "INSTANCEMATRIX", 1, FORMAT_R32G32B32A32_FLOAT, 5, VertexLayoutDesc::APPEND_ALIGNED_ELEMENT, INPUT_PER_INSTANCE_DATA, 1 },
+ { "INSTANCEMATRIX", 2, FORMAT_R32G32B32A32_FLOAT, 5, VertexLayoutDesc::APPEND_ALIGNED_ELEMENT, INPUT_PER_INSTANCE_DATA, 1 },
+ { "INSTANCECOLOR", 0, FORMAT_R32G32B32A32_FLOAT, 5, VertexLayoutDesc::APPEND_ALIGNED_ELEMENT, INPUT_PER_INSTANCE_DATA, 1 },
+ { "INSTANCEMATRIXPREV", 0, FORMAT_R32G32B32A32_FLOAT, 5, VertexLayoutDesc::APPEND_ALIGNED_ELEMENT, INPUT_PER_INSTANCE_DATA, 1 },
+ { "INSTANCEMATRIXPREV", 1, FORMAT_R32G32B32A32_FLOAT, 5, VertexLayoutDesc::APPEND_ALIGNED_ELEMENT, INPUT_PER_INSTANCE_DATA, 1 },
+ { "INSTANCEMATRIXPREV", 2, FORMAT_R32G32B32A32_FLOAT, 5, VertexLayoutDesc::APPEND_ALIGNED_ELEMENT, INPUT_PER_INSTANCE_DATA, 1 },
+ { "INSTANCEATLAS", 0, FORMAT_R32G32B32A32_FLOAT, 5, VertexLayoutDesc::APPEND_ALIGNED_ELEMENT, INPUT_PER_INSTANCE_DATA, 1 },
};
vertexShaders[VSTYPE_OBJECT_COMMON] = static_cast(wiResourceManager::GetShaderManager().add(SHADERPATH + "objectVS_common.cso", wiResourceManager::VERTEXSHADER));
device->CreateInputLayout(layout, ARRAYSIZE(layout), &vertexShaders[VSTYPE_OBJECT_COMMON]->code, &vertexLayouts[VLTYPE_OBJECT_ALL]);
@@ -1838,10 +1845,10 @@ void LoadShaders()
{
{ "POSITION_NORMAL_SUBSETINDEX", 0, MeshComponent::Vertex_POS::FORMAT, 0, VertexLayoutDesc::APPEND_ALIGNED_ELEMENT, INPUT_PER_VERTEX_DATA, 0 },
- { "MATI", 0, FORMAT_R32G32B32A32_FLOAT, 1, VertexLayoutDesc::APPEND_ALIGNED_ELEMENT, INPUT_PER_INSTANCE_DATA, 1 },
- { "MATI", 1, FORMAT_R32G32B32A32_FLOAT, 1, VertexLayoutDesc::APPEND_ALIGNED_ELEMENT, INPUT_PER_INSTANCE_DATA, 1 },
- { "MATI", 2, FORMAT_R32G32B32A32_FLOAT, 1, VertexLayoutDesc::APPEND_ALIGNED_ELEMENT, INPUT_PER_INSTANCE_DATA, 1 },
- { "COLOR_DITHER", 0, FORMAT_R32G32B32A32_FLOAT, 1, VertexLayoutDesc::APPEND_ALIGNED_ELEMENT, INPUT_PER_INSTANCE_DATA, 1 },
+ { "INSTANCEMATRIX", 0, FORMAT_R32G32B32A32_FLOAT, 1, VertexLayoutDesc::APPEND_ALIGNED_ELEMENT, INPUT_PER_INSTANCE_DATA, 1 },
+ { "INSTANCEMATRIX", 1, FORMAT_R32G32B32A32_FLOAT, 1, VertexLayoutDesc::APPEND_ALIGNED_ELEMENT, INPUT_PER_INSTANCE_DATA, 1 },
+ { "INSTANCEMATRIX", 2, FORMAT_R32G32B32A32_FLOAT, 1, VertexLayoutDesc::APPEND_ALIGNED_ELEMENT, INPUT_PER_INSTANCE_DATA, 1 },
+ { "INSTANCECOLOR", 0, FORMAT_R32G32B32A32_FLOAT, 1, VertexLayoutDesc::APPEND_ALIGNED_ELEMENT, INPUT_PER_INSTANCE_DATA, 1 },
};
vertexShaders[VSTYPE_OBJECT_POSITIONSTREAM] = static_cast(wiResourceManager::GetShaderManager().add(SHADERPATH + "objectVS_positionstream.cso", wiResourceManager::VERTEXSHADER));
device->CreateInputLayout(layout, ARRAYSIZE(layout), &vertexShaders[VSTYPE_OBJECT_POSITIONSTREAM]->code, &vertexLayouts[VLTYPE_OBJECT_POS]);
@@ -1853,10 +1860,10 @@ void LoadShaders()
{ "POSITION_NORMAL_SUBSETINDEX", 0, MeshComponent::Vertex_POS::FORMAT, 0, VertexLayoutDesc::APPEND_ALIGNED_ELEMENT, INPUT_PER_VERTEX_DATA, 0 },
{ "TEXCOORD", 0, MeshComponent::Vertex_TEX::FORMAT, 1, VertexLayoutDesc::APPEND_ALIGNED_ELEMENT, INPUT_PER_VERTEX_DATA, 0 },
- { "MATI", 0, FORMAT_R32G32B32A32_FLOAT, 2, VertexLayoutDesc::APPEND_ALIGNED_ELEMENT, INPUT_PER_INSTANCE_DATA, 1 },
- { "MATI", 1, FORMAT_R32G32B32A32_FLOAT, 2, VertexLayoutDesc::APPEND_ALIGNED_ELEMENT, INPUT_PER_INSTANCE_DATA, 1 },
- { "MATI", 2, FORMAT_R32G32B32A32_FLOAT, 2, VertexLayoutDesc::APPEND_ALIGNED_ELEMENT, INPUT_PER_INSTANCE_DATA, 1 },
- { "COLOR_DITHER", 0, FORMAT_R32G32B32A32_FLOAT, 2, VertexLayoutDesc::APPEND_ALIGNED_ELEMENT, INPUT_PER_INSTANCE_DATA, 1 },
+ { "INSTANCEMATRIX", 0, FORMAT_R32G32B32A32_FLOAT, 2, VertexLayoutDesc::APPEND_ALIGNED_ELEMENT, INPUT_PER_INSTANCE_DATA, 1 },
+ { "INSTANCEMATRIX", 1, FORMAT_R32G32B32A32_FLOAT, 2, VertexLayoutDesc::APPEND_ALIGNED_ELEMENT, INPUT_PER_INSTANCE_DATA, 1 },
+ { "INSTANCEMATRIX", 2, FORMAT_R32G32B32A32_FLOAT, 2, VertexLayoutDesc::APPEND_ALIGNED_ELEMENT, INPUT_PER_INSTANCE_DATA, 1 },
+ { "INSTANCECOLOR", 0, FORMAT_R32G32B32A32_FLOAT, 2, VertexLayoutDesc::APPEND_ALIGNED_ELEMENT, INPUT_PER_INSTANCE_DATA, 1 },
};
vertexShaders[VSTYPE_OBJECT_SIMPLE] = static_cast(wiResourceManager::GetShaderManager().add(SHADERPATH + "objectVS_simple.cso", wiResourceManager::VERTEXSHADER));
device->CreateInputLayout(layout, ARRAYSIZE(layout), &vertexShaders[VSTYPE_OBJECT_SIMPLE]->code, &vertexLayouts[VLTYPE_OBJECT_POS_TEX]);
@@ -1867,10 +1874,10 @@ void LoadShaders()
{
{ "POSITION_NORMAL_SUBSETINDEX", 0, MeshComponent::Vertex_POS::FORMAT, 0, VertexLayoutDesc::APPEND_ALIGNED_ELEMENT, INPUT_PER_VERTEX_DATA, 0 },
- { "MATI", 0, FORMAT_R32G32B32A32_FLOAT, 1, VertexLayoutDesc::APPEND_ALIGNED_ELEMENT, INPUT_PER_INSTANCE_DATA, 1 },
- { "MATI", 1, FORMAT_R32G32B32A32_FLOAT, 1, VertexLayoutDesc::APPEND_ALIGNED_ELEMENT, INPUT_PER_INSTANCE_DATA, 1 },
- { "MATI", 2, FORMAT_R32G32B32A32_FLOAT, 1, VertexLayoutDesc::APPEND_ALIGNED_ELEMENT, INPUT_PER_INSTANCE_DATA, 1 },
- { "COLOR_DITHER", 0, FORMAT_R32G32B32A32_FLOAT, 1, VertexLayoutDesc::APPEND_ALIGNED_ELEMENT, INPUT_PER_INSTANCE_DATA, 1 },
+ { "INSTANCEMATRIX", 0, FORMAT_R32G32B32A32_FLOAT, 1, VertexLayoutDesc::APPEND_ALIGNED_ELEMENT, INPUT_PER_INSTANCE_DATA, 1 },
+ { "INSTANCEMATRIX", 1, FORMAT_R32G32B32A32_FLOAT, 1, VertexLayoutDesc::APPEND_ALIGNED_ELEMENT, INPUT_PER_INSTANCE_DATA, 1 },
+ { "INSTANCEMATRIX", 2, FORMAT_R32G32B32A32_FLOAT, 1, VertexLayoutDesc::APPEND_ALIGNED_ELEMENT, INPUT_PER_INSTANCE_DATA, 1 },
+ { "INSTANCECOLOR", 0, FORMAT_R32G32B32A32_FLOAT, 1, VertexLayoutDesc::APPEND_ALIGNED_ELEMENT, INPUT_PER_INSTANCE_DATA, 1 },
};
vertexShaders[VSTYPE_SHADOW] = static_cast(wiResourceManager::GetShaderManager().add(SHADERPATH + "shadowVS.cso", wiResourceManager::VERTEXSHADER));
device->CreateInputLayout(layout, ARRAYSIZE(layout), &vertexShaders[VSTYPE_SHADOW]->code, &vertexLayouts[VLTYPE_SHADOW_POS]);
@@ -1882,10 +1889,10 @@ void LoadShaders()
{ "POSITION_NORMAL_SUBSETINDEX", 0, MeshComponent::Vertex_POS::FORMAT, 0, VertexLayoutDesc::APPEND_ALIGNED_ELEMENT, INPUT_PER_VERTEX_DATA, 0 },
{ "TEXCOORD", 0, MeshComponent::Vertex_TEX::FORMAT, 1, VertexLayoutDesc::APPEND_ALIGNED_ELEMENT, INPUT_PER_VERTEX_DATA, 0 },
- { "MATI", 0, FORMAT_R32G32B32A32_FLOAT, 2, VertexLayoutDesc::APPEND_ALIGNED_ELEMENT, INPUT_PER_INSTANCE_DATA, 1 },
- { "MATI", 1, FORMAT_R32G32B32A32_FLOAT, 2, VertexLayoutDesc::APPEND_ALIGNED_ELEMENT, INPUT_PER_INSTANCE_DATA, 1 },
- { "MATI", 2, FORMAT_R32G32B32A32_FLOAT, 2, VertexLayoutDesc::APPEND_ALIGNED_ELEMENT, INPUT_PER_INSTANCE_DATA, 1 },
- { "COLOR_DITHER", 0, FORMAT_R32G32B32A32_FLOAT, 2, VertexLayoutDesc::APPEND_ALIGNED_ELEMENT, INPUT_PER_INSTANCE_DATA, 1 },
+ { "INSTANCEMATRIX", 0, FORMAT_R32G32B32A32_FLOAT, 2, VertexLayoutDesc::APPEND_ALIGNED_ELEMENT, INPUT_PER_INSTANCE_DATA, 1 },
+ { "INSTANCEMATRIX", 1, FORMAT_R32G32B32A32_FLOAT, 2, VertexLayoutDesc::APPEND_ALIGNED_ELEMENT, INPUT_PER_INSTANCE_DATA, 1 },
+ { "INSTANCEMATRIX", 2, FORMAT_R32G32B32A32_FLOAT, 2, VertexLayoutDesc::APPEND_ALIGNED_ELEMENT, INPUT_PER_INSTANCE_DATA, 1 },
+ { "INSTANCECOLOR", 0, FORMAT_R32G32B32A32_FLOAT, 2, VertexLayoutDesc::APPEND_ALIGNED_ELEMENT, INPUT_PER_INSTANCE_DATA, 1 },
};
vertexShaders[VSTYPE_SHADOW_ALPHATEST] = static_cast(wiResourceManager::GetShaderManager().add(SHADERPATH + "shadowVS_alphatest.cso", wiResourceManager::VERTEXSHADER));
device->CreateInputLayout(layout, ARRAYSIZE(layout), &vertexShaders[VSTYPE_SHADOW_ALPHATEST]->code, &vertexLayouts[VLTYPE_SHADOW_POS_TEX]);
@@ -1922,11 +1929,11 @@ void LoadShaders()
VertexLayoutDesc layout[] =
{
{ "POSITION_NORMAL_SUBSETINDEX", 0, MeshComponent::Vertex_POS::FORMAT, 0, VertexLayoutDesc::APPEND_ALIGNED_ELEMENT, INPUT_PER_VERTEX_DATA, 0 },
- { "ATLAS", 0, MeshComponent::Vertex_TEX::FORMAT, 1, VertexLayoutDesc::APPEND_ALIGNED_ELEMENT, INPUT_PER_VERTEX_DATA, 0 },
+ { "ATLAS", 0, MeshComponent::Vertex_TEX::FORMAT, 1, VertexLayoutDesc::APPEND_ALIGNED_ELEMENT, INPUT_PER_VERTEX_DATA, 0 },
- { "MATIPREV", 0, FORMAT_R32G32B32A32_FLOAT, 2, VertexLayoutDesc::APPEND_ALIGNED_ELEMENT, INPUT_PER_INSTANCE_DATA, 1 },
- { "MATIPREV", 1, FORMAT_R32G32B32A32_FLOAT, 2, VertexLayoutDesc::APPEND_ALIGNED_ELEMENT, INPUT_PER_INSTANCE_DATA, 1 },
- { "MATIPREV", 2, FORMAT_R32G32B32A32_FLOAT, 2, VertexLayoutDesc::APPEND_ALIGNED_ELEMENT, INPUT_PER_INSTANCE_DATA, 1 },
+ { "INSTANCEMATRIXPREV", 0, FORMAT_R32G32B32A32_FLOAT, 2, VertexLayoutDesc::APPEND_ALIGNED_ELEMENT, INPUT_PER_INSTANCE_DATA, 1 },
+ { "INSTANCEMATRIXPREV", 1, FORMAT_R32G32B32A32_FLOAT, 2, VertexLayoutDesc::APPEND_ALIGNED_ELEMENT, INPUT_PER_INSTANCE_DATA, 1 },
+ { "INSTANCEMATRIXPREV", 2, FORMAT_R32G32B32A32_FLOAT, 2, VertexLayoutDesc::APPEND_ALIGNED_ELEMENT, INPUT_PER_INSTANCE_DATA, 1 },
};
vertexShaders[VSTYPE_RENDERLIGHTMAP] = static_cast(wiResourceManager::GetShaderManager().add(SHADERPATH + "renderlightmapVS.cso", wiResourceManager::VERTEXSHADER));
device->CreateInputLayout(layout, ARRAYSIZE(layout), &vertexShaders[VSTYPE_RENDERLIGHTMAP]->code, &vertexLayouts[VLTYPE_RENDERLIGHTMAP]);
@@ -3773,6 +3780,7 @@ void UpdateRenderData(GRAPHICSTHREAD threadID)
materialGPUData.g_xMat_normalMapStrength = (material.normalMap == nullptr ? 0 : material.normalMapStrength);
materialGPUData.g_xMat_normalMapFlip = (material._flags & MaterialComponent::FLIP_NORMALMAP ? -1.0f : 1.0f);
materialGPUData.g_xMat_parallaxOcclusionMapping = material.parallaxOcclusionMapping;
+ materialGPUData.g_xMat_useVertexColors = material.IsUsingVertexColors() ? 1 : 0;
device->UpdateBuffer(material.constantBuffer.get(), &materialGPUData, threadID);
}
@@ -5305,6 +5313,75 @@ void DrawDebugWorld(const CameraComponent& camera, GRAPHICSTHREAD threadID)
device->EventBegin("DrawDebugWorld", threadID);
+ if (debugPartitionTree)
+ {
+ // Actually, there is no SPTree any more, so this will just render all aabbs...
+ device->EventBegin("DebugPartitionTree", threadID);
+
+ device->BindGraphicsPSO(&PSO_debug[DEBUGRENDERING_CUBE], threadID);
+
+ GPUBuffer* vbs[] = {
+ wiCube::GetVertexBuffer(),
+ };
+ const UINT strides[] = {
+ sizeof(XMFLOAT4) + sizeof(XMFLOAT4),
+ };
+ device->BindVertexBuffers(vbs, 0, ARRAYSIZE(vbs), strides, nullptr, threadID);
+ device->BindIndexBuffer(wiCube::GetIndexBuffer(), INDEXFORMAT_16BIT, 0, threadID);
+
+ MiscCB sb;
+
+ for (size_t i = 0; i < scene.aabb_objects.GetCount(); ++i)
+ {
+ const AABB& aabb = scene.aabb_objects[i];
+
+ XMStoreFloat4x4(&sb.g_xTransform, XMMatrixTranspose(aabb.getAsBoxMatrix()*camera.GetViewProjection()));
+ sb.g_xColor = XMFLOAT4(1, 0, 0, 1);
+
+ device->UpdateBuffer(&constantBuffers[CBTYPE_MISC], &sb, threadID);
+
+ device->DrawIndexed(24, 0, 0, threadID);
+ }
+
+ for (size_t i = 0; i < scene.aabb_lights.GetCount(); ++i)
+ {
+ const AABB& aabb = scene.aabb_lights[i];
+
+ XMStoreFloat4x4(&sb.g_xTransform, XMMatrixTranspose(aabb.getAsBoxMatrix()*camera.GetViewProjection()));
+ sb.g_xColor = XMFLOAT4(1, 1, 0, 1);
+
+ device->UpdateBuffer(&constantBuffers[CBTYPE_MISC], &sb, threadID);
+
+ device->DrawIndexed(24, 0, 0, threadID);
+ }
+
+ for (size_t i = 0; i < scene.aabb_decals.GetCount(); ++i)
+ {
+ const AABB& aabb = scene.aabb_decals[i];
+
+ XMStoreFloat4x4(&sb.g_xTransform, XMMatrixTranspose(aabb.getAsBoxMatrix()*camera.GetViewProjection()));
+ sb.g_xColor = XMFLOAT4(1, 0, 1, 1);
+
+ device->UpdateBuffer(&constantBuffers[CBTYPE_MISC], &sb, threadID);
+
+ device->DrawIndexed(24, 0, 0, threadID);
+ }
+
+ for (size_t i = 0; i < scene.aabb_probes.GetCount(); ++i)
+ {
+ const AABB& aabb = scene.aabb_probes[i];
+
+ XMStoreFloat4x4(&sb.g_xTransform, XMMatrixTranspose(aabb.getAsBoxMatrix()*camera.GetViewProjection()));
+ sb.g_xColor = XMFLOAT4(0, 1, 1, 1);
+
+ device->UpdateBuffer(&constantBuffers[CBTYPE_MISC], &sb, threadID);
+
+ device->DrawIndexed(24, 0, 0, threadID);
+ }
+
+ device->EventEnd(threadID);
+ }
+
if (debugBoneLines)
{
device->EventBegin("DebugBoneLines", threadID);
@@ -5347,6 +5424,8 @@ void DrawDebugWorld(const CameraComponent& camera, GRAPHICSTHREAD threadID)
LineSegment segment;
XMStoreFloat4(&segment.a, a);
XMStoreFloat4(&segment.b, b);
+ segment.colorA = XMFLOAT4(1, 1, 1, 1);
+ segment.colorB = XMFLOAT4(1, 0, 1, 1);
memcpy((void*)((size_t)mem.data + j * sizeof(LineSegment)), &segment, sizeof(LineSegment));
j++;
@@ -6240,6 +6319,7 @@ void RefreshImpostors(GRAPHICSTHREAD threadID)
mesh.IsSkinned() ? mesh.streamoutBuffer_POS.get() : mesh.vertexBuffer_POS.get(),
mesh.vertexBuffer_TEX.get(),
mesh.vertexBuffer_ATL.get(),
+ mesh.vertexBuffer_COL.get(),
mesh.IsSkinned() ? mesh.streamoutBuffer_POS.get() : mesh.vertexBuffer_POS.get(),
mem.buffer
};
@@ -6247,6 +6327,7 @@ void RefreshImpostors(GRAPHICSTHREAD threadID)
sizeof(MeshComponent::Vertex_POS),
sizeof(MeshComponent::Vertex_TEX),
sizeof(MeshComponent::Vertex_TEX),
+ sizeof(MeshComponent::Vertex_COL),
sizeof(MeshComponent::Vertex_POS),
sizeof(InstBuf)
};
@@ -6255,6 +6336,7 @@ void RefreshImpostors(GRAPHICSTHREAD threadID)
0,
0,
0,
+ 0,
mem.offset
};
device->BindVertexBuffers(vbs, 0, ARRAYSIZE(vbs), strides, offsets, threadID);
@@ -6317,6 +6399,7 @@ void RefreshImpostors(GRAPHICSTHREAD threadID)
}
const MaterialComponent& material = *scene.materials.GetComponent(subset.materialID);
+ device->BindConstantBuffer(VS, material.constantBuffer.get(), CB_GETBINDSLOT(MaterialCB), threadID);
device->BindConstantBuffer(PS, material.constantBuffer.get(), CB_GETBINDSLOT(MaterialCB), threadID);
const GPUResource* res[] = {
@@ -7028,226 +7111,6 @@ void CopyTexture2D(const Texture2D* dst, UINT DstMIP, UINT DstX, UINT DstY, cons
}
-// These will hold all materials in the scene, ready to be accessed randomly in shaders:
-std::unique_ptr globalMaterialBuffer;
-std::unique_ptr globalMaterialAtlas;
-void UpdateGlobalMaterialResources(GRAPHICSTHREAD threadID)
-{
- GraphicsDevice* device = GetDevice();
- const Scene& scene = GetScene();
-
- using namespace wiRectPacker;
- static unordered_set sceneTextures;
- if (sceneTextures.empty())
- {
- sceneTextures.insert(wiTextureHelper::getWhite());
- sceneTextures.insert(wiTextureHelper::getNormalMapDefault());
- }
-
- for (size_t i = 0; i < scene.objects.GetCount(); ++i)
- {
- const ObjectComponent& object = scene.objects[i];
-
- if (object.meshID != INVALID_ENTITY)
- {
- const MeshComponent& mesh = *scene.meshes.GetComponent(object.meshID);
-
- for (auto& subset : mesh.subsets)
- {
- const MaterialComponent& material = *scene.materials.GetComponent(subset.materialID);
-
- sceneTextures.insert(material.GetBaseColorMap());
- sceneTextures.insert(material.GetSurfaceMap());
- sceneTextures.insert(material.GetEmissiveMap());
- }
- }
-
- }
-
- bool repackAtlas = false;
- static unordered_map storedTextures;
- const int atlasWrapBorder = 1;
- for (const Texture2D* tex : sceneTextures)
- {
- if (tex == nullptr)
- {
- continue;
- }
-
- if (storedTextures.find(tex) == storedTextures.end())
- {
- // we need to pack this texture into the atlas
- rect_xywh newRect = rect_xywh(0, 0, tex->GetDesc().Width + atlasWrapBorder * 2, tex->GetDesc().Height + atlasWrapBorder * 2);
- storedTextures[tex] = newRect;
-
- repackAtlas = true;
- }
-
- }
-
- if (repackAtlas)
- {
- rect_xywh** out_rects = new rect_xywh*[storedTextures.size()];
- int i = 0;
- for (auto& it : storedTextures)
- {
- out_rects[i] = &it.second;
- i++;
- }
-
- std::vector bins;
- if (pack(out_rects, (int)storedTextures.size(), 16384, bins))
- {
- assert(bins.size() == 1 && "The regions won't fit into the texture!");
-
- TextureDesc desc;
- desc.Width = (UINT)bins[0].size.w;
- desc.Height = (UINT)bins[0].size.h;
- desc.MipLevels = 1;
- desc.ArraySize = 1;
- desc.Format = FORMAT_R8G8B8A8_UNORM;
- desc.SampleDesc.Count = 1;
- desc.SampleDesc.Quality = 0;
- desc.Usage = USAGE_DEFAULT;
- desc.BindFlags = BIND_SHADER_RESOURCE | BIND_UNORDERED_ACCESS;
- desc.CPUAccessFlags = 0;
- desc.MiscFlags = 0;
-
- globalMaterialAtlas.reset(new Texture2D);
- device->CreateTexture2D(&desc, nullptr, globalMaterialAtlas.get());
-
- for (auto& it : storedTextures)
- {
- CopyTexture2D(globalMaterialAtlas.get(), 0, it.second.x + atlasWrapBorder, it.second.y + atlasWrapBorder, it.first, 0, threadID, BORDEREXPAND_WRAP);
- }
- }
- else
- {
- wiBackLog::post("Tracing atlas packing failed!");
- }
-
- SAFE_DELETE_ARRAY(out_rects);
- }
-
- static std::vector materialArray;
- materialArray.clear();
-
- // Pre-gather scene properties:
- for (size_t i = 0; i < scene.objects.GetCount(); ++i)
- {
- const ObjectComponent& object = scene.objects[i];
-
- if (object.meshID != INVALID_ENTITY)
- {
- const MeshComponent& mesh = *scene.meshes.GetComponent(object.meshID);
-
- for (auto& subset : mesh.subsets)
- {
- const MaterialComponent& material = *scene.materials.GetComponent(subset.materialID);
-
- TracedRenderingMaterial global_material;
-
- // Copy base params:
- global_material.baseColor = material.baseColor;
- global_material.emissiveColor = material.emissiveColor;
- global_material.texMulAdd = material.texMulAdd;
- global_material.roughness = material.roughness;
- global_material.reflectance = material.reflectance;
- global_material.metalness = material.metalness;
- global_material.refractionIndex = material.refractionIndex;
- global_material.subsurfaceScattering = material.subsurfaceScattering;
- global_material.normalMapStrength = material.normalMapStrength;
- global_material.normalMapFlip = (material._flags & MaterialComponent::FLIP_NORMALMAP ? -1.0f : 1.0f);
- global_material.parallaxOcclusionMapping = material.parallaxOcclusionMapping;
-
- // Add extended properties:
- const TextureDesc& desc = globalMaterialAtlas->GetDesc();
- rect_xywh rect;
-
-
- if (material.GetBaseColorMap() != nullptr)
- {
- rect = storedTextures[material.GetBaseColorMap()];
- }
- else
- {
- rect = storedTextures[wiTextureHelper::getWhite()];
- }
- // eliminate border expansion:
- rect.x += atlasWrapBorder;
- rect.y += atlasWrapBorder;
- rect.w -= atlasWrapBorder * 2;
- rect.h -= atlasWrapBorder * 2;
- global_material.baseColorAtlasMulAdd = XMFLOAT4((float)rect.w / (float)desc.Width, (float)rect.h / (float)desc.Height,
- (float)rect.x / (float)desc.Width, (float)rect.y / (float)desc.Height);
-
-
-
- if (material.GetSurfaceMap() != nullptr)
- {
- rect = storedTextures[material.GetSurfaceMap()];
- }
- else
- {
- rect = storedTextures[wiTextureHelper::getWhite()];
- }
- // eliminate border expansion:
- rect.x += atlasWrapBorder;
- rect.y += atlasWrapBorder;
- rect.w -= atlasWrapBorder * 2;
- rect.h -= atlasWrapBorder * 2;
- global_material.surfaceMapAtlasMulAdd = XMFLOAT4((float)rect.w / (float)desc.Width, (float)rect.h / (float)desc.Height,
- (float)rect.x / (float)desc.Width, (float)rect.y / (float)desc.Height);
-
-
-
- if (material.GetEmissiveMap() != nullptr)
- {
- rect = storedTextures[material.GetEmissiveMap()];
- }
- else
- {
-
- rect = storedTextures[wiTextureHelper::getWhite()];
- }
- // eliminate border expansion:
- rect.x += atlasWrapBorder;
- rect.y += atlasWrapBorder;
- rect.w -= atlasWrapBorder * 2;
- rect.h -= atlasWrapBorder * 2;
- global_material.emissiveMapAtlasMulAdd = XMFLOAT4((float)rect.w / (float)desc.Width, (float)rect.h / (float)desc.Height,
- (float)rect.x / (float)desc.Width, (float)rect.y / (float)desc.Height);
-
- materialArray.push_back(global_material);
- }
- }
- }
-
- if (materialArray.empty())
- {
- return;
- }
-
- if (globalMaterialBuffer == nullptr || globalMaterialBuffer->GetDesc().ByteWidth != sizeof(TracedRenderingMaterial) * materialArray.size())
- {
- GPUBufferDesc desc;
- HRESULT hr;
-
- desc.BindFlags = BIND_SHADER_RESOURCE;
- desc.StructureByteStride = sizeof(TracedRenderingMaterial);
- desc.ByteWidth = desc.StructureByteStride * (UINT)materialArray.size();
- desc.CPUAccessFlags = 0;
- desc.Format = FORMAT_UNKNOWN;
- desc.MiscFlags = RESOURCE_MISC_BUFFER_STRUCTURED;
- desc.Usage = USAGE_DEFAULT;
-
- globalMaterialBuffer.reset(new GPUBuffer);
- hr = device->CreateBuffer(&desc, nullptr, globalMaterialBuffer.get());
- assert(SUCCEEDED(hr));
- }
- device->UpdateBuffer(globalMaterialBuffer.get(), materialArray.data(), threadID, sizeof(TracedRenderingMaterial) * (int)materialArray.size());
-
-}
void BuildSceneBVH(GRAPHICSTHREAD threadID)
{
const Scene& scene = GetScene();
@@ -7333,8 +7196,6 @@ void DrawTracedScene(const CameraComponent& camera, const Texture2D* result, GRA
assert(SUCCEEDED(hr));
}
- UpdateGlobalMaterialResources(threadID);
-
// Begin raytrace
wiProfiler::BeginRange("RayTrace - ALL", wiProfiler::DOMAIN_GPU, threadID);
@@ -7390,20 +7251,6 @@ void DrawTracedScene(const CameraComponent& camera, const Texture2D* result, GRA
// Set up tracing resources:
sceneBVH.Bind(CS, threadID);
- GPUResource* res[] = {
- globalMaterialBuffer.get(),
- };
- device->BindResources(CS, res, TEXSLOT_ONDEMAND0, ARRAYSIZE(res), threadID);
-
- if (globalMaterialAtlas != nullptr)
- {
- device->BindResource(CS, globalMaterialAtlas.get(), TEXSLOT_ONDEMAND8, threadID);
- }
- else
- {
- device->BindResource(CS, wiTextureHelper::getWhite(), TEXSLOT_ONDEMAND8, threadID);
- }
-
for (int bounce = 0; bounce < 8; ++bounce)
{
const int __readBufferID = bounce % 2;
@@ -7943,21 +7790,6 @@ void RefreshLightmapAtlas(GRAPHICSTHREAD threadID)
scene_bvh_invalid = false;
BuildSceneBVH(threadID);
}
- UpdateGlobalMaterialResources(threadID);
-
- GPUResource* res[] = {
- globalMaterialBuffer.get(),
- };
- device->BindResources(PS, res, TEXSLOT_ONDEMAND0, ARRAYSIZE(res), threadID);
-
- if (globalMaterialAtlas != nullptr)
- {
- device->BindResource(PS, globalMaterialAtlas.get(), TEXSLOT_ONDEMAND8, threadID);
- }
- else
- {
- device->BindResource(PS, wiTextureHelper::getWhite(), TEXSLOT_ONDEMAND8, threadID);
- }
sceneBVH.Bind(PS, threadID);
}
@@ -8012,9 +7844,9 @@ const Texture2D* GetGlobalLightmap()
{
if (globalLightmap.IsValid())
{
- return wiTextureHelper::getTransparent();
+ return &globalLightmap;
}
- return &globalLightmap;
+ return wiTextureHelper::getTransparent();
}
void BindPersistentState(GRAPHICSTHREAD threadID)
diff --git a/WickedEngine/wiSceneSystem.cpp b/WickedEngine/wiSceneSystem.cpp
index 98cc89d49..b583f0dfe 100644
--- a/WickedEngine/wiSceneSystem.cpp
+++ b/WickedEngine/wiSceneSystem.cpp
@@ -442,7 +442,7 @@ namespace wiSceneSystem
bd.CPUAccessFlags = 0;
bd.BindFlags = BIND_VERTEX_BUFFER | BIND_SHADER_RESOURCE;
bd.MiscFlags = 0;
- bd.StructureByteStride = sizeof(uint32_t);
+ bd.StructureByteStride = sizeof(Vertex_COL);
bd.ByteWidth = (UINT)(bd.StructureByteStride * vertex_colors.size());
bd.Format = FORMAT_R8G8B8A8_UNORM;
diff --git a/WickedEngine/wiSceneSystem.h b/WickedEngine/wiSceneSystem.h
index 872f19cf4..196a6e311 100644
--- a/WickedEngine/wiSceneSystem.h
+++ b/WickedEngine/wiSceneSystem.h
@@ -104,6 +104,7 @@ namespace wiSceneSystem
PLANAR_REFLECTION = 1 << 2,
WATER = 1 << 3,
FLIP_NORMALMAP = 1 << 4,
+ USE_VERTEXCOLORS = 1 << 5,
};
uint32_t _flags = DIRTY | CAST_SHADOW;
@@ -177,6 +178,7 @@ namespace wiSceneSystem
inline bool IsCastingShadow() const { return _flags & CAST_SHADOW; }
inline bool IsAlphaTestEnabled() const { return alphaRef <= 1.0f - 1.0f / 256.0f; }
inline bool IsFlipNormalMap() const { return _flags & FLIP_NORMALMAP; }
+ inline bool IsUsingVertexColors() const { return _flags & USE_VERTEXCOLORS; }
inline bool IsCustomShader() const { return customShaderID >= 0; }
inline void SetBaseColor(const XMFLOAT4& value) { SetDirty(); baseColor = value; }
@@ -191,7 +193,8 @@ namespace wiSceneSystem
inline void SetParallaxOcclusionMapping(float value) { SetDirty(); parallaxOcclusionMapping = value; }
inline void SetOpacity(float value) { SetDirty(); baseColor.w = value; }
inline void SetAlphaRef(float value) { SetDirty(); alphaRef = value; }
- inline void SetFlipNormalMap(bool value) { SetDirty(); if (value) { _flags |= FLIP_NORMALMAP; } else { _flags &= ~FLIP_NORMALMAP; } }
+ inline void SetFlipNormalMap(bool value) { SetDirty(); if (value) { _flags |= FLIP_NORMALMAP; } else { _flags &= ~FLIP_NORMALMAP; } }
+ inline void SetUseVertexColors(bool value) { SetDirty(); if (value) { _flags |= USE_VERTEXCOLORS; } else { _flags &= ~USE_VERTEXCOLORS; } }
inline void SetCustomShaderID(int id) { customShaderID = id; }
inline void DisableCustomShader() { customShaderID = -1; }
@@ -373,6 +376,11 @@ namespace wiSceneSystem
return wei_FULL;
}
};
+ struct Vertex_COL
+ {
+ uint32_t color = 0;
+ static const wiGraphics::FORMAT FORMAT = wiGraphics::FORMAT::FORMAT_R8G8B8A8_UNORM;
+ };
};
diff --git a/WickedEngine/wiVersion.cpp b/WickedEngine/wiVersion.cpp
index cc3c32cdf..53736340e 100644
--- a/WickedEngine/wiVersion.cpp
+++ b/WickedEngine/wiVersion.cpp
@@ -9,7 +9,7 @@ namespace wiVersion
// minor features, major updates
const int minor = 25;
// minor bug fixes, alterations, refactors, updates
- const int revision = 3;
+ const int revision = 4;
long GetVersion()