Skip to content

Commit

Permalink
Traktor: Separated size of decals into width and depth.
Browse files Browse the repository at this point in the history
  • Loading branch information
apistol78 committed Apr 16, 2024
1 parent 3de757c commit ed11212
Show file tree
Hide file tree
Showing 12 changed files with 226 additions and 94 deletions.
8 changes: 4 additions & 4 deletions code/World/Entity/DecalComponent.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* TRAKTOR
* Copyright (c) 2022 Anders Pistol.
* Copyright (c) 2022-2024 Anders Pistol.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
Expand All @@ -14,7 +14,7 @@ namespace traktor::world
T_IMPLEMENT_RTTI_CLASS(L"traktor.world.DecalComponent", DecalComponent, IEntityComponent)

DecalComponent::DecalComponent(
float size,
const Vector2& size,
float thickness,
float alpha,
float cullDistance,
Expand Down Expand Up @@ -45,8 +45,8 @@ void DecalComponent::setTransform(const Transform& transform)
Aabb3 DecalComponent::getBoundingBox() const
{
return Aabb3(
Vector4(-m_size, -m_thickness, -m_size, 1.0f),
Vector4(m_size, m_thickness, m_size, 1.0f)
Vector4(-m_size.x, -m_thickness, -m_size.y, 1.0f),
Vector4(m_size.x, m_thickness, m_size.y, 1.0f)
);
}

Expand Down
6 changes: 3 additions & 3 deletions code/World/Entity/DecalComponent.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class T_DLLCLASS DecalComponent : public IEntityComponent

public:
explicit DecalComponent(
float size,
const Vector2& size,
float thickness,
float alpha,
float cullDistance,
Expand All @@ -48,7 +48,7 @@ class T_DLLCLASS DecalComponent : public IEntityComponent

virtual void update(const UpdateParams& update) override final;

float getSize() const { return m_size; }
const Vector2& getSize() const { return m_size; }

float getThickness() const { return m_thickness; }

Expand All @@ -64,7 +64,7 @@ class T_DLLCLASS DecalComponent : public IEntityComponent

private:
Transform m_transform;
float m_size;
Vector2 m_size;
float m_thickness;
float m_alpha;
float m_cullDistance;
Expand Down
13 changes: 10 additions & 3 deletions code/World/Entity/DecalComponentData.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* TRAKTOR
* Copyright (c) 2022 Anders Pistol.
* Copyright (c) 2022-2024 Anders Pistol.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
Expand All @@ -15,7 +15,7 @@
namespace traktor::world
{

T_IMPLEMENT_RTTI_EDIT_CLASS(L"traktor.world.DecalComponentData", 0, DecalComponentData, IEntityComponentData)
T_IMPLEMENT_RTTI_EDIT_CLASS(L"traktor.world.DecalComponentData", 1, DecalComponentData, IEntityComponentData)

int32_t DecalComponentData::getOrdinal() const
{
Expand All @@ -28,7 +28,14 @@ void DecalComponentData::setTransform(const EntityData* owner, const Transform&

void DecalComponentData::serialize(ISerializer& s)
{
s >> Member< float >(L"size", m_size, AttributeRange(0.0f) | AttributeUnit(UnitType::Metres));
if (s.getVersion< DecalComponentData >() >= 1)
s >> Member< Vector2 >(L"size", m_size, AttributeRange(0.0f) | AttributeUnit(UnitType::Metres));
else
{
float size;
s >> Member< float >(L"size", size, AttributeRange(0.0f) | AttributeUnit(UnitType::Metres));
m_size = Vector2(size, size);
}
s >> Member< float >(L"thickness", m_thickness, AttributeRange(0.0f) | AttributeUnit(UnitType::Metres));
s >> Member< float >(L"alpha", m_alpha, AttributeRange(0.0f) | AttributeUnit(UnitType::Percent));
s >> Member< float >(L"cullDistance", m_cullDistance, AttributeRange(0.0f) | AttributeUnit(UnitType::Metres));
Expand Down
7 changes: 4 additions & 3 deletions code/World/Entity/DecalComponentData.h
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
/*
* TRAKTOR
* Copyright (c) 2022 Anders Pistol.
* Copyright (c) 2022-2024 Anders Pistol.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/
#pragma once

#include "Core/Math/Vector2.h"
#include "Resource/Id.h"
#include "World/IEntityComponentData.h"

Expand Down Expand Up @@ -43,7 +44,7 @@ class T_DLLCLASS DecalComponentData : public IEntityComponentData

virtual void serialize(ISerializer& s) override final;

float getSize() const { return m_size; }
const Vector2& getSize() const { return m_size; }

float getThickness() const { return m_thickness; }

Expand All @@ -54,7 +55,7 @@ class T_DLLCLASS DecalComponentData : public IEntityComponentData
const resource::Id< render::Shader >& getShader() const { return m_shader; }

private:
float m_size = 1.0f;
Vector2 m_size = Vector2(1.0f, 1.0f);
float m_thickness = 1.0f;
float m_alpha = 1.0f;
float m_cullDistance = 100.0f;
Expand Down
7 changes: 4 additions & 3 deletions code/World/Entity/DecalEvent.h
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
/*
* TRAKTOR
* Copyright (c) 2022 Anders Pistol.
* Copyright (c) 2022-2024 Anders Pistol.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/
#pragma once

#include "Core/Math/Vector2.h"
#include "Resource/Proxy.h"
#include "World/IEntityEvent.h"

Expand All @@ -31,7 +32,7 @@ class DecalEvent : public IEntityEvent
public:
virtual Ref< IEntityEventInstance > createInstance(EntityEventManager* eventManager, Entity* sender, const Transform& Toffset) const override final;

float getSize() const { return m_size; }
const Vector2& getSize() const { return m_size; }

float getThickness() const { return m_thickness; }

Expand All @@ -44,7 +45,7 @@ class DecalEvent : public IEntityEvent
private:
friend class WorldEntityFactory;

float m_size = 1.0f;
Vector2 m_size = Vector2(1.0f, 1.0f);
float m_thickness = 1.0f;
float m_alpha = 2.0f;
float m_cullDistance = 100.0f;
Expand Down
13 changes: 10 additions & 3 deletions code/World/Entity/DecalEventData.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* TRAKTOR
* Copyright (c) 2022 Anders Pistol.
* Copyright (c) 2022-2024 Anders Pistol.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
Expand All @@ -15,11 +15,18 @@
namespace traktor::world
{

T_IMPLEMENT_RTTI_EDIT_CLASS(L"traktor.world.DecalEventData", 0, DecalEventData, IEntityEventData)
T_IMPLEMENT_RTTI_EDIT_CLASS(L"traktor.world.DecalEventData", 1, DecalEventData, IEntityEventData)

void DecalEventData::serialize(ISerializer& s)
{
s >> Member< float >(L"size", m_size, AttributeRange(0.0f) | AttributeUnit(UnitType::Metres));
if (s.getVersion< DecalEventData >() >= 1)
s >> Member< Vector2 >(L"size", m_size, AttributeRange(0.0f) | AttributeUnit(UnitType::Metres));
else
{
float size;
s >> Member< float >(L"size", size, AttributeRange(0.0f) | AttributeUnit(UnitType::Metres));
m_size = Vector2(size, size);
}
s >> Member< float >(L"thickness", m_thickness, AttributeRange(0.0f) | AttributeUnit(UnitType::Metres));
s >> Member< float >(L"alpha", m_alpha, AttributeRange(0.0f) | AttributeUnit(UnitType::Percent));
s >> Member< float >(L"cullDistance", m_cullDistance, AttributeRange(0.0f) | AttributeUnit(UnitType::Metres));
Expand Down
7 changes: 4 additions & 3 deletions code/World/Entity/DecalEventData.h
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
/*
* TRAKTOR
* Copyright (c) 2022 Anders Pistol.
* Copyright (c) 2022-2024 Anders Pistol.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/
#pragma once

#include "Core/Math/Vector2.h"
#include "Resource/Id.h"
#include "World/IEntityEventData.h"

Expand Down Expand Up @@ -39,7 +40,7 @@ class T_DLLCLASS DecalEventData : public IEntityEventData
public:
virtual void serialize(ISerializer& s) override final;

float getSize() const { return m_size; }
const Vector2& getSize() const { return m_size; }

float getThickness() const { return m_thickness; }

Expand All @@ -50,7 +51,7 @@ class T_DLLCLASS DecalEventData : public IEntityEventData
const resource::Id< render::Shader >& getShader() const { return m_shader; }

private:
float m_size = 1.0f;
Vector2 m_size = Vector2(1.0f, 1.0f);
float m_thickness = 1.0f;
float m_alpha = 2.0f;
float m_cullDistance = 100.0f;
Expand Down
16 changes: 11 additions & 5 deletions code/World/Entity/DecalRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,15 +111,15 @@ void DecalRenderer::build(
const DecalComponent* decalComponent = static_cast< const DecalComponent* >(renderable);
const Transform& transform = decalComponent->getTransform();

const float s = decalComponent->getSize();
const Vector2& s = decalComponent->getSize();
const float t = decalComponent->getThickness();
const float d = decalComponent->getCullDistance();

const Vector4 center = worldRenderView.getView() * transform.translation().xyz1();
if (center.length2() > d * d)
return;

const Scalar radius = Scalar(std::sqrt(s * s + s * s + t * t));
const Scalar radius = Scalar(std::sqrt(s.x * s.x + s.y * s.y + t * t));
if (worldRenderView.getCullFrustum().inside(center, radius) == Frustum::Result::Outside)
return;

Expand Down Expand Up @@ -184,11 +184,17 @@ void DecalRenderer::build(
transform
);

renderBlock->programParams->setVectorParameter(s_handleDecalParams, Vector4(
decalComponent->getSize(),
renderBlock->programParams->setVectorParameter(s_handleDecalParamsA, Vector4(
decalComponent->getSize().x,
decalComponent->getSize().y,
decalComponent->getThickness(),
0.0f
));
renderBlock->programParams->setVectorParameter(s_handleDecalParamsB, Vector4(
decalComponent->getAlpha(),
decalComponent->getAge()
decalComponent->getAge(),
0.0f,
0.0f
));
renderBlock->programParams->setVectorParameter(s_handleMagicCoeffs, magicCoeffs);
renderBlock->programParams->setMatrixParameter(s_handleWorldViewInv, worldViewInv);
Expand Down
3 changes: 2 additions & 1 deletion code/World/WorldHandles.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ const render::Handle s_handleIrradianceSingle(L"World_IrradianceSingle");
const render::Handle s_handleVolumetricFogEnable(L"World_VolumetricFogEnable");

// Shader parameters.
const render::Handle s_handleDecalParams(L"World_DecalParams");
const render::Handle s_handleDecalParamsA(L"World_DecalParamsA");
const render::Handle s_handleDecalParamsB(L"World_DecalParamsB");
const render::Handle s_handleExposure(L"World_Exposure");
const render::Handle s_handleFxRotate(L"World_FxRotate");
const render::Handle s_handleExtent(L"World_Extent");
Expand Down
3 changes: 2 additions & 1 deletion code/World/WorldHandles.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ extern const render::Handle T_DLLCLASS s_handleIrradianceSingle;
extern const render::Handle T_DLLCLASS s_handleVolumetricFogEnable;

// Shader parameters.
extern const render::Handle T_DLLCLASS s_handleDecalParams;
extern const render::Handle T_DLLCLASS s_handleDecalParamsA;
extern const render::Handle T_DLLCLASS s_handleDecalParamsB;
extern const render::Handle T_DLLCLASS s_handleExposure;
extern const render::Handle T_DLLCLASS s_handleFxRotate;
extern const render::Handle T_DLLCLASS s_handleExtent;
Expand Down
Loading

0 comments on commit ed11212

Please sign in to comment.