mirror of https://github.com/PCSX2/pcsx2.git
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:
parent
2ccf108534
commit
5e7ce63ed1
|
@ -187,7 +187,6 @@ struct vertex
|
||||||
{
|
{
|
||||||
vec4 t;
|
vec4 t;
|
||||||
vec4 c;
|
vec4 c;
|
||||||
vec2 a;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
void out_vertex(in vertex v)
|
void out_vertex(in vertex v)
|
||||||
|
@ -198,47 +197,62 @@ void out_vertex(in vertex v)
|
||||||
EmitVertex();
|
EmitVertex();
|
||||||
}
|
}
|
||||||
|
|
||||||
void out_flat(in vec2 dp)
|
void out_flat()
|
||||||
{
|
{
|
||||||
// Flat output
|
// Flat output
|
||||||
|
#if GS_POINT == 1
|
||||||
|
GSout.fc = GSin[0].fc;
|
||||||
|
#else
|
||||||
GSout.fc = GSin[1].fc;
|
GSout.fc = GSin[1].fc;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if GS_POINT == 1
|
||||||
|
layout(points) in;
|
||||||
|
#else
|
||||||
layout(lines) in;
|
layout(lines) in;
|
||||||
|
#endif
|
||||||
layout(triangle_strip, max_vertices = 6) out;
|
layout(triangle_strip, max_vertices = 6) out;
|
||||||
|
|
||||||
void gs_main()
|
void gs_main()
|
||||||
{
|
{
|
||||||
// Rescale from -1 1 to 0:1 (require window size)
|
|
||||||
vec2 dp = vec2(0.0f, 0.0f);
|
|
||||||
|
|
||||||
// left top => GSin[0];
|
// left top => GSin[0];
|
||||||
// right bottom => GSin[1];
|
// right bottom => GSin[1];
|
||||||
vertex rb = vertex(GSin[1].t, GSin[1].c, dp);
|
#if GS_POINT == 1
|
||||||
vertex lt = vertex(GSin[0].t, GSin[0].c, vec2(0.0f, 0.0f));
|
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 rb_p = gl_in[1].gl_Position;
|
||||||
vec4 lb_p = gl_in[1].gl_Position;
|
#endif
|
||||||
vec4 rt_p = gl_in[1].gl_Position;
|
vec4 lb_p = rb_p;
|
||||||
|
vec4 rt_p = rb_p;
|
||||||
vec4 lt_p = gl_in[0].gl_Position;
|
vec4 lt_p = gl_in[0].gl_Position;
|
||||||
|
|
||||||
|
#if GS_POINT == 0
|
||||||
// flat depth
|
// flat depth
|
||||||
lt_p.z = rb_p.z;
|
lt_p.z = rb_p.z;
|
||||||
// flat fog and texture perspective
|
// flat fog and texture perspective
|
||||||
lt.t.zw = rb.t.zw;
|
lt.t.zw = rb.t.zw;
|
||||||
// flat color
|
// flat color
|
||||||
lt.c = rb.c;
|
lt.c = rb.c;
|
||||||
|
#endif
|
||||||
|
|
||||||
// Swap texture and position coordinate
|
// Swap texture and position coordinate
|
||||||
vertex lb = rb;
|
vertex lb = rb;
|
||||||
lb_p.x = lt_p.x;
|
|
||||||
lb.t.x = lt.t.x;
|
lb.t.x = lt.t.x;
|
||||||
lb.a.x = lt.a.x;
|
lb_p.x = lt_p.x;
|
||||||
|
|
||||||
vertex rt = rb;
|
vertex rt = rb;
|
||||||
rt_p.y = lt_p.y;
|
rt_p.y = lt_p.y;
|
||||||
rt.t.y = lt.t.y;
|
rt.t.y = lt.t.y;
|
||||||
rt.a.y = lt.a.y;
|
|
||||||
|
|
||||||
// Triangle 1
|
// Triangle 1
|
||||||
gl_Position = lt_p;
|
gl_Position = lt_p;
|
||||||
|
@ -248,7 +262,7 @@ void gs_main()
|
||||||
out_vertex(lb);
|
out_vertex(lb);
|
||||||
|
|
||||||
gl_Position = rt_p;
|
gl_Position = rt_p;
|
||||||
out_flat(dp);
|
out_flat();
|
||||||
out_vertex(rt);
|
out_vertex(rt);
|
||||||
EndPrimitive();
|
EndPrimitive();
|
||||||
|
|
||||||
|
@ -260,7 +274,7 @@ void gs_main()
|
||||||
out_vertex(rt);
|
out_vertex(rt);
|
||||||
|
|
||||||
gl_Position = rb_p;
|
gl_Position = rb_p;
|
||||||
out_flat(dp);
|
out_flat();
|
||||||
out_vertex(rb);
|
out_vertex(rb);
|
||||||
EndPrimitive();
|
EndPrimitive();
|
||||||
}
|
}
|
||||||
|
|
|
@ -795,7 +795,6 @@ static const char* tfx_vgs_glsl =
|
||||||
"{\n"
|
"{\n"
|
||||||
" vec4 t;\n"
|
" vec4 t;\n"
|
||||||
" vec4 c;\n"
|
" vec4 c;\n"
|
||||||
" vec2 a;\n"
|
|
||||||
"};\n"
|
"};\n"
|
||||||
"\n"
|
"\n"
|
||||||
"void out_vertex(in vertex v)\n"
|
"void out_vertex(in vertex v)\n"
|
||||||
|
@ -806,47 +805,62 @@ static const char* tfx_vgs_glsl =
|
||||||
" EmitVertex();\n"
|
" EmitVertex();\n"
|
||||||
"}\n"
|
"}\n"
|
||||||
"\n"
|
"\n"
|
||||||
"void out_flat(in vec2 dp)\n"
|
"void out_flat()\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
" // Flat output\n"
|
" // Flat output\n"
|
||||||
|
"#if GS_POINT == 1\n"
|
||||||
|
" GSout.fc = GSin[0].fc;\n"
|
||||||
|
"#else\n"
|
||||||
" GSout.fc = GSin[1].fc;\n"
|
" GSout.fc = GSin[1].fc;\n"
|
||||||
|
"#endif\n"
|
||||||
"}\n"
|
"}\n"
|
||||||
"\n"
|
"\n"
|
||||||
|
"#if GS_POINT == 1\n"
|
||||||
|
"layout(points) in;\n"
|
||||||
|
"#else\n"
|
||||||
"layout(lines) in;\n"
|
"layout(lines) in;\n"
|
||||||
|
"#endif\n"
|
||||||
"layout(triangle_strip, max_vertices = 6) out;\n"
|
"layout(triangle_strip, max_vertices = 6) out;\n"
|
||||||
"\n"
|
"\n"
|
||||||
"void gs_main()\n"
|
"void gs_main()\n"
|
||||||
"{\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"
|
" // left top => GSin[0];\n"
|
||||||
" // right bottom => GSin[1];\n"
|
" // right bottom => GSin[1];\n"
|
||||||
" vertex rb = vertex(GSin[1].t, GSin[1].c, dp);\n"
|
"#if GS_POINT == 1\n"
|
||||||
" vertex lt = vertex(GSin[0].t, GSin[0].c, vec2(0.0f, 0.0f));\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"
|
"\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 rb_p = gl_in[1].gl_Position;\n"
|
||||||
" vec4 lb_p = gl_in[1].gl_Position;\n"
|
"#endif\n"
|
||||||
" vec4 rt_p = gl_in[1].gl_Position;\n"
|
" vec4 lb_p = rb_p;\n"
|
||||||
|
" vec4 rt_p = rb_p;\n"
|
||||||
" vec4 lt_p = gl_in[0].gl_Position;\n"
|
" vec4 lt_p = gl_in[0].gl_Position;\n"
|
||||||
"\n"
|
"\n"
|
||||||
|
"#if GS_POINT == 0\n"
|
||||||
" // flat depth\n"
|
" // flat depth\n"
|
||||||
" lt_p.z = rb_p.z;\n"
|
" lt_p.z = rb_p.z;\n"
|
||||||
" // flat fog and texture perspective\n"
|
" // flat fog and texture perspective\n"
|
||||||
" lt.t.zw = rb.t.zw;\n"
|
" lt.t.zw = rb.t.zw;\n"
|
||||||
" // flat color\n"
|
" // flat color\n"
|
||||||
" lt.c = rb.c;\n"
|
" lt.c = rb.c;\n"
|
||||||
|
"#endif\n"
|
||||||
"\n"
|
"\n"
|
||||||
" // Swap texture and position coordinate\n"
|
" // Swap texture and position coordinate\n"
|
||||||
" vertex lb = rb;\n"
|
" vertex lb = rb;\n"
|
||||||
" lb_p.x = lt_p.x;\n"
|
|
||||||
" lb.t.x = lt.t.x;\n"
|
" lb.t.x = lt.t.x;\n"
|
||||||
" lb.a.x = lt.a.x;\n"
|
" lb_p.x = lt_p.x;\n"
|
||||||
"\n"
|
"\n"
|
||||||
" vertex rt = rb;\n"
|
" vertex rt = rb;\n"
|
||||||
" rt_p.y = lt_p.y;\n"
|
" rt_p.y = lt_p.y;\n"
|
||||||
" rt.t.y = lt.t.y;\n"
|
" rt.t.y = lt.t.y;\n"
|
||||||
" rt.a.y = lt.a.y;\n"
|
"\n"
|
||||||
"\n"
|
"\n"
|
||||||
" // Triangle 1\n"
|
" // Triangle 1\n"
|
||||||
" gl_Position = lt_p;\n"
|
" gl_Position = lt_p;\n"
|
||||||
|
@ -856,7 +870,7 @@ static const char* tfx_vgs_glsl =
|
||||||
" out_vertex(lb);\n"
|
" out_vertex(lb);\n"
|
||||||
"\n"
|
"\n"
|
||||||
" gl_Position = rt_p;\n"
|
" gl_Position = rt_p;\n"
|
||||||
" out_flat(dp);\n"
|
" out_flat();\n"
|
||||||
" out_vertex(rt);\n"
|
" out_vertex(rt);\n"
|
||||||
" EndPrimitive();\n"
|
" EndPrimitive();\n"
|
||||||
"\n"
|
"\n"
|
||||||
|
@ -868,7 +882,7 @@ static const char* tfx_vgs_glsl =
|
||||||
" out_vertex(rt);\n"
|
" out_vertex(rt);\n"
|
||||||
"\n"
|
"\n"
|
||||||
" gl_Position = rb_p;\n"
|
" gl_Position = rb_p;\n"
|
||||||
" out_flat(dp);\n"
|
" out_flat();\n"
|
||||||
" out_vertex(rb);\n"
|
" out_vertex(rb);\n"
|
||||||
" EndPrimitive();\n"
|
" EndPrimitive();\n"
|
||||||
"}\n"
|
"}\n"
|
||||||
|
|
Loading…
Reference in New Issue