Skip to content

Commit

Permalink
gsdx-ogl: add a shader to convert depth texture into uint
Browse files Browse the repository at this point in the history
  • Loading branch information
gregory38 committed May 19, 2015
1 parent 18a6403 commit 358e0d4
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 8 deletions.
2 changes: 1 addition & 1 deletion plugins/GSdx/GSDeviceOGL.h
Expand Up @@ -485,7 +485,7 @@ class GSDeviceOGL : public GSDevice

struct {
GLuint vs; // program object
GLuint ps[10]; // program object
GLuint ps[11]; // program object
GLuint ln; // sampler object
GLuint pt; // sampler object
GSDepthStencilOGL* dss;
Expand Down
4 changes: 2 additions & 2 deletions plugins/GSdx/GSTextureCacheOGL.cpp
Expand Up @@ -67,12 +67,12 @@ void GSTextureCacheOGL::Read(Target* t, const GSVector4i& r)

case PSM_PSMZ24:
fmt = GL_R32UI;
ps_shader = 11;
ps_shader = 10;
return;

case PSM_PSMZ16:
fmt = GL_R16UI;
ps_shader = 12;
ps_shader = 10;
return;

default:
Expand Down
11 changes: 10 additions & 1 deletion plugins/GSdx/res/glsl/convert.glsl
Expand Up @@ -58,7 +58,7 @@ in SHADER
#define PSin_t (PSin.t)

// Give a different name so I remember there is a special case!
#ifdef ps_main1
#if defined(ps_main1) || defined(ps_main10)
layout(location = 0) out uint SV_Target1;
#else
layout(location = 0) out vec4 SV_Target0;
Expand Down Expand Up @@ -137,6 +137,15 @@ void ps_main1()
}
#endif

#ifdef ps_main10
void ps_main10()
{
vec4 c = sample_c();
const float exp2_32 = exp2(32.0f);
SV_Target1 = uint(exp2_32 * c.r);
}
#endif

#ifdef ps_main7
void ps_main7()
{
Expand Down
24 changes: 20 additions & 4 deletions plugins/GSdx/res/glsl_source.h
Expand Up @@ -83,7 +83,7 @@ static const char* convert_glsl =
"#define PSin_t (PSin.t)\n"
"\n"
"// Give a different name so I remember there is a special case!\n"
"#ifdef ps_main1\n"
"#if defined(ps_main1) || defined(ps_main10)\n"
"layout(location = 0) out uint SV_Target1;\n"
"#else\n"
"layout(location = 0) out vec4 SV_Target0;\n"
Expand Down Expand Up @@ -133,18 +133,25 @@ static const char* convert_glsl =
"#ifdef ps_main1\n"
"void ps_main1()\n"
"{\n"
" vec4 c = sample_c();\n"
" // Color is RGBA8\n"
" // Input Color is RGBA8\n"
"\n"
" // We want to output a pixel on the PSMCT16* format\n"
" // A1-BGR5\n"
"\n"
"#if 0\n"
" // For me this code is more accurate but it will require some tests\n"
"\n"
" vec4 c = sample_c() * 255.0f + 0.5f; // Denormalize value\n"
"\n"
" highp uvec4 i = uvec4(255.0f * c * vec4(1/32.0f, 4.0f, 64.0f, 512.0f));\n"
" highp uvec4 i = uvec4(c * vec4(1/32.0f, 4.0f, 64.0f, 512.0f)); // Shift value\n"
"\n"
" SV_Target1 = (i.x & uint(0x001f)) | (i.y & uint(0x03e0)) | (i.z & uint(0x7c00)) | (i.w & uint(0x8000));\n"
"\n"
"#else\n"
" // Old code which is likely wrong.\n"
"\n"
" vec4 c = sample_c();\n"
"\n"
" c.a *= 256.0f / 127.0f; // hm, 0.5 won't give us 1.0 if we just multiply with 2\n"
"\n"
" highp uvec4 i = uvec4(c * vec4(uint(0x001f), uint(0x03e0), uint(0x7c00), uint(0x8000)));\n"
Expand All @@ -155,6 +162,15 @@ static const char* convert_glsl =
"}\n"
"#endif\n"
"\n"
"#ifdef ps_main10\n"
"void ps_main10()\n"
"{\n"
" vec4 c = sample_c();\n"
" const float exp2_32 = exp2(32.0f);\n"
" SV_Target1 = uint(exp2_32 * c.r);\n"
"}\n"
"#endif\n"
"\n"
"#ifdef ps_main7\n"
"void ps_main7()\n"
"{\n"
Expand Down

0 comments on commit 358e0d4

Please sign in to comment.