implement scroll fog, fixes a tonne of missing fx

This commit is contained in:
Ian Curtis 2016-10-09 16:34:12 +00:00
parent ef11990d19
commit f0a15febd1
6 changed files with 189 additions and 4 deletions

View file

@ -81,6 +81,20 @@ void CNew3D::UploadTextures(unsigned x, unsigned y, unsigned width, unsigned hei
m_texSheet.Invalidate(x, y, width, height); m_texSheet.Invalidate(x, y, width, height);
} }
void CNew3D::DrawScrollFog()
{
for (auto &n : m_nodes) {
if (n.viewport.scrollFog > 0) {
float *rgb = n.viewport.fogParams;
m_r3dScrollFog.DrawScrollFog(rgb[0], rgb[1], rgb[2], n.viewport.scrollFog);
return; // only allowed once per frame?
}
}
}
void CNew3D::RenderScene(int priority, bool alpha) void CNew3D::RenderScene(int priority, bool alpha)
{ {
if (alpha) { if (alpha) {
@ -178,6 +192,10 @@ void CNew3D::RenderFrame(void)
m_modelMat.Release(); // would hope we wouldn't need this but no harm in checking m_modelMat.Release(); // would hope we wouldn't need this but no harm in checking
m_nodeAttribs.Reset(); m_nodeAttribs.Reset();
RenderViewport(0x800000); // build model structure
DrawScrollFog(); // fog layer if applicable must be drawn here
glDepthFunc (GL_LEQUAL); glDepthFunc (GL_LEQUAL);
glEnable (GL_DEPTH_TEST); glEnable (GL_DEPTH_TEST);
glActiveTexture (GL_TEXTURE0); glActiveTexture (GL_TEXTURE0);
@ -188,8 +206,6 @@ void CNew3D::RenderFrame(void)
glStencilOp (GL_KEEP, GL_INCR, GL_INCR); // if the stencil test passes, we incriment the value glStencilOp (GL_KEEP, GL_INCR, GL_INCR); // if the stencil test passes, we incriment the value
glStencilMask (0xFF); glStencilMask (0xFF);
RenderViewport(0x800000); // build model structure
m_vbo.Bind(true); m_vbo.Bind(true);
m_vbo.BufferSubData(MAX_ROM_POLYS*sizeof(Poly), m_polyBufferRam.size()*sizeof(Poly), m_polyBufferRam.data()); // upload all the dynamic data to GPU in one go m_vbo.BufferSubData(MAX_ROM_POLYS*sizeof(Poly), m_polyBufferRam.size()*sizeof(Poly), m_polyBufferRam.data()); // upload all the dynamic data to GPU in one go

View file

@ -39,6 +39,7 @@
#include "R3DData.h" #include "R3DData.h"
#include "Plane.h" #include "Plane.h"
#include "Vec.h" #include "Vec.h"
#include "R3DScrollFog.h"
namespace New3D { namespace New3D {
@ -177,6 +178,7 @@ private:
float Determinant3x3(const float m[16]); float Determinant3x3(const float m[16]);
bool IsDynamicModel(UINT32 *data); // check if the model has a colour palette bool IsDynamicModel(UINT32 *data); // check if the model has a colour palette
bool IsVROMModel(UINT32 modelAddr); bool IsVROMModel(UINT32 modelAddr);
void DrawScrollFog();
void CalcTexOffset(int offX, int offY, int page, int x, int y, int& newX, int& newY); void CalcTexOffset(int offX, int offY, int page, int x, int y, int& newX, int& newY);
@ -216,6 +218,7 @@ private:
VBO m_vbo; // large VBO to hold our poly data, start of VBO is ROM data, ram polys follow VBO m_vbo; // large VBO to hold our poly data, start of VBO is ROM data, ram polys follow
R3DShader m_r3dShader; R3DShader m_r3dShader;
R3DScrollFog m_r3dScrollFog;
Plane m_planes[6]; Plane m_planes[6];

View file

@ -0,0 +1,104 @@
#include "R3DScrollFog.h"
#include "Graphics/Shader.h"
#include "Mat4.h"
namespace New3D {
static const char *vertexShaderFog =
"uniform mat4 mvp;\n"
"void main(void)\n"
"{\n"
"gl_Position = mvp * gl_Vertex;\n"
"}\n";
static const char *fragmentShaderFog =
"uniform vec4 fogColour;\n"
"void main()\n"
"{\n"
"gl_FragColor = fogColour;\n"
"}\n";
R3DScrollFog::R3DScrollFog()
{
//default coordinates are NDC -1,1 etc
m_triangles[0].p1.Set(-1,-1, 0);
m_triangles[0].p2.Set(-1, 1, 0);
m_triangles[0].p3.Set( 1, 1, 0);
m_triangles[1].p1.Set(-1,-1, 0);
m_triangles[1].p2.Set( 1, 1, 0);
m_triangles[1].p3.Set( 1,-1, 0);
m_shaderProgram = 0;
m_vertexShader = 0;
m_fragmentShader = 0;
AllocResources();
}
R3DScrollFog::~R3DScrollFog()
{
DeallocResources();
}
void R3DScrollFog::DrawScrollFog(float r, float g, float b, float a)
{
//=======
Mat4 mvp;
//=======
// yeah this would have been much easier with immediate mode and fixed function .. >_<
// some ogl states
glDepthMask (GL_FALSE); // disable z writes
glDisable (GL_DEPTH_TEST); // disable depth testing
glEnable (GL_BLEND);
glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
m_vbo.Bind (true);
glUseProgram (m_shaderProgram);
glUniform4f (m_locFogColour, r, g, b, a);
glUniformMatrix4fv (m_locMVP, 1, GL_FALSE, mvp);
glEnableClientState (GL_VERTEX_ARRAY);
glVertexPointer (3, GL_FLOAT, sizeof(SFVertex), 0);
glDrawArrays (GL_TRIANGLES, 0, 6);
glDisableClientState(GL_VERTEX_ARRAY);
glUseProgram (0);
m_vbo.Bind (false);
glDisable (GL_BLEND);
glDepthMask (GL_TRUE);
}
void R3DScrollFog::AllocResources()
{
bool success = LoadShaderProgram(&m_shaderProgram, &m_vertexShader, &m_fragmentShader, nullptr, nullptr, vertexShaderFog, fragmentShaderFog);
m_locMVP = glGetUniformLocation(m_shaderProgram, "mvp");
m_locFogColour = glGetUniformLocation(m_shaderProgram, "fogColour");
m_vbo.Create(GL_ARRAY_BUFFER, GL_STATIC_DRAW, sizeof(SFTriangle) * (2), m_triangles);
}
void R3DScrollFog::DeallocResources()
{
if (m_shaderProgram) {
DestroyShaderProgram(m_shaderProgram, m_vertexShader, m_fragmentShader);
}
m_shaderProgram = 0;
m_vertexShader = 0;
m_fragmentShader = 0;
m_vbo.Destroy();
}
}

View file

@ -0,0 +1,54 @@
#ifndef _R3DSCROLLFOG_H_
#define _R3DSCROLLFOG_H_
#include "VBO.h"
namespace New3D {
class R3DScrollFog
{
public:
R3DScrollFog();
~R3DScrollFog();
void DrawScrollFog(float r, float g, float b, float a);
private:
void AllocResources();
void DeallocResources();
struct SFVertex
{
void Set(float x, float y, float z) {
v[0] = x;
v[1] = y;
v[2] = z;
}
float v[3];
};
struct SFTriangle
{
SFVertex p1;
SFVertex p2;
SFVertex p3;
};
SFTriangle m_triangles[2];
GLuint m_shaderProgram;
GLuint m_vertexShader;
GLuint m_fragmentShader;
GLuint m_locFogColour;
GLuint m_locMVP;
VBO m_vbo;
};
}
#endif

View file

@ -317,6 +317,7 @@ xcopy /D /Y "$(ProjectDir)\SDL\$(Platform)\$(Configuration)\SDL.dll" "$(TargetDi
<ClCompile Include="..\Src\Graphics\New3D\New3D.cpp" /> <ClCompile Include="..\Src\Graphics\New3D\New3D.cpp" />
<ClCompile Include="..\Src\Graphics\New3D\PolyHeader.cpp" /> <ClCompile Include="..\Src\Graphics\New3D\PolyHeader.cpp" />
<ClCompile Include="..\Src\Graphics\New3D\R3DFloat.cpp" /> <ClCompile Include="..\Src\Graphics\New3D\R3DFloat.cpp" />
<ClCompile Include="..\Src\Graphics\New3D\R3DScrollFog.cpp" />
<ClCompile Include="..\Src\Graphics\New3D\R3DShader.cpp" /> <ClCompile Include="..\Src\Graphics\New3D\R3DShader.cpp" />
<ClCompile Include="..\Src\Graphics\New3D\Texture.cpp" /> <ClCompile Include="..\Src\Graphics\New3D\Texture.cpp" />
<ClCompile Include="..\Src\Graphics\New3D\TextureSheet.cpp" /> <ClCompile Include="..\Src\Graphics\New3D\TextureSheet.cpp" />
@ -542,6 +543,7 @@ xcopy /D /Y "$(ProjectDir)\SDL\$(Platform)\$(Configuration)\SDL.dll" "$(TargetDi
<ClInclude Include="..\Src\Graphics\New3D\PolyHeader.h" /> <ClInclude Include="..\Src\Graphics\New3D\PolyHeader.h" />
<ClInclude Include="..\Src\Graphics\New3D\R3DData.h" /> <ClInclude Include="..\Src\Graphics\New3D\R3DData.h" />
<ClInclude Include="..\Src\Graphics\New3D\R3DFloat.h" /> <ClInclude Include="..\Src\Graphics\New3D\R3DFloat.h" />
<ClInclude Include="..\Src\Graphics\New3D\R3DScrollFog.h" />
<ClInclude Include="..\Src\Graphics\New3D\R3DShader.h" /> <ClInclude Include="..\Src\Graphics\New3D\R3DShader.h" />
<ClInclude Include="..\Src\Graphics\New3D\Texture.h" /> <ClInclude Include="..\Src\Graphics\New3D\Texture.h" />
<ClInclude Include="..\Src\Graphics\New3D\TextureSheet.h" /> <ClInclude Include="..\Src\Graphics\New3D\TextureSheet.h" />

View file

@ -434,6 +434,9 @@
<ClCompile Include="..\Src\OSD\Logger.cpp"> <ClCompile Include="..\Src\OSD\Logger.cpp">
<Filter>Source Files\OSD</Filter> <Filter>Source Files\OSD</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="..\Src\Graphics\New3D\R3DScrollFog.cpp">
<Filter>Source Files\Graphics\New</Filter>
</ClCompile>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<MASM Include="..\Src\CPU\68K\Turbo68K\Turbo68K.asm"> <MASM Include="..\Src\CPU\68K\Turbo68K\Turbo68K.asm">
@ -802,6 +805,9 @@
<ClInclude Include="..\Src\Pkgs\tinyxml2.h"> <ClInclude Include="..\Src\Pkgs\tinyxml2.h">
<Filter>Header Files\Pkgs</Filter> <Filter>Header Files\Pkgs</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="..\Src\Graphics\New3D\R3DScrollFog.h">
<Filter>Source Files\Graphics\New</Filter>
</ClInclude>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<CustomBuild Include="..\Src\Debugger\ReadMe.txt"> <CustomBuild Include="..\Src\Debugger\ReadMe.txt">