From 2664b1cf26869bca06cce44b12fbbe75bc658b29 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tur=C3=A1nszki=20J=C3=A1nos?= Date: Fri, 12 Apr 2024 07:50:21 +0200 Subject: [PATCH] paint tool: redirect alpha --- Editor/PaintToolWindow.cpp | 9 +++++++- Editor/PaintToolWindow.h | 1 + WickedEngine/shaders/ShaderInterop_Renderer.h | 2 +- WickedEngine/shaders/paint_textureCS.hlsl | 21 +++++++++++-------- WickedEngine/wiRenderer.cpp | 1 - WickedEngine/wiVersion.cpp | 2 +- 6 files changed, 23 insertions(+), 13 deletions(-) diff --git a/Editor/PaintToolWindow.cpp b/Editor/PaintToolWindow.cpp index 8bf2a2419..c8dd48313 100644 --- a/Editor/PaintToolWindow.cpp +++ b/Editor/PaintToolWindow.cpp @@ -176,6 +176,12 @@ void PaintToolWindow::Create(EditorComponent* _editor) pressureCheckBox.SetCheckText(ICON_PEN); AddWidget(&pressureCheckBox); + alphaCheckBox.Create("Redirect alpha: "); + alphaCheckBox.SetTooltip("The red color will be redirected to write alpha channel. Alpha value controls the blending like normally."); + alphaCheckBox.SetSize(XMFLOAT2(hei, hei)); + alphaCheckBox.SetPos(XMFLOAT2(x - 20 + 200, y)); + AddWidget(&alphaCheckBox); + axisCombo.Create("Axis Lock: "); axisCombo.SetTooltip("You can lock modification to an axis here."); axisCombo.SetPos(XMFLOAT2(x, y)); @@ -567,7 +573,7 @@ void PaintToolWindow::Update(float dt) paintparams.push.xPaintBrushAmount = amount; paintparams.push.xPaintBrushSmoothness = smoothness; paintparams.push.xPaintBrushColor = color.rgba; - paintparams.push.xPaintReveal = revealTex.IsValid() ? 1 : 0; + paintparams.push.xPaintRedirectAlpha = alphaCheckBox.GetCheck(); paintparams.push.xPaintBrushRotation = brush_rotation; paintparams.push.xPaintBrushShape = (uint)brushShapeComboBox.GetSelected(); @@ -1650,6 +1656,7 @@ void PaintToolWindow::ResizeLayout() add_right(backfaceCheckBox); wireCheckBox.SetPos(XMFLOAT2(backfaceCheckBox.GetPos().x - wireCheckBox.GetSize().x - 100, backfaceCheckBox.GetPos().y)); add_right(pressureCheckBox); + alphaCheckBox.SetPos(XMFLOAT2(pressureCheckBox.GetPos().x - alphaCheckBox.GetSize().x - 100, pressureCheckBox.GetPos().y)); add(textureSlotComboBox); add(brushShapeComboBox); add(axisCombo); diff --git a/Editor/PaintToolWindow.h b/Editor/PaintToolWindow.h index 499432db0..e6438b134 100644 --- a/Editor/PaintToolWindow.h +++ b/Editor/PaintToolWindow.h @@ -52,6 +52,7 @@ public: wi::gui::CheckBox backfaceCheckBox; wi::gui::CheckBox wireCheckBox; wi::gui::CheckBox pressureCheckBox; + wi::gui::CheckBox alphaCheckBox; wi::gui::ColorPicker colorPicker; wi::gui::ComboBox textureSlotComboBox; wi::gui::ComboBox brushShapeComboBox; diff --git a/WickedEngine/shaders/ShaderInterop_Renderer.h b/WickedEngine/shaders/ShaderInterop_Renderer.h index e86d4679d..80331c88d 100644 --- a/WickedEngine/shaders/ShaderInterop_Renderer.h +++ b/WickedEngine/shaders/ShaderInterop_Renderer.h @@ -1264,7 +1264,7 @@ struct PaintTexturePushConstants float xPaintBrushSmoothness; uint xPaintBrushColor; - uint xPaintReveal; + uint xPaintRedirectAlpha; float xPaintBrushRotation; uint xPaintBrushShape; diff --git a/WickedEngine/shaders/paint_textureCS.hlsl b/WickedEngine/shaders/paint_textureCS.hlsl index d4faf6cc1..f9ff65e4c 100644 --- a/WickedEngine/shaders/paint_textureCS.hlsl +++ b/WickedEngine/shaders/paint_textureCS.hlsl @@ -35,7 +35,6 @@ void main( uint3 DTid : SV_DispatchThreadID ) } float4 brush_color = 1; - float4 reveal_color = 1; [branch] if(push.texture_brush >= 0) @@ -46,7 +45,7 @@ void main( uint3 DTid : SV_DispatchThreadID ) const float2 brush_uv_quad_y = QuadReadAcrossY(brush_uv); const float2 brush_uv_dx = brush_uv - brush_uv_quad_x; const float2 brush_uv_dy = brush_uv - brush_uv_quad_y; - brush_color = texture_brush.SampleGrad(sampler_linear_clamp, brush_uv, brush_uv_dx, brush_uv_dy); + brush_color *= texture_brush.SampleGrad(sampler_linear_clamp, brush_uv, brush_uv_dx, brush_uv_dy); } [branch] @@ -58,22 +57,26 @@ void main( uint3 DTid : SV_DispatchThreadID ) const float2 reveal_uv_quad_y = QuadReadAcrossY(reveal_uv); const float2 reveal_uv_dx = reveal_uv - reveal_uv_quad_x; const float2 reveal_uv_dy = reveal_uv - reveal_uv_quad_y; - reveal_color = texture_reveal.SampleGrad(sampler_linear_clamp, reveal_uv, reveal_uv_dx, reveal_uv_dy); + brush_color *= texture_reveal.SampleGrad(sampler_linear_clamp, reveal_uv, reveal_uv_dx, reveal_uv_dy); } const float affection = push.xPaintBrushAmount * smoothstep(0, push.xPaintBrushSmoothness, 1 - dist / radius); if (affection > 0 && dist < radius) { - if (push.xPaintReveal) - { - brush_color *= reveal_color; - } brush_color.a *= affection; brush_color *= unpack_rgba(push.xPaintBrushColor); float4 prevColor = texture_output[pixel]; float4 color = 0; - color.rgb = prevColor.rgb * (1 - brush_color.a) + brush_color.rgb * brush_color.a; - color.a = prevColor.a * (1 - brush_color.a) + brush_color.a; + if(push.xPaintRedirectAlpha) + { + color.rgb = prevColor.rgb; + color.a = prevColor.a * (1 - brush_color.a) + brush_color.r * brush_color.a; + } + else + { + color.rgb = prevColor.rgb * (1 - brush_color.a) + brush_color.rgb * brush_color.a; + color.a = prevColor.a * (1 - brush_color.a) + brush_color.a; + } texture_output[pixel] = color; } } diff --git a/WickedEngine/wiRenderer.cpp b/WickedEngine/wiRenderer.cpp index 607050fcd..e6fa9b245 100644 --- a/WickedEngine/wiRenderer.cpp +++ b/WickedEngine/wiRenderer.cpp @@ -3021,7 +3021,6 @@ void ProcessDeferredTextureRequests(CommandList cmd) for (auto& params : painttextures) { // overwrites some params! - params.push.xPaintReveal = params.revealTex.IsValid() ? 1 : 0; if (params.brushTex.IsValid()) { params.push.texture_brush = device->GetDescriptorIndex(¶ms.brushTex, SubresourceType::SRV); diff --git a/WickedEngine/wiVersion.cpp b/WickedEngine/wiVersion.cpp index 2f023d2aa..23d3bfa9b 100644 --- a/WickedEngine/wiVersion.cpp +++ b/WickedEngine/wiVersion.cpp @@ -9,7 +9,7 @@ namespace wi::version // minor features, major updates, breaking compatibility changes const int minor = 71; // minor bug fixes, alterations, refactors, updates - const int revision = 430; + const int revision = 431; const std::string version_string = std::to_string(major) + "." + std::to_string(minor) + "." + std::to_string(revision);