Skip to content

Commit

Permalink
#5584: Brushes store the entity colour in the vertex attributes now, …
Browse files Browse the repository at this point in the history
…to fix their wireframe rendering colour
  • Loading branch information
codereader committed Dec 16, 2021
1 parent 40f6537 commit 1852e40
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 5 deletions.
7 changes: 7 additions & 0 deletions include/irender.h
Expand Up @@ -7,6 +7,7 @@
#include <vector>

#include "math/Vector3.h"
#include "math/Vector4.h"
#include "math/AABB.h"
#include "render/ArbitraryMeshVertex.h"

Expand Down Expand Up @@ -158,6 +159,12 @@ class IRenderEntity
* visualisations such as target lines and light boxes.
*/
virtual const ShaderPtr& getColourShader() const = 0;

/**
* Returns the colour of this entity, that is used to display its
* wireframe representation.
*/
virtual Vector4 getEntityColour() const = 0;
};
typedef std::shared_ptr<IRenderEntity> IRenderEntityPtr;
typedef std::weak_ptr<IRenderEntity> IRenderEntityWeakPtr;
Expand Down
4 changes: 2 additions & 2 deletions radiantcore/brush/BrushNode.cpp
Expand Up @@ -361,11 +361,11 @@ void BrushNode::onPreRender(const VolumeTest& volume)

if (volume.fill())
{
face.getWindingSurfaceSolid().update(face.getFaceShader().getGLShader());
face.getWindingSurfaceSolid().update(face.getFaceShader().getGLShader(), *_renderEntity);
}
else
{
face.getWindingSurfaceWireframe().update(_renderEntity->getWireShader());
face.getWindingSurfaceWireframe().update(_renderEntity->getWireShader(), *_renderEntity);
}
}
}
Expand Down
7 changes: 5 additions & 2 deletions radiantcore/brush/RenderableWinding.h
Expand Up @@ -31,7 +31,7 @@ class RenderableWinding :
_needsUpdate = true;
}

void update(const ShaderPtr& shader)
void update(const ShaderPtr& shader, const IRenderEntity& entity)
{
bool shaderChanged = _shader != shader;

Expand All @@ -50,9 +50,12 @@ class RenderableWinding :
std::vector<ArbitraryMeshVertex> vertices;
vertices.reserve(numPoints);

// Use the colour defined by the entity as vertex colour
auto entityColour = entity.getEntityColour();

for (const auto& vertex : _winding)
{
vertices.emplace_back(ArbitraryMeshVertex(vertex.vertex, vertex.normal, vertex.texcoord, { 1, 1, 1 }));
vertices.emplace_back(ArbitraryMeshVertex(vertex.vertex, vertex.normal, vertex.texcoord, entityColour));
}

if (_shader && _slot != IWindingRenderer::InvalidSlot && (shaderChanged || numPoints != _windingSize))
Expand Down
5 changes: 5 additions & 0 deletions radiantcore/entity/EntityNode.cpp
Expand Up @@ -481,6 +481,11 @@ const ShaderPtr& EntityNode::getFillShader() const
return _fillShader;
}

Vector4 EntityNode::getEntityColour() const
{
return Vector4(_spawnArgs.getEntityClass()->getColour(), 1.0);
}

void EntityNode::onPostUndo()
{
// After undo operations there might remain some child nodes
Expand Down
1 change: 1 addition & 0 deletions radiantcore/entity/EntityNode.h
Expand Up @@ -164,6 +164,7 @@ class EntityNode :
const ShaderPtr& getWireShader() const override;
const ShaderPtr& getColourShader() const override;
const ShaderPtr& getFillShader() const;
Vector4 getEntityColour() const override;

virtual void onPostUndo() override;
virtual void onPostRedo() override;
Expand Down
1 change: 0 additions & 1 deletion radiantcore/particles/ParticleNode.h
Expand Up @@ -35,7 +35,6 @@ class ParticleNode :
const AABB& localAABB() const override;
std::size_t getHighlightFlags() override;

bool isOriented() const override;
void onPreRender(const VolumeTest& volume) override;
void renderSolid(IRenderableCollector& collector, const VolumeTest& volume) const override;
void renderWireframe(IRenderableCollector& collector, const VolumeTest& volume) const override;
Expand Down

0 comments on commit 1852e40

Please sign in to comment.