Skip to content

Commit

Permalink
#5532: Start building the system needed to support the chained transf…
Browse files Browse the repository at this point in the history
…ormations possible in the idTech4 stages
  • Loading branch information
codereader committed Mar 14, 2021
1 parent 18ed818 commit 4a656d0
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 0 deletions.
28 changes: 28 additions & 0 deletions include/ishaderlayer.h
Expand Up @@ -9,6 +9,7 @@

#include "math/Vector2.h"
#include "math/Vector4.h"
#include "math/Matrix4.h"
#include "render/Colour4.h"

class IRenderEntity;
Expand Down Expand Up @@ -117,6 +118,24 @@ class IShaderLayer
};
};

// The various texture transformations
enum class TransformType
{
Translate,
Scale,
CenterScale,
Shear,
Rotate,
};

// A texture transformation consists of a type and two arguments at most
struct Transformation
{
TransformType type;
shaders::IShaderExpression::Ptr expression1;
shaders::IShaderExpression::Ptr expression2;
};

/**
* \brief
* Destructor
Expand Down Expand Up @@ -257,6 +276,15 @@ class IShaderLayer
*/
virtual const Vector2& getRenderMapSize() const = 0;

// Adds a transformation at the end of the list of existing transforms in this stage
virtual void appendTransformation(const Transformation& transform) = 0;

// The list of transformations defined in this stage, in the order they appear in the declaration
virtual const std::vector<Transformation>& getTransformations() = 0;

// Returns the current texture matrix
virtual Matrix4 getTextureTransform() = 0;

/**
* Returns the value of the scale expressions of this stage.
*/
Expand Down
15 changes: 15 additions & 0 deletions radiantcore/shaders/Doom3ShaderLayer.cpp
Expand Up @@ -292,6 +292,21 @@ void Doom3ShaderLayer::setColour(const Vector4& col)
}
}

void Doom3ShaderLayer::appendTransformation(const Transformation& transform)
{
_transformations.emplace_back(transform);
}

const std::vector<IShaderLayer::Transformation>& Doom3ShaderLayer::getTransformations()
{
return _transformations;
}

Matrix4 Doom3ShaderLayer::getTextureTransform()
{
return Matrix4::getIdentity();
}

IShaderLayer::VertexColourMode Doom3ShaderLayer::getVertexColourMode() const
{
return _vertexColourMode;
Expand Down
7 changes: 7 additions & 0 deletions radiantcore/shaders/Doom3ShaderLayer.h
Expand Up @@ -70,6 +70,9 @@ class Doom3ShaderLayer :
// texgen normal, reflect, skybox, wobblesky
TexGenType _texGenType;

// The list of declared transformations
std::vector<IShaderLayer::Transformation> _transformations;

// The register indices of this stage's scale expressions
std::size_t _scale[2];
std::size_t _scaleExpression[2];
Expand Down Expand Up @@ -361,6 +364,10 @@ class Doom3ShaderLayer :
_texture = tex;
}

void appendTransformation(const Transformation& transform) override;
const std::vector<Transformation>& getTransformations() override;
Matrix4 getTextureTransform() override;

Vector2 getScale() const override
{
return Vector2(_registers[_scale[0]], _registers[_scale[1]]);
Expand Down

0 comments on commit 4a656d0

Please sign in to comment.