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

Correct depth_compare_shader.

Add primDeltaZ support.
This commit is contained in:
Sergey Lipskiy 2015-01-20 15:50:22 +06:00
parent 54f01961f2
commit 0197bfa104
4 changed files with 28 additions and 21 deletions

View File

@ -564,6 +564,7 @@ void ShaderCombiner::_locateUniforms() {
LocateUniform(uEnableDepthCompare) LocateUniform(uEnableDepthCompare)
LocateUniform(uEnableDepthUpdate); LocateUniform(uEnableDepthUpdate);
LocateUniform(uDepthMode); LocateUniform(uDepthMode);
LocateUniform(uDepthSource);
LocateUniform(uFb8Bit); LocateUniform(uFb8Bit);
LocateUniform(uFbFixedAlpha); LocateUniform(uFbFixedAlpha);
LocateUniform(uMaxTile) LocateUniform(uMaxTile)
@ -582,8 +583,7 @@ void ShaderCombiner::_locateUniforms() {
LocateUniform(uLodXScale); LocateUniform(uLodXScale);
LocateUniform(uLodYScale); LocateUniform(uLodYScale);
LocateUniform(uMinLod); LocateUniform(uMinLod);
LocateUniform(uDepthTrans); LocateUniform(uDeltaZ);
LocateUniform(uDepthScale);
LocateUniform(uAlphaTestValue); LocateUniform(uAlphaTestValue);
LocateUniform(uEnvColor); LocateUniform(uEnvColor);
@ -596,6 +596,7 @@ void ShaderCombiner::_locateUniforms() {
LocateUniform(uRenderState); LocateUniform(uRenderState);
LocateUniform(uTexScale); LocateUniform(uTexScale);
LocateUniform(uDepthScale);
LocateUniform(uTexOffset[0]); LocateUniform(uTexOffset[0]);
LocateUniform(uTexOffset[1]); LocateUniform(uTexOffset[1]);
LocateUniform(uTexMask[0]); LocateUniform(uTexMask[0]);
@ -844,8 +845,10 @@ void ShaderCombiner::updateDepthInfo(bool _bForce) {
_setIUniform(m_uniforms.uEnableDepthUpdate, gDP.otherMode.depthUpdate, _bForce); _setIUniform(m_uniforms.uEnableDepthUpdate, gDP.otherMode.depthUpdate, _bForce);
} }
_setIUniform(m_uniforms.uDepthMode, gDP.otherMode.depthMode, _bForce); _setIUniform(m_uniforms.uDepthMode, gDP.otherMode.depthMode, _bForce);
_setFUniform(m_uniforms.uDepthScale, gSP.viewport.vscale[2]*32768.0f, _bForce); _setIUniform(m_uniforms.uDepthSource, gDP.otherMode.depthSource, _bForce);
_setFUniform(m_uniforms.uDepthTrans, gSP.viewport.vtrans[2]*32768.0f, _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);
} }
void ShaderCombiner::updateAlphaTestInfo(bool _bForce) { void ShaderCombiner::updateAlphaTestInfo(bool _bForce) {

View File

@ -38,17 +38,17 @@ private:
iUniform uTex0, uTex1, uTlutImage, uZlutImage, uDepthImage, iUniform uTex0, uTex1, uTlutImage, uZlutImage, uDepthImage,
uFogMode, uFogUsage, uEnableLod, uEnableAlphaTest, uFogMode, uFogUsage, uEnableLod, uEnableAlphaTest,
uEnableDepth, uEnableDepthCompare, uEnableDepthUpdate, uEnableDepth, uEnableDepthCompare, uEnableDepthUpdate,
uDepthMode, uFb8Bit, uFbFixedAlpha, uRenderState, uSpecialBlendMode, uDepthMode, uDepthSource, uFb8Bit, uFbFixedAlpha, uRenderState, uSpecialBlendMode,
uMaxTile, uTextureDetail, uTexturePersp, uMaxTile, uTextureDetail, uTexturePersp,
uAlphaCompareMode, uAlphaDitherMode, uColorDitherMode, uGammaCorrectionEnabled; uAlphaCompareMode, uAlphaDitherMode, uColorDitherMode, uGammaCorrectionEnabled;
fUniform uFogMultiplier, uFogOffset, uK4, uK5, uPrimLod, uNoiseTime, uScreenWidth, uScreenHeight, fUniform uFogMultiplier, uFogOffset, uK4, uK5, uPrimLod, uNoiseTime, uScreenWidth, uScreenHeight,
uLodXScale, uLodYScale, uMinLod, uDepthTrans, uDepthScale, uAlphaTestValue; uLodXScale, uLodYScale, uMinLod, uDeltaZ, uAlphaTestValue;
fv4Uniform uEnvColor, uPrimColor, uFogColor, uCenterColor, uScaleColor, uBlendColor; fv4Uniform uEnvColor, uPrimColor, uFogColor, uCenterColor, uScaleColor, uBlendColor;
fv2Uniform uTexScale, uTexOffset[2], uTexMask[2], fv2Uniform uTexScale, uTexOffset[2], uTexMask[2],
uCacheShiftScale[2], uCacheScale[2], uCacheOffset[2]; uCacheShiftScale[2], uCacheScale[2], uCacheOffset[2], uDepthScale;
fv3Uniform uLightDirection[8], uLightColor[8]; fv3Uniform uLightDirection[8], uLightColor[8];

View File

@ -544,44 +544,48 @@ static const char* fragment_shader_mipmap =
#ifdef GL_IMAGE_TEXTURES_SUPPORT #ifdef GL_IMAGE_TEXTURES_SUPPORT
static const char* depth_compare_shader_float = static const char* depth_compare_shader_float =
"#version 420 \n" "#version 430 \n"
//"uniform int uEnableDepth; \n" //"uniform int uEnableDepth; \n"
"uniform int uDepthMode; \n" "uniform lowp int uDepthMode; \n"
"uniform int uEnableDepthCompare; \n" "uniform lowp int uDepthSource; \n"
"uniform int uEnableDepthUpdate; \n" "uniform lowp int uEnableDepthCompare; \n"
"uniform mediump float uDepthTrans; \n" "uniform lowp int uEnableDepthUpdate; \n"
"uniform mediump float uDepthScale; \n" "uniform mediump float uDeltaZ; \n"
"uniform mediump vec2 uDepthScale; \n"
"layout(binding = 0, r16ui) uniform readonly uimage2D uZlutImage;\n" "layout(binding = 0, r16ui) uniform readonly uimage2D uZlutImage;\n"
"layout(binding = 2, rgba32f) uniform coherent image2D uDepthImage;\n" "layout(binding = 2, rgba32f) uniform coherent image2D uDepthImage;\n"
"void write_depth(in highp float dz, in ivec2 coord) \n" "void write_depth(in highp float dz, in ivec2 coord) \n"
"{ \n" "{ \n"
" highp float fZ = 2.0*gl_FragCoord.z - 1.0; \n" " highp float fZ = 2.0*gl_FragCoord.z - 1.0; \n"
" fZ = (uDepthScale*fZ + uDepthTrans)*8.0; \n" " fZ = (uDepthScale.x*fZ + uDepthScale.y)*8.0; \n"
" const highp int iZ = int(floor(fZ + 0.5)); \n" " const highp int iZ = int(floor(fZ + 0.5)); \n"
" int y0 = clamp(iZ/512, 0, 511); \n" " int y0 = clamp(iZ/512, 0, 511); \n"
" int x0 = iZ - 512*y0; \n" " int x0 = iZ - 512*y0; \n"
" unsigned int iN64z = imageLoad(uZlutImage,ivec2(x0,y0)).r;\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 float n64z = clamp(float(iN64z)/65532.0, 0.0, 1.0);\n"
" highp vec4 depth = vec4(n64z, gl_FragCoord.z, dz, 1.0); \n" " highp vec4 depth = vec4(n64z, gl_FragCoord.z, dz, 1.0); \n"
" memoryBarrier(); \n"
" imageStore(uDepthImage,coord,depth); \n" " imageStore(uDepthImage,coord,depth); \n"
"} \n" "} \n"
"lowp bool depth_compare() \n" "lowp bool depth_compare() \n"
"{ \n" "{ \n"
//" if (uEnableDepth == 0) return true; \n" //" if (uEnableDepth == 0) return true; \n"
" ivec2 coord = ivec2(gl_FragCoord.xy); \n" " ivec2 coord = ivec2(gl_FragCoord.xy); \n"
//" memoryBarrier(); \n"
" highp vec4 depth = imageLoad(uDepthImage,coord); \n" " highp vec4 depth = imageLoad(uDepthImage,coord); \n"
" highp float bufZ = depth.g; \n" " highp float bufZ = depth.g; \n"
" highp float curZ = gl_FragCoord.z; \n" " highp float curZ = gl_FragCoord.z; \n"
" highp float dz = 4.0*fwidth(gl_FragCoord.z); \n" " highp float dz, dzMin; \n"
" highp float dzMin = min(dz, depth.b); \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"
" } \n"
" const bool bInfront = curZ < bufZ; \n" " const bool bInfront = curZ < bufZ; \n"
" const bool bFarther = (curZ + dzMin) >= bufZ; \n" " const bool bFarther = (curZ + dzMin) >= bufZ; \n"
" const bool bNearer = (curZ - dzMin) <= bufZ; \n" " const bool bNearer = (curZ - dzMin) <= bufZ; \n"
" const bool bMax = bufZ == 1.0; \n" " const bool bMax = bufZ == 1.0; \n"
" bool bRes; \n" " bool bRes; \n"
" switch(uDepthMode) { \n" " switch (uDepthMode) { \n"
" case 1: \n" " case 1: \n"
" bRes = bMax || bNearer; \n" " bRes = bMax || bNearer; \n"
" break; \n" " break; \n"

View File

@ -64,7 +64,7 @@ void gDPSetPrimDepth( u16 z, u16 dz )
gDP.primDepth.z = _FIXED2FLOAT(_SHIFTR(z, 0, 15), 15); gDP.primDepth.z = _FIXED2FLOAT(_SHIFTR(z, 0, 15), 15);
else else
gDP.primDepth.z = min(1.0f, max(-1.0f, (_FIXED2FLOAT(_SHIFTR(z, 0, 15), 15) - gSP.viewport.vtrans[2]) / gSP.viewport.vscale[2])); gDP.primDepth.z = min(1.0f, max(-1.0f, (_FIXED2FLOAT(_SHIFTR(z, 0, 15), 15) - gSP.viewport.vtrans[2]) / gSP.viewport.vscale[2]));
gDP.primDepth.deltaZ = dz; gDP.primDepth.deltaZ = _FIXED2FLOAT(_SHIFTR(dz, 0, 15), 15);
#ifdef DEBUG #ifdef DEBUG
DebugMsg( DEBUG_HIGH | DEBUG_HANDLED, "gDPSetPrimDepth( %f, %f );\n", DebugMsg( DEBUG_HIGH | DEBUG_HANDLED, "gDPSetPrimDepth( %f, %f );\n",