Render skyboxes with rotation-only view matrix, a few new CDrawUtil overloads, other rendering tweaks
This commit is contained in:
parent
614f73487e
commit
db970c6c51
|
@ -97,6 +97,12 @@ void CDrawUtil::DrawLine(const CVector3f& PointA, const CVector3f& PointB)
|
||||||
DrawLine(PointA, PointB, CColor::skWhite);
|
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)
|
void CDrawUtil::DrawLine(const CVector3f& PointA, const CVector3f& PointB, const CColor& LineColor)
|
||||||
{
|
{
|
||||||
Init();
|
Init();
|
||||||
|
@ -116,6 +122,12 @@ void CDrawUtil::DrawLine(const CVector3f& PointA, const CVector3f& PointB, const
|
||||||
mLineVertices.Unbind();
|
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()
|
void CDrawUtil::DrawCube()
|
||||||
{
|
{
|
||||||
Init();
|
Init();
|
||||||
|
@ -129,6 +141,14 @@ void CDrawUtil::DrawCube(const CColor& Color)
|
||||||
DrawCube();
|
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)
|
void CDrawUtil::DrawShadedCube(const CColor& Color)
|
||||||
{
|
{
|
||||||
Init();
|
Init();
|
||||||
|
|
|
@ -54,9 +54,12 @@ public:
|
||||||
static void DrawSquare(const CVector2f& TexUL, const CVector2f& TexUR, const CVector2f& TexBR, const CVector2f& TexBL);
|
static void DrawSquare(const CVector2f& TexUL, const CVector2f& TexUR, const CVector2f& TexBR, const CVector2f& TexBL);
|
||||||
static void DrawSquare(const float *pTexCoords);
|
static void DrawSquare(const float *pTexCoords);
|
||||||
static void DrawLine(const CVector3f& PointA, const CVector3f& PointB);
|
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 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();
|
||||||
static void DrawCube(const CColor& Color);
|
static void DrawCube(const CColor& Color);
|
||||||
|
static void DrawCube(const CVector3f& Position, const CColor& Color);
|
||||||
static void DrawShadedCube(const CColor& Color);
|
static void DrawShadedCube(const CColor& Color);
|
||||||
static void DrawWireCube();
|
static void DrawWireCube();
|
||||||
static void DrawWireCube(const CAABox& AABox, const CColor& Color);
|
static void DrawWireCube(const CAABox& AABox, const CColor& Color);
|
||||||
|
|
|
@ -126,6 +126,7 @@ void CRenderer::RenderBuckets(CCamera& Camera)
|
||||||
{
|
{
|
||||||
if (!mInitialized) Init();
|
if (!mInitialized) Init();
|
||||||
mSceneFramebuffer.Bind();
|
mSceneFramebuffer.Bind();
|
||||||
|
Camera.LoadMatrices();
|
||||||
|
|
||||||
// Set backface culling
|
// Set backface culling
|
||||||
if (mOptions & eEnableBackfaceCull) glEnable(GL_CULL_FACE);
|
if (mOptions & eEnableBackfaceCull) glEnable(GL_CULL_FACE);
|
||||||
|
@ -250,21 +251,18 @@ void CRenderer::RenderBloom()
|
||||||
glEnable(GL_DEPTH_TEST);
|
glEnable(GL_DEPTH_TEST);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CRenderer::RenderSky(CModel *pSkyboxModel, CVector3f CameraPosition)
|
void CRenderer::RenderSky(CModel *pSkyboxModel, CCamera& Camera)
|
||||||
{
|
{
|
||||||
if (!mInitialized) Init();
|
if (!mInitialized) Init();
|
||||||
|
|
||||||
if (!pSkyboxModel) return;
|
if (!pSkyboxModel) return;
|
||||||
|
|
||||||
glEnable(GL_CULL_FACE);
|
glEnable(GL_CULL_FACE);
|
||||||
|
Camera.LoadRotationOnlyMatrices();
|
||||||
|
|
||||||
CTransform4f ModelMtx;
|
CGraphics::sMVPBlock.ModelMatrix = CMatrix4f::skIdentity;
|
||||||
ModelMtx.Translate(CameraPosition);
|
|
||||||
|
|
||||||
CGraphics::sMVPBlock.ModelMatrix = ModelMtx.ToMatrix4f();
|
|
||||||
CGraphics::sVertexBlock.COLOR0_Amb = CVector4f(1.f, 1.f, 1.f, 1.f);
|
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::sPixelBlock.TevColor = CVector4f(1.f, 1.f, 1.f, 1.f);
|
||||||
CGraphics::sNumLights = 0;
|
CGraphics::sNumLights = 0;
|
||||||
CGraphics::UpdateMVPBlock();
|
|
||||||
CGraphics::UpdateVertexBlock();
|
CGraphics::UpdateVertexBlock();
|
||||||
CGraphics::UpdatePixelBlock();
|
CGraphics::UpdatePixelBlock();
|
||||||
CGraphics::UpdateLightBlock();
|
CGraphics::UpdateLightBlock();
|
||||||
|
|
|
@ -67,7 +67,7 @@ public:
|
||||||
// Render
|
// Render
|
||||||
void RenderBuckets(CCamera& Camera);
|
void RenderBuckets(CCamera& Camera);
|
||||||
void RenderBloom();
|
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 AddOpaqueMesh(IRenderable *pRenderable, u32 AssetID, CAABox& AABox, ERenderCommand Command);
|
||||||
void AddTransparentMesh(IRenderable *pRenderable, u32 AssetID, CAABox& AABox, ERenderCommand Command);
|
void AddTransparentMesh(IRenderable *pRenderable, u32 AssetID, CAABox& AABox, ERenderCommand Command);
|
||||||
void BeginFrame();
|
void BeginFrame();
|
||||||
|
|
|
@ -218,8 +218,8 @@ bool CShaderGenerator::CreateVertexShader(const CMaterial& Mat)
|
||||||
ShaderCode << "// Main\n"
|
ShaderCode << "// Main\n"
|
||||||
<< "void main()\n"
|
<< "void main()\n"
|
||||||
<< "{\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 & ePosition) ShaderCode << " gl_Position = vec4(RawPosition, 1) * MVP;\n";
|
||||||
if (VtxDesc & eNormal) ShaderCode << " Normal = normalize(RawNormal.xyz * inverse(transpose(mat3(MV))));\n";
|
if (VtxDesc & eNormal) ShaderCode << " Normal = normalize(RawNormal.xyz * inverse(transpose(mat3(MV))));\n";
|
||||||
|
|
|
@ -67,7 +67,6 @@ void CEditorGLWidget::paintGL()
|
||||||
// Camera movement is processed here in order to sync it with the paint event
|
// 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
|
// This way movement happens exactly once per frame - no more, no less
|
||||||
ProcessInput(DeltaTime);
|
ProcessInput(DeltaTime);
|
||||||
mCamera.LoadMatrices();
|
|
||||||
|
|
||||||
// Pre-render signal allows for per-frame operations to be performed before the draw happens
|
// Pre-render signal allows for per-frame operations to be performed before the draw happens
|
||||||
emit PreRender();
|
emit PreRender();
|
||||||
|
|
|
@ -387,9 +387,10 @@ void CWorldEditor::ViewportRender(CCamera& Camera)
|
||||||
if (mDrawSky)
|
if (mDrawSky)
|
||||||
{
|
{
|
||||||
CModel *pSky = mpSceneManager->GetActiveSkybox();
|
CModel *pSky = mpSceneManager->GetActiveSkybox();
|
||||||
if (pSky) mpRenderer->RenderSky(pSky, Camera.Position());
|
if (pSky) mpRenderer->RenderSky(pSky, Camera);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Camera.LoadMatrices();
|
||||||
mpRenderer->RenderBuckets(Camera);
|
mpRenderer->RenderBuckets(Camera);
|
||||||
mpRenderer->RenderBloom();
|
mpRenderer->RenderBloom();
|
||||||
|
|
||||||
|
|
|
@ -95,7 +95,7 @@ void CWorldEditorWindow::PaintViewport(double DeltaTime)
|
||||||
if (mShouldDrawSky)
|
if (mShouldDrawSky)
|
||||||
{
|
{
|
||||||
CModel *pSky = mpSceneManager->GetActiveSkybox();
|
CModel *pSky = mpSceneManager->GetActiveSkybox();
|
||||||
if (pSky) mpRenderer->RenderSky(pSky, mCamera.Position());
|
if (pSky) mpRenderer->RenderSky(pSky, mCamera);
|
||||||
}
|
}
|
||||||
|
|
||||||
mpRenderer->RenderBuckets(mCamera);
|
mpRenderer->RenderBuckets(mCamera);
|
||||||
|
|
Loading…
Reference in New Issue