2015-04-17 18:18:07 +00:00
|
|
|
//#version 420 // Keep it for text editor detection
|
|
|
|
|
2015-07-11 07:32:27 +00:00
|
|
|
layout(std140, binding = 20) uniform cb20
|
|
|
|
{
|
|
|
|
vec2 VertexScale;
|
|
|
|
vec2 VertexOffset;
|
2015-08-20 19:39:30 +00:00
|
|
|
vec2 _removed_TextureScale;
|
2015-07-11 07:32:27 +00:00
|
|
|
vec2 PointSize;
|
|
|
|
};
|
|
|
|
|
2015-08-20 19:39:30 +00:00
|
|
|
// Warning duplicated in both GLSL file
|
|
|
|
layout(std140, binding = 21) uniform cb21
|
|
|
|
{
|
2015-08-20 22:33:45 +00:00
|
|
|
vec3 FogColor;
|
|
|
|
float AREF;
|
2015-08-20 19:39:30 +00:00
|
|
|
|
2015-08-20 22:33:45 +00:00
|
|
|
vec4 WH;
|
2015-08-20 19:39:30 +00:00
|
|
|
|
2015-08-20 22:33:45 +00:00
|
|
|
vec2 _pad0;
|
|
|
|
vec2 TA;
|
2015-08-20 19:39:30 +00:00
|
|
|
|
2015-08-20 22:33:45 +00:00
|
|
|
uvec4 MskFix;
|
2015-08-20 19:39:30 +00:00
|
|
|
|
2015-08-20 22:33:45 +00:00
|
|
|
uvec4 FbMask;
|
2015-08-20 19:39:30 +00:00
|
|
|
|
2015-08-20 22:33:45 +00:00
|
|
|
vec3 _pad1;
|
|
|
|
float Af;
|
2015-08-20 19:39:30 +00:00
|
|
|
|
2015-08-20 22:33:45 +00:00
|
|
|
vec4 HalfTexel;
|
2015-08-20 19:39:30 +00:00
|
|
|
|
2015-08-20 22:33:45 +00:00
|
|
|
vec4 MinMax;
|
2015-08-20 19:39:30 +00:00
|
|
|
|
2015-08-20 22:33:45 +00:00
|
|
|
vec2 TextureScale;
|
|
|
|
vec2 TC_OffsetHack;
|
2015-08-20 19:39:30 +00:00
|
|
|
};
|
|
|
|
|
2015-04-17 18:18:07 +00:00
|
|
|
#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
|
|
|
|
|
|
|
out SHADER
|
|
|
|
{
|
|
|
|
vec4 t;
|
|
|
|
vec4 c;
|
2015-07-17 17:59:32 +00:00
|
|
|
flat vec4 fc;
|
2015-04-17 18:18:07 +00:00
|
|
|
} VSout;
|
|
|
|
|
|
|
|
#define VSout_t (VSout.t)
|
|
|
|
#define VSout_c (VSout.c)
|
|
|
|
#define VSout_fc (VSout.fc)
|
|
|
|
|
|
|
|
out gl_PerVertex {
|
2015-04-27 16:52:55 +00:00
|
|
|
vec4 gl_Position;
|
2015-04-17 18:18:07 +00:00
|
|
|
float gl_PointSize;
|
|
|
|
#if !pGL_ES
|
2015-08-25 16:57:02 +00:00
|
|
|
float gl_ClipDistance[1];
|
2015-04-17 18:18:07 +00:00
|
|
|
#endif
|
|
|
|
};
|
|
|
|
|
|
|
|
#ifdef ZERO_TO_ONE_DEPTH
|
|
|
|
const float exp_min32 = exp2(-32.0f);
|
|
|
|
#else
|
|
|
|
const float exp_min31 = exp2(-31.0f);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
void texture_coord()
|
|
|
|
{
|
|
|
|
if(VS_TME != 0)
|
|
|
|
{
|
|
|
|
if(VS_FST != 0)
|
|
|
|
{
|
|
|
|
if (VS_WILDHACK == 1) {
|
|
|
|
VSout_t.xy = vec2(i_uv & uvec2(0x3FEF, 0x3FEF)) * TextureScale;
|
|
|
|
} else {
|
|
|
|
VSout_t.xy = vec2(i_uv) * TextureScale;
|
|
|
|
}
|
|
|
|
VSout_t.w = 1.0f;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
VSout_t.xy = i_st;
|
|
|
|
VSout_t.w = i_q;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
VSout_t.xy = vec2(0.0f, 0.0f);
|
|
|
|
VSout_t.w = 1.0f;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void vs_main()
|
|
|
|
{
|
|
|
|
highp uint z;
|
|
|
|
if(VS_BPPZ == 1) // 24
|
|
|
|
z = i_z & uint(0xffffff);
|
|
|
|
else if(VS_BPPZ == 2) // 16
|
|
|
|
z = i_z & uint(0xffff);
|
|
|
|
else
|
|
|
|
z = i_z;
|
|
|
|
|
|
|
|
// 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;
|
|
|
|
#ifdef ZERO_TO_ONE_DEPTH
|
|
|
|
if(VS_LOGZ == 1) {
|
2015-04-26 15:51:33 +00:00
|
|
|
p.z = max(0.0f, log2(float(z))) / 32.0f;
|
2015-04-17 18:18:07 +00:00
|
|
|
} else {
|
|
|
|
p.z = float(z) * exp_min32;
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
if(VS_LOGZ == 1) {
|
2015-04-26 15:51:33 +00:00
|
|
|
p.z = max(0.0f, log2(float(z))) / 31.0f - 1.0f;
|
2015-04-17 18:18:07 +00:00
|
|
|
} else {
|
|
|
|
p.z = float(z) * exp_min31 - 1.0f;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
gl_Position = p;
|
|
|
|
|
|
|
|
texture_coord();
|
|
|
|
|
|
|
|
VSout_c = i_c;
|
2015-07-17 17:59:32 +00:00
|
|
|
VSout_fc = i_c;
|
2015-04-27 16:50:59 +00:00
|
|
|
VSout_t.z = i_f.x;
|
2015-04-17 18:18:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef GEOMETRY_SHADER
|
2015-04-19 16:22:20 +00:00
|
|
|
|
2015-04-17 18:18:07 +00:00
|
|
|
in gl_PerVertex {
|
2015-04-27 16:52:55 +00:00
|
|
|
vec4 gl_Position;
|
2015-04-17 18:18:07 +00:00
|
|
|
float gl_PointSize;
|
|
|
|
#if !pGL_ES
|
2015-08-25 16:57:02 +00:00
|
|
|
float gl_ClipDistance[1];
|
2015-04-17 18:18:07 +00:00
|
|
|
#endif
|
|
|
|
} gl_in[];
|
|
|
|
//in int gl_PrimitiveIDIn;
|
|
|
|
|
|
|
|
out gl_PerVertex {
|
|
|
|
vec4 gl_Position;
|
|
|
|
float gl_PointSize;
|
|
|
|
#if !pGL_ES
|
2015-08-25 16:57:02 +00:00
|
|
|
float gl_ClipDistance[1];
|
2015-04-17 18:18:07 +00:00
|
|
|
#endif
|
|
|
|
};
|
|
|
|
//out int gl_PrimitiveID;
|
|
|
|
|
|
|
|
in SHADER
|
|
|
|
{
|
|
|
|
vec4 t;
|
|
|
|
vec4 c;
|
|
|
|
flat vec4 fc;
|
|
|
|
} GSin[];
|
|
|
|
|
|
|
|
out SHADER
|
|
|
|
{
|
|
|
|
vec4 t;
|
|
|
|
vec4 c;
|
|
|
|
flat vec4 fc;
|
|
|
|
} GSout;
|
|
|
|
|
2015-04-19 16:22:20 +00:00
|
|
|
layout(std140, binding = 22) uniform cb22
|
|
|
|
{
|
|
|
|
vec4 rt_size;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
struct vertex
|
|
|
|
{
|
|
|
|
vec4 t;
|
|
|
|
vec4 c;
|
|
|
|
};
|
|
|
|
|
2015-04-17 18:18:07 +00:00
|
|
|
void out_vertex(in vertex v)
|
|
|
|
{
|
|
|
|
GSout.t = v.t;
|
|
|
|
GSout.c = v.c;
|
|
|
|
gl_PrimitiveID = gl_PrimitiveIDIn;
|
|
|
|
EmitVertex();
|
|
|
|
}
|
|
|
|
|
2015-07-10 22:03:33 +00:00
|
|
|
void out_flat()
|
2015-04-19 16:22:20 +00:00
|
|
|
{
|
|
|
|
// Flat output
|
2015-07-10 22:03:33 +00:00
|
|
|
#if GS_POINT == 1
|
|
|
|
GSout.fc = GSin[0].fc;
|
|
|
|
#else
|
2015-04-19 16:22:20 +00:00
|
|
|
GSout.fc = GSin[1].fc;
|
2015-07-10 22:03:33 +00:00
|
|
|
#endif
|
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
|
2015-04-17 18:18:07 +00:00
|
|
|
layout(triangle_strip, max_vertices = 6) out;
|
|
|
|
|
|
|
|
void gs_main()
|
|
|
|
{
|
|
|
|
// left top => GSin[0];
|
|
|
|
// right bottom => GSin[1];
|
2015-07-10 22:03:33 +00:00
|
|
|
#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);
|
2015-04-17 18:18:07 +00:00
|
|
|
|
2015-07-10 22:03:33 +00:00
|
|
|
#if GS_POINT == 1
|
2015-07-11 07:32:27 +00:00
|
|
|
vec4 rb_p = gl_in[0].gl_Position + vec4(PointSize.x, PointSize.y, 0.0f, 0.0f);
|
2015-07-10 22:03:33 +00:00
|
|
|
#else
|
2015-04-17 18:18:07 +00:00
|
|
|
vec4 rb_p = gl_in[1].gl_Position;
|
2015-07-10 22:03:33 +00:00
|
|
|
#endif
|
|
|
|
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;
|
|
|
|
|
2015-07-10 22:03:33 +00:00
|
|
|
#if GS_POINT == 0
|
2015-04-17 18:18:07 +00:00
|
|
|
// 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;
|
2015-07-10 22:03:33 +00:00
|
|
|
#endif
|
2015-04-17 18:18:07 +00:00
|
|
|
|
2015-07-17 17:59:32 +00:00
|
|
|
// Swap texture and position coordinate
|
2015-04-17 18:18:07 +00:00
|
|
|
vertex lb = rb;
|
|
|
|
lb.t.x = lt.t.x;
|
2015-07-10 22:03:33 +00:00
|
|
|
lb_p.x = lt_p.x;
|
2015-04-17 18:18:07 +00:00
|
|
|
|
|
|
|
vertex rt = rb;
|
|
|
|
rt_p.y = lt_p.y;
|
|
|
|
rt.t.y = lt.t.y;
|
2015-07-10 22:03:33 +00:00
|
|
|
|
2015-04-17 18:18:07 +00:00
|
|
|
|
|
|
|
// Triangle 1
|
|
|
|
gl_Position = lt_p;
|
|
|
|
out_vertex(lt);
|
|
|
|
|
|
|
|
gl_Position = lb_p;
|
|
|
|
out_vertex(lb);
|
|
|
|
|
|
|
|
gl_Position = rt_p;
|
2015-07-10 22:03:33 +00:00
|
|
|
out_flat();
|
2015-04-17 18:18:07 +00:00
|
|
|
out_vertex(rt);
|
|
|
|
EndPrimitive();
|
|
|
|
|
|
|
|
// Triangle 2
|
|
|
|
gl_Position = lb_p;
|
|
|
|
out_vertex(lb);
|
|
|
|
|
|
|
|
gl_Position = rt_p;
|
|
|
|
out_vertex(rt);
|
|
|
|
|
|
|
|
gl_Position = rb_p;
|
2015-07-10 22:03:33 +00:00
|
|
|
out_flat();
|
2015-04-17 18:18:07 +00:00
|
|
|
out_vertex(rb);
|
|
|
|
EndPrimitive();
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|