Skip to content

Commit

Permalink
Add a directional billboard type
Browse files Browse the repository at this point in the history
  • Loading branch information
ueshita authored and durswd committed Jan 1, 2024
1 parent d4772a0 commit fc42561
Show file tree
Hide file tree
Showing 18 changed files with 70 additions and 16 deletions.
1 change: 1 addition & 0 deletions Dev/Cpp/Effekseer/Effekseer/Effekseer.Base.Pre.h
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@ enum class BillboardType : int32_t
YAxisFixed = 1,
Fixed = 2,
RotatedBillboard = 3,
DirectionalBillboard = 4,
};

enum class CoordinateSystem : int32_t
Expand Down
5 changes: 5 additions & 0 deletions Dev/Cpp/Effekseer/Effekseer/Effekseer.EffectNodeModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
5 changes: 5 additions & 0 deletions Dev/Cpp/Effekseer/Effekseer/Effekseer.EffectNodeRing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
5 changes: 5 additions & 0 deletions Dev/Cpp/Effekseer/Effekseer/Effekseer.EffectNodeSprite.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
15 changes: 14 additions & 1 deletion Dev/Cpp/Effekseer/Effekseer/Effekseer.Instance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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)
{
// 計算済なら終了
Expand Down Expand Up @@ -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;
}
Expand Down
4 changes: 4 additions & 0 deletions Dev/Cpp/Effekseer/Effekseer/Effekseer.Instance.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ class alignas(16) Instance : public IntrusiveList<Instance>::Node
SIMD::Vec3f location_modify_global_;
SIMD::Vec3f velocity_modify_global_;

SIMD::Vec3f globalDirection_;

public:
static const int32_t ChildrenMax = 16;

Expand Down Expand Up @@ -246,6 +248,8 @@ class alignas(16) Instance : public IntrusiveList<Instance>::Node

float GetFlipbookIndexAndNextRate() const;

SIMD::Vec3f GetGlobalDirection() const;

private:
void UpdateTransform(float deltaFrame);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ class ModelRenderer : public ReferenceObject

Color AllColor;
int32_t Time;
SIMD::Vec3f Direction;

std::array<float, 4> CustomData1;
std::array<float, 4> CustomData2;
};
Expand Down
2 changes: 2 additions & 0 deletions Dev/Cpp/Effekseer/Effekseer/Renderer/Effekseer.RingRenderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ class RingRenderer : public ReferenceObject

float ViewOffsetDistance;

SIMD::Vec3f Direction;

std::array<float, 4> CustomData1;
std::array<float, 4> CustomData2;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ class SpriteRenderer : public ReferenceObject

float ViewOffsetDistance;

SIMD::Vec3f Direction;

std::array<float, 4> CustomData1;
std::array<float, 4> CustomData2;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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()};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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++)
Expand Down
2 changes: 2 additions & 0 deletions Dev/Editor/EffekseerCore/Data/RendererValues.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,固定
Expand Down

0 comments on commit fc42561

Please sign in to comment.