Skip to content

Commit

Permalink
Implement Tile feature in Trail
Browse files Browse the repository at this point in the history
  • Loading branch information
durswd committed Jan 10, 2024
1 parent 8424f9a commit c932bd0
Show file tree
Hide file tree
Showing 15 changed files with 143 additions and 24 deletions.
3 changes: 3 additions & 0 deletions Dev/Cpp/Effekseer/Effekseer/Effekseer.EffectNodeRibbon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,9 @@ void EffectNodeRibbon::BeginRendering(int32_t count, Manager* manager, const Ins
m_nodeParameter.BasicParameterPtr = &RendererCommon.BasicParameter;
m_nodeParameter.TextureUVTypeParameterPtr = &TextureUVType;
m_nodeParameter.IsRightHand = manager->GetCoordinateSystem() == CoordinateSystem::RH;

auto scale = global->EffectGlobalMatrix.GetScale();
m_nodeParameter.GlobalScale = (scale.GetX() + scale.GetY() + scale.GetZ()) / 3.0f;
m_nodeParameter.Maginification = GetEffect()->GetMaginification();

m_nodeParameter.EnableViewOffset = (TranslationParam.TranslationType == ParameterTranslationType_ViewOffset);
Expand Down
4 changes: 4 additions & 0 deletions Dev/Cpp/Effekseer/Effekseer/Effekseer.EffectNodeTrack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,9 @@ void EffectNodeTrack::BeginRendering(int32_t count, Manager* manager, const Inst
m_nodeParameter.BasicParameterPtr = &RendererCommon.BasicParameter;
m_nodeParameter.TextureUVTypeParameterPtr = &TextureUVType;
m_nodeParameter.IsRightHand = manager->GetCoordinateSystem() == CoordinateSystem::RH;

auto scale = global->EffectGlobalMatrix.GetScale();
m_nodeParameter.GlobalScale = (scale.GetX() + scale.GetY() + scale.GetZ()) / 3.0f;
m_nodeParameter.Maginification = GetEffect()->GetMaginification();

m_nodeParameter.EnableViewOffset = (TranslationParam.TranslationType == ParameterTranslationType_ViewOffset);
Expand Down Expand Up @@ -134,6 +137,7 @@ void EffectNodeTrack::BeginRenderingGroup(InstanceGroup* group, Manager* manager
{
assert(false);
}
bool isParentAlived = true;

m_instanceParameter.UV = groupFirst->GetUV(0, livingTime, livedTime);
m_instanceParameter.AlphaUV = groupFirst->GetUV(1, livingTime, livedTime);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ void NodeRendererTextureUVTypeParameter::Load(uint8_t*& pos, int32_t version)
if (Type == TextureUVType::Strech)
{
}
else if (Type == TextureUVType::Tile)
else if (Type == TextureUVType::TilePerParticle)
{
memcpy(&TileEdgeHead, pos, sizeof(TileEdgeHead));
pos += sizeof(TileEdgeHead);
Expand All @@ -50,6 +50,11 @@ void NodeRendererTextureUVTypeParameter::Load(uint8_t*& pos, int32_t version)
memcpy(&TileLoopAreaEnd, pos, sizeof(TileLoopAreaEnd));
pos += sizeof(TileLoopAreaEnd);
}
else if (Type == TextureUVType::Tile)
{
memcpy(&TileLength, pos, sizeof(TileLength));
pos += sizeof(TileLength);
}
}

template <typename T, typename U>
Expand Down
5 changes: 3 additions & 2 deletions Dev/Cpp/Effekseer/Effekseer/Parameter/Effekseer.Parameters.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@ void LoadGradient(Gradient& gradient, uint8_t*& pos, int32_t version);
*/
enum class TextureUVType : int32_t
{
Strech,
Tile,
Strech = 0,
TilePerParticle = 1,
Tile = 2,
};

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ class RibbonRenderer : public ReferenceObject
bool ViewpointDependent;

bool IsRightHand;
float GlobalScale = 1.0f;
float Maginification = 1.0f;

int32_t SplineDivision;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class TrackRenderer : public ReferenceObject
int32_t SplineDivision;

bool IsRightHand;
float GlobalScale = 1.0f;
float Maginification = 1.0f;

NodeRendererDepthParameter* DepthParameterPtr = nullptr;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -410,18 +410,20 @@ class RibbonRendererBase : public ::Effekseer::RibbonRenderer, public ::Effeksee
}

// calculate UV
TrailRendererUtils::AssignUVs<VERTEX, efkRibbonInstanceParam, 0>(*parameter.TextureUVTypeParameterPtr, instances, verteies, parameter.SplineDivision);
const auto global_scale = parameter.GlobalScale * parameter.Maginification;

TrailRendererUtils::AssignUVs<VERTEX, efkRibbonInstanceParam, 0>(*parameter.TextureUVTypeParameterPtr, instances, verteies, parameter.SplineDivision, global_scale);

if (VertexUV2Required<VERTEX>())
{
TrailRendererUtils::AssignUVs<VERTEX, efkRibbonInstanceParam, 1>(*parameter.TextureUVTypeParameterPtr, instances, verteies, parameter.SplineDivision);
TrailRendererUtils::AssignUVs<VERTEX, efkRibbonInstanceParam, 1>(*parameter.TextureUVTypeParameterPtr, instances, verteies, parameter.SplineDivision, global_scale);
}

TrailRendererUtils::AssignUVs<VERTEX, efkRibbonInstanceParam, 2>(*parameter.TextureUVTypeParameterPtr, instances, verteies, parameter.SplineDivision);
TrailRendererUtils::AssignUVs<VERTEX, efkRibbonInstanceParam, 3>(*parameter.TextureUVTypeParameterPtr, instances, verteies, parameter.SplineDivision);
TrailRendererUtils::AssignUVs<VERTEX, efkRibbonInstanceParam, 4>(*parameter.TextureUVTypeParameterPtr, instances, verteies, parameter.SplineDivision);
TrailRendererUtils::AssignUVs<VERTEX, efkRibbonInstanceParam, 5>(*parameter.TextureUVTypeParameterPtr, instances, verteies, parameter.SplineDivision);
TrailRendererUtils::AssignUVs<VERTEX, efkRibbonInstanceParam, 6>(*parameter.TextureUVTypeParameterPtr, instances, verteies, parameter.SplineDivision);
TrailRendererUtils::AssignUVs<VERTEX, efkRibbonInstanceParam, 2>(*parameter.TextureUVTypeParameterPtr, instances, verteies, parameter.SplineDivision, global_scale);
TrailRendererUtils::AssignUVs<VERTEX, efkRibbonInstanceParam, 3>(*parameter.TextureUVTypeParameterPtr, instances, verteies, parameter.SplineDivision, global_scale);
TrailRendererUtils::AssignUVs<VERTEX, efkRibbonInstanceParam, 4>(*parameter.TextureUVTypeParameterPtr, instances, verteies, parameter.SplineDivision, global_scale);
TrailRendererUtils::AssignUVs<VERTEX, efkRibbonInstanceParam, 5>(*parameter.TextureUVTypeParameterPtr, instances, verteies, parameter.SplineDivision, global_scale);
TrailRendererUtils::AssignUVs<VERTEX, efkRibbonInstanceParam, 6>(*parameter.TextureUVTypeParameterPtr, instances, verteies, parameter.SplineDivision, global_scale);

// custom parameter
if (customData1Count_ > 0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -475,18 +475,20 @@ class TrackRendererBase : public ::Effekseer::TrackRenderer, public ::Effekseer:
}

// calculate UV
TrailRendererUtils::AssignUVs<VERTEX, efkTrackInstanceParam, 0>(*parameter.TextureUVTypeParameterPtr, instances, verteies, parameter.SplineDivision);
const auto global_scale = parameter.GlobalScale * parameter.Maginification;

TrailRendererUtils::AssignUVs<VERTEX, efkTrackInstanceParam, 0>(*parameter.TextureUVTypeParameterPtr, instances, verteies, parameter.SplineDivision, global_scale);

if (VertexUV2Required<VERTEX>())
{
TrailRendererUtils::AssignUVs<VERTEX, efkTrackInstanceParam, 1>(*parameter.TextureUVTypeParameterPtr, instances, verteies, parameter.SplineDivision);
TrailRendererUtils::AssignUVs<VERTEX, efkTrackInstanceParam, 1>(*parameter.TextureUVTypeParameterPtr, instances, verteies, parameter.SplineDivision, global_scale);
}

TrailRendererUtils::AssignUVs<VERTEX, efkTrackInstanceParam, 2>(*parameter.TextureUVTypeParameterPtr, instances, verteies, parameter.SplineDivision);
TrailRendererUtils::AssignUVs<VERTEX, efkTrackInstanceParam, 3>(*parameter.TextureUVTypeParameterPtr, instances, verteies, parameter.SplineDivision);
TrailRendererUtils::AssignUVs<VERTEX, efkTrackInstanceParam, 4>(*parameter.TextureUVTypeParameterPtr, instances, verteies, parameter.SplineDivision);
TrailRendererUtils::AssignUVs<VERTEX, efkTrackInstanceParam, 5>(*parameter.TextureUVTypeParameterPtr, instances, verteies, parameter.SplineDivision);
TrailRendererUtils::AssignUVs<VERTEX, efkTrackInstanceParam, 6>(*parameter.TextureUVTypeParameterPtr, instances, verteies, parameter.SplineDivision);
TrailRendererUtils::AssignUVs<VERTEX, efkTrackInstanceParam, 2>(*parameter.TextureUVTypeParameterPtr, instances, verteies, parameter.SplineDivision, global_scale);
TrailRendererUtils::AssignUVs<VERTEX, efkTrackInstanceParam, 3>(*parameter.TextureUVTypeParameterPtr, instances, verteies, parameter.SplineDivision, global_scale);
TrailRendererUtils::AssignUVs<VERTEX, efkTrackInstanceParam, 4>(*parameter.TextureUVTypeParameterPtr, instances, verteies, parameter.SplineDivision, global_scale);
TrailRendererUtils::AssignUVs<VERTEX, efkTrackInstanceParam, 5>(*parameter.TextureUVTypeParameterPtr, instances, verteies, parameter.SplineDivision, global_scale);
TrailRendererUtils::AssignUVs<VERTEX, efkTrackInstanceParam, 6>(*parameter.TextureUVTypeParameterPtr, instances, verteies, parameter.SplineDivision, global_scale);

// custom parameter
if (customData1Count_ > 0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ class TrailRendererUtils
}

template <typename VERTEX, typename INSTANCE, int TARGET>
static void AssignUVs(const Effekseer::NodeRendererTextureUVTypeParameter& uvParam, Effekseer::CustomAlignedVector<INSTANCE>& instances, StrideView<VERTEX> verteies, int spline_division)
static void AssignUVs(const Effekseer::NodeRendererTextureUVTypeParameter& uvParam, Effekseer::CustomAlignedVector<INSTANCE>& instances, StrideView<VERTEX> verteies, int spline_division, float globalScale)
{
float uvx = 0.0f;
float uvw = 1.0f;
Expand Down Expand Up @@ -275,7 +275,7 @@ class TrailRendererUtils
}
}
}
else if (uvParam.Type == ::Effekseer::TextureUVType::Tile)
else if (uvParam.Type == ::Effekseer::TextureUVType::TilePerParticle)
{
verteies.Reset();

Expand Down Expand Up @@ -400,6 +400,89 @@ class TrailRendererUtils
}
}
}
else if (uvParam.Type == ::Effekseer::TextureUVType::Tile)
{
float current = 0.0f;
float lengthAll = 0.0f;
const float lengthPerUV = uvParam.TileLength * globalScale;
for (size_t loop = 0; loop < instances.size() - 1; loop++)
{
const float length = (instances[loop + 1].SRTMatrix43.GetTranslation() - instances[loop].SRTMatrix43.GetTranslation()).GetLength();
lengthAll += length;
}

current = lengthPerUV - fmod(lengthAll, lengthPerUV);

verteies.Reset();
for (size_t loop = 0; loop < instances.size() - 1; loop++)
{
const float length = (instances[loop + 1].SRTMatrix43.GetTranslation() - instances[loop].SRTMatrix43.GetTranslation()).GetLength();
const auto& param = instances[loop];
if (TARGET == 0)
{
uvx = param.UV.X;
uvw = param.UV.Width;
uvy = param.UV.Y;
uvh = param.UV.Height;
}
else if (TARGET == 2)
{
uvx = param.AlphaUV.X;
uvw = param.AlphaUV.Width;
uvy = param.AlphaUV.Y;
uvh = param.AlphaUV.Height;
}
else if (TARGET == 3)
{
uvx = param.UVDistortionUV.X;
uvw = param.UVDistortionUV.Width;
uvy = param.UVDistortionUV.Y;
uvh = param.UVDistortionUV.Height;
}
else if (TARGET == 4)
{
uvx = param.BlendUV.X;
uvw = param.BlendUV.Width;
uvy = param.BlendUV.Y;
uvh = param.BlendUV.Height;
}
else if (TARGET == 5)
{
uvx = param.BlendAlphaUV.X;
uvw = param.BlendAlphaUV.Width;
uvy = param.BlendAlphaUV.Y;
uvh = param.BlendAlphaUV.Height;
}
else if (TARGET == 6)
{
uvx = param.BlendUVDistortionUV.X;
uvw = param.BlendUVDistortionUV.Width;
uvy = param.BlendUVDistortionUV.Y;
uvh = param.BlendUVDistortionUV.Height;
}

for (int32_t sploop = 0; sploop < spline_division; sploop++)
{
float percent1 = (float)(sploop) / (float)(spline_division);
float percent2 = (float)(sploop + 1) / (float)(spline_division);
float current1 = current + length * percent1;
float current2 = current + length * percent2;

auto uvX1 = uvx;
auto uvX2 = uvx + uvw * 0.5f;
auto uvX3 = uvx + uvw;

auto uvY1 = uvy + (current1 / lengthPerUV) * uvh;
auto uvY2 = uvy + (current2 / lengthPerUV) * uvh;

AssignUV<VERTEX, TARGET>(verteies, uvX1, uvX2, uvX3, uvY1, uvY2);

verteies += 8;
}

current += length;
}
}
}
};
} // namespace EffekseerRenderer
4 changes: 4 additions & 0 deletions Dev/Editor/EffekseerCore/Binary/RendererValues.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ public static byte[] GetBytes(Data.TextureUVTypeParameter value)
data.Add(BitConverter.GetBytes((int)value.Type.Value));

if (value.Type.Value == Data.TextureUVType.Tile)
{
data.Add(value.TileLength.Value.GetBytes());
}
else if (value.Type.Value == Data.TextureUVType.TilePerParticle)
{
data.Add(value.TileEdgeHead.Value.GetBytes());
data.Add(value.TileEdgeTail.Value.GetBytes());
Expand Down
14 changes: 10 additions & 4 deletions Dev/Editor/EffekseerCore/Data/RendererValues.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ public enum TextureUVType
[Key(key = "TextureUVTypeParameter_Type_Strech")]
Strech = 0,
[Key(key = "TextureUVTypeParameter_Type_Tile")]
Tile = 1,
Tile = 2,
[Key(key = "TextureUVTypeParameter_Type_TilePerParticle")]
TilePerParticle = 1,
}

public enum TrailSmoothingType : int
Expand Down Expand Up @@ -40,16 +42,20 @@ public Value.Enum<TextureUVType> Type
private set;
}

[Key(key = "TextureUVTypeParameter_TileEdgeHead")]
[Key(key = "TextureUVTypeParameter_TileLength")]
[Selected(ID = 0, Value = (int)TextureUVType.Tile)]
public Value.Float TileLength { get; private set; } = new Value.Float(1, float.MaxValue, 0.1f);

[Key(key = "TextureUVTypeParameter_TileEdgeHead")]
[Selected(ID = 0, Value = (int)TextureUVType.TilePerParticle)]
public Value.Int TileEdgeHead { get; private set; }

[Key(key = "TextureUVTypeParameter_TileEdgeTail")]
[Selected(ID = 0, Value = (int)TextureUVType.Tile)]
[Selected(ID = 0, Value = (int)TextureUVType.TilePerParticle)]
public Value.Int TileEdgeTail { get; private set; }

[Key(key = "TextureUVTypeParameter_TileLoopingArea")]
[Selected(ID = 0, Value = (int)TextureUVType.Tile)]
[Selected(ID = 0, Value = (int)TextureUVType.TilePerParticle)]
public Value.Vector2D TileLoopingArea { get; private set; }
public TextureUVTypeParameter()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,13 @@ StandardColorType_Easing_Name,Easing
StandardColorType_FCurve_Name,F-Curve (RGBA)
StandardColorType_Gradient_Name,Gradient
TextureUVTypeParameter_Type_Name,UV Type
TextureUVTypeParameter_TileLength_Name,Tile Length
TextureUVTypeParameter_TileEdgeHead_Name,The number of tile on Head
TextureUVTypeParameter_TileEdgeTail_Name,The number of tile on Tail
TextureUVTypeParameter_TileLoopingArea_Name,Looping area
TextureUVTypeParameter_Type_Strech_Name,Strech
TextureUVTypeParameter_Type_Tile_Name,Tile
TextureUVTypeParameter_Type_TilePerParticle_Name,Tile(Per particle)
,
CullingType_Front_Name,Front view
CullingType_Back_Name,Back view
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,13 @@ TextureUVTypeParameter_Type_Name,Tipo UV
TextureUVTypeParameter_Type_Desc,"Tipo de UV
Estirar: Estirará la imagen
Tile: Colocará tiles"
TextureUVTypeParameter_TileLength_Name,Tile Length
TextureUVTypeParameter_TileEdgeHead_Name,El número del tile en la cabecera
TextureUVTypeParameter_TileEdgeTail_Name,El número del tile en la cola
TextureUVTypeParameter_TileLoopingArea_Name,Area de Bucle
TextureUVTypeParameter_Type_Strech_Name,Estirar
TextureUVTypeParameter_Type_Tile_Name,Tile
TextureUVTypeParameter_Type_TilePerParticle_Name,Tile(Per particle)
,
CullingType_Front_Name,Mostrar cara frontal
CullingType_Back_Name,Mostrar cara trasera
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,13 @@ StandardColorType_Easing_Name,イージング
StandardColorType_FCurve_Name,Fカーブ(RGBA)
StandardColorType_Gradient_Name,グラディエント
TextureUVTypeParameter_Type_Name,UV タイプ
TextureUVTypeParameter_TileLength_Name,タイルの長さ
TextureUVTypeParameter_TileEdgeHead_Name,頭のタイル数
TextureUVTypeParameter_TileEdgeTail_Name,尻尾のタイル数
TextureUVTypeParameter_TileLoopingArea_Name,ループ領域
TextureUVTypeParameter_Type_Strech_Name,ストレッチ
TextureUVTypeParameter_Type_Tile_Name,タイル
,
TextureUVTypeParameter_Type_TilePerParticle_Name,タイル(パーティクル毎)
CullingType_Front_Name,表表示
CullingType_Back_Name,裏表示
CullingType_Double_Name,両面表示
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,13 @@ StandardColorType_Easing_Name,缓动
StandardColorType_FCurve_Name,F曲线(RGBA)
StandardColorType_Gradient_Name,梯度
TextureUVTypeParameter_Type_Name,UV类型
TextureUVTypeParameter_TileLength_Name,Tile Length
TextureUVTypeParameter_TileEdgeHead_Name,头部的瓦片数量
TextureUVTypeParameter_TileEdgeTail_Name,尾部的瓦片数量
TextureUVTypeParameter_TileLoopingArea_Name,循环区域
TextureUVTypeParameter_Type_Strech_Name,拉伸
TextureUVTypeParameter_Type_Tile_Name,瓦片
TextureUVTypeParameter_Type_TilePerParticle_Name,Tile(Per particle)
,
CullingType_Front_Name,正面可见
CullingType_Back_Name,背面可见
Expand Down

0 comments on commit c932bd0

Please sign in to comment.