mirror of
https://github.com/blawar/GLideN64.git
synced 2024-07-07 03:13:49 +00:00
Fix depth beffer rendering.
Corrected bug with Z calculation in depth_compare_shader.
This commit is contained in:
parent
9b8b667fab
commit
d4953abb91
|
@ -18,7 +18,7 @@
|
|||
|
||||
bool g_bCopyToRDRAM = false;
|
||||
bool g_bCopyFromRDRAM = false;
|
||||
bool g_bCopyDepthToRDRAM = false;
|
||||
bool g_bCopyDepthToRDRAM = true;
|
||||
bool g_bUseFloatDepthTexture = true;
|
||||
static const GLint depthTextureInternalFormat = g_bUseFloatDepthTexture ? GL_R32F : GL_R16;
|
||||
static const GLenum depthTextureType = g_bUseFloatDepthTexture ? GL_FLOAT : GL_UNSIGNED_INT;
|
||||
|
|
|
@ -599,11 +599,11 @@ void GLSLCombiner::UpdateDepthInfo() {
|
|||
if (nDepthEnabled == 0)
|
||||
return;
|
||||
|
||||
int depth_compare_location = glGetUniformLocation(m_program, "depthCompareEnabled");
|
||||
const int depth_compare_location = glGetUniformLocation(m_program, "depthCompareEnabled");
|
||||
glUniform1i(depth_compare_location, gDP.otherMode.depthCompare);
|
||||
int depth_update_location = glGetUniformLocation(m_program, "depthUpdateEnabled");
|
||||
const int depth_update_location = glGetUniformLocation(m_program, "depthUpdateEnabled");
|
||||
glUniform1i(depth_update_location, gDP.otherMode.depthUpdate);
|
||||
int depth_polygon_offset = glGetUniformLocation(m_program, "depthPolygonOffset");
|
||||
const int depth_polygon_offset = glGetUniformLocation(m_program, "depthPolygonOffset");
|
||||
if (g_bUseFloatDepthTexture) {
|
||||
float fPlygonOffset = gDP.otherMode.depthMode == ZMODE_DEC ? 0.005f : 0.0f;
|
||||
glUniform1f(depth_polygon_offset, fPlygonOffset);
|
||||
|
@ -611,6 +611,10 @@ void GLSLCombiner::UpdateDepthInfo() {
|
|||
int iPlygonOffset = gDP.otherMode.depthMode == ZMODE_DEC ? 5 : 0;
|
||||
glUniform1i(depth_polygon_offset, iPlygonOffset);
|
||||
}
|
||||
const int depth_scale_location = glGetUniformLocation(m_program, "depthScale");
|
||||
glUniform1f(depth_scale_location, gSP.viewport.vscale[2]*32768);
|
||||
const int depth_trans_location = glGetUniformLocation(m_program, "depthTrans");
|
||||
glUniform1f(depth_trans_location, gSP.viewport.vtrans[2]*32768);
|
||||
|
||||
GLuint texture = frameBuffer.top->pDepthBuffer->depth_texture->glName;
|
||||
glBindImageTexture(ZlutImageUnit, g_zlut_tex, 0, GL_FALSE, 0, GL_READ_ONLY, GL_R16UI);
|
||||
|
|
7
RSP.cpp
7
RSP.cpp
|
@ -281,11 +281,8 @@ void RSP_ProcessDList()
|
|||
GBI.cmd[RSP.cmd]( w0, w1 );
|
||||
}
|
||||
|
||||
/* if (OGL.frameBufferTextures && gDP.colorImage.changed)
|
||||
{
|
||||
FrameBuffer_SaveBuffer( gDP.colorImage.address, gDP.colorImage.size, gDP.colorImage.width, gDP.colorImage.height );
|
||||
gDP.colorImage.changed = FALSE;
|
||||
}*/
|
||||
if (g_bCopyDepthToRDRAM)
|
||||
FrameBuffer_CopyDepthBuffer( gDP.colorImage.address );
|
||||
|
||||
RSP.busy = FALSE;
|
||||
RSP.DList++;
|
||||
|
|
46
Shaders.h
46
Shaders.h
|
@ -153,17 +153,21 @@ static const char* depth_compare_shader_int =
|
|||
"uniform int depthCompareEnabled; \n"
|
||||
"uniform int depthUpdateEnabled; \n"
|
||||
"uniform unsigned int depthPolygonOffset; \n"
|
||||
"uniform float depthTrans; \n"
|
||||
"uniform float depthScale; \n"
|
||||
"layout(binding = 0, r16ui) uniform readonly uimage2D zlut_image;\n"
|
||||
"layout(binding = 2, r16ui) uniform restrict uimage2D depth_image;\n"
|
||||
"bool depth_compare() \n"
|
||||
"{ \n"
|
||||
" if (depthEnabled == 0) return true; \n"
|
||||
" ivec2 coord = ivec2(gl_FragCoord.xy); \n"
|
||||
" highp uvec4 depth = imageLoad(depth_image,coord); \n"
|
||||
" highp unsigned int bufZ = depth.r; \n"
|
||||
" highp int iZ = int(gl_FragCoord.z*262143.0); \n"
|
||||
" int y0 = iZ / 512; \n"
|
||||
" int x0 = iZ - 512*y0; \n"
|
||||
" highp uvec4 depth = imageLoad(depth_image,coord); \n"
|
||||
" highp unsigned int bufZ = depth.r; \n"
|
||||
" highp float fZ = 2.0*gl_FragCoord.z - 1.0; \n"
|
||||
" fZ = (depthScale*fZ + depthTrans)*8.0; \n"
|
||||
" highp int iZ = int(floor(fZ + 0.5)); \n"
|
||||
" int y0 = iZ / 512; \n"
|
||||
" int x0 = iZ - 512*y0; \n"
|
||||
" highp unsigned int curZ = imageLoad(zlut_image,ivec2(x0,y0)).r; \n"
|
||||
" curZ = curZ - depthPolygonOffset;\n"
|
||||
" if (depthUpdateEnabled > 0 && curZ < depth.r) { \n"
|
||||
|
@ -183,24 +187,28 @@ static const char* depth_compare_shader_float =
|
|||
"uniform int depthCompareEnabled; \n"
|
||||
"uniform int depthUpdateEnabled; \n"
|
||||
"uniform float depthPolygonOffset; \n"
|
||||
"uniform float depthTrans; \n"
|
||||
"uniform float depthScale; \n"
|
||||
"layout(binding = 0, r16ui) uniform readonly uimage2D zlut_image;\n"
|
||||
"layout(binding = 2, r32f) uniform restrict image2D depth_image;\n"
|
||||
"bool depth_compare() \n"
|
||||
"{ \n"
|
||||
" if (depthEnabled == 0) return true; \n"
|
||||
" ivec2 coord = ivec2(gl_FragCoord.xy); \n"
|
||||
" highp vec4 depth = imageLoad(depth_image,coord); \n"
|
||||
" highp float bufZ = depth.r; \n"
|
||||
" highp int iZ = max(0, int((gl_FragCoord.z-0.005)*262143.0)); \n"
|
||||
" int y0 = clamp(iZ / 512, 0, 511); \n"
|
||||
" int x0 = iZ - 512*y0; \n"
|
||||
"bool depth_compare() \n"
|
||||
"{ \n"
|
||||
" if (depthEnabled == 0) return true; \n"
|
||||
" ivec2 coord = ivec2(gl_FragCoord.xy); \n"
|
||||
" highp vec4 depth = imageLoad(depth_image,coord); \n"
|
||||
" highp float bufZ = depth.r; \n"
|
||||
" highp float fZ = 2.0*gl_FragCoord.z - 1.0; \n"
|
||||
" fZ = (depthScale*fZ + depthTrans)*8.0; \n"
|
||||
" highp int iZ = int(floor(fZ + 0.5)); \n"
|
||||
" int y0 = clamp(iZ/512, 0, 511); \n"
|
||||
" int x0 = iZ - 512*y0; \n"
|
||||
" unsigned int icurZ = imageLoad(zlut_image,ivec2(x0,y0)).r;\n"
|
||||
//" highp float curZ = clamp(float(icurZ)/65535.0 - depthPolygonOffset, 0.0, 1.0); \n"
|
||||
" highp float curZ = clamp(float(icurZ)/65532.0, 0.0, 1.0); \n"
|
||||
" if (depthUpdateEnabled > 0 && curZ < depth.r) { \n"
|
||||
" depth.r = curZ; \n"
|
||||
" highp float curZ = clamp(float(icurZ)/65532.0 - depthPolygonOffset, 0.0, 1.0); \n"
|
||||
//" highp float curZ = clamp(float(icurZ)/65532.0, 0.0, 1.0); \n"
|
||||
" if (depthUpdateEnabled > 0 && curZ < depth.r) { \n"
|
||||
" depth.r = curZ; \n"
|
||||
" imageStore(depth_image,coord,depth); \n"
|
||||
" } \n"
|
||||
" } \n"
|
||||
" memoryBarrier(); \n"
|
||||
" if (depthCompareEnabled > 0) \n"
|
||||
" return curZ <= bufZ; \n"
|
||||
|
|
4
VI.cpp
4
VI.cpp
|
@ -69,10 +69,6 @@ void VI_UpdateScreen()
|
|||
VI_UpdateSize();
|
||||
FrameBuffer_CopyFromRDRAM( *REG.VI_ORIGIN, g_bCopyFromRDRAM && !bCFB );
|
||||
}
|
||||
if (g_bCopyToRDRAM && !bCFB)
|
||||
FrameBuffer_CopyToRDRAM( *REG.VI_ORIGIN, false );
|
||||
if (g_bCopyDepthToRDRAM && !bCFB)
|
||||
FrameBuffer_CopyDepthBuffer( *REG.VI_ORIGIN );
|
||||
FrameBuffer_RenderBuffer( *REG.VI_ORIGIN );
|
||||
|
||||
gDP.colorImage.changed = FALSE;
|
||||
|
|
Loading…
Reference in New Issue
Block a user