editor update: material selection outline; general fixes;
This commit is contained in:
+91
-1
@@ -152,13 +152,31 @@ void EditorComponent::ChangeRenderPath(RENDERPATH path)
|
||||
oceanWnd.reset(new OceanWindow(&GetGUI()));
|
||||
}
|
||||
|
||||
void EditorComponent::ResizeBuffers()
|
||||
{
|
||||
__super::ResizeBuffers();
|
||||
|
||||
TextureDesc desc;
|
||||
desc.Width = wiRenderer::GetInternalResolution().x;
|
||||
desc.Height = wiRenderer::GetInternalResolution().y;
|
||||
|
||||
HRESULT hr;
|
||||
desc.Format = wiRenderer::RTFormat_lineardepth;
|
||||
desc.BindFlags = BIND_RENDER_TARGET | BIND_SHADER_RESOURCE;
|
||||
hr = wiRenderer::GetDevice()->CreateTexture2D(&desc, nullptr, &rt_selectionOutline[0]);
|
||||
assert(SUCCEEDED(hr));
|
||||
|
||||
desc.Format = wiRenderer::RTFormat_hdr;
|
||||
desc.BindFlags = BIND_RENDER_TARGET | BIND_SHADER_RESOURCE | BIND_UNORDERED_ACCESS;
|
||||
hr = wiRenderer::GetDevice()->CreateTexture2D(&desc, nullptr, &rt_selectionOutline[1]);
|
||||
assert(SUCCEEDED(hr));
|
||||
}
|
||||
void EditorComponent::Load()
|
||||
{
|
||||
__super::Load();
|
||||
|
||||
translator.enabled = false;
|
||||
|
||||
|
||||
float screenW = (float)wiRenderer::GetDevice()->GetScreenWidth();
|
||||
float screenH = (float)wiRenderer::GetDevice()->GetScreenHeight();
|
||||
|
||||
@@ -1144,6 +1162,7 @@ void EditorComponent::Update(float dt)
|
||||
// Union selection:
|
||||
list<wiSceneSystem::PickResult> saved = selected;
|
||||
EndTranslate();
|
||||
selected.clear(); // endtranslate would clear it, but not if translator is not enabled
|
||||
for (const wiSceneSystem::PickResult& picked : saved)
|
||||
{
|
||||
AddSelected(picked);
|
||||
@@ -1232,6 +1251,31 @@ void EditorComponent::Update(float dt)
|
||||
|
||||
}
|
||||
|
||||
// Clear material highlite state:
|
||||
for (size_t i = 0; i < scene.materials.GetCount(); ++i)
|
||||
{
|
||||
scene.materials[i].SetUserStencilRef(EditorComponent::EDITORSTENCILREF_CLEAR);
|
||||
}
|
||||
for (auto& x : selected)
|
||||
{
|
||||
if (x.subsetIndex >= 0)
|
||||
{
|
||||
const ObjectComponent* object = scene.objects.GetComponent(x.entity);
|
||||
if (object != nullptr) // maybe it was deleted...
|
||||
{
|
||||
const MeshComponent* mesh = scene.meshes.GetComponent(object->meshID);
|
||||
if (mesh != nullptr && (int)mesh->subsets.size() > x.subsetIndex)
|
||||
{
|
||||
MaterialComponent* material = scene.materials.GetComponent(mesh->subsets[x.subsetIndex].materialID);
|
||||
if (material != nullptr)
|
||||
{
|
||||
material->SetUserStencilRef(EDITORSTENCILREF_HIGHLIGHT);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Delete
|
||||
if (wiInputManager::press(VK_DELETE))
|
||||
{
|
||||
@@ -1490,6 +1534,45 @@ void EditorComponent::Render() const
|
||||
|
||||
renderPath->Render();
|
||||
|
||||
// Selection outline:
|
||||
{
|
||||
GraphicsDevice* device = wiRenderer::GetDevice();
|
||||
CommandList cmd = device->BeginCommandList();
|
||||
|
||||
device->EventBegin("Editor - Selection Outline", cmd);
|
||||
|
||||
const Texture2D* rts[] = {
|
||||
&rt_selectionOutline[0],
|
||||
};
|
||||
device->BindRenderTargets(ARRAYSIZE(rts), rts, renderPath->GetDepthStencil(), cmd);
|
||||
const float rgba[] = { 0,0,0,0 };
|
||||
device->ClearRenderTarget(rts[0], rgba, cmd);
|
||||
|
||||
ViewPort vp;
|
||||
vp.Width = (float)rt_selectionOutline[0].GetDesc().Width;
|
||||
vp.Height = (float)rt_selectionOutline[0].GetDesc().Height;
|
||||
device->BindViewports(1, &vp, cmd);
|
||||
|
||||
wiImageParams fx;
|
||||
fx.enableFullScreen();
|
||||
fx.stencilComp = STENCILMODE::STENCILMODE_EQUAL;
|
||||
|
||||
// Draw solid blocks of selected materials with STENCILREF_DEFAULT engine stencil ref
|
||||
fx.stencilRef = wiRenderer::CombineStencilrefs(STENCILREF_DEFAULT, EDITORSTENCILREF_HIGHLIGHT);
|
||||
wiImage::Draw(wiTextureHelper::getWhite(), fx, cmd);
|
||||
|
||||
// Draw solid blocks of selected materials with STENCILREF_SKIN engine stencil ref
|
||||
fx.stencilRef = wiRenderer::CombineStencilrefs(STENCILREF_SKIN, EDITORSTENCILREF_HIGHLIGHT);
|
||||
wiImage::Draw(wiTextureHelper::getWhite(), fx, cmd);
|
||||
|
||||
// Outline the solid blocks:
|
||||
device->ClearRenderTarget(&rt_selectionOutline[1], rgba, cmd);
|
||||
wiRenderer::BindCommonResources(cmd);
|
||||
wiRenderer::Postprocess_Outline(rt_selectionOutline[0], rt_selectionOutline[1], cmd, 0.1f, 1, XMFLOAT4(1, 0.6f, 0, 1));
|
||||
|
||||
device->EventEnd(cmd);
|
||||
}
|
||||
|
||||
__super::Render();
|
||||
|
||||
}
|
||||
@@ -1502,6 +1585,13 @@ void EditorComponent::Compose(CommandList cmd) const
|
||||
return;
|
||||
}
|
||||
|
||||
// Compose the selection outline to the screen:
|
||||
{
|
||||
wiImageParams fx;
|
||||
fx.enableFullScreen();
|
||||
wiImage::Draw(&rt_selectionOutline[1], fx, cmd);
|
||||
}
|
||||
|
||||
const CameraComponent& camera = wiRenderer::GetCamera();
|
||||
|
||||
Scene& scene = wiSceneSystem::GetScene();
|
||||
|
||||
@@ -69,6 +69,7 @@ public:
|
||||
};
|
||||
void ChangeRenderPath(RENDERPATH path);
|
||||
|
||||
void ResizeBuffers() override;
|
||||
void Load() override;
|
||||
void Start() override;
|
||||
void FixedUpdate() override;
|
||||
@@ -84,6 +85,7 @@ public:
|
||||
EDITORSTENCILREF_HIGHLIGHT = 0x01,
|
||||
EDITORSTENCILREF_LAST = 0x0F,
|
||||
};
|
||||
wiGraphics::Texture2D rt_selectionOutline[2];
|
||||
|
||||
Translator translator;
|
||||
std::list<wiSceneSystem::PickResult> selected;
|
||||
|
||||
@@ -783,8 +783,6 @@ void MaterialWindow::SetEntity(Entity entity)
|
||||
|
||||
if (material != nullptr)
|
||||
{
|
||||
material->SetUserStencilRef(0);
|
||||
|
||||
const NameComponent& name = *scene.names.GetComponent(entity);
|
||||
stringstream ss("");
|
||||
ss << name.name << " (" << entity << ")";
|
||||
|
||||
@@ -80,7 +80,7 @@ SoundWindow::SoundWindow(wiGUI* gui) : GUI(gui)
|
||||
|
||||
if (result.ok) {
|
||||
string fileName = result.filenames.front();
|
||||
Entity entity = GetScene().Entity_CreateSound(fileName);
|
||||
Entity entity = GetScene().Entity_CreateSound("editorSound", fileName);
|
||||
}
|
||||
});
|
||||
soundWindow->AddWidget(addButton);
|
||||
|
||||
@@ -15,7 +15,7 @@ private:
|
||||
float sharpenFilterAmount = 0.28f;
|
||||
float outlineThreshold = 0.2f;
|
||||
float outlineThickness = 1.0f;
|
||||
XMFLOAT3 outlineColor = XMFLOAT3(0, 0, 0);
|
||||
XMFLOAT4 outlineColor = XMFLOAT4(0, 0, 0, 1);
|
||||
float ssaoRange = 1.0f;
|
||||
UINT ssaoSampleCount = 16;
|
||||
float chromaticAberrationAmount = 2.0f;
|
||||
@@ -112,7 +112,7 @@ public:
|
||||
inline float getSharpenFilterAmount() const { return sharpenFilterAmount; }
|
||||
inline float getOutlineThreshold() const { return outlineThreshold; }
|
||||
inline float getOutlineThickness() const { return outlineThickness; }
|
||||
inline XMFLOAT3 getOutlineColor() const { return outlineColor; }
|
||||
inline XMFLOAT4 getOutlineColor() const { return outlineColor; }
|
||||
inline float getSSAORange() const { return ssaoRange; }
|
||||
inline UINT getSSAOSampleCount() const { return ssaoSampleCount; }
|
||||
inline float getChromaticAberrationAmount() const { return chromaticAberrationAmount; }
|
||||
@@ -151,7 +151,7 @@ public:
|
||||
inline void setSharpenFilterAmount(float value) { sharpenFilterAmount = value; }
|
||||
inline void setOutlineThreshold(float value) { outlineThreshold = value; }
|
||||
inline void setOutlineThickness(float value) { outlineThickness = value; }
|
||||
inline void setOutlineColor(const XMFLOAT3& value) { outlineColor = value; }
|
||||
inline void setOutlineColor(const XMFLOAT4& value) { outlineColor = value; }
|
||||
inline void setSSAORange(float value) { ssaoRange = value; }
|
||||
inline void setSSAOSampleCount(UINT value) { ssaoSampleCount = value; }
|
||||
inline void setChromaticAberrationAmount(float value) { chromaticAberrationAmount = value; }
|
||||
|
||||
@@ -257,6 +257,7 @@
|
||||
<ClInclude Include="$(MSBuildThisFileDirectory)Utility\stb_image.h" />
|
||||
<ClInclude Include="$(MSBuildThisFileDirectory)Utility\stb_image_write.h" />
|
||||
<ClInclude Include="$(MSBuildThisFileDirectory)Utility\stb_truetype.h" />
|
||||
<ClInclude Include="$(MSBuildThisFileDirectory)Utility\tinyddsloader.h" />
|
||||
<ClInclude Include="$(MSBuildThisFileDirectory)wiAllocators.h" />
|
||||
<ClInclude Include="$(MSBuildThisFileDirectory)wiArchive.h" />
|
||||
<ClInclude Include="$(MSBuildThisFileDirectory)wiAudio.h" />
|
||||
|
||||
@@ -1128,6 +1128,9 @@
|
||||
<ClInclude Include="$(MSBuildThisFileDirectory)wiNetwork.h">
|
||||
<Filter>ENGINE\Network</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="$(MSBuildThisFileDirectory)Utility\tinyddsloader.h">
|
||||
<Filter>UTILITY</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="$(MSBuildThisFileDirectory)LUA\lapi.c">
|
||||
|
||||
+16
-14
@@ -1,6 +1,8 @@
|
||||
#include "globals.hlsli"
|
||||
#include "ShaderInterop_Postprocess.h"
|
||||
|
||||
TEXTURE2D(input, float, TEXSLOT_ONDEMAND0);
|
||||
|
||||
RWTEXTURE2D(output, float4, 0);
|
||||
|
||||
[numthreads(POSTPROCESS_BLOCKSIZE, POSTPROCESS_BLOCKSIZE, 1)]
|
||||
@@ -8,30 +10,30 @@ void main(uint3 DTid : SV_DispatchThreadID)
|
||||
{
|
||||
const float2 uv = (DTid.xy + 0.5f) * xPPResolution_rcp;
|
||||
|
||||
const float midDepth = texture_lineardepth.SampleLevel(sampler_linear_clamp, uv, 0);
|
||||
const float middle = input.SampleLevel(sampler_linear_clamp, uv, 0);
|
||||
|
||||
const float outlineThickness = xPPParams0.y;
|
||||
const float3 outlineColor = xPPParams1.xyz;
|
||||
const float outlineThreshold = xPPParams0.x * midDepth;
|
||||
const float4 outlineColor = xPPParams1;
|
||||
const float outlineThreshold = xPPParams0.x * middle;
|
||||
|
||||
float2 dim;
|
||||
texture_lineardepth.GetDimensions(dim.x, dim.y);
|
||||
input.GetDimensions(dim.x, dim.y);
|
||||
|
||||
float2 ox = float2(outlineThickness / dim.x, 0.0);
|
||||
float2 oy = float2(0.0, outlineThickness / dim.y);
|
||||
float2 PP = uv - oy;
|
||||
|
||||
float CC = texture_lineardepth.SampleLevel(sampler_linear_clamp, (PP - ox), 0); float g00 = (CC);
|
||||
CC = texture_lineardepth.SampleLevel(sampler_linear_clamp, PP, 0); float g01 = (CC);
|
||||
CC = texture_lineardepth.SampleLevel(sampler_linear_clamp, (PP + ox), 0); float g02 = (CC);
|
||||
float CC = input.SampleLevel(sampler_linear_clamp, (PP - ox), 0); float g00 = (CC);
|
||||
CC = input.SampleLevel(sampler_linear_clamp, PP, 0); float g01 = (CC);
|
||||
CC = input.SampleLevel(sampler_linear_clamp, (PP + ox), 0); float g02 = (CC);
|
||||
PP = uv;
|
||||
CC = texture_lineardepth.SampleLevel(sampler_linear_clamp, (PP - ox), 0); float g10 = (CC);
|
||||
CC = midDepth; float g11 = (CC)*0.01f;
|
||||
CC = texture_lineardepth.SampleLevel(sampler_linear_clamp, (PP + ox), 0); float g12 = (CC);
|
||||
CC = input.SampleLevel(sampler_linear_clamp, (PP - ox), 0); float g10 = (CC);
|
||||
CC = middle; float g11 = (CC) * 0.01f;
|
||||
CC = input.SampleLevel(sampler_linear_clamp, (PP + ox), 0); float g12 = (CC);
|
||||
PP = uv + oy;
|
||||
CC = texture_lineardepth.SampleLevel(sampler_linear_clamp, (PP - ox), 0); float g20 = (CC);
|
||||
CC = texture_lineardepth.SampleLevel(sampler_linear_clamp, PP, 0); float g21 = (CC);
|
||||
CC = texture_lineardepth.SampleLevel(sampler_linear_clamp, (PP + ox), 0); float g22 = (CC);
|
||||
CC = input.SampleLevel(sampler_linear_clamp, (PP - ox), 0); float g20 = (CC);
|
||||
CC = input.SampleLevel(sampler_linear_clamp, PP, 0); float g21 = (CC);
|
||||
CC = input.SampleLevel(sampler_linear_clamp, (PP + ox), 0); float g22 = (CC);
|
||||
float K00 = -1;
|
||||
float K01 = -2;
|
||||
float K02 = -1;
|
||||
@@ -66,5 +68,5 @@ void main(uint3 DTid : SV_DispatchThreadID)
|
||||
float edge = dist > outlineThreshold ? 1 : 0;
|
||||
|
||||
float4 color_prev = output[DTid.xy];
|
||||
output[DTid.xy] = lerp(color_prev, float4(outlineColor.rgb, color_prev.a), edge);
|
||||
output[DTid.xy] = lerp(color_prev, outlineColor, edge);
|
||||
}
|
||||
|
||||
@@ -9025,12 +9025,12 @@ void Postprocess_DepthOfField(
|
||||
device->EventEnd(cmd);
|
||||
}
|
||||
void Postprocess_Outline(
|
||||
const Texture2D& lineardepth,
|
||||
const Texture2D& input,
|
||||
const Texture2D& output,
|
||||
CommandList cmd,
|
||||
float threshold,
|
||||
float thickness,
|
||||
const XMFLOAT3& color
|
||||
const XMFLOAT4& color
|
||||
)
|
||||
{
|
||||
GraphicsDevice* device = GetDevice();
|
||||
@@ -9042,7 +9042,7 @@ void Postprocess_Outline(
|
||||
|
||||
device->BindComputeShader(computeShaders[CSTYPE_POSTPROCESS_OUTLINE], cmd);
|
||||
|
||||
device->BindResource(CS, &lineardepth, TEXSLOT_LINEARDEPTH, cmd);
|
||||
device->BindResource(CS, &input, TEXSLOT_ONDEMAND0, cmd);
|
||||
|
||||
const TextureDesc& desc = output.GetDesc();
|
||||
|
||||
@@ -9056,6 +9056,7 @@ void Postprocess_Outline(
|
||||
cb.xPPParams1.x = color.x;
|
||||
cb.xPPParams1.y = color.y;
|
||||
cb.xPPParams1.z = color.z;
|
||||
cb.xPPParams1.w = color.w;
|
||||
device->UpdateBuffer(&constantBuffers[CBTYPE_POSTPROCESS], &cb, cmd);
|
||||
device->BindConstantBuffer(CS, &constantBuffers[CBTYPE_POSTPROCESS], CB_GETBINDSLOT(PostProcessCB), cmd);
|
||||
|
||||
|
||||
@@ -32,6 +32,11 @@ namespace wiRenderer
|
||||
static const wiGraphics::FORMAT DSFormat_small = wiGraphics::FORMAT_D16_UNORM;
|
||||
static const wiGraphics::FORMAT DSFormat_small_alias = wiGraphics::FORMAT_R16_TYPELESS;
|
||||
|
||||
inline UINT CombineStencilrefs(STENCILREF engineStencilRef, uint8_t userStencilRef)
|
||||
{
|
||||
return (userStencilRef << 4) | static_cast<uint8_t>(engineStencilRef);
|
||||
}
|
||||
|
||||
const wiGraphics::Sampler* GetSampler(int slot);
|
||||
const wiGraphics::VertexShader* GetVertexShader(VSTYPES id);
|
||||
const wiGraphics::HullShader* GetHullShader(VSTYPES id);
|
||||
@@ -244,12 +249,12 @@ namespace wiRenderer
|
||||
float focus = 10.0f
|
||||
);
|
||||
void Postprocess_Outline(
|
||||
const wiGraphics::Texture2D& lineardepth,
|
||||
const wiGraphics::Texture2D& input,
|
||||
const wiGraphics::Texture2D& output,
|
||||
wiGraphics::CommandList cmd,
|
||||
float threshold = 0.1f,
|
||||
float thickness = 1.0f,
|
||||
const XMFLOAT3& color = XMFLOAT3(0, 0, 0)
|
||||
const XMFLOAT4& color = XMFLOAT4(0, 0, 0, 1)
|
||||
);
|
||||
void Postprocess_MotionBlur(
|
||||
const wiGraphics::Texture2D& input,
|
||||
|
||||
@@ -1396,12 +1396,15 @@ namespace wiSceneSystem
|
||||
return entity;
|
||||
}
|
||||
Entity Scene::Entity_CreateSound(
|
||||
const std::string& name,
|
||||
const std::string& filename,
|
||||
const XMFLOAT3& position
|
||||
)
|
||||
{
|
||||
Entity entity = CreateEntity();
|
||||
|
||||
names.Create(entity) = name;
|
||||
|
||||
SoundComponent& sound = sounds.Create(entity);
|
||||
sound.filename = filename;
|
||||
sound.sound = (wiAudio::Sound*)wiResourceManager::GetGlobal().add(filename);
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
#include "ShaderInterop_Renderer.h"
|
||||
#include "wiJobSystem.h"
|
||||
#include "wiAudio.h"
|
||||
#include "wiRenderer.h"
|
||||
|
||||
#include "wiECS.h"
|
||||
#include "wiSceneSystem_Decl.h"
|
||||
@@ -168,7 +169,7 @@ namespace wiSceneSystem
|
||||
}
|
||||
inline UINT GetStencilRef() const
|
||||
{
|
||||
return (userStencilRef << 4) | static_cast<uint8_t>(engineStencilRef);
|
||||
return wiRenderer::CombineStencilrefs(engineStencilRef, userStencilRef);
|
||||
}
|
||||
|
||||
const wiGraphics::Texture2D* GetBaseColorMap() const;
|
||||
@@ -1075,6 +1076,7 @@ namespace wiSceneSystem
|
||||
const XMFLOAT3& position = XMFLOAT3(0, 0, 0)
|
||||
);
|
||||
wiECS::Entity Entity_CreateSound(
|
||||
const std::string& name,
|
||||
const std::string& filename,
|
||||
const XMFLOAT3& position = XMFLOAT3(0, 0, 0)
|
||||
);
|
||||
|
||||
@@ -9,7 +9,7 @@ namespace wiVersion
|
||||
// minor features, major updates
|
||||
const int minor = 30;
|
||||
// minor bug fixes, alterations, refactors, updates
|
||||
const int revision = 2;
|
||||
const int revision = 3;
|
||||
|
||||
|
||||
long GetVersion()
|
||||
|
||||
Reference in New Issue
Block a user