diff --git a/Content/Documentation/ScriptingAPI-Documentation.md b/Content/Documentation/ScriptingAPI-Documentation.md index 5212a13361..753b73f583 100644 --- a/Content/Documentation/ScriptingAPI-Documentation.md +++ b/Content/Documentation/ScriptingAPI-Documentation.md @@ -434,9 +434,13 @@ Gives you the ability to render text with a custom font. ### Texture -Just holds texture information in VRAM. +A texture image data. - [constructor]Texture(opt string filename) -- creates a texture from file - [outer]texturehelper -- a global helper texture creation utility +- GetWidth() : int +- GetHeight() : int +- GetDepth() : int +- GetArraySize() : int - GetLogo() : Texture -- returns the Wicked Engine logo texture - CreateGradientTexture( GradientType type = GradientType.Linear, @@ -1963,11 +1967,11 @@ Playstation button codes: - SetLinearVelocity(RigidBodyPhysicsComponent component, Vector velocity) -- Set the linear velocity manually - SetAngularVelocity(RigidBodyPhysicsComponent component, Vector velocity) -- Set the angular velocity manually - ApplyForce(RigidBodyPhysicsComponent component, Vector force) -- Apply force at body center -- ApplyForceAt(RigidBodyPhysicsComponent component, Vector force, Vector at) -- Apply force at body local position +- ApplyForceAt(RigidBodyPhysicsComponent component, Vector force, Vector at, bool at_local = true) -- Apply force at body local position (at_local controls whether the at is in body's local space or not) - ApplyImpulse(RigidBodyPhysicsComponent component, Vector impulse) -- Apply impulse at body center - ApplyImpulse(HumanoidComponent humanoid, HumanoidBone bone, Vector impulse) -- Apply impulse at body center of ragdoll bone -- ApplyImpulseAt(RigidBodyPhysicsComponent component, Vector impulse, Vector at) -- Apply impulse at body local position -- ApplyImpulseAt(HumanoidComponent humanoid, HumanoidBone bone, Vector impulse, Vector at) -- Apply impulse at body local position of ragdoll bone +- ApplyImpulseAt(RigidBodyPhysicsComponent component, Vector impulse, Vector at, bool at_local = true) -- Apply impulse at body local position (at_local controls whether the at is in body's local space or not) +- ApplyImpulseAt(HumanoidComponent humanoid, HumanoidBone bone, Vector impulse, Vector at, bool at_local = true) -- Apply impulse at body local position of ragdoll bone (at_local controls whether the at is in body's local space or not) - ApplyTorque(RigidBodyPhysicsComponent component, Vector torque) -- Apply torque at body center - ActivateAllRigidBodies(Scene scene) -- Activate all rigid bodies in the scene - SetActivationState(RigidBodyPhysicsComponent component, int state) -- Force set activation state to rigid body. Use a value ACTIVATION_STATE_ACTIVE or ACTIVATION_STATE_INACTIVE diff --git a/Editor/MaterialWindow.cpp b/Editor/MaterialWindow.cpp index a3848aab05..4c8a13e04c 100644 --- a/Editor/MaterialWindow.cpp +++ b/Editor/MaterialWindow.cpp @@ -29,7 +29,7 @@ void MaterialWindow::Create(EditorComponent* _editor) { editor = _editor; wi::gui::Window::Create(ICON_MATERIAL " Material", wi::gui::Window::WindowControls::COLLAPSE | wi::gui::Window::WindowControls::CLOSE); - SetSize(XMFLOAT2(300, 1460)); + SetSize(XMFLOAT2(300, 1500)); closeButton.SetTooltip("Delete MaterialComponent"); OnClose([=](wi::gui::EventArgs args) { @@ -405,6 +405,22 @@ void MaterialWindow::Create(EditorComponent* _editor) }); AddWidget(&emissiveSlider); + saturationSlider.Create(0, 2, 1, 1000, "Saturation: "); + saturationSlider.SetTooltip("Adjust the saturation of the material."); + saturationSlider.SetSize(XMFLOAT2(wid, hei)); + saturationSlider.SetPos(XMFLOAT2(x, y += step)); + saturationSlider.OnSlide([&](wi::gui::EventArgs args) { + wi::scene::Scene& scene = editor->GetCurrentScene(); + for (auto& x : editor->translator.selected) + { + MaterialComponent* material = get_material(scene, x); + if (material == nullptr) + continue; + material->SetSaturation(args.fValue); + } + }); + AddWidget(&saturationSlider); + cloakSlider.Create(0, 1.0f, 0.02f, 1000, "Cloak: "); cloakSlider.SetTooltip("The cloak effect is a combination of transmission, refraction and roughness, without color tinging."); cloakSlider.SetSize(XMFLOAT2(wid, hei)); @@ -1037,6 +1053,7 @@ void MaterialWindow::SetEntity(Entity entity) transmissionSlider.SetValue(material->transmission); refractionSlider.SetValue(material->refraction); emissiveSlider.SetValue(material->emissiveColor.w); + saturationSlider.SetValue(material->saturation); pomSlider.SetValue(material->parallaxOcclusionMapping); anisotropyStrengthSlider.SetValue(material->anisotropy_strength); anisotropyRotationSlider.SetValue(wi::math::RadiansToDegrees(material->anisotropy_rotation)); @@ -1215,6 +1232,7 @@ void MaterialWindow::ResizeLayout() add(reflectanceSlider); add(metalnessSlider); add(emissiveSlider); + add(saturationSlider); add(cloakSlider); add(chromaticAberrationSlider); add(transmissionSlider); diff --git a/Editor/MaterialWindow.h b/Editor/MaterialWindow.h index ecc02ae61e..415b0b5a84 100644 --- a/Editor/MaterialWindow.h +++ b/Editor/MaterialWindow.h @@ -30,6 +30,7 @@ class MaterialWindow : public wi::gui::Window wi::gui::Slider reflectanceSlider; wi::gui::Slider metalnessSlider; wi::gui::Slider emissiveSlider; + wi::gui::Slider saturationSlider; wi::gui::Slider cloakSlider; wi::gui::Slider chromaticAberrationSlider; wi::gui::Slider transmissionSlider; diff --git a/Editor/SpriteWindow.cpp b/Editor/SpriteWindow.cpp index 92d8a70aa4..9ac628aa41 100644 --- a/Editor/SpriteWindow.cpp +++ b/Editor/SpriteWindow.cpp @@ -10,7 +10,7 @@ void SpriteWindow::Create(EditorComponent* _editor) editor = _editor; wi::gui::Window::Create(ICON_SPRITE " Sprite", wi::gui::Window::WindowControls::COLLAPSE | wi::gui::Window::WindowControls::CLOSE); - SetSize(XMFLOAT2(670, 1500)); + SetSize(XMFLOAT2(670, 1540)); closeButton.SetTooltip("Delete Sprite"); OnClose([=](wi::gui::EventArgs args) { @@ -175,6 +175,20 @@ void SpriteWindow::Create(EditorComponent* _editor) }); AddWidget(&rotationSlider); + saturationSlider.Create(0, 2, 1, 1000, "Saturation: "); + saturationSlider.SetTooltip("Modify saturation of the image."); + saturationSlider.OnSlide([=](wi::gui::EventArgs args) { + wi::scene::Scene& scene = editor->GetCurrentScene(); + for (auto& x : editor->translator.selected) + { + wi::Sprite* sprite = scene.sprites.GetComponent(x.entity); + if (sprite == nullptr) + continue; + sprite->params.saturation = args.fValue; + } + }); + AddWidget(&saturationSlider); + alphaStartSlider.Create(0, 1, 0, 10000, "Mask Alpha Start: "); alphaStartSlider.SetTooltip("Constrain mask alpha to not go below this level."); alphaStartSlider.OnSlide([=](wi::gui::EventArgs args) { @@ -604,6 +618,7 @@ void SpriteWindow::SetEntity(wi::ecs::Entity entity) pivotYSlider.SetValue(sprite->params.pivot.y); intensitySlider.SetValue(sprite->params.intensity); rotationSlider.SetValue(wi::math::RadiansToDegrees(sprite->params.rotation)); + saturationSlider.SetValue(sprite->params.saturation); alphaStartSlider.SetValue(sprite->params.mask_alpha_range_start); alphaEndSlider.SetValue(sprite->params.mask_alpha_range_end); borderSoftenSlider.SetValue(sprite->params.border_soften); @@ -673,6 +688,7 @@ void SpriteWindow::ResizeLayout() add(pivotYSlider); add(intensitySlider); add(rotationSlider); + add(saturationSlider); add(alphaStartSlider); add(alphaEndSlider); add(borderSoftenSlider); diff --git a/Editor/SpriteWindow.h b/Editor/SpriteWindow.h index 95ab44b44f..cf389d938f 100644 --- a/Editor/SpriteWindow.h +++ b/Editor/SpriteWindow.h @@ -16,6 +16,7 @@ class SpriteWindow : public wi::gui::Window wi::gui::Slider pivotYSlider; wi::gui::Slider intensitySlider; wi::gui::Slider rotationSlider; + wi::gui::Slider saturationSlider; wi::gui::Slider alphaStartSlider; wi::gui::Slider alphaEndSlider; wi::gui::Slider borderSoftenSlider; diff --git a/WickedEngine/shaders/ShaderInterop_Image.h b/WickedEngine/shaders/ShaderInterop_Image.h index ea23d0f14f..c8c06b5099 100644 --- a/WickedEngine/shaders/ShaderInterop_Image.h +++ b/WickedEngine/shaders/ShaderInterop_Image.h @@ -38,8 +38,8 @@ struct ImageConstants float2 b3; float2 angular_softness_direction; - float angular_softness_scale; - float angular_softness_offset; + uint angular_softness_mad; // packed half2 + float saturation; }; CONSTANTBUFFER(image, ImageConstants, CBSLOT_IMAGE); diff --git a/WickedEngine/shaders/ShaderInterop_Renderer.h b/WickedEngine/shaders/ShaderInterop_Renderer.h index 6b7988a50d..43d72d931b 100644 --- a/WickedEngine/shaders/ShaderInterop_Renderer.h +++ b/WickedEngine/shaders/ShaderInterop_Renderer.h @@ -334,7 +334,7 @@ struct alignas(16) ShaderMaterial uint2 subsurfaceScattering_inv; uint2 specular_chromatic; - uint2 sheenColor; + uint2 sheenColor_saturation; float4 texMulAdd; @@ -362,7 +362,7 @@ struct alignas(16) ShaderMaterial subsurfaceScattering_inv = uint2(0, 0); specular_chromatic = uint2(0, 0); - sheenColor = uint2(0, 0); + sheenColor_saturation = uint2(0, 0); texMulAdd = float4(1, 1, 0, 0); @@ -390,7 +390,8 @@ struct alignas(16) ShaderMaterial inline half GetCloak() { return unpack_half4(emissive_cloak).a; } inline half3 GetSpecular() { return unpack_half3(specular_chromatic); } inline half GetChromaticAberration() { return unpack_half4(specular_chromatic).w; } - inline half3 GetSheenColor() { return unpack_half3(sheenColor); } + inline half3 GetSheenColor() { return unpack_half3(sheenColor_saturation); } + inline half GetSaturation() { return unpack_half4(sheenColor_saturation).w; } inline half GetRoughness() { return unpack_half4(roughness_reflectance_metalness_refraction).x; } inline half GetReflectance() { return unpack_half4(roughness_reflectance_metalness_refraction).y; } inline half GetMetalness() { return unpack_half4(roughness_reflectance_metalness_refraction).z; } diff --git a/WickedEngine/shaders/globals.hlsli b/WickedEngine/shaders/globals.hlsli index 07d992d433..713e6edcc7 100644 --- a/WickedEngine/shaders/globals.hlsli +++ b/WickedEngine/shaders/globals.hlsli @@ -1939,4 +1939,21 @@ inline float3 get_right(float4x4 m) return float3(m[0][0], m[0][1], m[0][2]); } +half3x3 saturationMatrix(half saturation) +{ + half3 luminance = half3(0.3086, 0.6094, 0.0820); + half oneMinusSat = 1.0 - saturation; + + half3 red = half3(luminance * oneMinusSat); + red += half3(saturation, 0, 0); + + half3 green = half3(luminance * oneMinusSat); + green += half3(0, saturation, 0); + + half3 blue = half3(luminance * oneMinusSat); + blue += half3(0, 0, saturation); + + return half3x3(red, green, blue); +} + #endif // WI_SHADER_GLOBALS_HF diff --git a/WickedEngine/shaders/imagePS.hlsl b/WickedEngine/shaders/imagePS.hlsl index a12a7e13a6..f9bfc0b0b6 100644 --- a/WickedEngine/shaders/imagePS.hlsl +++ b/WickedEngine/shaders/imagePS.hlsl @@ -79,7 +79,7 @@ float4 main(VertextoPixel input) : SV_TARGET } [branch] - if (image.angular_softness_scale > 0) + if (image.angular_softness_mad > 0) { float2 direction = normalize(uvsets.xy - 0.5); float dp = dot(direction, image.angular_softness_direction); @@ -91,7 +91,8 @@ float4 main(VertextoPixel input) : SV_TARGET { dp = saturate(dp); } - float angular = saturate(mad(dp, image.angular_softness_scale, image.angular_softness_offset)); + float2 angular_softness_mad = unpack_half2(image.angular_softness_mad); + float angular = saturate(mad(dp, angular_softness_mad.x, angular_softness_mad.y)); if (image.flags & IMAGE_FLAG_ANGULAR_INVERSE) { angular = 1 - angular; @@ -99,6 +100,8 @@ float4 main(VertextoPixel input) : SV_TARGET angular = smoothstep(0, 1, angular); color.a *= angular; } + + color.rgb = mul(saturationMatrix(image.saturation), color.rgb); return color; } diff --git a/WickedEngine/shaders/objectHF.hlsli b/WickedEngine/shaders/objectHF.hlsli index 19ae0b27c4..196d0973d4 100644 --- a/WickedEngine/shaders/objectHF.hlsli +++ b/WickedEngine/shaders/objectHF.hlsli @@ -1082,6 +1082,7 @@ float4 main(PixelInput input, in bool is_frontface : SV_IsFrontFace) : SV_Target ApplyFog(dist, surface.V, color); #endif // OBJECTSHADER_USE_POSITION3D + color.rgb = mul(saturationMatrix(material.GetSaturation()), color.rgb); color = saturateMediump(color); diff --git a/WickedEngine/shaders/tonemapCS.hlsl b/WickedEngine/shaders/tonemapCS.hlsl index d0721fe7b8..732598794f 100644 --- a/WickedEngine/shaders/tonemapCS.hlsl +++ b/WickedEngine/shaders/tonemapCS.hlsl @@ -42,23 +42,6 @@ float3 ACESFitted(float3 color) return color; } -float4x4 saturationMatrix(float saturation) -{ - float3 luminance = float3(0.3086f, 0.6094f, 0.0820f); - float oneMinusSat = 1.0f - saturation; - - float3 red = float3(luminance * oneMinusSat); - red += float3(saturation, 0, 0); - - float3 green = float3(luminance * oneMinusSat); - green += float3(0, saturation, 0); - - float3 blue = float3(luminance * oneMinusSat); - blue += float3(0, 0, saturation); - - return float4x4(red, 0, green, 0, blue, 0, 0, 0, 0, 1); -} - [numthreads(POSTPROCESS_BLOCKSIZE, POSTPROCESS_BLOCKSIZE, 1)] void main(uint3 DTid : SV_DispatchThreadID) { @@ -137,7 +120,7 @@ void main(uint3 DTid : SV_DispatchThreadID) } result.rgb = (result.rgb - 0.5f) * contrast + 0.5f + brightness; - result.rgb = (float3)(mul(saturationMatrix(saturation), result)); + result.rgb = mul(saturationMatrix(saturation), result.rgb); [branch] if (tonemap_push.texture_output >= 0) diff --git a/WickedEngine/wiImage.cpp b/WickedEngine/wiImage.cpp index baee16a745..3fa01d8434 100644 --- a/WickedEngine/wiImage.cpp +++ b/WickedEngine/wiImage.cpp @@ -129,10 +129,11 @@ namespace wi::image const float lightAngleScale = 1.0f / std::max(0.001f, innerConeAngleCos - outerConeAngleCos); const float lightAngleOffset = -outerConeAngleCos * lightAngleScale; image.angular_softness_direction = params.angular_softness_direction; - image.angular_softness_scale = lightAngleScale; - image.angular_softness_offset = lightAngleOffset; + image.angular_softness_mad = wi::math::pack_half2(lightAngleScale, lightAngleOffset); } + image.saturation = params.saturation; + image.flags = 0; if (params.isExtractNormalMapEnabled()) { diff --git a/WickedEngine/wiImage.h b/WickedEngine/wiImage.h index b899481862..ddc48454de 100644 --- a/WickedEngine/wiImage.h +++ b/WickedEngine/wiImage.h @@ -83,6 +83,7 @@ namespace wi::image XMFLOAT2 angular_softness_direction = XMFLOAT2(0, 1); float angular_softness_inner_angle = 0; float angular_softness_outer_angle = 0; + float saturation = 1; // you can deform the image by its corners (0: top left, 1: top right, 2: bottom left, 3: bottom right) XMFLOAT2 corners[4] = { diff --git a/WickedEngine/wiImageParams_BindLua.cpp b/WickedEngine/wiImageParams_BindLua.cpp index dc4e7bacc9..08c02c462e 100644 --- a/WickedEngine/wiImageParams_BindLua.cpp +++ b/WickedEngine/wiImageParams_BindLua.cpp @@ -9,6 +9,7 @@ namespace wi::lua lunamethod(ImageParams_BindLua, GetPivot), lunamethod(ImageParams_BindLua, GetColor), lunamethod(ImageParams_BindLua, GetOpacity), + lunamethod(ImageParams_BindLua, GetSaturation), lunamethod(ImageParams_BindLua, GetFade), lunamethod(ImageParams_BindLua, GetRotation), lunamethod(ImageParams_BindLua, GetTexOffset), @@ -28,6 +29,7 @@ namespace wi::lua lunamethod(ImageParams_BindLua, SetPivot), lunamethod(ImageParams_BindLua, SetColor), lunamethod(ImageParams_BindLua, SetOpacity), + lunamethod(ImageParams_BindLua, SetSaturation), lunamethod(ImageParams_BindLua, SetFade), lunamethod(ImageParams_BindLua, SetStencil), lunamethod(ImageParams_BindLua, SetStencilRefMode), @@ -97,6 +99,11 @@ namespace wi::lua wi::lua::SSetFloat(L, params.opacity); return 1; } + int ImageParams_BindLua::GetSaturation(lua_State* L) + { + wi::lua::SSetFloat(L, params.saturation); + return 1; + } int ImageParams_BindLua::GetFade(lua_State* L) { wi::lua::SSetFloat(L, params.fade); @@ -244,6 +251,19 @@ namespace wi::lua } return 0; } + int ImageParams_BindLua::SetSaturation(lua_State* L) + { + int argc = wi::lua::SGetArgCount(L); + if (argc > 0) + { + params.saturation = wi::lua::SGetFloat(L, 1); + } + else + { + wi::lua::SError(L, "SetSaturation(float x) not enough arguments!"); + } + return 0; + } int ImageParams_BindLua::SetFade(lua_State* L) { int argc = wi::lua::SGetArgCount(L); diff --git a/WickedEngine/wiImageParams_BindLua.h b/WickedEngine/wiImageParams_BindLua.h index 468c49acff..df65b546f9 100644 --- a/WickedEngine/wiImageParams_BindLua.h +++ b/WickedEngine/wiImageParams_BindLua.h @@ -22,6 +22,7 @@ namespace wi::lua int GetPivot(lua_State* L); int GetColor(lua_State* L); int GetOpacity(lua_State* L); + int GetSaturation(lua_State* L); int GetFade(lua_State* L); int GetRotation(lua_State* L); int GetTexOffset(lua_State* L); @@ -41,6 +42,7 @@ namespace wi::lua int SetPivot(lua_State* L); int SetColor(lua_State* L); int SetOpacity(lua_State* L); + int SetSaturation(lua_State* L); int SetFade(lua_State* L); int SetStencil(lua_State* L); int SetStencilRefMode(lua_State* L); diff --git a/WickedEngine/wiPhysics.h b/WickedEngine/wiPhysics.h index 34bb915449..41c47bfcb2 100644 --- a/WickedEngine/wiPhysics.h +++ b/WickedEngine/wiPhysics.h @@ -63,11 +63,12 @@ namespace wi::physics wi::scene::RigidBodyPhysicsComponent& physicscomponent, const XMFLOAT3& force ); - // Apply force at body local position + // Apply force at position void ApplyForceAt( wi::scene::RigidBodyPhysicsComponent& physicscomponent, const XMFLOAT3& force, - const XMFLOAT3& at + const XMFLOAT3& at, + bool at_local = true // whether at is in local space of the body or not (global) ); // Apply impulse at body center @@ -80,17 +81,19 @@ namespace wi::physics wi::scene::HumanoidComponent::HumanoidBone bone, const XMFLOAT3& impulse ); - // Apply impulse at body local position + // Apply impulse at position void ApplyImpulseAt( wi::scene::RigidBodyPhysicsComponent& physicscomponent, const XMFLOAT3& impulse, - const XMFLOAT3& at + const XMFLOAT3& at, + bool at_local = true // whether at is in local space of the body or not (global) ); void ApplyImpulseAt( wi::scene::HumanoidComponent& humanoid, wi::scene::HumanoidComponent::HumanoidBone bone, const XMFLOAT3& impulse, - const XMFLOAT3& at + const XMFLOAT3& at, + bool at_local = true // whether at is in local space of the body or not (global) ); void ApplyTorque( diff --git a/WickedEngine/wiPhysics_BindLua.cpp b/WickedEngine/wiPhysics_BindLua.cpp index 5292ca391c..b847d377ec 100644 --- a/WickedEngine/wiPhysics_BindLua.cpp +++ b/WickedEngine/wiPhysics_BindLua.cpp @@ -236,10 +236,15 @@ namespace wi::lua wi::lua::SError(L, "ApplyForceAt(RigidBodyPhysicsComponent component, Vector force, Vector at) third argument is not a Vector!"); return 0; } + bool at_local = true; + if (argc > 3) + at_local = wi::lua::SGetBool(L, 4); + wi::physics::ApplyForceAt( *component->component, *(XMFLOAT3*)vec, - *(XMFLOAT3*)vec2 + *(XMFLOAT3*)vec2, + at_local ); } else @@ -318,11 +323,16 @@ namespace wi::lua wi::lua::SError(L, "ApplyImpulseAt(HumanoidComponent component, HumanoidBone bone, Vector impulse, Vector at) fourth argument is not a Vector!"); return 0; } + bool at_local = true; + if (argc > 4) + at_local = wi::lua::SGetBool(L, 5); + wi::physics::ApplyImpulseAt( *humanoid->component, bone, *(XMFLOAT3*)vec, - *(XMFLOAT3*)vec2 + *(XMFLOAT3*)vec2, + at_local ); return 0; } @@ -338,10 +348,15 @@ namespace wi::lua wi::lua::SError(L, "ApplyImpulseAt(RigidBodyPhysicsComponent component, Vector impulse, Vector at) third argument is not a Vector!"); return 0; } + bool at_local = true; + if (argc > 3) + at_local = wi::lua::SGetBool(L, 4); + wi::physics::ApplyImpulseAt( *component->component, *(XMFLOAT3*)vec, - *(XMFLOAT3*)vec2 + *(XMFLOAT3*)vec2, + at_local ); } else diff --git a/WickedEngine/wiPhysics_Jolt.cpp b/WickedEngine/wiPhysics_Jolt.cpp index 1db2ad8a44..a5b770720c 100644 --- a/WickedEngine/wiPhysics_Jolt.cpp +++ b/WickedEngine/wiPhysics_Jolt.cpp @@ -1808,7 +1808,8 @@ namespace wi::physics void ApplyForceAt( wi::scene::RigidBodyPhysicsComponent& physicscomponent, const XMFLOAT3& force, - const XMFLOAT3& at + const XMFLOAT3& at, + bool at_local ) { if (physicscomponent.physicsobject != nullptr) @@ -1816,7 +1817,7 @@ namespace wi::physics RigidBody& physicsobject = GetRigidBody(physicscomponent); PhysicsScene& physics_scene = *(PhysicsScene*)physicsobject.physics_scene.get(); BodyInterface& body_interface = physics_scene.physics_system.GetBodyInterfaceNoLock(); - Vec3 at_world = body_interface.GetCenterOfMassTransform(physicsobject.bodyID).Inversed() * cast(at); + Vec3 at_world = at_local ? body_interface.GetCenterOfMassTransform(physicsobject.bodyID).Inversed() * cast(at) : cast(at); body_interface.AddForce(physicsobject.bodyID, cast(force), at_world); } } @@ -1896,7 +1897,8 @@ namespace wi::physics void ApplyImpulseAt( wi::scene::RigidBodyPhysicsComponent& physicscomponent, const XMFLOAT3& impulse, - const XMFLOAT3& at + const XMFLOAT3& at, + bool at_local ) { if (physicscomponent.physicsobject != nullptr) @@ -1904,7 +1906,7 @@ namespace wi::physics RigidBody& physicsobject = GetRigidBody(physicscomponent); PhysicsScene& physics_scene = *(PhysicsScene*)physicsobject.physics_scene.get(); BodyInterface& body_interface = physics_scene.physics_system.GetBodyInterfaceNoLock(); - Vec3 at_world = body_interface.GetCenterOfMassTransform(physicsobject.bodyID) * cast(at); + Vec3 at_world = at_local ? body_interface.GetCenterOfMassTransform(physicsobject.bodyID) * cast(at) : cast(at); body_interface.AddImpulse(physicsobject.bodyID, cast(impulse), at_world); } } @@ -1912,7 +1914,8 @@ namespace wi::physics wi::scene::HumanoidComponent& humanoid, wi::scene::HumanoidComponent::HumanoidBone bone, const XMFLOAT3& impulse, - const XMFLOAT3& at + const XMFLOAT3& at, + bool at_local ) { if (humanoid.ragdoll == nullptr) @@ -1965,7 +1968,7 @@ namespace wi::physics RigidBody& physicsobject = ragdoll.rigidbodies[bodypart]; PhysicsScene& physics_scene = *(PhysicsScene*)physicsobject.physics_scene.get(); BodyInterface& body_interface = physics_scene.physics_system.GetBodyInterfaceNoLock(); - Vec3 at_world = body_interface.GetCenterOfMassTransform(physicsobject.bodyID) * cast(at); + Vec3 at_world = at_local ? body_interface.GetCenterOfMassTransform(physicsobject.bodyID) * cast(at) : cast(at); body_interface.SetMotionType(physicsobject.bodyID, EMotionType::Dynamic, EActivation::Activate); body_interface.AddImpulse(physicsobject.bodyID, cast(impulse), at_world); } diff --git a/WickedEngine/wiScene.h b/WickedEngine/wiScene.h index bdb6745667..c6f2182c40 100644 --- a/WickedEngine/wiScene.h +++ b/WickedEngine/wiScene.h @@ -32,7 +32,7 @@ namespace wi::scene wi::ecs::ComponentManager& layers = componentLibrary.Register("wi::scene::Scene::layers"); wi::ecs::ComponentManager& transforms = componentLibrary.Register("wi::scene::Scene::transforms"); wi::ecs::ComponentManager& hierarchy = componentLibrary.Register("wi::scene::Scene::hierarchy"); - wi::ecs::ComponentManager& materials = componentLibrary.Register("wi::scene::Scene::materials", 7); // version = 7 + wi::ecs::ComponentManager& materials = componentLibrary.Register("wi::scene::Scene::materials", 8); // version = 8 wi::ecs::ComponentManager& meshes = componentLibrary.Register("wi::scene::Scene::meshes", 3); // version = 3 wi::ecs::ComponentManager& impostors = componentLibrary.Register("wi::scene::Scene::impostors"); wi::ecs::ComponentManager& objects = componentLibrary.Register("wi::scene::Scene::objects", 4); // version = 4 @@ -58,7 +58,7 @@ namespace wi::scene wi::ecs::ComponentManager& expressions = componentLibrary.Register("wi::scene::Scene::expressions"); wi::ecs::ComponentManager& humanoids = componentLibrary.Register("wi::scene::Scene::humanoids", 1); // version = 1 wi::ecs::ComponentManager& terrains = componentLibrary.Register("wi::scene::Scene::terrains", 5); // version = 5 - wi::ecs::ComponentManager& sprites = componentLibrary.Register("wi::scene::Scene::sprites"); + wi::ecs::ComponentManager& sprites = componentLibrary.Register("wi::scene::Scene::sprites", 1); // version = 1 wi::ecs::ComponentManager& fonts = componentLibrary.Register("wi::scene::Scene::fonts"); wi::ecs::ComponentManager& voxel_grids = componentLibrary.Register("wi::scene::Scene::voxel_grids"); wi::ecs::ComponentManager& metadatas = componentLibrary.Register("wi::scene::Scene::metadatas"); diff --git a/WickedEngine/wiScene_BindLua.cpp b/WickedEngine/wiScene_BindLua.cpp index 37040ed4b7..63f8c25e14 100644 --- a/WickedEngine/wiScene_BindLua.cpp +++ b/WickedEngine/wiScene_BindLua.cpp @@ -4443,6 +4443,7 @@ Luna::PropertyType MaterialComponent_BindLua::propert lunaproperty(MaterialComponent_BindLua, Transmission), lunaproperty(MaterialComponent_BindLua, Cloak), lunaproperty(MaterialComponent_BindLua, ChromaticAberration), + lunaproperty(MaterialComponent_BindLua, Saturation), lunaproperty(MaterialComponent_BindLua, AlphaRef), lunaproperty(MaterialComponent_BindLua, SheenColor), lunaproperty(MaterialComponent_BindLua, SheenRoughness), diff --git a/WickedEngine/wiScene_BindLua.h b/WickedEngine/wiScene_BindLua.h index c7c6afb806..12d37b2327 100644 --- a/WickedEngine/wiScene_BindLua.h +++ b/WickedEngine/wiScene_BindLua.h @@ -420,6 +420,7 @@ namespace wi::lua::scene Transmission = FloatProperty(&component->transmission); Cloak = FloatProperty(&component->cloak); ChromaticAberration = FloatProperty(&component->chromatic_aberration); + Saturation = FloatProperty(&component->saturation); AlphaRef = FloatProperty(&component->alphaRef); SheenColor = VectorProperty(&component->sheenColor); SheenRoughness = FloatProperty(&component->sheenRoughness); @@ -457,6 +458,7 @@ namespace wi::lua::scene FloatProperty Transmission; FloatProperty Cloak; FloatProperty ChromaticAberration; + FloatProperty Saturation; FloatProperty AlphaRef; VectorProperty SheenColor; FloatProperty SheenRoughness; @@ -484,6 +486,7 @@ namespace wi::lua::scene PropertyFunction(Transmission) PropertyFunction(Cloak) PropertyFunction(ChromaticAberration) + PropertyFunction(Saturation) PropertyFunction(AlphaRef) PropertyFunction(SheenColor) PropertyFunction(SheenRoughness) diff --git a/WickedEngine/wiScene_Components.cpp b/WickedEngine/wiScene_Components.cpp index 568f14df54..66203da865 100644 --- a/WickedEngine/wiScene_Components.cpp +++ b/WickedEngine/wiScene_Components.cpp @@ -292,11 +292,11 @@ namespace wi::scene if (shaderType == SHADERTYPE_WATER) { - material.sheenColor = pack_half3(XMFLOAT3(1 - extinctionColor.x, 1 - extinctionColor.y, 1 - extinctionColor.z)); + material.sheenColor_saturation = pack_half4(XMFLOAT4(1 - extinctionColor.x, 1 - extinctionColor.y, 1 - extinctionColor.z, saturation)); } else { - material.sheenColor = pack_half3(XMFLOAT3(sheenColor.x, sheenColor.y, sheenColor.z)); + material.sheenColor_saturation = pack_half4(XMFLOAT4(sheenColor.x, sheenColor.y, sheenColor.z, saturation)); } material.transmission_sheenroughness_clearcoat_clearcoatroughness = pack_half4(transmission, sheenRoughness, clearcoat, clearcoatRoughness); material.layerMask = layerMask; diff --git a/WickedEngine/wiScene_Components.h b/WickedEngine/wiScene_Components.h index 128848ba9d..7ed1a3b115 100644 --- a/WickedEngine/wiScene_Components.h +++ b/WickedEngine/wiScene_Components.h @@ -190,6 +190,7 @@ namespace wi::scene float blend_with_terrain_height = 0; float cloak = 0; float chromatic_aberration = 0; + float saturation = 1; XMFLOAT4 sheenColor = XMFLOAT4(1, 1, 1, 1); float sheenRoughness = 0; @@ -293,6 +294,7 @@ namespace wi::scene inline void SetReflectance(float value) { SetDirty(); reflectance = value; } inline void SetMetalness(float value) { SetDirty(); metalness = value; } inline void SetEmissiveStrength(float value) { SetDirty(); emissiveColor.w = value; } + inline void SetSaturation(float value) { SetDirty(); saturation = value; } inline void SetTransmissionAmount(float value) { SetDirty(); transmission = value; } inline void SetCloakAmount(float value) { SetDirty(); cloak = value; } inline void SetChromaticAberrationAmount(float value) { SetDirty(); chromatic_aberration = value; } diff --git a/WickedEngine/wiScene_Serializers.cpp b/WickedEngine/wiScene_Serializers.cpp index 769b6756bb..6855a7d40e 100644 --- a/WickedEngine/wiScene_Serializers.cpp +++ b/WickedEngine/wiScene_Serializers.cpp @@ -252,6 +252,10 @@ namespace wi::scene { archive >> chromatic_aberration; } + if (seri.GetVersion() >= 8) + { + archive >> saturation; + } for (auto& x : textures) { @@ -413,6 +417,10 @@ namespace wi::scene { archive << chromatic_aberration; } + if (seri.GetVersion() >= 8) + { + archive << saturation; + } } } void MeshComponent::Serialize(wi::Archive& archive, EntitySerializer& seri) diff --git a/WickedEngine/wiSprite.cpp b/WickedEngine/wiSprite.cpp index db937b94e8..2f7a706d56 100644 --- a/WickedEngine/wiSprite.cpp +++ b/WickedEngine/wiSprite.cpp @@ -199,6 +199,11 @@ namespace wi archive >> anim.wobbleAnim.amount; archive >> anim.wobbleAnim.speed; + if (seri.GetVersion() >= 1) + { + archive >> params.saturation; + } + if (!textureName.empty() || !maskName.empty()) { wi::jobsystem::Execute(seri.ctx, [&](wi::jobsystem::JobArgs args) { @@ -274,6 +279,11 @@ namespace wi archive << anim.drawRectAnim.horizontalFrameCount; archive << anim.wobbleAnim.amount; archive << anim.wobbleAnim.speed; + + if (seri.GetVersion() >= 1) + { + archive << params.saturation; + } } } diff --git a/WickedEngine/wiTexture_BindLua.cpp b/WickedEngine/wiTexture_BindLua.cpp index 244f06ce54..19416b1007 100644 --- a/WickedEngine/wiTexture_BindLua.cpp +++ b/WickedEngine/wiTexture_BindLua.cpp @@ -13,6 +13,11 @@ namespace wi::lua lunamethod(Texture_BindLua, CreateGradientTexture), lunamethod(Texture_BindLua, CreateLensDistortionNormalMap), lunamethod(Texture_BindLua, Save), + + lunamethod(Texture_BindLua, GetWidth), + lunamethod(Texture_BindLua, GetHeight), + lunamethod(Texture_BindLua, GetDepth), + lunamethod(Texture_BindLua, GetArraySize), { NULL, NULL } }; Luna::PropertyType Texture_BindLua::properties[] = { @@ -198,6 +203,47 @@ namespace wi::lua return 0; } + int Texture_BindLua::GetWidth(lua_State* L) + { + if (!resource.IsValid() || !resource.GetTexture().IsValid()) + { + wi::lua::SSetInt(L, 0); + return 1; + } + wi::lua::SSetInt(L, resource.GetTexture().GetDesc().width); + return 1; + } + int Texture_BindLua::GetHeight(lua_State* L) + { + if (!resource.IsValid() || !resource.GetTexture().IsValid()) + { + wi::lua::SSetInt(L, 0); + return 1; + } + wi::lua::SSetInt(L, resource.GetTexture().GetDesc().height); + return 1; + } + int Texture_BindLua::GetDepth(lua_State* L) + { + if (!resource.IsValid() || !resource.GetTexture().IsValid()) + { + wi::lua::SSetInt(L, 0); + return 1; + } + wi::lua::SSetInt(L, resource.GetTexture().GetDesc().depth); + return 1; + } + int Texture_BindLua::GetArraySize(lua_State* L) + { + if (!resource.IsValid() || !resource.GetTexture().IsValid()) + { + wi::lua::SSetInt(L, 0); + return 1; + } + wi::lua::SSetInt(L, resource.GetTexture().GetDesc().array_size); + return 1; + } + void Texture_BindLua::Bind() { static bool initialized = false; diff --git a/WickedEngine/wiTexture_BindLua.h b/WickedEngine/wiTexture_BindLua.h index 1420d41596..2c5b5fb050 100644 --- a/WickedEngine/wiTexture_BindLua.h +++ b/WickedEngine/wiTexture_BindLua.h @@ -26,6 +26,11 @@ namespace wi::lua int CreateLensDistortionNormalMap(lua_State* L); int Save(lua_State* L); + int GetWidth(lua_State* L); + int GetHeight(lua_State* L); + int GetDepth(lua_State* L); + int GetArraySize(lua_State* L); + static void Bind(); }; diff --git a/WickedEngine/wiVersion.cpp b/WickedEngine/wiVersion.cpp index 8363a00993..d3dc18110e 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 = 561; + const int revision = 562; const std::string version_string = std::to_string(major) + "." + std::to_string(minor) + "." + std::to_string(revision);