2015-04-17 18:18:07 +00:00
|
|
|
//#version 420 // Keep it for text editor detection
|
|
|
|
|
|
|
|
#ifdef VERTEX_SHADER
|
|
|
|
layout(location = 0) in vec2 i_st;
|
|
|
|
layout(location = 2) in vec4 i_c;
|
|
|
|
layout(location = 3) in float i_q;
|
|
|
|
layout(location = 4) in uvec2 i_p;
|
|
|
|
layout(location = 5) in uint i_z;
|
|
|
|
layout(location = 6) in uvec2 i_uv;
|
2015-04-27 16:50:59 +00:00
|
|
|
layout(location = 7) in vec4 i_f;
|
2015-04-17 18:18:07 +00:00
|
|
|
|
2016-10-23 10:24:59 +00:00
|
|
|
#if !defined(BROKEN_DRIVER) && defined(GL_ARB_enhanced_layouts) && GL_ARB_enhanced_layouts
|
2016-10-19 21:03:39 +00:00
|
|
|
layout(location = 0)
|
|
|
|
#endif
|
2015-04-17 18:18:07 +00:00
|
|
|
out SHADER
|
|
|
|
{
|
2016-02-17 21:49:05 +00:00
|
|
|
vec4 t_float;
|
|
|
|
vec4 t_int;
|
2021-12-23 11:35:05 +00:00
|
|
|
#if VS_IIP != 0
|
|
|
|
vec4 c;
|
|
|
|
#else
|
|
|
|
flat vec4 c;
|
|
|
|
#endif
|
2015-04-17 18:18:07 +00:00
|
|
|
} VSout;
|
|
|
|
|
|
|
|
const float exp_min32 = exp2(-32.0f);
|
|
|
|
|
|
|
|
void texture_coord()
|
|
|
|
{
|
2021-11-16 04:46:38 +00:00
|
|
|
vec2 uv = vec2(i_uv) - TextureOffset;
|
|
|
|
vec2 st = i_st - TextureOffset;
|
2016-02-21 10:48:30 +00:00
|
|
|
|
2016-02-17 21:49:05 +00:00
|
|
|
// Float coordinate
|
2017-07-02 16:54:43 +00:00
|
|
|
VSout.t_float.xy = st;
|
2016-02-17 21:49:05 +00:00
|
|
|
VSout.t_float.w = i_q;
|
|
|
|
|
2016-02-21 10:48:30 +00:00
|
|
|
// Integer coordinate => normalized
|
|
|
|
VSout.t_int.xy = uv * TextureScale;
|
2017-07-02 16:54:43 +00:00
|
|
|
#if VS_INT_FST == 1
|
|
|
|
// Some games uses float coordinate for post-processing effect
|
|
|
|
VSout.t_int.zw = st / TextureScale;
|
|
|
|
#else
|
2016-02-21 10:48:30 +00:00
|
|
|
// Integer coordinate => integral
|
|
|
|
VSout.t_int.zw = uv;
|
2017-07-02 16:54:43 +00:00
|
|
|
#endif
|
2015-04-17 18:18:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void vs_main()
|
|
|
|
{
|
2020-05-23 18:37:51 +00:00
|
|
|
// Clamp to max depth, gs doesn't wrap
|
|
|
|
highp uint z = min(i_z, MaxDepth);
|
2015-04-17 18:18:07 +00:00
|
|
|
|
|
|
|
// pos -= 0.05 (1/320 pixel) helps avoiding rounding problems (integral part of pos is usually 5 digits, 0.05 is about as low as we can go)
|
|
|
|
// example: ceil(afterseveralvertextransformations(y = 133)) => 134 => line 133 stays empty
|
|
|
|
// input granularity is 1/16 pixel, anything smaller than that won't step drawing up/left by one pixel
|
|
|
|
// example: 133.0625 (133 + 1/16) should start from line 134, ceil(133.0625 - 0.05) still above 133
|
|
|
|
vec4 p;
|
|
|
|
|
|
|
|
p.xy = vec2(i_p) - vec2(0.05f, 0.05f);
|
|
|
|
p.xy = p.xy * VertexScale - VertexOffset;
|
|
|
|
p.w = 1.0f;
|
2016-04-07 19:57:54 +00:00
|
|
|
p.z = float(z) * exp_min32;
|
2015-04-17 18:18:07 +00:00
|
|
|
|
|
|
|
gl_Position = p;
|
|
|
|
|
|
|
|
texture_coord();
|
|
|
|
|
2016-04-24 08:54:39 +00:00
|
|
|
VSout.c = i_c;
|
2016-02-17 21:49:05 +00:00
|
|
|
VSout.t_float.z = i_f.x; // pack for with texture
|
2021-12-30 05:25:12 +00:00
|
|
|
|
|
|
|
#if VS_POINT_SIZE
|
|
|
|
gl_PointSize = float(VS_POINT_SIZE_VALUE);
|
|
|
|
#endif
|
2015-04-17 18:18:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef GEOMETRY_SHADER
|
2015-04-19 16:22:20 +00:00
|
|
|
|
2016-10-23 10:24:59 +00:00
|
|
|
#if !defined(BROKEN_DRIVER) && defined(GL_ARB_enhanced_layouts) && GL_ARB_enhanced_layouts
|
2016-10-19 21:03:39 +00:00
|
|
|
layout(location = 0)
|
|
|
|
#endif
|
2015-04-17 18:18:07 +00:00
|
|
|
in SHADER
|
|
|
|
{
|
2016-02-17 21:49:05 +00:00
|
|
|
vec4 t_float;
|
|
|
|
vec4 t_int;
|
2021-12-23 11:35:05 +00:00
|
|
|
#if GS_IIP != 0
|
|
|
|
vec4 c;
|
|
|
|
#else
|
|
|
|
flat vec4 c;
|
|
|
|
#endif
|
2015-04-17 18:18:07 +00:00
|
|
|
} GSin[];
|
|
|
|
|
2016-10-23 10:24:59 +00:00
|
|
|
#if !defined(BROKEN_DRIVER) && defined(GL_ARB_enhanced_layouts) && GL_ARB_enhanced_layouts
|
2016-10-19 21:03:39 +00:00
|
|
|
layout(location = 0)
|
|
|
|
#endif
|
2015-04-17 18:18:07 +00:00
|
|
|
out SHADER
|
|
|
|
{
|
2016-02-17 21:49:05 +00:00
|
|
|
vec4 t_float;
|
|
|
|
vec4 t_int;
|
2021-12-23 11:35:05 +00:00
|
|
|
#if GS_IIP != 0
|
|
|
|
vec4 c;
|
|
|
|
#else
|
|
|
|
flat vec4 c;
|
|
|
|
#endif
|
2015-04-17 18:18:07 +00:00
|
|
|
} GSout;
|
|
|
|
|
2015-04-19 16:22:20 +00:00
|
|
|
struct vertex
|
|
|
|
{
|
2016-02-17 21:49:05 +00:00
|
|
|
vec4 t_float;
|
|
|
|
vec4 t_int;
|
2015-04-19 16:22:20 +00:00
|
|
|
vec4 c;
|
|
|
|
};
|
|
|
|
|
2017-07-02 20:37:24 +00:00
|
|
|
void out_vertex(in vec4 position, in vertex v)
|
2015-04-17 18:18:07 +00:00
|
|
|
{
|
2016-02-17 21:49:05 +00:00
|
|
|
GSout.t_float = v.t_float;
|
|
|
|
GSout.t_int = v.t_int;
|
2015-04-19 16:22:20 +00:00
|
|
|
// Flat output
|
2015-07-10 22:03:33 +00:00
|
|
|
#if GS_POINT == 1
|
2021-12-23 11:35:05 +00:00
|
|
|
GSout.c = GSin[0].c;
|
2015-07-10 22:03:33 +00:00
|
|
|
#else
|
2021-12-23 11:35:05 +00:00
|
|
|
GSout.c = GSin[1].c;
|
2015-07-10 22:03:33 +00:00
|
|
|
#endif
|
2017-07-02 20:37:24 +00:00
|
|
|
gl_Position = position;
|
2016-02-17 21:49:05 +00:00
|
|
|
gl_PrimitiveID = gl_PrimitiveIDIn;
|
|
|
|
EmitVertex();
|
2015-04-19 16:22:20 +00:00
|
|
|
}
|
|
|
|
|
2015-07-10 22:03:33 +00:00
|
|
|
#if GS_POINT == 1
|
|
|
|
layout(points) in;
|
|
|
|
#else
|
2015-04-17 18:18:07 +00:00
|
|
|
layout(lines) in;
|
2015-07-10 22:03:33 +00:00
|
|
|
#endif
|
2017-07-02 20:37:24 +00:00
|
|
|
layout(triangle_strip, max_vertices = 4) out;
|
2015-04-17 18:18:07 +00:00
|
|
|
|
2016-08-21 16:34:03 +00:00
|
|
|
#if GS_POINT == 1
|
|
|
|
|
|
|
|
void gs_main()
|
|
|
|
{
|
|
|
|
// Transform a point to a NxN sprite
|
|
|
|
vertex point = vertex(GSin[0].t_float, GSin[0].t_int, GSin[0].c);
|
|
|
|
|
|
|
|
// Get new position
|
|
|
|
vec4 lt_p = gl_in[0].gl_Position;
|
|
|
|
vec4 rb_p = gl_in[0].gl_Position + vec4(PointSize.x, PointSize.y, 0.0f, 0.0f);
|
|
|
|
vec4 lb_p = rb_p;
|
|
|
|
vec4 rt_p = rb_p;
|
|
|
|
lb_p.x = lt_p.x;
|
|
|
|
rt_p.y = lt_p.y;
|
|
|
|
|
2017-07-02 20:37:24 +00:00
|
|
|
out_vertex(lt_p, point);
|
2016-08-21 16:34:03 +00:00
|
|
|
|
2017-07-02 20:37:24 +00:00
|
|
|
out_vertex(lb_p, point);
|
2016-08-21 16:34:03 +00:00
|
|
|
|
2017-07-02 20:37:24 +00:00
|
|
|
out_vertex(rt_p, point);
|
2016-08-21 16:34:03 +00:00
|
|
|
|
2017-07-02 20:37:24 +00:00
|
|
|
out_vertex(rb_p, point);
|
2016-08-21 16:34:03 +00:00
|
|
|
|
|
|
|
EndPrimitive();
|
|
|
|
}
|
|
|
|
|
2016-08-16 21:42:35 +00:00
|
|
|
#elif GS_LINE == 1
|
|
|
|
|
|
|
|
void gs_main()
|
|
|
|
{
|
|
|
|
// Transform a line to a thick line-sprite
|
|
|
|
vertex left = vertex(GSin[0].t_float, GSin[0].t_int, GSin[0].c);
|
2020-07-31 11:33:04 +00:00
|
|
|
vertex right = vertex(GSin[1].t_float, GSin[1].t_int, GSin[1].c);
|
2016-08-16 21:42:35 +00:00
|
|
|
vec4 lt_p = gl_in[0].gl_Position;
|
|
|
|
vec4 rt_p = gl_in[1].gl_Position;
|
|
|
|
|
|
|
|
// Potentially there is faster math
|
|
|
|
vec2 line_vector = normalize(rt_p.xy - lt_p.xy);
|
|
|
|
vec2 line_normal = vec2(line_vector.y, -line_vector.x);
|
2020-07-31 11:33:04 +00:00
|
|
|
vec2 line_width = (line_normal * PointSize) / 2;
|
2016-08-16 21:42:35 +00:00
|
|
|
|
2020-07-31 11:33:04 +00:00
|
|
|
lt_p.xy -= line_width;
|
|
|
|
rt_p.xy -= line_width;
|
2016-08-16 21:42:35 +00:00
|
|
|
vec4 lb_p = gl_in[0].gl_Position + vec4(line_width, 0.0f, 0.0f);
|
|
|
|
vec4 rb_p = gl_in[1].gl_Position + vec4(line_width, 0.0f, 0.0f);
|
|
|
|
|
2017-07-02 20:37:24 +00:00
|
|
|
out_vertex(lt_p, left);
|
2016-08-16 21:42:35 +00:00
|
|
|
|
2017-07-02 20:37:24 +00:00
|
|
|
out_vertex(lb_p, left);
|
2016-08-16 21:42:35 +00:00
|
|
|
|
2017-07-02 20:37:24 +00:00
|
|
|
out_vertex(rt_p, right);
|
2016-08-16 21:42:35 +00:00
|
|
|
|
2017-07-02 20:37:24 +00:00
|
|
|
out_vertex(rb_p, right);
|
2016-08-16 21:42:35 +00:00
|
|
|
|
|
|
|
EndPrimitive();
|
|
|
|
}
|
|
|
|
|
2016-08-21 16:34:03 +00:00
|
|
|
#else
|
|
|
|
|
2015-04-17 18:18:07 +00:00
|
|
|
void gs_main()
|
|
|
|
{
|
|
|
|
// left top => GSin[0];
|
|
|
|
// right bottom => GSin[1];
|
2016-02-17 21:49:05 +00:00
|
|
|
vertex rb = vertex(GSin[1].t_float, GSin[1].t_int, GSin[1].c);
|
|
|
|
vertex lt = vertex(GSin[0].t_float, GSin[0].t_int, GSin[0].c);
|
2015-04-17 18:18:07 +00:00
|
|
|
|
|
|
|
vec4 rb_p = gl_in[1].gl_Position;
|
2015-07-10 22:03:33 +00:00
|
|
|
vec4 lb_p = rb_p;
|
|
|
|
vec4 rt_p = rb_p;
|
2015-04-17 18:18:07 +00:00
|
|
|
vec4 lt_p = gl_in[0].gl_Position;
|
|
|
|
|
|
|
|
// flat depth
|
|
|
|
lt_p.z = rb_p.z;
|
|
|
|
// flat fog and texture perspective
|
2016-02-17 21:49:05 +00:00
|
|
|
lt.t_float.zw = rb.t_float.zw;
|
2015-04-17 18:18:07 +00:00
|
|
|
// flat color
|
|
|
|
lt.c = rb.c;
|
|
|
|
|
2015-07-17 17:59:32 +00:00
|
|
|
// Swap texture and position coordinate
|
2016-02-21 10:48:30 +00:00
|
|
|
vertex lb = rb;
|
|
|
|
lb.t_float.x = lt.t_float.x;
|
|
|
|
lb.t_int.x = lt.t_int.x;
|
|
|
|
lb.t_int.z = lt.t_int.z;
|
|
|
|
lb_p.x = lt_p.x;
|
|
|
|
|
|
|
|
vertex rt = rb;
|
|
|
|
rt_p.y = lt_p.y;
|
|
|
|
rt.t_float.y = lt.t_float.y;
|
|
|
|
rt.t_int.y = lt.t_int.y;
|
|
|
|
rt.t_int.w = lt.t_int.w;
|
2015-04-17 18:18:07 +00:00
|
|
|
|
2017-07-02 20:37:24 +00:00
|
|
|
out_vertex(lt_p, lt);
|
2015-04-17 18:18:07 +00:00
|
|
|
|
2017-07-02 20:37:24 +00:00
|
|
|
out_vertex(lb_p, lb);
|
2015-04-17 18:18:07 +00:00
|
|
|
|
2017-07-02 20:37:24 +00:00
|
|
|
out_vertex(rt_p, rt);
|
2015-04-17 18:18:07 +00:00
|
|
|
|
2017-07-02 20:37:24 +00:00
|
|
|
out_vertex(rb_p, rb);
|
2015-04-17 18:18:07 +00:00
|
|
|
|
|
|
|
EndPrimitive();
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
2016-08-21 16:34:03 +00:00
|
|
|
|
|
|
|
#endif
|