From 6bb2a8519b0c837cefd77ea7045284d71d5e54c3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tur=C3=A1nszki=20J=C3=A1nos?= Date: Wed, 8 Mar 2023 18:06:31 +0100 Subject: [PATCH] decal texture tiling support --- Content/Documentation/ScriptingAPI-Documentation.md | 2 ++ Editor/DecalWindow.cpp | 2 +- WickedEngine/shaders/objectHF.hlsli | 6 ++++-- WickedEngine/shaders/surfaceHF.hlsli | 3 ++- WickedEngine/wiRenderer.cpp | 1 + WickedEngine/wiScene.cpp | 1 + WickedEngine/wiScene_BindLua.cpp | 2 ++ WickedEngine/wiScene_Components.h | 1 + WickedEngine/wiVersion.cpp | 2 +- 9 files changed, 15 insertions(+), 5 deletions(-) diff --git a/Content/Documentation/ScriptingAPI-Documentation.md b/Content/Documentation/ScriptingAPI-Documentation.md index a6ee7e5cb..6ebb5e340 100644 --- a/Content/Documentation/ScriptingAPI-Documentation.md +++ b/Content/Documentation/ScriptingAPI-Documentation.md @@ -776,6 +776,8 @@ Describes an orientation in 3D space. - SetEngineStencilRef(int value) - SetUserStencilRef(int value) - GetStencilRef() : int result +- SetTexMulAdd(Vector vector) +- GetTexMulAdd() : Vector - SetTexture(TextureSlot slot, string texturefile) - SetTexture(TextureSlot slot, Texture texture) - SetTextureUVSet(TextureSlot slot, int uvset) diff --git a/Editor/DecalWindow.cpp b/Editor/DecalWindow.cpp index 476429cf6..b9859bdfb 100644 --- a/Editor/DecalWindow.cpp +++ b/Editor/DecalWindow.cpp @@ -56,7 +56,7 @@ void DecalWindow::Create(EditorComponent* _editor) y += step; infoLabel.Create(""); - infoLabel.SetText("Set decal properties in the Material component. Decals support the following material properties:\n - Base color\n - Base color texture\n - Emissive strength\n - Normalmap texture\n - Normalmap strength\n - Surfacemap texture"); + infoLabel.SetText("Set decal properties in the Material component. Decals support the following material properties:\n - Base color\n - Base color texture\n - Emissive strength\n - Normalmap texture\n - Normalmap strength\n - Surfacemap texture\n - Texture tiling (TexMulAdd)"); infoLabel.SetSize(XMFLOAT2(300, 100)); infoLabel.SetPos(XMFLOAT2(10, y)); infoLabel.SetColor(wi::Color::Transparent()); diff --git a/WickedEngine/shaders/objectHF.hlsli b/WickedEngine/shaders/objectHF.hlsli index af71add7a..c0fb22e9a 100644 --- a/WickedEngine/shaders/objectHF.hlsli +++ b/WickedEngine/shaders/objectHF.hlsli @@ -521,10 +521,11 @@ inline void ForwardDecals(inout Surface surface, inout float4 surfaceMap) int decalSurfacemap = asint(decalProjection[3][3]); decalProjection[3] = float4(0, 0, 0, 1); const float3 clipSpacePos = mul(decalProjection, float4(surface.P, 1)).xyz; - const float3 uvw = clipspace_to_uv(clipSpacePos.xyz); + float3 uvw = clipspace_to_uv(clipSpacePos.xyz); [branch] if (is_saturated(uvw)) { + uvw.xy = mad(uvw.xy, decal.shadowAtlasMulAdd.xy, decal.shadowAtlasMulAdd.zw); // mipmapping needs to be performed by hand: const float2 decalDX = mul(P_dx, (float3x3)decalProjection).xy; const float2 decalDY = mul(P_dy, (float3x3)decalProjection).xy; @@ -850,10 +851,11 @@ inline void TiledDecals(inout Surface surface, uint flatTileIndex, inout float4 int decalSurfacemap = asint(decalProjection[3][3]); decalProjection[3] = float4(0, 0, 0, 1); const float3 clipSpacePos = mul(decalProjection, float4(surface.P, 1)).xyz; - const float3 uvw = clipspace_to_uv(clipSpacePos.xyz); + float3 uvw = clipspace_to_uv(clipSpacePos.xyz); [branch] if (is_saturated(uvw)) { + uvw.xy = mad(uvw.xy, decal.shadowAtlasMulAdd.xy, decal.shadowAtlasMulAdd.zw); // mipmapping needs to be performed by hand: const float2 decalDX = mul(P_dx, (float3x3)decalProjection).xy; const float2 decalDY = mul(P_dy, (float3x3)decalProjection).xy; diff --git a/WickedEngine/shaders/surfaceHF.hlsli b/WickedEngine/shaders/surfaceHF.hlsli index fd3ccb4cc..df5cbdcfa 100644 --- a/WickedEngine/shaders/surfaceHF.hlsli +++ b/WickedEngine/shaders/surfaceHF.hlsli @@ -523,10 +523,11 @@ struct Surface int decalSurfacemap = asint(decalProjection[3][3]); decalProjection[3] = float4(0, 0, 0, 1); const float3 clipSpacePos = mul(decalProjection, float4(P, 1)).xyz; - const float3 uvw = clipspace_to_uv(clipSpacePos.xyz); + float3 uvw = clipspace_to_uv(clipSpacePos.xyz); [branch] if (is_saturated(uvw)) { + uvw.xy = mad(uvw.xy, decal.shadowAtlasMulAdd.xy, decal.shadowAtlasMulAdd.zw); // mipmapping needs to be performed by hand: const float2 decalDX = mul(P_dx, (float3x3)decalProjection).xy; const float2 decalDY = mul(P_dy, (float3x3)decalProjection).xy; diff --git a/WickedEngine/wiRenderer.cpp b/WickedEngine/wiRenderer.cpp index 2f126d7d0..a3b7d4868 100644 --- a/WickedEngine/wiRenderer.cpp +++ b/WickedEngine/wiRenderer.cpp @@ -3768,6 +3768,7 @@ void UpdateRenderData( shaderentity.SetRange(decal.range); float emissive_mul = 1 + decal.emissive; shaderentity.SetColor(float4(decal.color.x * emissive_mul, decal.color.y * emissive_mul, decal.color.z * emissive_mul, decal.color.w)); + shaderentity.shadowAtlasMulAdd = decal.texMulAdd; shaderentity.SetIndices(matrixCounter, 0); shadermatrix = XMMatrixInverse(nullptr, XMLoadFloat4x4(&decal.world)); diff --git a/WickedEngine/wiScene.cpp b/WickedEngine/wiScene.cpp index bc1af9e6c..ecd2b3078 100644 --- a/WickedEngine/wiScene.cpp +++ b/WickedEngine/wiScene.cpp @@ -3801,6 +3801,7 @@ namespace wi::scene decal.normal = material.textures[MaterialComponent::NORMALMAP].resource; decal.surfacemap = material.textures[MaterialComponent::SURFACEMAP].resource; decal.normal_strength = material.normalMapStrength; + decal.texMulAdd = material.texMulAdd; } } void Scene::RunProbeUpdateSystem(wi::jobsystem::context& ctx) diff --git a/WickedEngine/wiScene_BindLua.cpp b/WickedEngine/wiScene_BindLua.cpp index 8db40df7c..848f81dd9 100644 --- a/WickedEngine/wiScene_BindLua.cpp +++ b/WickedEngine/wiScene_BindLua.cpp @@ -3507,6 +3507,8 @@ Luna::FunctionType MaterialComponent_BindLua::methods lunamethod(MaterialComponent_BindLua, SetEngineStencilRef), lunamethod(MaterialComponent_BindLua, SetUserStencilRef), lunamethod(MaterialComponent_BindLua, GetStencilRef), + lunamethod(MaterialComponent_BindLua, SetTexMulAdd), + lunamethod(MaterialComponent_BindLua, GetTexMulAdd), lunamethod(MaterialComponent_BindLua, SetTexture), lunamethod(MaterialComponent_BindLua, SetTextureUVSet), diff --git a/WickedEngine/wiScene_Components.h b/WickedEngine/wiScene_Components.h index d93a23852..93b6ad092 100644 --- a/WickedEngine/wiScene_Components.h +++ b/WickedEngine/wiScene_Components.h @@ -1065,6 +1065,7 @@ namespace wi::scene XMFLOAT3 position; float range; XMFLOAT4X4 world; + XMFLOAT4 texMulAdd; wi::Resource texture; wi::Resource normal; diff --git a/WickedEngine/wiVersion.cpp b/WickedEngine/wiVersion.cpp index 6f0e54fa6..ebcf623e5 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 = 175; + const int revision = 176; const std::string version_string = std::to_string(major) + "." + std::to_string(minor) + "." + std::to_string(revision);