From fc4256160345e5f514840dac5a7813eafa1a5542 Mon Sep 17 00:00:00 2001 From: ueshita Date: Wed, 27 Dec 2023 21:31:16 +0900 Subject: [PATCH] Add a directional billboard type --- .../Effekseer/Effekseer/Effekseer.Base.Pre.h | 1 + .../Effekseer/Effekseer.EffectNodeModel.cpp | 5 +++++ .../Effekseer/Effekseer.EffectNodeRing.cpp | 5 +++++ .../Effekseer/Effekseer.EffectNodeSprite.cpp | 5 +++++ .../Effekseer/Effekseer.Instance.cpp | 15 ++++++++++++++- .../Effekseer/Effekseer/Effekseer.Instance.h | 4 ++++ .../Renderer/Effekseer.ModelRenderer.h | 2 ++ .../Renderer/Effekseer.RingRenderer.h | 2 ++ .../Renderer/Effekseer.SpriteRenderer.h | 2 ++ .../EffekseerRenderer.CommonUtils.cpp | 19 ++++++++++++++++--- .../EffekseerRenderer.CommonUtils.h | 3 ++- .../EffekseerRenderer.ModelRendererBase.h | 2 +- .../EffekseerRenderer.RingRendererBase.h | 8 +++----- .../EffekseerRenderer.SpriteRendererBase.h | 8 +++----- .../EffekseerCore/Data/RendererValues.cs | 2 ++ .../languages/en/Effekseer_RenderSettings.csv | 1 + .../languages/es/Effekseer_RenderSettings.csv | 1 + .../languages/ja/Effekseer_RenderSettings.csv | 1 + 18 files changed, 70 insertions(+), 16 deletions(-) diff --git a/Dev/Cpp/Effekseer/Effekseer/Effekseer.Base.Pre.h b/Dev/Cpp/Effekseer/Effekseer/Effekseer.Base.Pre.h index e15d266a14..6d0d18aca8 100644 --- a/Dev/Cpp/Effekseer/Effekseer/Effekseer.Base.Pre.h +++ b/Dev/Cpp/Effekseer/Effekseer/Effekseer.Base.Pre.h @@ -208,6 +208,7 @@ enum class BillboardType : int32_t YAxisFixed = 1, Fixed = 2, RotatedBillboard = 3, + DirectionalBillboard = 4, }; enum class CoordinateSystem : int32_t diff --git a/Dev/Cpp/Effekseer/Effekseer/Effekseer.EffectNodeModel.cpp b/Dev/Cpp/Effekseer/Effekseer/Effekseer.EffectNodeModel.cpp index 2a3bb7c76d..bbe44a4dad 100644 --- a/Dev/Cpp/Effekseer/Effekseer/Effekseer.EffectNodeModel.cpp +++ b/Dev/Cpp/Effekseer/Effekseer/Effekseer.EffectNodeModel.cpp @@ -147,6 +147,11 @@ void EffectNodeModel::Rendering(const Instance& instance, const Instance* next_i instanceParameter.ViewOffsetDistance = instance.translation_state_.view_offset.distance; } + if (nodeParam_.Billboard == BillboardType::DirectionalBillboard) + { + instanceParameter.Direction = instance.GetGlobalDirection(); + } + CalcCustomData(&instance, instanceParameter.CustomData1, instanceParameter.CustomData2); Color _color; diff --git a/Dev/Cpp/Effekseer/Effekseer/Effekseer.EffectNodeRing.cpp b/Dev/Cpp/Effekseer/Effekseer/Effekseer.EffectNodeRing.cpp index 540fa42983..4af2ff20eb 100644 --- a/Dev/Cpp/Effekseer/Effekseer/Effekseer.EffectNodeRing.cpp +++ b/Dev/Cpp/Effekseer/Effekseer/Effekseer.EffectNodeRing.cpp @@ -315,6 +315,11 @@ void EffectNodeRing::Rendering(const Instance& instance, const Instance* next_in instanceParameter.ViewOffsetDistance = instance.translation_state_.view_offset.distance; } + if (nodeParameter.Billboard == BillboardType::DirectionalBillboard) + { + instanceParameter.Direction = instance.GetGlobalDirection(); + } + CalcCustomData(&instance, instanceParameter.CustomData1, instanceParameter.CustomData2); renderer->Rendering(nodeParameter, instanceParameter, userData); diff --git a/Dev/Cpp/Effekseer/Effekseer/Effekseer.EffectNodeSprite.cpp b/Dev/Cpp/Effekseer/Effekseer/Effekseer.EffectNodeSprite.cpp index a56c90938f..9f080e9767 100644 --- a/Dev/Cpp/Effekseer/Effekseer/Effekseer.EffectNodeSprite.cpp +++ b/Dev/Cpp/Effekseer/Effekseer/Effekseer.EffectNodeSprite.cpp @@ -229,6 +229,11 @@ void EffectNodeSprite::Rendering(const Instance& instance, const Instance* next_ instanceParameter.ViewOffsetDistance = instance.translation_state_.view_offset.distance; } + if (nodeParam_.Billboard == BillboardType::DirectionalBillboard) + { + instanceParameter.Direction = instance.GetGlobalDirection(); + } + CalcCustomData(&instance, instanceParameter.CustomData1, instanceParameter.CustomData2); renderer->Rendering(nodeParam_, instanceParameter, userData); diff --git a/Dev/Cpp/Effekseer/Effekseer/Effekseer.Instance.cpp b/Dev/Cpp/Effekseer/Effekseer/Effekseer.Instance.cpp index e0137b9bf8..411e31d73b 100644 --- a/Dev/Cpp/Effekseer/Effekseer/Effekseer.Instance.cpp +++ b/Dev/Cpp/Effekseer/Effekseer/Effekseer.Instance.cpp @@ -231,6 +231,7 @@ void Instance::Initialize(Instance* parent, float spawnDeltaFrame, int32_t insta prevPosition_ = SIMD::Vec3f(0, 0, 0); prevLocalVelocity_ = SIMD::Vec3f(0, 0, 0); + globalDirection_ = SIMD::Vec3f(0, 1, 0); location_modify_global_ = SIMD::Vec3f(0, 0, 0); velocity_modify_global_ = SIMD::Vec3f(0, 0, 0); } @@ -572,6 +573,11 @@ float Instance::GetFlipbookIndexAndNextRate() const return GetFlipbookIndexAndNextRate(CommonValue.UVs[0].Type, CommonValue.UVs[0], uvAnimationData_[0]); } +SIMD::Vec3f Instance::GetGlobalDirection() const +{ + return globalDirection_; +} + void Instance::UpdateTransform(float deltaFrame) { // 計算済なら終了 @@ -758,7 +764,14 @@ void Instance::UpdateTransform(float deltaFrame) globalMatrix_.Step(calcMat, m_LivingTime); - prevGlobalPosition_ = globalMatrix_.GetCurrent().GetTranslation(); + SIMD::Vec3f currentGlbalPosition = globalMatrix_.GetCurrent().GetTranslation(); + SIMD::Vec3f deltaPosition = currentGlbalPosition - prevGlobalPosition_; + + if (!deltaPosition.IsZero()) + { + globalDirection_ = deltaPosition.GetNormal(); + } + prevGlobalPosition_ = currentGlbalPosition; globalMatrix_rendered = calcMat; } diff --git a/Dev/Cpp/Effekseer/Effekseer/Effekseer.Instance.h b/Dev/Cpp/Effekseer/Effekseer/Effekseer.Instance.h index 78f3f2b658..7dc547659b 100644 --- a/Dev/Cpp/Effekseer/Effekseer/Effekseer.Instance.h +++ b/Dev/Cpp/Effekseer/Effekseer/Effekseer.Instance.h @@ -81,6 +81,8 @@ class alignas(16) Instance : public IntrusiveList::Node SIMD::Vec3f location_modify_global_; SIMD::Vec3f velocity_modify_global_; + SIMD::Vec3f globalDirection_; + public: static const int32_t ChildrenMax = 16; @@ -246,6 +248,8 @@ class alignas(16) Instance : public IntrusiveList::Node float GetFlipbookIndexAndNextRate() const; + SIMD::Vec3f GetGlobalDirection() const; + private: void UpdateTransform(float deltaFrame); diff --git a/Dev/Cpp/Effekseer/Effekseer/Renderer/Effekseer.ModelRenderer.h b/Dev/Cpp/Effekseer/Effekseer/Renderer/Effekseer.ModelRenderer.h index 3333b364ec..fe63477a30 100644 --- a/Dev/Cpp/Effekseer/Effekseer/Renderer/Effekseer.ModelRenderer.h +++ b/Dev/Cpp/Effekseer/Effekseer/Renderer/Effekseer.ModelRenderer.h @@ -79,6 +79,8 @@ class ModelRenderer : public ReferenceObject Color AllColor; int32_t Time; + SIMD::Vec3f Direction; + std::array CustomData1; std::array CustomData2; }; diff --git a/Dev/Cpp/Effekseer/Effekseer/Renderer/Effekseer.RingRenderer.h b/Dev/Cpp/Effekseer/Effekseer/Renderer/Effekseer.RingRenderer.h index 7be45ca39b..09dfbae38d 100644 --- a/Dev/Cpp/Effekseer/Effekseer/Renderer/Effekseer.RingRenderer.h +++ b/Dev/Cpp/Effekseer/Effekseer/Renderer/Effekseer.RingRenderer.h @@ -81,6 +81,8 @@ class RingRenderer : public ReferenceObject float ViewOffsetDistance; + SIMD::Vec3f Direction; + std::array CustomData1; std::array CustomData2; }; diff --git a/Dev/Cpp/Effekseer/Effekseer/Renderer/Effekseer.SpriteRenderer.h b/Dev/Cpp/Effekseer/Effekseer/Renderer/Effekseer.SpriteRenderer.h index 2e5391398a..128e4e2bb5 100644 --- a/Dev/Cpp/Effekseer/Effekseer/Renderer/Effekseer.SpriteRenderer.h +++ b/Dev/Cpp/Effekseer/Effekseer/Renderer/Effekseer.SpriteRenderer.h @@ -74,6 +74,8 @@ class SpriteRenderer : public ReferenceObject float ViewOffsetDistance; + SIMD::Vec3f Direction; + std::array CustomData1; std::array CustomData2; }; diff --git a/Dev/Cpp/EffekseerRendererCommon/EffekseerRendererCommon/EffekseerRenderer.CommonUtils.cpp b/Dev/Cpp/EffekseerRendererCommon/EffekseerRendererCommon/EffekseerRenderer.CommonUtils.cpp index a9bcfd9bb0..ee7f5746cc 100644 --- a/Dev/Cpp/EffekseerRendererCommon/EffekseerRendererCommon/EffekseerRenderer.CommonUtils.cpp +++ b/Dev/Cpp/EffekseerRendererCommon/EffekseerRendererCommon/EffekseerRenderer.CommonUtils.cpp @@ -86,12 +86,12 @@ void CalcBillboard(::Effekseer::BillboardType billboardType, ::Effekseer::SIMD::Vec3f& R, ::Effekseer::SIMD::Vec3f& F, const ::Effekseer::SIMD::Mat43f& src, - const ::Effekseer::SIMD::Vec3f& frontDirection) + const ::Effekseer::SIMD::Vec3f& frontDirection, + const ::Effekseer::SIMD::Vec3f& instanceDirection) { auto frontDir = frontDirection; - if (billboardType == ::Effekseer::BillboardType::Billboard || billboardType == ::Effekseer::BillboardType::RotatedBillboard || - billboardType == ::Effekseer::BillboardType::YAxisFixed) + if (billboardType != ::Effekseer::BillboardType::Fixed) { ::Effekseer::SIMD::Mat43f r; ::Effekseer::SIMD::Vec3f t; @@ -144,6 +144,19 @@ void CalcBillboard(::Effekseer::BillboardType billboardType, R = ::Effekseer::SIMD::Vec3f::Cross(U, F).GetNormal(); F = ::Effekseer::SIMD::Vec3f::Cross(R, U).GetNormal(); } + else if (billboardType == ::Effekseer::BillboardType::DirectionalBillboard) + { + U = instanceDirection; + if (instanceDirection.IsZero()) + { + U = Effekseer::SIMD::Vec3f(0.0f, 1.0f, 0.0f); + } + + F = frontDir; + R = ::Effekseer::SIMD::Vec3f::Cross(U, F).GetNormal(); + U = ::Effekseer::SIMD::Vec3f::Cross(F, R).GetNormal(); + R = ::Effekseer::SIMD::Vec3f::Cross(U, F).GetNormal(); + } dst.X = {R.GetX(), U.GetX(), F.GetX(), t.GetX()}; dst.Y = {R.GetY(), U.GetY(), F.GetY(), t.GetY()}; diff --git a/Dev/Cpp/EffekseerRendererCommon/EffekseerRendererCommon/EffekseerRenderer.CommonUtils.h b/Dev/Cpp/EffekseerRendererCommon/EffekseerRendererCommon/EffekseerRenderer.CommonUtils.h index 49e96e4087..235590ebc2 100644 --- a/Dev/Cpp/EffekseerRendererCommon/EffekseerRendererCommon/EffekseerRenderer.CommonUtils.h +++ b/Dev/Cpp/EffekseerRendererCommon/EffekseerRendererCommon/EffekseerRenderer.CommonUtils.h @@ -651,7 +651,8 @@ void CalcBillboard(::Effekseer::BillboardType billboardType, ::Effekseer::SIMD::Vec3f& R, ::Effekseer::SIMD::Vec3f& F, const ::Effekseer::SIMD::Mat43f& src, - const ::Effekseer::SIMD::Vec3f& frontDirection); + const ::Effekseer::SIMD::Vec3f& frontDirection, + const ::Effekseer::SIMD::Vec3f& instanceDirection = ::Effekseer::SIMD::Vec3f(0.0f, 0.0f, 0.0f)); void ApplyDepthParameters(::Effekseer::SIMD::Mat43f& mat, const ::Effekseer::SIMD::Vec3f& cameraFront, diff --git a/Dev/Cpp/EffekseerRendererCommon/EffekseerRendererCommon/EffekseerRenderer.ModelRendererBase.h b/Dev/Cpp/EffekseerRendererCommon/EffekseerRendererCommon/EffekseerRenderer.ModelRendererBase.h index 407065f73a..2cf087d98b 100644 --- a/Dev/Cpp/EffekseerRendererCommon/EffekseerRendererCommon/EffekseerRenderer.ModelRendererBase.h +++ b/Dev/Cpp/EffekseerRendererCommon/EffekseerRendererCommon/EffekseerRenderer.ModelRendererBase.h @@ -779,7 +779,7 @@ class ModelRendererBase : public ::Effekseer::ModelRenderer, public ::Effekseer: Effekseer::SIMD::Vec3f R; Effekseer::SIMD::Vec3f F; - CalcBillboard(btype, mat43, s, R, F, instanceParameter.SRTMatrix43, renderer->GetCameraFrontDirection()); + CalcBillboard(btype, mat43, s, R, F, instanceParameter.SRTMatrix43, renderer->GetCameraFrontDirection(), instanceParameter.Direction); mat44 = ::Effekseer::SIMD::Mat43f::Scaling(s) * mat43; } diff --git a/Dev/Cpp/EffekseerRendererCommon/EffekseerRendererCommon/EffekseerRenderer.RingRendererBase.h b/Dev/Cpp/EffekseerRendererCommon/EffekseerRendererCommon/EffekseerRenderer.RingRendererBase.h index f27ba3e7ce..4bf0b50627 100644 --- a/Dev/Cpp/EffekseerRendererCommon/EffekseerRendererCommon/EffekseerRenderer.RingRendererBase.h +++ b/Dev/Cpp/EffekseerRendererCommon/EffekseerRendererCommon/EffekseerRenderer.RingRendererBase.h @@ -199,9 +199,7 @@ class RingRendererBase : public ::Effekseer::RingRenderer, public ::Effekseer::S { ::Effekseer::SIMD::Mat43f mat43{}; - if (parameter.Billboard == ::Effekseer::BillboardType::Billboard || - parameter.Billboard == ::Effekseer::BillboardType::RotatedBillboard || - parameter.Billboard == ::Effekseer::BillboardType::YAxisFixed) + if (parameter.Billboard != ::Effekseer::BillboardType::Fixed) { Effekseer::SIMD::Vec3f s; Effekseer::SIMD::Vec3f R; @@ -213,11 +211,11 @@ class RingRendererBase : public ::Effekseer::RingRenderer, public ::Effekseer::S ApplyViewOffset(instMat, camera, instanceParameter.ViewOffsetDistance); - CalcBillboard(parameter.Billboard, mat43, s, R, F, instMat, m_renderer->GetCameraFrontDirection()); + CalcBillboard(parameter.Billboard, mat43, s, R, F, instMat, m_renderer->GetCameraFrontDirection(), instanceParameter.Direction); } else { - CalcBillboard(parameter.Billboard, mat43, s, R, F, instanceParameter.SRTMatrix43, m_renderer->GetCameraFrontDirection()); + CalcBillboard(parameter.Billboard, mat43, s, R, F, instanceParameter.SRTMatrix43, m_renderer->GetCameraFrontDirection(), instanceParameter.Direction); } ApplyDepthParameters(mat43, diff --git a/Dev/Cpp/EffekseerRendererCommon/EffekseerRendererCommon/EffekseerRenderer.SpriteRendererBase.h b/Dev/Cpp/EffekseerRendererCommon/EffekseerRendererCommon/EffekseerRenderer.SpriteRendererBase.h index c5f2c0cb26..16309cc8ae 100644 --- a/Dev/Cpp/EffekseerRendererCommon/EffekseerRendererCommon/EffekseerRenderer.SpriteRendererBase.h +++ b/Dev/Cpp/EffekseerRendererCommon/EffekseerRendererCommon/EffekseerRenderer.SpriteRendererBase.h @@ -279,9 +279,7 @@ class SpriteRendererBase : public ::Effekseer::SpriteRenderer, public ::Effeksee vs[3].SetUV2(1.0f, 0.0f); } - if (parameter.Billboard == ::Effekseer::BillboardType::Billboard || - parameter.Billboard == ::Effekseer::BillboardType::RotatedBillboard || - parameter.Billboard == ::Effekseer::BillboardType::YAxisFixed) + if (parameter.Billboard != ::Effekseer::BillboardType::Fixed) { Effekseer::SIMD::Mat43f mat_rot = Effekseer::SIMD::Mat43f::Identity; Effekseer::SIMD::Vec3f s; @@ -294,11 +292,11 @@ class SpriteRendererBase : public ::Effekseer::SpriteRenderer, public ::Effeksee ApplyViewOffset(instMat, camera, instanceParameter.ViewOffsetDistance); - CalcBillboard(parameter.Billboard, mat_rot, s, R, F, instMat, m_renderer->GetCameraFrontDirection()); + CalcBillboard(parameter.Billboard, mat_rot, s, R, F, instMat, m_renderer->GetCameraFrontDirection(), instanceParameter.Direction); } else { - CalcBillboard(parameter.Billboard, mat_rot, s, R, F, instanceParameter.SRTMatrix43, m_renderer->GetCameraFrontDirection()); + CalcBillboard(parameter.Billboard, mat_rot, s, R, F, instanceParameter.SRTMatrix43, m_renderer->GetCameraFrontDirection(), instanceParameter.Direction); } for (int i = 0; i < 4; i++) diff --git a/Dev/Editor/EffekseerCore/Data/RendererValues.cs b/Dev/Editor/EffekseerCore/Data/RendererValues.cs index 8caa95207b..1e8068f8cd 100644 --- a/Dev/Editor/EffekseerCore/Data/RendererValues.cs +++ b/Dev/Editor/EffekseerCore/Data/RendererValues.cs @@ -1045,6 +1045,8 @@ public enum BillboardType : int Billboard = 0, [Key(key = "BillboardType_RotatedBillboard")] RotatedBillboard = 3, + [Key(key = "BillboardType_DirectionalBillboard")] + DirectionalBillboard = 4, [Key(key = "BillboardType_YAxisFixed")] YAxisFixed = 1, [Key(key = "BillboardType_Fixed")] diff --git a/Dev/release/resources/languages/en/Effekseer_RenderSettings.csv b/Dev/release/resources/languages/en/Effekseer_RenderSettings.csv index b278eb08a2..34dbcb2cea 100644 --- a/Dev/release/resources/languages/en/Effekseer_RenderSettings.csv +++ b/Dev/release/resources/languages/en/Effekseer_RenderSettings.csv @@ -9,6 +9,7 @@ RS_RenderingOrder_FirstCreatedInstanceIsFirst_Name,Order of spawn RS_RenderingOrder_FirstCreatedInstanceIsLast_Name,Reversed BillboardType_Billboard_Name,Billboard BillboardType_RotatedBillboard_Name,Rotated Billboard +BillboardType_DirectionalBillboard_Name,Direccional Billboard BillboardType_YAxisFixed_Name,Fixed Y-Axis BillboardType_Fixed_Name,Fixed StandardColorType_Fixed_Name,Fixed diff --git a/Dev/release/resources/languages/es/Effekseer_RenderSettings.csv b/Dev/release/resources/languages/es/Effekseer_RenderSettings.csv index 3c354d0066..3c3e0976b2 100644 --- a/Dev/release/resources/languages/es/Effekseer_RenderSettings.csv +++ b/Dev/release/resources/languages/es/Effekseer_RenderSettings.csv @@ -9,6 +9,7 @@ RS_RenderingOrder_FirstCreatedInstanceIsFirst_Name,Orden de aparición RS_RenderingOrder_FirstCreatedInstanceIsLast_Name,Revertido BillboardType_Billboard_Name,Panel BillboardType_RotatedBillboard_Name,Rotar Panel +BillboardType_DirectionalBillboard_Name,移動方向ビルボード BillboardType_YAxisFixed_Name,Eje-Y fijado BillboardType_Fixed_Name,Fijado StandardColorType_Fixed_Name,Fijado diff --git a/Dev/release/resources/languages/ja/Effekseer_RenderSettings.csv b/Dev/release/resources/languages/ja/Effekseer_RenderSettings.csv index 5c53ea676b..0dfa97f16c 100644 --- a/Dev/release/resources/languages/ja/Effekseer_RenderSettings.csv +++ b/Dev/release/resources/languages/ja/Effekseer_RenderSettings.csv @@ -9,6 +9,7 @@ RS_RenderingOrder_FirstCreatedInstanceIsFirst_Name,生成順 RS_RenderingOrder_FirstCreatedInstanceIsLast_Name,生成順の逆 BillboardType_Billboard_Name,ビルボード BillboardType_RotatedBillboard_Name,Z軸回転ビルボード +BillboardType_DirectionalBillboard_Name,移動方向ビルボード BillboardType_YAxisFixed_Name,Y軸固定 BillboardType_Fixed_Name,固定 StandardColorType_Fixed_Name,固定