Add SortOrder to drawable object types for transparency sorting override
This commit is contained in:
@@ -297,6 +297,7 @@ void Camera::Draw(RenderContext& renderContext)
|
||||
draw.PerInstanceRandom = GetPerInstanceRandom();
|
||||
draw.LODBias = 0;
|
||||
draw.ForcedLOD = -1;
|
||||
draw.SortOrder = 0;
|
||||
draw.VertexColors = nullptr;
|
||||
if (draw.DrawModes != DrawPass::None)
|
||||
{
|
||||
|
||||
@@ -25,6 +25,7 @@ StaticModel::StaticModel(const SpawnParams& params)
|
||||
, _forcedLod(-1)
|
||||
, _vertexColorsDirty(false)
|
||||
, _vertexColorsCount(0)
|
||||
, _sortOrder(0)
|
||||
{
|
||||
_drawCategory = SceneRendering::SceneDrawAsync;
|
||||
Model.Changed.Bind<StaticModel, &StaticModel::OnModelChanged>(this);
|
||||
@@ -37,11 +38,21 @@ StaticModel::~StaticModel()
|
||||
SAFE_DELETE_GPU_RESOURCE(_vertexColorsBuffer[lodIndex]);
|
||||
}
|
||||
|
||||
float StaticModel::GetScaleInLightmap() const
|
||||
{
|
||||
return _scaleInLightmap;
|
||||
}
|
||||
|
||||
void StaticModel::SetScaleInLightmap(float value)
|
||||
{
|
||||
_scaleInLightmap = value;
|
||||
}
|
||||
|
||||
float StaticModel::GetBoundsScale() const
|
||||
{
|
||||
return _boundsScale;
|
||||
}
|
||||
|
||||
void StaticModel::SetBoundsScale(float value)
|
||||
{
|
||||
if (Math::NearEqual(_boundsScale, value))
|
||||
@@ -51,6 +62,46 @@ void StaticModel::SetBoundsScale(float value)
|
||||
UpdateBounds();
|
||||
}
|
||||
|
||||
int32 StaticModel::GetLODBias() const
|
||||
{
|
||||
return _lodBias;
|
||||
}
|
||||
|
||||
void StaticModel::SetLODBias(int32 value)
|
||||
{
|
||||
_lodBias = static_cast<char>(Math::Clamp(value, -100, 100));
|
||||
}
|
||||
|
||||
int32 StaticModel::GetForcedLOD() const
|
||||
{
|
||||
return _forcedLod;
|
||||
}
|
||||
|
||||
void StaticModel::SetForcedLOD(int32 value)
|
||||
{
|
||||
_forcedLod = static_cast<char>(Math::Clamp(value, -1, 100));
|
||||
}
|
||||
|
||||
int32 StaticModel::GetSortOrder() const
|
||||
{
|
||||
return _sortOrder;
|
||||
}
|
||||
|
||||
void StaticModel::SetSortOrder(int32 value)
|
||||
{
|
||||
_sortOrder = (int16)Math::Clamp<int32>(value, MIN_int16, MAX_int16);
|
||||
}
|
||||
|
||||
bool StaticModel::HasLightmap() const
|
||||
{
|
||||
return Lightmap.TextureIndex != INVALID_INDEX;
|
||||
}
|
||||
|
||||
void StaticModel::RemoveLightmap()
|
||||
{
|
||||
Lightmap.TextureIndex = INVALID_INDEX;
|
||||
}
|
||||
|
||||
MaterialBase* StaticModel::GetMaterial(int32 meshIndex, int32 lodIndex) const
|
||||
{
|
||||
auto model = Model.Get();
|
||||
@@ -153,6 +204,11 @@ void StaticModel::SetVertexColor(int32 lodIndex, int32 meshIndex, int32 vertexIn
|
||||
LOG(Warning, "Specified model mesh index was out of range. LOD{0} mesh {1}.", lodIndex, meshIndex);
|
||||
}
|
||||
|
||||
bool StaticModel::HasVertexColors() const
|
||||
{
|
||||
return _vertexColorsCount != 0;
|
||||
}
|
||||
|
||||
void StaticModel::RemoveVertexColors()
|
||||
{
|
||||
for (int32 lodIndex = 0; lodIndex < _vertexColorsCount; lodIndex++)
|
||||
@@ -292,6 +348,7 @@ void StaticModel::Draw(RenderContext& renderContext)
|
||||
draw.PerInstanceRandom = GetPerInstanceRandom();
|
||||
draw.LODBias = _lodBias;
|
||||
draw.ForcedLOD = _forcedLod;
|
||||
draw.SortOrder = _sortOrder;
|
||||
draw.VertexColors = _vertexColorsCount ? _vertexColorsBuffer : nullptr;
|
||||
|
||||
Model->Draw(renderContext, draw);
|
||||
@@ -324,6 +381,7 @@ void StaticModel::Draw(RenderContextBatch& renderContextBatch)
|
||||
draw.PerInstanceRandom = GetPerInstanceRandom();
|
||||
draw.LODBias = _lodBias;
|
||||
draw.ForcedLOD = _forcedLod;
|
||||
draw.SortOrder = _sortOrder;
|
||||
draw.VertexColors = _vertexColorsCount ? _vertexColorsBuffer : nullptr;
|
||||
|
||||
Model->Draw(renderContextBatch, draw);
|
||||
@@ -356,6 +414,7 @@ void StaticModel::Serialize(SerializeStream& stream, const void* otherObj)
|
||||
SERIALIZE(Model);
|
||||
SERIALIZE_MEMBER(LODBias, _lodBias);
|
||||
SERIALIZE_MEMBER(ForcedLOD, _forcedLod);
|
||||
SERIALIZE_MEMBER(SortOrder, _sortOrder);
|
||||
SERIALIZE(DrawModes);
|
||||
|
||||
if (HasLightmap()
|
||||
@@ -405,22 +464,9 @@ void StaticModel::Deserialize(DeserializeStream& stream, ISerializeModifier* mod
|
||||
DESERIALIZE_MEMBER(ScaleInLightmap, _scaleInLightmap);
|
||||
DESERIALIZE_MEMBER(BoundsScale, _boundsScale);
|
||||
DESERIALIZE(Model);
|
||||
|
||||
{
|
||||
const auto member = stream.FindMember("LODBias");
|
||||
if (member != stream.MemberEnd() && member->value.IsInt())
|
||||
{
|
||||
SetLODBias(member->value.GetInt());
|
||||
}
|
||||
}
|
||||
{
|
||||
const auto member = stream.FindMember("ForcedLOD");
|
||||
if (member != stream.MemberEnd() && member->value.IsInt())
|
||||
{
|
||||
SetForcedLOD(member->value.GetInt());
|
||||
}
|
||||
}
|
||||
|
||||
DESERIALIZE_MEMBER(LODBias, _lodBias);
|
||||
DESERIALIZE_MEMBER(ForcedLOD, _forcedLod);
|
||||
DESERIALIZE_MEMBER(SortOrder, _sortOrder);
|
||||
DESERIALIZE(DrawModes);
|
||||
DESERIALIZE_MEMBER(LightmapIndex, Lightmap.TextureIndex);
|
||||
DESERIALIZE_MEMBER(LightmapArea, Lightmap.UVsArea);
|
||||
|
||||
@@ -21,6 +21,7 @@ private:
|
||||
char _forcedLod;
|
||||
bool _vertexColorsDirty;
|
||||
byte _vertexColorsCount;
|
||||
int16 _sortOrder;
|
||||
Array<Color32> _vertexColorsData[MODEL_MAX_LODS];
|
||||
GPUBuffer* _vertexColorsBuffer[MODEL_MAX_LODS];
|
||||
Model* _residencyChangedModel = nullptr;
|
||||
@@ -53,10 +54,7 @@ public:
|
||||
/// Gets the model scale in lightmap (applied to all the meshes).
|
||||
/// </summary>
|
||||
API_PROPERTY(Attributes="EditorOrder(10), DefaultValue(1.0f), EditorDisplay(\"Model\", \"Scale In Lightmap\"), Limit(0, 1000.0f, 0.1f)")
|
||||
FORCE_INLINE float GetScaleInLightmap() const
|
||||
{
|
||||
return _scaleInLightmap;
|
||||
}
|
||||
float GetScaleInLightmap() const;
|
||||
|
||||
/// <summary>
|
||||
/// Sets the model scale in lightmap (applied to all the meshes).
|
||||
@@ -67,10 +65,7 @@ public:
|
||||
/// Gets the model bounds scale. It is useful when using Position Offset to animate the vertices of the object outside of its bounds. Increasing the bounds of an object will reduce performance.
|
||||
/// </summary>
|
||||
API_PROPERTY(Attributes="EditorOrder(12), DefaultValue(1.0f), EditorDisplay(\"Model\"), Limit(0, 10.0f, 0.1f)")
|
||||
FORCE_INLINE float GetBoundsScale() const
|
||||
{
|
||||
return _boundsScale;
|
||||
}
|
||||
float GetBoundsScale() const;
|
||||
|
||||
/// <summary>
|
||||
/// Sets the model bounds scale. It is useful when using Position Offset to animate the vertices of the object outside of its bounds.
|
||||
@@ -81,51 +76,44 @@ public:
|
||||
/// Gets the model Level Of Detail bias value. Allows to increase or decrease rendered model quality.
|
||||
/// </summary>
|
||||
API_PROPERTY(Attributes="EditorOrder(40), DefaultValue(0), Limit(-100, 100, 0.1f), EditorDisplay(\"Model\", \"LOD Bias\")")
|
||||
FORCE_INLINE int32 GetLODBias() const
|
||||
{
|
||||
return static_cast<int32>(_lodBias);
|
||||
}
|
||||
int32 GetLODBias() const;
|
||||
|
||||
/// <summary>
|
||||
/// Sets the model Level Of Detail bias value. Allows to increase or decrease rendered model quality.
|
||||
/// </summary>
|
||||
API_PROPERTY() void SetLODBias(int32 value)
|
||||
{
|
||||
_lodBias = static_cast<char>(Math::Clamp(value, -100, 100));
|
||||
}
|
||||
API_PROPERTY() void SetLODBias(int32 value);
|
||||
|
||||
/// <summary>
|
||||
/// Gets the model forced Level Of Detail index. Allows to bind the given model LOD to show. Value -1 disables this feature.
|
||||
/// </summary>
|
||||
API_PROPERTY(Attributes="EditorOrder(50), DefaultValue(-1), Limit(-1, 100, 0.1f), EditorDisplay(\"Model\", \"Forced LOD\")")
|
||||
FORCE_INLINE int32 GetForcedLOD() const
|
||||
{
|
||||
return static_cast<int32>(_forcedLod);
|
||||
}
|
||||
int32 GetForcedLOD() const;
|
||||
|
||||
/// <summary>
|
||||
/// Sets the model forced Level Of Detail index. Allows to bind the given model LOD to show. Value -1 disables this feature.
|
||||
/// </summary>
|
||||
API_PROPERTY() void SetForcedLOD(int32 value)
|
||||
{
|
||||
_forcedLod = static_cast<char>(Math::Clamp(value, -1, 100));
|
||||
}
|
||||
API_PROPERTY() void SetForcedLOD(int32 value);
|
||||
|
||||
/// <summary>
|
||||
/// Gets the model sort order key used when sorting drawable objects during rendering. Use lower values to draw object before others, higher values are rendered later (on top). Can be use to control transparency drawing.
|
||||
/// </summary>
|
||||
API_PROPERTY(Attributes="EditorOrder(60), DefaultValue(0), EditorDisplay(\"Model\")")
|
||||
int32 GetSortOrder() const;
|
||||
|
||||
/// <summary>
|
||||
/// Sets the model sort order key used when sorting drawable objects during rendering. Use lower values to draw object before others, higher values are rendered later (on top). Can be use to control transparency drawing.
|
||||
/// </summary>
|
||||
API_PROPERTY() void SetSortOrder(int32 value);
|
||||
|
||||
/// <summary>
|
||||
/// Determines whether this model has valid lightmap data.
|
||||
/// </summary>
|
||||
API_PROPERTY() FORCE_INLINE bool HasLightmap() const
|
||||
{
|
||||
return Lightmap.TextureIndex != INVALID_INDEX;
|
||||
}
|
||||
API_PROPERTY() bool HasLightmap() const;
|
||||
|
||||
/// <summary>
|
||||
/// Removes the lightmap data from the model.
|
||||
/// </summary>
|
||||
API_FUNCTION() FORCE_INLINE void RemoveLightmap()
|
||||
{
|
||||
Lightmap.TextureIndex = INVALID_INDEX;
|
||||
}
|
||||
API_FUNCTION() void RemoveLightmap();
|
||||
|
||||
/// <summary>
|
||||
/// Gets the material used to render mesh at given index (overriden by model instance buffer or model default).
|
||||
@@ -156,10 +144,7 @@ public:
|
||||
/// <summary>
|
||||
/// Returns true if model instance is using custom painted vertex colors buffer, otherwise it will use vertex colors from the original asset.
|
||||
/// </summary>
|
||||
API_PROPERTY() bool HasVertexColors() const
|
||||
{
|
||||
return _vertexColorsCount != 0;
|
||||
}
|
||||
API_PROPERTY() bool HasVertexColors() const;
|
||||
|
||||
/// <summary>
|
||||
/// Removes the vertex colors buffer from this instance.
|
||||
|
||||
Reference in New Issue
Block a user