Skip to content

Commit

Permalink
gsdx ogl: implement an alternate shader for Jak Shadows
Browse files Browse the repository at this point in the history
The game sets the framebuffer as an input texture. So I did the same for
openGL. Code is protected with a CRC. It is working because the game want to sample
pixels.

For the record, I tested it GTA too, it doesn't work as expected because
the game will resize the framebuffer to a smaller one. So you don't have
the guarantee that pixel will be read before a data write.

Note: it requires at least accurate blending set on basic

Note: I need CRC of all Jak games that suffers of this issue. Thanks you :)
  • Loading branch information
gregory38 committed Sep 8, 2016
1 parent c03b388 commit c2b67cc
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 5 deletions.
1 change: 1 addition & 0 deletions plugins/GSdx/GSCrc.cpp
Expand Up @@ -515,6 +515,7 @@ CRC::Game CRC::m_games[] =
{0XE1BF5DCA, SuperManReturns, US, 0},
{0x06A7506A, SacredBlaze, JP, 0},
{0x4CE7FB04, ItadakiStreet, JP, 0},
{0x12804727, Jak3, PAL, 0},
};

map<uint32, CRC::Game*> CRC::m_map;
Expand Down
1 change: 1 addition & 0 deletions plugins/GSdx/GSCrc.h
Expand Up @@ -175,6 +175,7 @@ class CRC
SacredBlaze,
SuperManReturns,
ItadakiStreet,
Jak3,
TitleCount,
};

Expand Down
1 change: 1 addition & 0 deletions plugins/GSdx/GSDeviceOGL.cpp
Expand Up @@ -943,6 +943,7 @@ GLuint GSDeviceOGL::CompilePS(PSSelector sel)
+ format("#define PS_CHANNEL_FETCH %d\n", sel.channel)
+ format("#define PS_URBAN_CHAOS_HLE %d\n", sel.urban_chaos_hle)
+ format("#define PS_TALES_OF_ABYSS_HLE %d\n", sel.tales_of_abyss_hle)
+ format("#define PS_TEX_IS_FB %d\n", sel.tex_is_fb)
+ format("#define PS_AEM %d\n", sel.aem)
+ format("#define PS_TFX %d\n", sel.tfx)
+ format("#define PS_TCC %d\n", sel.tcc)
Expand Down
3 changes: 2 additions & 1 deletion plugins/GSdx/GSDeviceOGL.h
Expand Up @@ -292,8 +292,9 @@ class GSDeviceOGL final : public GSDevice
uint32 tcoffsethack:1;
uint32 urban_chaos_hle:1;
uint32 tales_of_abyss_hle:1;
uint32 tex_is_fb:1; // Jak Shadows

uint32 _free2:14;
uint32 _free2:13;
};

uint64 key;
Expand Down
12 changes: 8 additions & 4 deletions plugins/GSdx/GSRendererOGL.cpp
Expand Up @@ -1142,11 +1142,15 @@ void GSRendererOGL::DrawPrims(GSTexture* rt, GSTexture* ds, GSTextureCache::Sour

// Always check if primitive overlap. The function will return PRIM_OVERLAP_UNKNOW for non sprite primitive
m_prim_overlap = PrimitiveOverlap();
#ifdef ENABLE_OGL_DEBUG
if (PRIM->TME && m_sw_blending && (m_prim_overlap != PRIM_OVERLAP_NO) && (m_context->FRAME.Block() == m_context->TEX0.TBP0) && (m_vertex.next > 2)) {
GL_INS("ERROR: Source and Target are the same!");
if ((m_context->FRAME.Block() == m_context->TEX0.TBP0) && PRIM->TME && m_sw_blending && (m_prim_overlap != PRIM_OVERLAP_NO) && (m_vertex.next > 2)) {
if (m_game.title == CRC::Jak3) {
GL_INS("ERROR: Source and Target are the same! Let's sample the framebuffer");
m_ps_sel.tex_is_fb = 1;
m_require_full_barrier = true;
} else {
GL_INS("ERROR: Source and Target are the same!");
}
}
#endif

EmulateTextureShuffleAndFbmask();

Expand Down
4 changes: 4 additions & 0 deletions plugins/GSdx/res/glsl/tfx_fs.glsl
Expand Up @@ -75,7 +75,11 @@ layout(early_fragment_tests) in;

vec4 sample_c(vec2 uv)
{
#if PS_TEX_IS_FB == 1
return texelFetch(RtSampler, ivec2(gl_FragCoord.xy), 0);
#else
return texture(TextureSampler, uv);
#endif
}

vec4 sample_p(float idx)
Expand Down
4 changes: 4 additions & 0 deletions plugins/GSdx/res/glsl_source.h
Expand Up @@ -995,7 +995,11 @@ static const char* const tfx_fs_all_glsl =
"\n"
"vec4 sample_c(vec2 uv)\n"
"{\n"
"#if PS_TEX_IS_FB == 1\n"
" return texelFetch(RtSampler, ivec2(gl_FragCoord.xy), 0);\n"
"#else\n"
" return texture(TextureSampler, uv);\n"
"#endif\n"
"}\n"
"\n"
"vec4 sample_p(float idx)\n"
Expand Down

0 comments on commit c2b67cc

Please sign in to comment.