gsdx-ogl: add some shaders to convert depth <-> color

I'm afraid of rounding error
This commit is contained in:
Gregory Hainaut 2015-05-29 18:58:26 +02:00
parent a5fe8478ae
commit 23f8203a22
3 changed files with 53 additions and 1 deletions

View File

@ -486,7 +486,7 @@ class GSDeviceOGL : public GSDevice
struct {
GLuint vs; // program object
GLuint ps[11]; // program object
GLuint ps[13]; // program object
GLuint ln; // sampler object
GLuint pt; // sampler object
GSDepthStencilOGL* dss;

View File

@ -151,12 +151,38 @@ void ps_main1()
#ifdef ps_main10
void ps_main10()
{
// Convert a GL_FLOAT32 depth texture into a 32 bits UINT texture
vec4 c = sample_c();
const float exp2_32 = exp2(32.0f);
SV_Target1 = uint(exp2_32 * c.r);
}
#endif
#ifdef ps_main11
void ps_main11()
{
const float exp2_32 = exp2(32.0f);
const vec4 bitSh = vec4(256.0*256.0*256.0, 256.0*256.0, 256.0, 1.0);
const vec4 bitMsk = vec4(0.0, 1.0/256.0, 1.0/256.0, 1.0/256.0);
// Convert a GL_FLOAT32 depth texture into a RGBA texture
vec4 res = fract(vec4(sample_c().r) * bitSh);
SV_Target0 = (res - res.xxyz * bitMsk) * 256.0f/255.0f;
}
#endif
#ifdef ps_main12
out float gl_FragDepth;
void ps_main12()
{
// Convert a RRGBA texture into a float depth texture
// FIXME: I'm afraid of the accuracy
const vec4 bitSh = vec4(1.0/(256.0*256.0*256.0), 1.0/(256.0*256.0), 1.0/256.0, 1.0) * vec4(255.0/256.0);
gl_FragDepth = dot(sample_c(), bitSh);
}
#endif
#ifdef ps_main7
void ps_main7()
{

View File

@ -176,12 +176,38 @@ static const char* convert_glsl =
"#ifdef ps_main10\n"
"void ps_main10()\n"
"{\n"
" // Convert a GL_FLOAT32 depth texture into a 32 bits UINT texture\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_main11\n"
"void ps_main11()\n"
"{\n"
" const float exp2_32 = exp2(32.0f);\n"
" const vec4 bitSh = vec4(256.0*256.0*256.0, 256.0*256.0, 256.0, 1.0);\n"
" const vec4 bitMsk = vec4(0.0, 1.0/256.0, 1.0/256.0, 1.0/256.0);\n"
"\n"
" // Convert a GL_FLOAT32 depth texture into a RGBA texture\n"
" vec4 res = fract(vec4(sample_c().r) * bitSh);\n"
"\n"
" SV_Target0 = (res - res.xxyz * bitMsk) * 256.0f/255.0f;\n"
"}\n"
"#endif\n"
"\n"
"#ifdef ps_main12\n"
"out float gl_FragDepth;\n"
"void ps_main12()\n"
"{\n"
" // Convert a RRGBA texture into a float depth texture\n"
" // FIXME: I'm afraid of the accuracy\n"
" const vec4 bitSh = vec4(1.0/(256.0*256.0*256.0), 1.0/(256.0*256.0), 1.0/256.0, 1.0) * vec4(255.0/256.0);\n"
" gl_FragDepth = dot(sample_c(), bitSh);\n"
"}\n"
"#endif\n"
"\n"
"#ifdef ps_main7\n"
"void ps_main7()\n"
"{\n"