1
0
mirror of https://github.com/blawar/GLideN64.git synced 2024-07-04 10:03:36 +00:00

Change DepthImageTexture texture format from GL_RGBA32F to GL_RG32F

Correct depth_compare() shader: do not calculate N64 z value.
This commit is contained in:
Sergey Lipskiy 2015-01-27 20:07:30 +06:00
parent 6ab92eac4f
commit 12a2b3741e
4 changed files with 15 additions and 30 deletions

View File

@ -64,14 +64,14 @@ void DepthBuffer::initDepthImageTexture(FrameBuffer * _pBuffer)
m_pDepthImageTexture->mirrorT = 0;
m_pDepthImageTexture->realWidth = m_pDepthImageTexture->width;
m_pDepthImageTexture->realHeight = m_pDepthImageTexture->height;
m_pDepthImageTexture->textureBytes = m_pDepthImageTexture->realWidth * m_pDepthImageTexture->realHeight * 4 * 4; // Width*Height*RGBA*sizeof(GL_RGBA32F)
m_pDepthImageTexture->textureBytes = m_pDepthImageTexture->realWidth * m_pDepthImageTexture->realHeight * 2 * sizeof(float); // Width*Height*RG*sizeof(GL_RGBA32F)
textureCache().addFrameBufferTextureSize(m_pDepthImageTexture->textureBytes);
glBindTexture( GL_TEXTURE_2D, m_pDepthImageTexture->glName );
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA32F, m_pDepthImageTexture->realWidth, m_pDepthImageTexture->realHeight, 0, GL_RGBA, GL_FLOAT, NULL);
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST );
glBindTexture( GL_TEXTURE_2D, 0);
glBindTexture(GL_TEXTURE_2D, m_pDepthImageTexture->glName);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RG32F, m_pDepthImageTexture->realWidth, m_pDepthImageTexture->realHeight, 0, GL_RG, GL_FLOAT, NULL);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glBindTexture(GL_TEXTURE_2D, 0);
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0);
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, m_FBO);
@ -144,7 +144,7 @@ void DepthBuffer::activateDepthBufferTexture() {
void DepthBuffer::bindDepthImageTexture() {
#ifdef GL_IMAGE_TEXTURES_SUPPORT
glBindImageTexture(depthImageUnit, m_pDepthImageTexture->glName, 0, GL_FALSE, 0, GL_READ_WRITE, GL_RGBA32F);
glBindImageTexture(depthImageUnit, m_pDepthImageTexture->glName, 0, GL_FALSE, 0, GL_READ_WRITE, GL_RG32F);
#endif
}
@ -238,13 +238,13 @@ void DepthBufferList::clearBuffer()
if (m_pCurrent == NULL || m_pCurrent->m_FBO == 0)
return;
float color[4] = {1.0f, 1.0f, 0.0f, 1.0f};
glBindImageTexture(depthImageUnit, 0, 0, GL_FALSE, 0, GL_READ_WRITE, GL_RGBA32F);
glBindImageTexture(depthImageUnit, 0, 0, GL_FALSE, 0, GL_READ_WRITE, GL_RG32F);
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, m_pCurrent->m_FBO);
const u32 cycleType = gDP.otherMode.cycleType;
gDP.otherMode.cycleType = G_CYC_FILL;
video().getRender().drawRect(0,0,VI.width, VI.height, color);
gDP.otherMode.cycleType = cycleType;
glBindImageTexture(depthImageUnit, m_pCurrent->m_pDepthImageTexture->glName, 0, GL_FALSE, 0, GL_READ_WRITE, GL_RGBA32F);
glBindImageTexture(depthImageUnit, m_pCurrent->m_pDepthImageTexture->glName, 0, GL_FALSE, 0, GL_READ_WRITE, GL_RG32F);
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, frameBufferList().getCurrent()->m_FBO);
#endif // GL_IMAGE_TEXTURES_SUPPORT
}

View File

@ -584,7 +584,6 @@ void ShaderCombiner::_locateUniforms() {
LocateUniform(uRenderState);
LocateUniform(uTexScale);
LocateUniform(uDepthScale);
LocateUniform(uTexOffset[0]);
LocateUniform(uTexOffset[1]);
LocateUniform(uTexMask[0]);
@ -834,7 +833,6 @@ void ShaderCombiner::updateDepthInfo(bool _bForce) {
}
_setIUniform(m_uniforms.uDepthMode, gDP.otherMode.depthMode, _bForce);
_setIUniform(m_uniforms.uDepthSource, gDP.otherMode.depthSource, _bForce);
_setFV2Uniform(m_uniforms.uDepthScale, gSP.viewport.vscale[2] * 32768.0f, gSP.viewport.vtrans[2] * 32768.0f, _bForce);
if (gDP.otherMode.depthSource == G_ZS_PRIM)
_setFUniform(m_uniforms.uDeltaZ, gDP.primDepth.deltaZ, _bForce);
}

View File

@ -48,7 +48,7 @@ private:
fv4Uniform uEnvColor, uPrimColor, uFogColor, uCenterColor, uScaleColor, uBlendColor;
fv2Uniform uTexScale, uTexOffset[2], uTexMask[2],
uCacheShiftScale[2], uCacheScale[2], uCacheOffset[2], uDepthScale;
uCacheShiftScale[2], uCacheScale[2], uCacheOffset[2];
fv3Uniform uLightDirection[8], uLightColor[8];

View File

@ -551,34 +551,20 @@ static const char* depth_compare_shader_float =
"uniform lowp int uEnableDepthCompare; \n"
"uniform lowp int uEnableDepthUpdate; \n"
"uniform mediump float uDeltaZ; \n"
"uniform mediump vec2 uDepthScale; \n"
"layout(binding = 0, r16ui) uniform readonly uimage2D uZlutImage;\n"
"layout(binding = 2, rgba32f) uniform coherent image2D uDepthImage;\n"
"void write_depth(in highp float dz, in ivec2 coord) \n"
"{ \n"
" highp float fZ = 2.0*gl_FragCoord.z - 1.0; \n"
" fZ = (uDepthScale.x*fZ + uDepthScale.y)*8.0; \n"
" const 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 iN64z = imageLoad(uZlutImage,ivec2(x0,y0)).r;\n"
" highp float n64z = clamp(float(iN64z)/65532.0, 0.0, 1.0);\n"
" highp vec4 depth = vec4(n64z, gl_FragCoord.z, dz, 1.0); \n"
" imageStore(uDepthImage,coord,depth); \n"
"} \n"
"layout(binding = 2, rg32f) uniform coherent image2D uDepthImage;\n"
"lowp bool depth_compare() \n"
"{ \n"
//" if (uEnableDepth == 0) return true; \n"
" ivec2 coord = ivec2(gl_FragCoord.xy); \n"
" highp vec4 depth = imageLoad(uDepthImage,coord); \n"
" highp float bufZ = depth.g; \n"
" highp float bufZ = depth.r; \n"
" highp float curZ = gl_FragCoord.z; \n"
" highp float dz, dzMin; \n"
" if (uDepthSource == 1) { \n"
" dzMin = dz = uDeltaZ; \n"
" } else { \n"
" dz = 4.0*fwidth(gl_FragCoord.z); \n"
" dzMin = min(dz, depth.b); \n"
" dzMin = min(dz, depth.g); \n"
" } \n"
" const bool bInfront = curZ < bufZ; \n"
" const bool bFarther = (curZ + dzMin) >= bufZ; \n"
@ -601,7 +587,8 @@ static const char* depth_compare_shader_float =
" break; \n"
" } \n"
" if (uEnableDepthUpdate != 0 && bRes) { \n"
" write_depth(dz, coord); \n"
" highp vec4 depth_out = vec4(gl_FragCoord.z, dz, 1.0, 1.0); \n"
" imageStore(uDepthImage,coord, depth_out); \n"
" } \n"
" memoryBarrierImage(); \n"
" if (uEnableDepthCompare != 0) \n"