Render skyboxes with rotation-only view matrix, a few new CDrawUtil overloads, other rendering tweaks

This commit is contained in:
parax0 2015-08-23 21:03:36 -04:00
parent 614f73487e
commit db970c6c51
8 changed files with 34 additions and 13 deletions

View File

@ -97,6 +97,12 @@ void CDrawUtil::DrawLine(const CVector3f& PointA, const CVector3f& PointB)
DrawLine(PointA, PointB, CColor::skWhite);
}
void CDrawUtil::DrawLine(const CVector2f& PointA, const CVector2f& PointB)
{
// Overload for 2D lines
DrawLine(CVector3f(PointA.x, PointA.y, 0.f), CVector3f(PointB.x, PointB.y, 0.f), CColor::skWhite);
}
void CDrawUtil::DrawLine(const CVector3f& PointA, const CVector3f& PointB, const CColor& LineColor)
{
Init();
@ -116,6 +122,12 @@ void CDrawUtil::DrawLine(const CVector3f& PointA, const CVector3f& PointB, const
mLineVertices.Unbind();
}
void CDrawUtil::DrawLine(const CVector2f& PointA, const CVector2f& PointB, const CColor& LineColor)
{
// Overload for 2D lines
DrawLine(CVector3f(PointA.x, PointA.y, 0.f), CVector3f(PointB.x, PointB.y, 0.f), LineColor);
}
void CDrawUtil::DrawCube()
{
Init();
@ -129,6 +141,14 @@ void CDrawUtil::DrawCube(const CColor& Color)
DrawCube();
}
void CDrawUtil::DrawCube(const CVector3f& Position, const CColor& Color)
{
CGraphics::sMVPBlock.ModelMatrix = CTransform4f::TranslationMatrix(Position).ToMatrix4f();
CGraphics::UpdateMVPBlock();
UseColorShader(Color);
DrawCube();
}
void CDrawUtil::DrawShadedCube(const CColor& Color)
{
Init();

View File

@ -54,9 +54,12 @@ public:
static void DrawSquare(const CVector2f& TexUL, const CVector2f& TexUR, const CVector2f& TexBR, const CVector2f& TexBL);
static void DrawSquare(const float *pTexCoords);
static void DrawLine(const CVector3f& PointA, const CVector3f& PointB);
static void DrawLine(const CVector2f& PointA, const CVector2f& PointB);
static void DrawLine(const CVector3f& PointA, const CVector3f& PointB, const CColor& LineColor);
static void DrawLine(const CVector2f& PointA, const CVector2f& PointB, const CColor& LineColor);
static void DrawCube();
static void DrawCube(const CColor& Color);
static void DrawCube(const CVector3f& Position, const CColor& Color);
static void DrawShadedCube(const CColor& Color);
static void DrawWireCube();
static void DrawWireCube(const CAABox& AABox, const CColor& Color);

View File

@ -126,6 +126,7 @@ void CRenderer::RenderBuckets(CCamera& Camera)
{
if (!mInitialized) Init();
mSceneFramebuffer.Bind();
Camera.LoadMatrices();
// Set backface culling
if (mOptions & eEnableBackfaceCull) glEnable(GL_CULL_FACE);
@ -250,21 +251,18 @@ void CRenderer::RenderBloom()
glEnable(GL_DEPTH_TEST);
}
void CRenderer::RenderSky(CModel *pSkyboxModel, CVector3f CameraPosition)
void CRenderer::RenderSky(CModel *pSkyboxModel, CCamera& Camera)
{
if (!mInitialized) Init();
if (!pSkyboxModel) return;
glEnable(GL_CULL_FACE);
Camera.LoadRotationOnlyMatrices();
CTransform4f ModelMtx;
ModelMtx.Translate(CameraPosition);
CGraphics::sMVPBlock.ModelMatrix = ModelMtx.ToMatrix4f();
CGraphics::sMVPBlock.ModelMatrix = CMatrix4f::skIdentity;
CGraphics::sVertexBlock.COLOR0_Amb = CVector4f(1.f, 1.f, 1.f, 1.f);
CGraphics::sPixelBlock.TevColor = CVector4f(1.f, 1.f, 1.f, 1.f);
CGraphics::sNumLights = 0;
CGraphics::UpdateMVPBlock();
CGraphics::UpdateVertexBlock();
CGraphics::UpdatePixelBlock();
CGraphics::UpdateLightBlock();

View File

@ -67,7 +67,7 @@ public:
// Render
void RenderBuckets(CCamera& Camera);
void RenderBloom();
void RenderSky(CModel *pSkyboxModel, CVector3f CameraPosition);
void RenderSky(CModel *pSkyboxModel, CCamera& Camera);
void AddOpaqueMesh(IRenderable *pRenderable, u32 AssetID, CAABox& AABox, ERenderCommand Command);
void AddTransparentMesh(IRenderable *pRenderable, u32 AssetID, CAABox& AABox, ERenderCommand Command);
void BeginFrame();

View File

@ -218,8 +218,8 @@ bool CShaderGenerator::CreateVertexShader(const CMaterial& Mat)
ShaderCode << "// Main\n"
<< "void main()\n"
<< "{\n"
<< " mat4 MVP = ModelMtx * ViewMtx * ProjMtx;\n"
<< " mat4 MV = ModelMtx * ViewMtx;\n";
<< " mat4 MV = ModelMtx * ViewMtx;\n"
<< " mat4 MVP = MV * ProjMtx;\n";
if (VtxDesc & ePosition) ShaderCode << " gl_Position = vec4(RawPosition, 1) * MVP;\n";
if (VtxDesc & eNormal) ShaderCode << " Normal = normalize(RawNormal.xyz * inverse(transpose(mat3(MV))));\n";

View File

@ -67,7 +67,6 @@ void CEditorGLWidget::paintGL()
// Camera movement is processed here in order to sync it with the paint event
// This way movement happens exactly once per frame - no more, no less
ProcessInput(DeltaTime);
mCamera.LoadMatrices();
// Pre-render signal allows for per-frame operations to be performed before the draw happens
emit PreRender();

View File

@ -387,9 +387,10 @@ void CWorldEditor::ViewportRender(CCamera& Camera)
if (mDrawSky)
{
CModel *pSky = mpSceneManager->GetActiveSkybox();
if (pSky) mpRenderer->RenderSky(pSky, Camera.Position());
if (pSky) mpRenderer->RenderSky(pSky, Camera);
}
Camera.LoadMatrices();
mpRenderer->RenderBuckets(Camera);
mpRenderer->RenderBloom();

View File

@ -95,7 +95,7 @@ void CWorldEditorWindow::PaintViewport(double DeltaTime)
if (mShouldDrawSky)
{
CModel *pSky = mpSceneManager->GetActiveSkybox();
if (pSky) mpRenderer->RenderSky(pSky, mCamera.Position());
if (pSky) mpRenderer->RenderSky(pSky, mCamera);
}
mpRenderer->RenderBuckets(mCamera);