2011-11-30 21:42:41 +00:00
//#version 420 // Keep it for editor detection
2012-01-02 20:08:11 +00:00
struct vertex_basic
{
vec4 p;
vec2 t;
};
2011-11-30 21:42:41 +00:00
#ifdef VERTEX_SHADER
2011-12-07 22:05:46 +00:00
out gl_PerVertex {
vec4 gl_Position;
float gl_PointSize;
float gl_ClipDistance[];
};
2011-11-30 21:42:41 +00:00
layout(location = 0) in vec4 POSITION;
layout(location = 1) in vec2 TEXCOORD0;
// FIXME set the interpolation (don't know what dx do)
// flat means that there is no interpolation. The value given to the fragment shader is based on the provoking vertex conventions.
//
// noperspective means that there will be linear interpolation in window-space. This is usually not what you want, but it can have its uses.
//
// smooth, the default, means to do perspective-correct interpolation.
//
// The centroid qualifier only matters when multisampling. If this qualifier is not present, then the value is interpolated to the pixel's center, anywhere in the pixel, or to one of the pixel's samples. This sample may lie outside of the actual primitive being rendered, since a primitive can cover only part of a pixel's area. The centroid qualifier is used to prevent this; the interpolation point must fall within both the pixel's area and the primitive's area.
2012-01-02 20:08:11 +00:00
layout(location = 0) out vertex_basic VSout;
2011-11-30 21:42:41 +00:00
void vs_main()
2011-11-21 22:36:03 +00:00
{
2012-01-02 20:08:11 +00:00
VSout.p = POSITION;
VSout.t = TEXCOORD0;
2011-11-30 21:42:41 +00:00
gl_Position = POSITION; // NOTE I don't know if it is possible to merge POSITION_OUT and gl_Position
2011-11-21 22:36:03 +00:00
}
2011-11-30 21:42:41 +00:00
#endif
2011-11-21 22:36:03 +00:00
2011-11-30 21:42:41 +00:00
#ifdef FRAGMENT_SHADER
// NOTE: pixel can be clip with "discard"
2011-11-21 22:36:03 +00:00
2012-01-02 20:08:11 +00:00
layout(location = 0) in vertex_basic PSin;
2011-11-21 22:36:03 +00:00
2011-12-07 22:05:46 +00:00
layout(location = 0) out vec4 SV_Target0;
2011-12-29 14:24:26 +00:00
layout(location = 1) out uint SV_Target1;
2011-11-21 22:36:03 +00:00
2011-11-30 21:42:41 +00:00
layout(binding = 0) uniform sampler2D TextureSampler;
2011-11-21 22:36:03 +00:00
2011-12-11 19:09:08 +00:00
vec4 sample_c()
2011-11-21 22:36:03 +00:00
{
2012-01-02 20:08:11 +00:00
return texture(TextureSampler, PSin.t );
2011-11-21 22:36:03 +00:00
}
2011-12-11 19:09:08 +00:00
vec4 ps_crt(uint i)
2011-11-21 22:36:03 +00:00
{
2011-11-30 21:42:41 +00:00
vec4 mask[4] =
2011-11-21 22:36:03 +00:00
{
2011-11-30 21:42:41 +00:00
vec4(1, 0, 0, 0),
vec4(0, 1, 0, 0),
vec4(0, 0, 1, 0),
vec4(1, 1, 1, 0)
2011-11-21 22:36:03 +00:00
};
2011-12-11 19:09:08 +00:00
return sample_c() * clamp((mask[i] + 0.5f), 0.0f, 1.0f);
2011-11-21 22:36:03 +00:00
}
2011-11-30 21:42:41 +00:00
void ps_main0()
2011-11-21 22:36:03 +00:00
{
2011-12-11 19:09:08 +00:00
SV_Target0 = sample_c();
2011-11-21 22:36:03 +00:00
}
2011-12-29 14:24:26 +00:00
void ps_main1()
{
vec4 c = sample_c();
c.a *= 256.0f / 127.0f; // hm, 0.5 won't give us 1.0 if we just multiply with 2
2012-05-26 09:58:37 +00:00
highp uvec4 i = uvec4(c * vec4(uint(0x001f), uint(0x03e0), uint(0x7c00), uint(0x8000)));
2011-12-29 14:24:26 +00:00
2012-01-04 11:14:57 +00:00
SV_Target1 = (i.x & uint(0x001f)) | (i.y & uint(0x03e0)) | (i.z & uint(0x7c00)) | (i.w & uint(0x8000));
2011-12-29 14:24:26 +00:00
}
2011-11-30 21:42:41 +00:00
void ps_main7()
2011-11-21 22:36:03 +00:00
{
2011-12-11 19:09:08 +00:00
vec4 c = sample_c();
2011-11-21 22:36:03 +00:00
2011-11-30 21:42:41 +00:00
c.a = dot(c.rgb, vec3(0.299, 0.587, 0.114));
2011-11-21 22:36:03 +00:00
2011-11-30 21:42:41 +00:00
SV_Target0 = c;
2011-11-21 22:36:03 +00:00
}
2011-11-30 21:42:41 +00:00
void ps_main5() // triangular
2011-11-21 22:36:03 +00:00
{
2012-01-02 20:08:11 +00:00
highp uvec4 p = uvec4(PSin.p);
2011-11-21 22:36:03 +00:00
2011-12-11 19:09:08 +00:00
vec4 c = ps_crt(((p.x + ((p.y >> 1u) & 1u) * 3u) >> 1u) % 3u);
2011-11-21 22:36:03 +00:00
2011-11-30 21:42:41 +00:00
SV_Target0 = c;
2011-11-21 22:36:03 +00:00
}
2011-11-30 21:42:41 +00:00
void ps_main6() // diagonal
2011-11-21 22:36:03 +00:00
{
2012-01-02 20:08:11 +00:00
uvec4 p = uvec4(PSin.p);
2011-11-21 22:36:03 +00:00
2012-01-04 11:14:57 +00:00
vec4 c = ps_crt((p.x + (p.y % 3u)) % 3u);
2011-11-21 22:36:03 +00:00
2011-11-30 21:42:41 +00:00
SV_Target0 = c;
2011-11-21 22:36:03 +00:00
}
2011-11-30 21:42:41 +00:00
2011-12-08 16:39:14 +00:00
void ps_main2()
{
2012-01-31 17:08:05 +00:00
if((sample_c().a - 128.0f / 255) < 0) // >= 0x80 pass
discard;
SV_Target0 = vec4(0.0f, 0.0f, 0.0f, 0.0f);
2011-12-08 16:39:14 +00:00
}
void ps_main3()
{
2012-01-31 17:08:05 +00:00
if((127.95f / 255 - sample_c().a) <0) // < 0x80 pass (== 0x80 should not pass)
discard;
SV_Target0 = vec4(0.0f, 0.0f, 0.0f, 0.0f);
2011-12-08 16:39:14 +00:00
}
void ps_main4()
{
2012-01-31 17:08:05 +00:00
// FIXME mod and fmod are different when value are negative
// output.c = fmod(sample_c(input.t) * 255 + 0.5f, 256) / 255;
vec4 c = mod(sample_c() * 255 + 0.5f, 256) / 255;
2011-12-08 16:39:14 +00:00
2012-01-31 17:08:05 +00:00
SV_Target0 = c;
}
2011-11-30 21:42:41 +00:00
2011-11-21 22:36:03 +00:00
#endif