Draw selected nodes as tinted with wireframe, instead of drawing the bounding box

This commit is contained in:
parax0 2015-11-26 03:42:42 -07:00
parent 7a69346ff3
commit c132197df0
23 changed files with 101 additions and 69 deletions

View File

@ -118,29 +118,26 @@ void CColor::operator-=(const CColor& other)
CColor CColor::operator*(const CColor& other) const
{
u16 NewR = r * other.r;
if (NewR > 255) NewR = 255;
u16 NewG = g * other.g;
if (NewG > 255) NewG = 255;
u16 NewB = b * other.b;
if (NewB > 255) NewB = 255;
u16 NewA = a * other.a;
if (NewA > 255) NewA = 255;
return CColor((u8) NewR, (u8) NewG, (u8) NewB, (u8) NewA);
CVector4f A = ToVector4f();
CVector4f B = other.ToVector4f();
float NewR = A.x * B.x;
float NewG = A.y * B.y;
float NewB = A.z * B.z;
float NewA = A.w * B.w;
return CColor(NewR, NewG, NewB, NewA);
}
void CColor::operator*=(const CColor& other)
{
*this = (*this - other);
*this = (*this * other);
}
CColor CColor::operator*(const float other) const
{
u8 NewR = (u8) (r * other);
u8 NewG = (u8) (g * other);
u8 NewB = (u8) (b * other);
u8 NewA = (u8) (a * other);
return CColor(NewR, NewG, NewB, NewA);
CVector4f Vec4f = ToVector4f() * other;
return CColor(Vec4f.x, Vec4f.y, Vec4f.z, Vec4f.w);
}
void CColor::operator*=(const float other)

View File

@ -316,12 +316,16 @@ void CDrawUtil::UseTextureShader(const CColor& TintColor)
CMaterial::KillCachedMaterial();
}
void CDrawUtil::UseCollisionShader()
void CDrawUtil::UseCollisionShader(const CColor& TintColor /*= CColor::skWhite*/)
{
Init();
mpCollisionShader->SetCurrent();
LoadCheckerboardTexture(0);
GLuint TintColorLoc = mpCollisionShader->GetUniformLocation("TintColor");
CVector4f Tint4f = TintColor.ToVector4f();
glUniform4f(TintColorLoc, Tint4f.x, Tint4f.y, Tint4f.z, Tint4f.w);
CMaterial::KillCachedMaterial();
}

View File

@ -7,6 +7,9 @@
#include <Resource/model/CModel.h>
#include <Resource/CLight.h>
// todo: CDrawUtil should work with CRenderer to queue primitives for rendering
// rather than trying to draw them straight away, so that CDrawUtil functions can
// be called from anywhere in the codebase and still function correctly
class CDrawUtil
{
// 7x7 Grid
@ -86,7 +89,7 @@ public:
static void UseColorShaderLighting(const CColor& Color);
static void UseTextureShader();
static void UseTextureShader(const CColor& TintColor);
static void UseCollisionShader();
static void UseCollisionShader(const CColor& TintColor = CColor::skWhite);
static CShader* GetTextShader();
static void LoadCheckerboardTexture(u32 GLTextureUnit);

View File

@ -2,6 +2,7 @@
#include <algorithm>
#include "CDrawUtil.h"
#include "CGraphics.h"
#include "CRenderer.h"
CRenderBucket::CRenderBucket()
{
@ -71,15 +72,17 @@ void CRenderBucket::Clear()
mSize = 0;
}
void CRenderBucket::Draw(ERenderOptions Options)
void CRenderBucket::Draw(const SViewInfo& ViewInfo)
{
ERenderOptions Options = ViewInfo.pRenderer->RenderOptions();
for (u32 n = 0; n < mSize; n++)
{
if (mRenderables[n].Command == eDrawMesh)
mRenderables[n].pRenderable->Draw(Options);
mRenderables[n].pRenderable->Draw(Options, ViewInfo);
else if (mRenderables[n].Command == eDrawAsset)
mRenderables[n].pRenderable->DrawAsset(Options, mRenderables[n].Asset);
mRenderables[n].pRenderable->DrawAsset(Options, mRenderables[n].Asset, ViewInfo);
else if (mRenderables[n].Command == eDrawSelection)
mRenderables[n].pRenderable->DrawSelection();

View File

@ -27,7 +27,7 @@ public:
void Add(const SRenderablePtr& ptr);
void Sort(CCamera* pCamera);
void Clear();
void Draw(ERenderOptions Options);
void Draw(const SViewInfo& ViewInfo);
};
#endif // CRENDERBUCKET_H

View File

@ -172,10 +172,10 @@ void CRenderer::RenderBuckets(const SViewInfo& ViewInfo)
glDepthRange(0.f, 1.f);
glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
mOpaqueBucket.Draw(mOptions);
mOpaqueBucket.Draw(ViewInfo);
mOpaqueBucket.Clear();
mTransparentBucket.Sort(ViewInfo.pCamera);
mTransparentBucket.Draw(mOptions);
mTransparentBucket.Draw(ViewInfo);
mTransparentBucket.Clear();
}

View File

@ -13,8 +13,8 @@ public:
IRenderable() {}
virtual ~IRenderable() {}
virtual void AddToRenderer(CRenderer* pRenderer, const SViewInfo& ViewInfo) = 0;
virtual void Draw(ERenderOptions /*options*/) {}
virtual void DrawAsset(ERenderOptions /*options*/, u32 /*asset*/) {}
virtual void Draw(ERenderOptions /*options*/, const SViewInfo& /*ViewInfo*/) {}
virtual void DrawAsset(ERenderOptions /*options*/, u32 /*asset*/, const SViewInfo& /*ViewInfo*/) {}
virtual void DrawSelection() {}
};

View File

@ -423,7 +423,7 @@ bool CShaderGenerator::CreatePixelShader(const CMaterial& Mat)
}
}
ShaderCode << " PixelColor = Prev.rgba;\n"
ShaderCode << " PixelColor = Prev.rgba * TintColor;\n"
<< "}\n\n";
// Done!

View File

@ -27,7 +27,7 @@ void CCollisionNode::AddToRenderer(CRenderer *pRenderer, const SViewInfo& ViewIn
pRenderer->AddOpaqueMesh(this, 0, AABox(), eDrawSelection);
}
void CCollisionNode::Draw(ERenderOptions)
void CCollisionNode::Draw(ERenderOptions, const SViewInfo& ViewInfo)
{
// Not using parameter 1 (ERenderOptions - Options)
if (!mpCollision) return;
@ -38,16 +38,12 @@ void CCollisionNode::Draw(ERenderOptions)
glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
glDepthMask(GL_TRUE);
CDrawUtil::UseCollisionShader();
CDrawUtil::UseCollisionShader(TintColor(ViewInfo));
mpCollision->Draw();
CDrawUtil::UseColorShader(CColor::skTransparentBlack);
mpCollision->DrawWireframe();
}
void CCollisionNode::DrawAsset(ERenderOptions /*Options*/, u32 /*asset*/)
{
}
SRayIntersection CCollisionNode::RayNodeIntersectTest(const CRay& /*Ray*/, u32 /*AssetID*/, const SViewInfo& /*ViewInfo*/)
{
// todo

View File

@ -13,8 +13,7 @@ public:
CCollisionNode(CSceneManager *pScene, CSceneNode *pParent = 0, CCollisionMeshGroup *pCollision = 0);
ENodeType NodeType();
void AddToRenderer(CRenderer *pRenderer, const SViewInfo& ViewInfo);
void Draw(ERenderOptions Options);
void DrawAsset(ERenderOptions Options, u32 asset);
void Draw(ERenderOptions Options, const SViewInfo& ViewInfo);
SRayIntersection RayNodeIntersectTest(const CRay &Ray, u32 AssetID, const SViewInfo& ViewInfo);
void SetCollision(CCollisionMeshGroup *pCollision);
};

View File

@ -33,9 +33,9 @@ void CLightNode::AddToRenderer(CRenderer *pRenderer, const SViewInfo& ViewInfo)
pRenderer->AddOpaqueMesh(this, 0, CAABox(mPosition + 0.5f, mPosition - 0.5f), eDrawMesh);
}
void CLightNode::Draw(ERenderOptions /*Options*/)
void CLightNode::Draw(ERenderOptions /*Options*/, const SViewInfo& ViewInfo)
{
CDrawUtil::DrawLightBillboard(mpLight->GetType(), mpLight->GetColor(), mPosition, BillboardScale(), TintColor());
CDrawUtil::DrawLightBillboard(mpLight->GetType(), mpLight->GetColor(), mPosition, BillboardScale(), TintColor(ViewInfo));
// Below commented-out code is for light radius visualization as a bounding box
/*float r = mLight->GetRadius();
@ -43,10 +43,6 @@ void CLightNode::Draw(ERenderOptions /*Options*/)
pRenderer->DrawBoundingBox(mLight->GetColor(), AABB);*/
}
void CLightNode::DrawAsset(ERenderOptions /*Options*/, u32 /*asset*/)
{
}
void CLightNode::RayAABoxIntersectTest(CRayCollisionTester &Tester)
{
CVector2f BillScale = BillboardScale();

View File

@ -11,8 +11,7 @@ public:
CLightNode(CSceneManager *pScene, CSceneNode *pParent = 0, CLight *Light = 0);
ENodeType NodeType();
void AddToRenderer(CRenderer *pRenderer, const SViewInfo& ViewInfo);
void Draw(ERenderOptions Options);
void DrawAsset(ERenderOptions Options, u32 asset);
void Draw(ERenderOptions Options, const SViewInfo& ViewInfo);
void RayAABoxIntersectTest(CRayCollisionTester& Tester);
SRayIntersection RayNodeIntersectTest(const CRay &Ray, u32 AssetID, const SViewInfo& ViewInfo);
CLight* Light();

View File

@ -1,5 +1,6 @@
#include "CModelNode.h"
#include <Common/Math.h>
#include <Core/CDrawUtil.h>
#include <Core/CRenderer.h>
#include <Core/CGraphics.h>
@ -45,7 +46,7 @@ void CModelNode::AddToRenderer(CRenderer *pRenderer, const SViewInfo& ViewInfo)
pRenderer->AddOpaqueMesh(this, 0, AABox(), eDrawSelection);
}
void CModelNode::Draw(ERenderOptions Options)
void CModelNode::Draw(ERenderOptions Options, const SViewInfo& ViewInfo)
{
if (!mpModel) return;
if (mForceAlphaOn) Options = (ERenderOptions) (Options & ~eNoAlpha);
@ -63,12 +64,13 @@ void CModelNode::Draw(ERenderOptions Options)
}
CGraphics::sPixelBlock.TevColor = CVector4f(1,1,1,1);
CGraphics::sPixelBlock.TintColor = TintColor(ViewInfo).ToVector4f();
LoadModelMatrix();
mpModel->Draw(Options, mActiveMatSet);
}
void CModelNode::DrawAsset(ERenderOptions Options, u32 Asset)
void CModelNode::DrawAsset(ERenderOptions Options, u32 Asset, const SViewInfo& ViewInfo)
{
if (!mpModel) return;
if (mForceAlphaOn) Options = (ERenderOptions) (Options & ~eNoAlpha);
@ -86,11 +88,19 @@ void CModelNode::DrawAsset(ERenderOptions Options, u32 Asset)
}
CGraphics::sPixelBlock.TevColor = CVector4f(1,1,1,1);
CGraphics::sPixelBlock.TintColor = TintColor(ViewInfo).ToVector4f();
LoadModelMatrix();
mpModel->DrawSurface(Options, Asset, mActiveMatSet);
}
void CModelNode::DrawSelection()
{
if (!mpModel) return;
LoadModelMatrix();
mpModel->DrawWireframe(eNoRenderOptions, WireframeColor());
}
void CModelNode::RayAABoxIntersectTest(CRayCollisionTester &Tester)
{
if (!mpModel) return;

View File

@ -17,8 +17,9 @@ public:
virtual ENodeType NodeType();
virtual void AddToRenderer(CRenderer *pRenderer, const SViewInfo& ViewInfo);
virtual void Draw(ERenderOptions Options);
virtual void DrawAsset(ERenderOptions Options, u32 asset);
virtual void Draw(ERenderOptions Options, const SViewInfo& ViewInfo);
virtual void DrawAsset(ERenderOptions Options, u32 asset, const SViewInfo& ViewInfo);
virtual void DrawSelection();
virtual void RayAABoxIntersectTest(CRayCollisionTester &Tester);
virtual SRayIntersection RayNodeIntersectTest(const CRay &Ray, u32 AssetID, const SViewInfo& ViewInfo);

View File

@ -16,8 +16,8 @@ public:
}
inline void AddToRenderer(CRenderer *, const SViewInfo&) {}
inline void Draw(ERenderOptions) {}
inline void DrawAsset(ERenderOptions, u32) {}
inline void Draw(ERenderOptions, const SViewInfo&) {}
inline void DrawAsset(ERenderOptions, u32, const SViewInfo&) {}
inline void RayAABoxIntersectTest(CRayCollisionTester &) {}
inline SRayIntersection RayNodeIntersectTest(const CRay &, u32, const SViewInfo&) {

View File

@ -10,7 +10,7 @@
#include <algorithm>
u32 CSceneNode::smNumNodes = 0;
CColor CSceneNode::skSelectionTint((u8) 156, 133, 155, 255);
CColor CSceneNode::skSelectionTint((u8) 39, 154, 167, 255);
CSceneNode::CSceneNode(CSceneManager *pScene, CSceneNode *pParent)
{
@ -71,6 +71,11 @@ bool CSceneNode::IsVisible() const
return mVisible;
}
CColor CSceneNode::WireframeColor() const
{
return CColor::skWhite;
}
// ************ MAIN FUNCTIONALITY ************
void CSceneNode::Unparent()
{
@ -303,10 +308,10 @@ CSceneManager* CSceneNode::Scene()
return mpScene;
}
CColor CSceneNode::TintColor() const
CColor CSceneNode::TintColor(const SViewInfo& ViewInfo) const
{
// convenience; this is/will be a fairly common operation
return (IsSelected() ? skSelectionTint : CColor::skWhite);
return (IsSelected() && !ViewInfo.GameMode ? skSelectionTint : CColor::skWhite);
}
CVector3f CSceneNode::LocalPosition() const

View File

@ -54,12 +54,11 @@ public:
virtual ~CSceneNode();
virtual ENodeType NodeType() = 0;
virtual TString PrefixedName() const;
virtual void Draw(ERenderOptions options) = 0;
virtual void DrawAsset(ERenderOptions options, u32 asset) = 0;
virtual void DrawSelection();
virtual void RayAABoxIntersectTest(CRayCollisionTester& Tester);
virtual SRayIntersection RayNodeIntersectTest(const CRay& Ray, u32 AssetID, const SViewInfo& ViewInfo) = 0;
virtual bool IsVisible() const;
virtual CColor WireframeColor() const;
void Unparent();
void RemoveChild(CSceneNode *pChild);
@ -83,7 +82,7 @@ public:
TString Name() const;
CSceneNode* Parent() const;
CSceneManager* Scene();
CColor TintColor() const;
CColor TintColor(const SViewInfo& ViewInfo) const;
CVector3f LocalPosition() const;
CVector3f AbsolutePosition() const;
CQuaternion LocalRotation() const;

View File

@ -164,7 +164,7 @@ void CScriptNode::AddToRenderer(CRenderer *pRenderer, const SViewInfo& ViewInfo)
}
}
void CScriptNode::Draw(ERenderOptions Options)
void CScriptNode::Draw(ERenderOptions Options, const SViewInfo& ViewInfo)
{
if (!mpInstance) return;
@ -173,13 +173,14 @@ void CScriptNode::Draw(ERenderOptions Options)
{
LoadModelMatrix();
LoadLights();
CGraphics::sPixelBlock.TintColor = TintColor(ViewInfo).ToVector4f();
mpActiveModel->Draw(Options, 0);
}
// Draw billboard
else if (mpBillboard)
{
CDrawUtil::DrawBillboard(mpBillboard, mPosition, BillboardScale(), TintColor());
CDrawUtil::DrawBillboard(mpBillboard, mPosition, BillboardScale(), TintColor(ViewInfo));
}
// If no model or billboard, default to drawing a purple box
@ -192,12 +193,12 @@ void CScriptNode::Draw(ERenderOptions Options)
LoadLights();
CGraphics::UpdateVertexBlock();
CGraphics::UpdateLightBlock();
CDrawUtil::DrawShadedCube(CColor::skTransparentPurple);
CDrawUtil::DrawShadedCube(CColor::skTransparentPurple * TintColor(ViewInfo));
return;
}
}
void CScriptNode::DrawAsset(ERenderOptions Options, u32 Asset)
void CScriptNode::DrawAsset(ERenderOptions Options, u32 Asset, const SViewInfo& ViewInfo)
{
if (!mpInstance) return;
if (!mpActiveModel) return;
@ -207,6 +208,7 @@ void CScriptNode::DrawAsset(ERenderOptions Options, u32 Asset)
else
CGraphics::sVertexBlock.COLOR0_Amb = CGraphics::skDefaultAmbientColor.ToVector4f();
CGraphics::sPixelBlock.TintColor = TintColor(ViewInfo).ToVector4f();
LoadModelMatrix();
LoadLights();
@ -217,11 +219,12 @@ void CScriptNode::DrawSelection()
{
glBlendFunc(GL_ONE, GL_ZERO);
// Only draw bounding box for models; billboards get a tint color
// Draw wireframe for models; billboards only get tinted
if (mpActiveModel || !mpBillboard)
{
LoadModelMatrix();
CDrawUtil::DrawWireCube(AABox(), CColor::skTransparentWhite);
CModel *pModel = (mpActiveModel ? mpActiveModel : CDrawUtil::GetCubeModel());
pModel->DrawWireframe(eNoRenderOptions, WireframeColor());
}
if (mpInstance)
@ -383,10 +386,15 @@ SRayIntersection CScriptNode::RayNodeIntersectTest(const CRay& Ray, u32 AssetID,
bool CScriptNode::IsVisible() const
{
// Reimplementation of CSceneNode::IsHidden() to allow for layer and template visiblity to be taken into account
// Reimplementation of CSceneNode::IsVisible() to allow for layer and template visiblity to be taken into account
return (mVisible && mpInstance->Layer()->IsVisible() && mpInstance->Template()->IsVisible());
}
CColor CScriptNode::WireframeColor() const
{
return CColor((u8) 12, 135, 194, 255);
}
CScriptObject* CScriptNode::Object()
{
return mpInstance;

View File

@ -27,12 +27,14 @@ public:
ENodeType NodeType();
TString PrefixedName() const;
void AddToRenderer(CRenderer *pRenderer, const SViewInfo& ViewInfo);
void Draw(ERenderOptions Options);
void DrawAsset(ERenderOptions Options, u32 Asset);
void Draw(ERenderOptions Options, const SViewInfo& ViewInfo);
void DrawAsset(ERenderOptions Options, u32 Asset, const SViewInfo& ViewInfo);
void DrawSelection();
void RayAABoxIntersectTest(CRayCollisionTester &Tester);
SRayIntersection RayNodeIntersectTest(const CRay &Ray, u32 AssetID, const SViewInfo& ViewInfo);
bool IsVisible() const;
CColor WireframeColor() const;
CScriptObject* Object();
CModel* ActiveModel();
void GeneratePosition();

View File

@ -42,13 +42,14 @@ void CStaticNode::AddToRenderer(CRenderer *pRenderer, const SViewInfo& ViewInfo)
pRenderer->AddOpaqueMesh(this, 0, AABox(), eDrawSelection);
}
void CStaticNode::Draw(ERenderOptions Options)
void CStaticNode::Draw(ERenderOptions Options, const SViewInfo& ViewInfo)
{
if (!mpModel) return;
CGraphics::sVertexBlock.COLOR0_Amb = CVector4f(0, 0, 0, 1);
float Multiplier = CGraphics::sWorldLightMultiplier;
CGraphics::sPixelBlock.TevColor = CVector4f(Multiplier,Multiplier,Multiplier,1);
CGraphics::sPixelBlock.TintColor = TintColor(ViewInfo).ToVector4f();
CGraphics::sNumLights = 0;
CGraphics::UpdateLightBlock();
LoadModelMatrix();
@ -56,12 +57,13 @@ void CStaticNode::Draw(ERenderOptions Options)
mpModel->Draw(Options);
}
void CStaticNode::DrawAsset(ERenderOptions Options, u32 Asset)
void CStaticNode::DrawAsset(ERenderOptions Options, u32 Asset, const SViewInfo& ViewInfo)
{
if (!mpModel) return;
CGraphics::sVertexBlock.COLOR0_Amb = CVector4f(0,0,0,1);
CGraphics::sPixelBlock.TevColor = CVector4f(1,1,1,1);
CGraphics::sPixelBlock.TintColor = TintColor(ViewInfo).ToVector4f();
CGraphics::sNumLights = 0;
CGraphics::UpdateLightBlock();
LoadModelMatrix();
@ -70,6 +72,13 @@ void CStaticNode::DrawAsset(ERenderOptions Options, u32 Asset)
//CDrawUtil::DrawWireCube(mpModel->GetSurfaceAABox(Asset), CColor::skWhite);
}
void CStaticNode::DrawSelection()
{
if (!mpModel) return;
LoadModelMatrix();
mpModel->DrawWireframe(eNoRenderOptions, WireframeColor());
}
void CStaticNode::RayAABoxIntersectTest(CRayCollisionTester &Tester)
{
if ((!mpModel) || (mpModel->IsOccluder()))

View File

@ -12,8 +12,9 @@ public:
CStaticNode(CSceneManager *pScene, CSceneNode *pParent = 0, CStaticModel *pModel = 0);
ENodeType NodeType();
void AddToRenderer(CRenderer *pRenderer, const SViewInfo& ViewInfo);
void Draw(ERenderOptions Options);
void DrawAsset(ERenderOptions Options, u32 asset);
void Draw(ERenderOptions Options, const SViewInfo& ViewInfo);
void DrawAsset(ERenderOptions Options, u32 asset, const SViewInfo& ViewInfo);
void DrawSelection();
void RayAABoxIntersectTest(CRayCollisionTester &Tester);
SRayIntersection RayNodeIntersectTest(const CRay &Ray, u32 AssetID, const SViewInfo& ViewInfo);
};

View File

@ -69,7 +69,7 @@ void CGizmo::AddToRenderer(CRenderer *pRenderer, const SViewInfo&)
}
}
void CGizmo::DrawAsset(ERenderOptions /*options*/, u32 asset)
void CGizmo::DrawAsset(ERenderOptions /*options*/, u32 asset, const SViewInfo& /*ViewInfo*/)
{
// Determine which SModelPart array to use
if (asset >= mNumCurrentParts) return;

View File

@ -125,7 +125,7 @@ public:
~CGizmo();
void AddToRenderer(CRenderer *pRenderer, const SViewInfo& ViewInfo);
void DrawAsset(ERenderOptions options, u32 asset);
void DrawAsset(ERenderOptions options, u32 asset, const SViewInfo& ViewInfo);
void IncrementSize();
void DecrementSize();