glsl: add a geometry shader to upscale GS_POINT

The purpose is to avoid upscaling issue on POINT rendering (black netting on some FMVs)
This commit is contained in:
Gregory Hainaut 2015-07-11 00:03:33 +02:00
parent 2ccf108534
commit 5e7ce63ed1
2 changed files with 56 additions and 28 deletions

View File

@ -187,7 +187,6 @@ struct vertex
{
vec4 t;
vec4 c;
vec2 a;
};
void out_vertex(in vertex v)
@ -198,47 +197,62 @@ void out_vertex(in vertex v)
EmitVertex();
}
void out_flat(in vec2 dp)
void out_flat()
{
// Flat output
#if GS_POINT == 1
GSout.fc = GSin[0].fc;
#else
GSout.fc = GSin[1].fc;
#endif
}
#if GS_POINT == 1
layout(points) in;
#else
layout(lines) in;
#endif
layout(triangle_strip, max_vertices = 6) out;
void gs_main()
{
// Rescale from -1 1 to 0:1 (require window size)
vec2 dp = vec2(0.0f, 0.0f);
// left top => GSin[0];
// right bottom => GSin[1];
vertex rb = vertex(GSin[1].t, GSin[1].c, dp);
vertex lt = vertex(GSin[0].t, GSin[0].c, vec2(0.0f, 0.0f));
#if GS_POINT == 1
vertex rb = vertex(GSin[0].t, GSin[0].c);
#else
vertex rb = vertex(GSin[1].t, GSin[1].c);
#endif
vertex lt = vertex(GSin[0].t, GSin[0].c);
#if GS_POINT == 1
// FIXME need pixel size
vec4 rb_p = gl_in[0].gl_Position + vec4(4.0f/1280.0f, 4.0f/1024.0f, 0.0f, 0.0f);
#else
vec4 rb_p = gl_in[1].gl_Position;
vec4 lb_p = gl_in[1].gl_Position;
vec4 rt_p = gl_in[1].gl_Position;
#endif
vec4 lb_p = rb_p;
vec4 rt_p = rb_p;
vec4 lt_p = gl_in[0].gl_Position;
#if GS_POINT == 0
// flat depth
lt_p.z = rb_p.z;
// flat fog and texture perspective
lt.t.zw = rb.t.zw;
// flat color
lt.c = rb.c;
#endif
// Swap texture and position coordinate
vertex lb = rb;
lb_p.x = lt_p.x;
lb.t.x = lt.t.x;
lb.a.x = lt.a.x;
lb_p.x = lt_p.x;
vertex rt = rb;
rt_p.y = lt_p.y;
rt.t.y = lt.t.y;
rt.a.y = lt.a.y;
// Triangle 1
gl_Position = lt_p;
@ -248,7 +262,7 @@ void gs_main()
out_vertex(lb);
gl_Position = rt_p;
out_flat(dp);
out_flat();
out_vertex(rt);
EndPrimitive();
@ -260,7 +274,7 @@ void gs_main()
out_vertex(rt);
gl_Position = rb_p;
out_flat(dp);
out_flat();
out_vertex(rb);
EndPrimitive();
}

View File

@ -795,7 +795,6 @@ static const char* tfx_vgs_glsl =
"{\n"
" vec4 t;\n"
" vec4 c;\n"
" vec2 a;\n"
"};\n"
"\n"
"void out_vertex(in vertex v)\n"
@ -806,47 +805,62 @@ static const char* tfx_vgs_glsl =
" EmitVertex();\n"
"}\n"
"\n"
"void out_flat(in vec2 dp)\n"
"void out_flat()\n"
"{\n"
" // Flat output\n"
"#if GS_POINT == 1\n"
" GSout.fc = GSin[0].fc;\n"
"#else\n"
" GSout.fc = GSin[1].fc;\n"
"#endif\n"
"}\n"
"\n"
"#if GS_POINT == 1\n"
"layout(points) in;\n"
"#else\n"
"layout(lines) in;\n"
"#endif\n"
"layout(triangle_strip, max_vertices = 6) out;\n"
"\n"
"void gs_main()\n"
"{\n"
" // Rescale from -1 1 to 0:1 (require window size)\n"
" vec2 dp = vec2(0.0f, 0.0f);\n"
"\n"
" // left top => GSin[0];\n"
" // right bottom => GSin[1];\n"
" vertex rb = vertex(GSin[1].t, GSin[1].c, dp);\n"
" vertex lt = vertex(GSin[0].t, GSin[0].c, vec2(0.0f, 0.0f));\n"
"#if GS_POINT == 1\n"
" vertex rb = vertex(GSin[0].t, GSin[0].c);\n"
"#else\n"
" vertex rb = vertex(GSin[1].t, GSin[1].c);\n"
"#endif\n"
" vertex lt = vertex(GSin[0].t, GSin[0].c);\n"
"\n"
"#if GS_POINT == 1\n"
" // FIXME need pixel size\n"
" vec4 rb_p = gl_in[0].gl_Position + vec4(4.0f/1280.0f, 4.0f/1024.0f, 0.0f, 0.0f);\n"
"#else\n"
" vec4 rb_p = gl_in[1].gl_Position;\n"
" vec4 lb_p = gl_in[1].gl_Position;\n"
" vec4 rt_p = gl_in[1].gl_Position;\n"
"#endif\n"
" vec4 lb_p = rb_p;\n"
" vec4 rt_p = rb_p;\n"
" vec4 lt_p = gl_in[0].gl_Position;\n"
"\n"
"#if GS_POINT == 0\n"
" // flat depth\n"
" lt_p.z = rb_p.z;\n"
" // flat fog and texture perspective\n"
" lt.t.zw = rb.t.zw;\n"
" // flat color\n"
" lt.c = rb.c;\n"
"#endif\n"
"\n"
" // Swap texture and position coordinate\n"
" vertex lb = rb;\n"
" lb_p.x = lt_p.x;\n"
" lb.t.x = lt.t.x;\n"
" lb.a.x = lt.a.x;\n"
" lb_p.x = lt_p.x;\n"
"\n"
" vertex rt = rb;\n"
" rt_p.y = lt_p.y;\n"
" rt.t.y = lt.t.y;\n"
" rt.a.y = lt.a.y;\n"
"\n"
"\n"
" // Triangle 1\n"
" gl_Position = lt_p;\n"
@ -856,7 +870,7 @@ static const char* tfx_vgs_glsl =
" out_vertex(lb);\n"
"\n"
" gl_Position = rt_p;\n"
" out_flat(dp);\n"
" out_flat();\n"
" out_vertex(rt);\n"
" EndPrimitive();\n"
"\n"
@ -868,7 +882,7 @@ static const char* tfx_vgs_glsl =
" out_vertex(rt);\n"
"\n"
" gl_Position = rb_p;\n"
" out_flat(dp);\n"
" out_flat();\n"
" out_vertex(rb);\n"
" EndPrimitive();\n"
"}\n"