mirror of
https://github.com/blawar/GLideN64.git
synced 2024-07-02 09:03:37 +00:00
Correct depth_compare_shader.
Add primDeltaZ support.
This commit is contained in:
parent
54f01961f2
commit
0197bfa104
|
@ -564,6 +564,7 @@ void ShaderCombiner::_locateUniforms() {
|
|||
LocateUniform(uEnableDepthCompare)
|
||||
LocateUniform(uEnableDepthUpdate);
|
||||
LocateUniform(uDepthMode);
|
||||
LocateUniform(uDepthSource);
|
||||
LocateUniform(uFb8Bit);
|
||||
LocateUniform(uFbFixedAlpha);
|
||||
LocateUniform(uMaxTile)
|
||||
|
@ -582,8 +583,7 @@ void ShaderCombiner::_locateUniforms() {
|
|||
LocateUniform(uLodXScale);
|
||||
LocateUniform(uLodYScale);
|
||||
LocateUniform(uMinLod);
|
||||
LocateUniform(uDepthTrans);
|
||||
LocateUniform(uDepthScale);
|
||||
LocateUniform(uDeltaZ);
|
||||
LocateUniform(uAlphaTestValue);
|
||||
|
||||
LocateUniform(uEnvColor);
|
||||
|
@ -596,6 +596,7 @@ void ShaderCombiner::_locateUniforms() {
|
|||
LocateUniform(uRenderState);
|
||||
|
||||
LocateUniform(uTexScale);
|
||||
LocateUniform(uDepthScale);
|
||||
LocateUniform(uTexOffset[0]);
|
||||
LocateUniform(uTexOffset[1]);
|
||||
LocateUniform(uTexMask[0]);
|
||||
|
@ -844,8 +845,10 @@ void ShaderCombiner::updateDepthInfo(bool _bForce) {
|
|||
_setIUniform(m_uniforms.uEnableDepthUpdate, gDP.otherMode.depthUpdate, _bForce);
|
||||
}
|
||||
_setIUniform(m_uniforms.uDepthMode, gDP.otherMode.depthMode, _bForce);
|
||||
_setFUniform(m_uniforms.uDepthScale, gSP.viewport.vscale[2]*32768.0f, _bForce);
|
||||
_setFUniform(m_uniforms.uDepthTrans, gSP.viewport.vtrans[2]*32768.0f, _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);
|
||||
}
|
||||
|
||||
void ShaderCombiner::updateAlphaTestInfo(bool _bForce) {
|
||||
|
|
|
@ -38,17 +38,17 @@ private:
|
|||
iUniform uTex0, uTex1, uTlutImage, uZlutImage, uDepthImage,
|
||||
uFogMode, uFogUsage, uEnableLod, uEnableAlphaTest,
|
||||
uEnableDepth, uEnableDepthCompare, uEnableDepthUpdate,
|
||||
uDepthMode, uFb8Bit, uFbFixedAlpha, uRenderState, uSpecialBlendMode,
|
||||
uDepthMode, uDepthSource, uFb8Bit, uFbFixedAlpha, uRenderState, uSpecialBlendMode,
|
||||
uMaxTile, uTextureDetail, uTexturePersp,
|
||||
uAlphaCompareMode, uAlphaDitherMode, uColorDitherMode, uGammaCorrectionEnabled;
|
||||
|
||||
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;
|
||||
|
||||
fv2Uniform uTexScale, uTexOffset[2], uTexMask[2],
|
||||
uCacheShiftScale[2], uCacheScale[2], uCacheOffset[2];
|
||||
uCacheShiftScale[2], uCacheScale[2], uCacheOffset[2], uDepthScale;
|
||||
|
||||
fv3Uniform uLightDirection[8], uLightColor[8];
|
||||
|
||||
|
|
30
Shaders.h
30
Shaders.h
|
@ -544,44 +544,48 @@ static const char* fragment_shader_mipmap =
|
|||
|
||||
#ifdef GL_IMAGE_TEXTURES_SUPPORT
|
||||
static const char* depth_compare_shader_float =
|
||||
"#version 420 \n"
|
||||
//"uniform int uEnableDepth; \n"
|
||||
"uniform int uDepthMode; \n"
|
||||
"uniform int uEnableDepthCompare; \n"
|
||||
"uniform int uEnableDepthUpdate; \n"
|
||||
"uniform mediump float uDepthTrans; \n"
|
||||
"uniform mediump float uDepthScale; \n"
|
||||
"#version 430 \n"
|
||||
//"uniform int uEnableDepth; \n"
|
||||
"uniform lowp int uDepthMode; \n"
|
||||
"uniform lowp int uDepthSource; \n"
|
||||
"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*fZ + uDepthTrans)*8.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"
|
||||
" memoryBarrier(); \n"
|
||||
" imageStore(uDepthImage,coord,depth); \n"
|
||||
"} \n"
|
||||
"lowp bool depth_compare() \n"
|
||||
"{ \n"
|
||||
//" if (uEnableDepth == 0) return true; \n"
|
||||
" ivec2 coord = ivec2(gl_FragCoord.xy); \n"
|
||||
//" memoryBarrier(); \n"
|
||||
" highp vec4 depth = imageLoad(uDepthImage,coord); \n"
|
||||
" highp float bufZ = depth.g; \n"
|
||||
" highp float curZ = gl_FragCoord.z; \n"
|
||||
" highp float dz = 4.0*fwidth(gl_FragCoord.z); \n"
|
||||
" highp float dzMin = min(dz, depth.b); \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"
|
||||
" } \n"
|
||||
" const bool bInfront = curZ < bufZ; \n"
|
||||
" const bool bFarther = (curZ + dzMin) >= bufZ; \n"
|
||||
" const bool bNearer = (curZ - dzMin) <= bufZ; \n"
|
||||
" const bool bMax = bufZ == 1.0; \n"
|
||||
" bool bRes; \n"
|
||||
" switch(uDepthMode) { \n"
|
||||
" switch (uDepthMode) { \n"
|
||||
" case 1: \n"
|
||||
" bRes = bMax || bNearer; \n"
|
||||
" break; \n"
|
||||
|
|
2
gDP.cpp
2
gDP.cpp
|
@ -64,7 +64,7 @@ void gDPSetPrimDepth( u16 z, u16 dz )
|
|||
gDP.primDepth.z = _FIXED2FLOAT(_SHIFTR(z, 0, 15), 15);
|
||||
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.deltaZ = dz;
|
||||
gDP.primDepth.deltaZ = _FIXED2FLOAT(_SHIFTR(dz, 0, 15), 15);
|
||||
|
||||
#ifdef DEBUG
|
||||
DebugMsg( DEBUG_HIGH | DEBUG_HANDLED, "gDPSetPrimDepth( %f, %f );\n",
|
||||
|
|
Loading…
Reference in New Issue
Block a user