mirror of
https://github.com/blawar/GLideN64.git
synced 2024-07-07 03:13:49 +00:00
Add Zelda Monochrome shader.
This commit is contained in:
parent
727112b9cd
commit
47d3a85534
|
@ -21,6 +21,7 @@ static GLuint g_test_alpha_shader_object;
|
|||
|
||||
#ifdef GL_IMAGE_TEXTURES_SUPPORT
|
||||
GLuint g_draw_shadow_map_program = 0;
|
||||
GLuint g_monochrome_image_program = 0;
|
||||
static GLuint g_zlut_tex = 0;
|
||||
GLuint g_tlut_tex = 0;
|
||||
static u32 g_paletteCRC256 = 0;
|
||||
|
@ -145,6 +146,7 @@ void InitShadowMapShader()
|
|||
glTexImage1D(GL_TEXTURE_1D, 0, GL_R16, 256, 0, GL_RED, GL_UNSIGNED_SHORT, NULL);
|
||||
|
||||
g_draw_shadow_map_program = createShaderProgram(default_vertex_shader, shadow_map_fragment_shader_float);
|
||||
g_monochrome_image_program = createShaderProgram(default_vertex_shader, zelda_monochrome_fragment_shader);
|
||||
}
|
||||
|
||||
static
|
||||
|
@ -162,6 +164,8 @@ void DestroyShadowMapShader()
|
|||
}
|
||||
glDeleteProgram(g_draw_shadow_map_program);
|
||||
g_draw_shadow_map_program = 0;
|
||||
glDeleteProgram(g_monochrome_image_program);
|
||||
g_monochrome_image_program = 0;
|
||||
}
|
||||
#endif // GL_IMAGE_TEXTURES_SUPPORT
|
||||
|
||||
|
|
|
@ -116,8 +116,11 @@ private:
|
|||
void InitShaderCombiner();
|
||||
void DestroyShaderCombiner();
|
||||
|
||||
#ifdef GL_IMAGE_TEXTURES_SUPPORT
|
||||
extern GLuint g_draw_shadow_map_program;
|
||||
extern GLuint g_monochrome_image_program;
|
||||
void SetMonochromeCombiner(GLuint _program);
|
||||
#endif // GL_IMAGE_TEXTURES_SUPPORT
|
||||
|
||||
GLuint createShaderProgram(const char * _strVertex, const char * _strFragment);
|
||||
|
||||
|
|
19
OpenGL.cpp
19
OpenGL.cpp
|
@ -926,6 +926,23 @@ bool texturedRectPaletteMod(const OGLRender::TexturedRectParams & _params)
|
|||
return true;
|
||||
}
|
||||
|
||||
static
|
||||
bool texturedRectMonochromeBackground(const OGLRender::TexturedRectParams & _params)
|
||||
{
|
||||
if (gDP.textureImage.address >= gDP.colorImage.address && gDP.textureImage.address <= (gDP.colorImage.address + gDP.colorImage.width*gDP.colorImage.height * 2)) {
|
||||
#ifdef GL_IMAGE_TEXTURES_SUPPORT
|
||||
FrameBufferList & fb = frameBufferList();
|
||||
if (fb.isFboMode()) {
|
||||
FrameBuffer_ActivateBufferTexture(0, fb.getCurrent());
|
||||
SetMonochromeCombiner(g_monochrome_image_program);
|
||||
return false;
|
||||
} else
|
||||
#endif
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// Special processing of textured rect.
|
||||
// Return true if actuial rendering is not necessary
|
||||
bool(*texturedRectSpecial)(const OGLRender::TexturedRectParams & _params) = NULL;
|
||||
|
@ -1223,6 +1240,8 @@ void OGLRender::_setSpecialTexrect() const
|
|||
texturedRectSpecial = texturedRectBGCopy;
|
||||
else if (strstr(name, (const char *)"PAPER MARIO") || strstr(name, (const char *)"MARIO STORY"))
|
||||
texturedRectSpecial = texturedRectPaletteMod;
|
||||
else if (strstr(name, (const char *)"ZELDA"))
|
||||
texturedRectSpecial = texturedRectMonochromeBackground;
|
||||
else
|
||||
texturedRectSpecial = NULL;
|
||||
}
|
||||
|
|
39
Shaders.h
39
Shaders.h
|
@ -598,4 +598,43 @@ static const char* shadow_map_fragment_shader_float =
|
|||
" fragColor = vec4(uFogColor.rgb, get_alpha()); \n"
|
||||
"} \n"
|
||||
;
|
||||
|
||||
#if 0 // Do palette based monochrome image. Exactly as N64 does
|
||||
static const char* zelda_monochrome_fragment_shader =
|
||||
"#version 420 core \n"
|
||||
"layout(binding = 0) uniform sampler2D uColorImage; \n"
|
||||
"layout(binding = 1, r16ui) uniform readonly uimage1D uTlutImage;\n"
|
||||
"out lowp vec4 fragColor; \n"
|
||||
"lowp float get_color() \n"
|
||||
"{ \n"
|
||||
" ivec2 coord = ivec2(gl_FragCoord.xy); \n"
|
||||
" vec4 color = 31.0*texelFetch(uColorImage, coord, 0); \n"
|
||||
" int r = int(color.r); int g = int(color.g); int b = int(color.b);\n"
|
||||
//" int a = 0; if ((color.r + color.g + color.b) > 0) a = 32768;\n"
|
||||
//" int color16 = 32768 + r*1024 + g*32 + b; \n"
|
||||
" int color16 = r*1024 + g*32 + b; \n"
|
||||
" int index = min(255, color16/256); \n"
|
||||
" unsigned int iAlpha = imageLoad(uTlutImage,index).r; \n"
|
||||
" memoryBarrier(); \n"
|
||||
" return clamp(float((iAlpha&255) + index)/255.0, 0.0, 1.0); \n"
|
||||
"} \n"
|
||||
"void main() \n"
|
||||
"{ \n"
|
||||
" fragColor = vec4(vec3(get_color()), 1.0); \n"
|
||||
"} \n"
|
||||
;
|
||||
#else // Cheat it
|
||||
static const char* zelda_monochrome_fragment_shader =
|
||||
"#version 420 core \n"
|
||||
"layout(binding = 0) uniform sampler2D uColorImage; \n"
|
||||
"out lowp vec4 fragColor; \n"
|
||||
"void main() \n"
|
||||
"{ \n"
|
||||
" ivec2 coord = ivec2(gl_FragCoord.xy); \n"
|
||||
" vec4 tex = texelFetch(uColorImage, coord, 0); \n"
|
||||
" lowp float c = (tex.r + tex.g + tex.b) / 3.0f; \n"
|
||||
" fragColor = vec4(vec3(c), 1.0); \n"
|
||||
"} \n"
|
||||
;
|
||||
#endif
|
||||
#endif // GL_IMAGE_TEXTURES_SUPPORT
|
||||
|
|
Loading…
Reference in New Issue
Block a user