From 97e08abfe5f1f086a845e353c832583c89f3edd3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tur=C3=A1nszki=20J=C3=A1nos?= Date: Sat, 14 Dec 2024 12:13:57 +0100 Subject: [PATCH] impostor fix, character controller script fix, and some other refactors --- .../character_controller.lua | 6 +++- WickedEngine/shaders/ShaderInterop_Renderer.h | 11 +++--- WickedEngine/shaders/globals.hlsli | 34 ++++--------------- WickedEngine/shaders/impostor_prepareCS.hlsl | 2 +- WickedEngine/wiHelper.cpp | 4 +-- WickedEngine/wiVersion.cpp | 2 +- 6 files changed, 22 insertions(+), 37 deletions(-) diff --git a/Content/scripts/character_controller/character_controller.lua b/Content/scripts/character_controller/character_controller.lua index 16bbe13d3..034cb0fda 100644 --- a/Content/scripts/character_controller/character_controller.lua +++ b/Content/scripts/character_controller/character_controller.lua @@ -900,7 +900,11 @@ runProcess(function() -- if player was not created from a metadata component, create a default player: if player == nil then - player = Character(character_scenes["character"], TransformComponent(), true, anim_scene) + if character_scenes["character"] == nil then + character_scenes["character"] = Scene() + LoadModel(character_scenes["character"], script_dir() .. "assets/" .. "character" .. ".wiscene") + end + player = Character(character_scenes["character"], TransformComponent(), true, anim_scene, "") end local camera = ThirdPersonCamera(player) diff --git a/WickedEngine/shaders/ShaderInterop_Renderer.h b/WickedEngine/shaders/ShaderInterop_Renderer.h index 61bdaf24a..074a03551 100644 --- a/WickedEngine/shaders/ShaderInterop_Renderer.h +++ b/WickedEngine/shaders/ShaderInterop_Renderer.h @@ -675,16 +675,19 @@ struct alignas(16) ShaderMeshInstance float3 center; float radius; - ShaderTransform transform; - ShaderTransform transformPrev; - ShaderTransform transformRaw; // without quantization remapping applied + ShaderTransform transform; // Note: this could contain quantization remapping from UNORM -> FLOAT depending on vertex position format + ShaderTransform transformPrev; // Note: this could contain quantization remapping from UNORM -> FLOAT depending on vertex position format + ShaderTransform transformRaw; // Note: this is the world matrix without any quantization remapping void init() { +#ifdef __cplusplus + using namespace wi::math; +#endif // __cplusplus uid = 0; flags = 0; layerMask = 0; - color = uint2(0, 0); + color = pack_half4(1, 1, 1, 1); emissive = uint2(0, 0); lightmap = -1; geometryOffset = 0; diff --git a/WickedEngine/shaders/globals.hlsli b/WickedEngine/shaders/globals.hlsli index 72b2e053f..0287571e4 100644 --- a/WickedEngine/shaders/globals.hlsli +++ b/WickedEngine/shaders/globals.hlsli @@ -120,7 +120,7 @@ inline uint2 pack_half4(in float4 value) retVal.y = f32tof16(value.z) | (f32tof16(value.w) << 16u); return retVal; } -inline uint2 pack_half3(in half a, in half b, in half c, in half d) +inline uint2 pack_half4(in half a, in half b, in half c, in half d) { return pack_half4(half4(a, b, c, d)); } @@ -155,33 +155,11 @@ T inverse_lerp(T value1, T value2, T pos) // Source: https://www.shadertoy.com/view/3s33zj float3x3 adjoint(in float4x4 m) { - return float3x3(cross(m[1].xyz, m[2].xyz), - cross(m[2].xyz, m[0].xyz), - cross(m[0].xyz, m[1].xyz)); - - /* - // alternative way to write the adjoint - - return mat3( - m[1].yzx*m[2].zxy-m[1].zxy*m[2].yzx, - m[2].yzx*m[0].zxy-m[2].zxy*m[0].yzx, - m[0].yzx*m[1].zxy-m[0].zxy*m[1].yzx ); - */ - - /* - // alternative way to write the adjoint - - return mat3( - m[1][1]*m[2][2]-m[1][2]*m[2][1], - m[1][2]*m[2][0]-m[1][0]*m[2][2], - m[1][0]*m[2][1]-m[1][1]*m[2][0], - m[0][2]*m[2][1]-m[0][1]*m[2][2], - m[0][0]*m[2][2]-m[0][2]*m[2][0], - m[0][1]*m[2][0]-m[0][0]*m[2][1], - m[0][1]*m[1][2]-m[0][2]*m[1][1], - m[0][2]*m[1][0]-m[0][0]*m[1][2], - m[0][0]*m[1][1]-m[0][1]*m[1][0] ); - */ + return float3x3( + cross(m[1].xyz, m[2].xyz), + cross(m[2].xyz, m[0].xyz), + cross(m[0].xyz, m[1].xyz) + ); } // The root signature will affect shader compilation for DX12. diff --git a/WickedEngine/shaders/impostor_prepareCS.hlsl b/WickedEngine/shaders/impostor_prepareCS.hlsl index 769f07f0b..a3acd84a2 100644 --- a/WickedEngine/shaders/impostor_prepareCS.hlsl +++ b/WickedEngine/shaders/impostor_prepareCS.hlsl @@ -94,7 +94,7 @@ void main(uint3 DTid : SV_DispatchThreadID) uint2 data = 0; data.x |= slice & 0xFFFFFF; data.x |= (uint(dither * 255) & 0xFF) << 24u; - data.y = instance.color; + data.y = pack_rgba(instance.GetColor()); output_impostor_data.Store2(impostorOffset * sizeof(uint2), data); // Write out vertices: diff --git a/WickedEngine/wiHelper.cpp b/WickedEngine/wiHelper.cpp index c2fe3a831..710ea8caa 100644 --- a/WickedEngine/wiHelper.cpp +++ b/WickedEngine/wiHelper.cpp @@ -987,7 +987,7 @@ namespace wi::helper std::filesystem::path relative = std::filesystem::relative(filepath, rootpath); if (!relative.empty()) { - path = FromWString(relative.generic_wstring()); + StringConvert(relative.generic_wstring(), path); } } @@ -998,7 +998,7 @@ namespace wi::helper std::filesystem::path absolute = std::filesystem::absolute(ToNativeString(path)); if (!absolute.empty()) { - path = FromWString(absolute.generic_wstring()); + StringConvert(absolute.generic_wstring(), path); } } diff --git a/WickedEngine/wiVersion.cpp b/WickedEngine/wiVersion.cpp index 7ab42aa0e..e9ab12e36 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 = 632; + const int revision = 633; const std::string version_string = std::to_string(major) + "." + std::to_string(minor) + "." + std::to_string(revision);