Compiles on MacOS; use sokol shader converter for shader x-compilation; update sokol

This commit is contained in:
2023-09-15 08:37:07 +00:00
parent e392f65485
commit d86133a317
56 changed files with 10528 additions and 8266 deletions

View File

@@ -1,5 +1,29 @@
#version 330
@vs vs9
in vec2 vert;
in vec2 vuv;
in vec4 vborder;
in vec2 vscale;
in vec4 vcolor;
out vec2 uv;
out vec4 border;
out vec2 scale;
out vec4 fcolor;
uniform vs9_params { mat4 projection; };
void main()
{
gl_Position = projection * vec4(vert, 0.0, 1.0);
uv = vuv;
border = vborder;
scale = vscale;
fcolor = vcolor;
}
@end
@fs fs9
in vec2 uv; /* image uv */
in vec4 border; /* uv length of border, normalized to image dimensions; left, bottom, right, top */
in vec2 scale; /* polygon dimensions ~ texture dimensions */
@@ -7,7 +31,8 @@ in vec4 fcolor;
out vec4 color;
uniform sampler2D image;
uniform texture2D image;
uniform sampler smp;
float map(float value, float min1, float max1, float min2, float max2)
{
@@ -33,5 +58,8 @@ vec2 uv9slice(vec2 uv, vec2 s, vec4 b)
void main()
{
vec2 nuv = uv9slice(uv, scale, border);
color = fcolor * texture(image, uv);
color = fcolor * texture(sampler2D(image,smp), uv);
}
@end
@program slice9 vs9 fs9

View File

@@ -1,30 +0,0 @@
#version 330 core
in vec2 TexCoords;
out vec4 frag_color;
uniform sampler2D diffuse_texture;
float[] kernel = float[9](1.0/9.0,1.0/9.0,1.0/9.0,
1.0/9.0,1.0/9.0,1.0/9.0,
1.0/9.0,1.0/9.0,1.0/9.0);
void main()
{
frag_color = texture(diffuse_texture, TexCoords);
return;
vec2 res = vec2(640,360);
vec2 uv = gl_FragCoord.xy;
vec2 screen = textureSize(diffuse_texture,0);
vec3 acc = vec3(0);
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
vec2 realRes = uv + vec2(i-1,j-1);
acc += texture(diffuse_texture, realRes / res).rgb * kernel[i*3+j];
}
}
frag_color = vec4(acc,1);
}

27
source/shaders/box.sglsl Normal file
View File

@@ -0,0 +1,27 @@
@vs bvs
in vec2 aPos;
in vec2 aTexCoords;
out vec2 TexCoords;
void main()
{
gl_Position = vec4(aPos.x, aPos.y, 0.0, 1.0);
TexCoords = aTexCoords;
}
@end
@fs bfs
in vec2 TexCoords;
out vec4 frag_color;
uniform texture2D diffuse;
uniform sampler smp;
void main()
{
frag_color = texture(sampler2D(diffuse,smp), TexCoords);
}
@end
@program box bvs bfs

View File

@@ -1,15 +1,39 @@
#version 330
in vec2 coords;
@vs circle_vs
in vec2 vertex;
in vec2 apos;
in float aradius;
in vec4 acolor;
in float asegsize;
in float afill;
out vec2 coords;
out vec4 fcolor;
out float segsize;
out float fill;
out float radius;
uniform cvs_params { mat4 proj; };
void main()
{
gl_Position = proj * vec4((vertex * aradius) + apos, 0.0, 1.0);
coords = vertex;
fcolor = acolor;
segsize = asegsize;
fill = afill;
radius = aradius;
}
@end
@fs circle_fs
out vec4 color;
in float radius;
in vec2 coords;
in vec4 fcolor;
in vec2 pos;
in float segsize;
in float fill;
in float radius;
#define PI 3.14
@@ -36,3 +60,7 @@ void main()
if (mod(f, segsize) < segsize/2)
discard;
}
@end
@program circle circle_vs circle_fs

View File

@@ -1,27 +0,0 @@
#version 330 core
layout (location = 0) in vec2 vertex;
layout (location = 1) in vec2 apos;
layout (location = 2) in float aradius;
layout (location = 3) in vec4 acolor;
layout (location = 4) in float asegsize;
layout (location = 5) in float afill;
out vec2 coords;
out vec4 fcolor;
out float segsize;
out float fill;
out float radius;
uniform mat4 proj;
void main()
{
gl_Position = proj * vec4((vertex * aradius) + apos, 0.0, 1.0);
coords = vertex;
fcolor = acolor;
segsize = asegsize;
fill = afill;
radius = aradius;
}

View File

@@ -1,17 +1,30 @@
#version 330 core
in vec2 TexCoords;
@vs vs
in vec2 aPos;
in vec2 aTexCoords;
out vec4 frag_color;
uniform sampler2D diffuse_texture;
out vec2 TexCoords;
void main()
{
frag_color = texture(diffuse_texture, TexCoords);
gl_Position = vec4(aPos.x, aPos.y, 0.0, 1.0);
TexCoords = aTexCoords;
}
@end
@fs fs
in vec2 TexCoords;
out vec4 frag_color;
uniform texture2D diffuse;
uniform sampler smp;
void main()
{
frag_color = texture(sampler2D(diffuse,smp), TexCoords);
return;
vec2 screensize = textureSize(diffuse_texture,0);
/* vec2 screensize = textureSize(diffuse,0);
vec4 color = texture(diffuse_texture, TexCoords);
vec4 color = texture(sampler2D(diffuse,smp), TexCoords);
float avg = 0.2126 * color.r + 0.7152 * color.g + 0.0722 * color.b;
frag_color = vec4(avg,avg,avg,1.0);
float lc = screensize.y/2.0;
@@ -26,4 +39,8 @@ void main()
float b = color.b;
frag_color = vec4(r, g*0.99, b, 1.0) * clamp(line_intensity, 0.85, 1.0);
*/
}
@end
@program crt vs fs

View File

@@ -1,4 +1,31 @@
#version 330 core
@vs vs
in vec3 a_pos;
in vec2 a_tex_coords;
in vec3 a_norm;
out vec2 tex_coords;
out vec3 normal;
out vec3 frag_pos;
out vec4 frag_pos_light;
uniform vs_p {
uniform mat4 vp;
uniform mat4 model;
uniform mat4 proj;
uniform mat4 lsm;
};
void main() {
frag_pos = vec3(model * vec4(a_pos, 1.0));
gl_Position = proj * vp * vec4(frag_pos, 1.0);
tex_coords = a_tex_coords;
normal = mat3(transpose(inverse(model))) * a_norm;
frag_pos_light = lsm * vec4(frag_pos, 1.0);
}
@end
@fs fs
in vec2 tex_coords;
in vec3 normal;
in vec3 frag_pos;
@@ -6,16 +33,19 @@ in vec4 frag_pos_light;
out vec4 frag_color;
uniform sampler2D diffuse;
uniform sampler2D normmap;
uniform sampler2D shadow_map;
uniform texture2D diffuse;
uniform texture2D normmap;
uniform texture2D shadow_map;
uniform sampler smp;
uniform fs_p {
uniform vec3 point_pos;
uniform vec3 dir_dir;
uniform vec3 view_pos;
uniform vec3 spot_pos;
uniform vec3 spot_dir;
uniform vec2 shadow_dim;
};
/* Ambient light */
float amb_str = 0.3;
@@ -52,7 +82,7 @@ float shadow_calc(vec4 fg)
if (pc.z > 1.0)
return 0.0;
float closest_depth = texture(shadow_map, pc.xy).r;
float closest_depth = texture(sampler2D(shadow_map,smp), pc.xy).r;
float cur_depth = pc.z;
vec3 light_dir = normalize(vec3(4,100,20) - frag_pos); /* light pos */
@@ -61,11 +91,11 @@ float shadow_calc(vec4 fg)
return cur_depth - bias > closest_depth ? 1.0 : 0.0;
float s;
vec2 texel_size = 1 / textureSize(shadow_map, 0);
vec2 texel_size = 1 / shadow_dim;
for (int x = -1; x <= 1; ++x) {
for (int y = -1; y <= 1; ++y) {
float pcf_depth = texture(shadow_map, pc.xy + vec2(x,y) * texel_size).r;
float pcf_depth = texture(sampler2D(shadow_map,smp), pc.xy + vec2(x,y) * texel_size).r;
s += cur_depth - bias > pcf_depth ? 1.0 : 0.0;
}
}
@@ -97,8 +127,11 @@ void main() {
spot_amt = light_str(spot_dir) * intensity;
}
vec4 mm = texture(diffuse,tex_coords);
vec4 mm = texture(sampler2D(diffuse,smp),tex_coords);
float shadow = shadow_calc(frag_pos_light);
vec3 res = mm.rgb * (amb_str + (point_amt + dir_amt) * (1 - shadow));
frag_color = vec4(res, mm.a);
}
@end
@program diffuse vs fs

View File

@@ -1,23 +0,0 @@
#version 330 core
layout (location=0) in vec3 a_pos;
layout (location=1) in vec2 a_tex_coords;
layout (location=2) in vec3 a_norm;
out vec2 tex_coords;
out vec3 normal;
out vec3 frag_pos;
out vec4 frag_pos_light;
uniform mat4 vp;
uniform mat4 model;
uniform mat4 proj;
uniform mat4 lsm;
void main() {
frag_pos = vec3(model * vec4(a_pos, 1.0));
gl_Position = proj * vp * vec4(frag_pos, 1.0);
tex_coords = a_tex_coords;
normal = mat3(transpose(inverse(model))) * a_norm;
frag_pos_light = lsm * vec4(frag_pos, 1.0);
}

49
source/shaders/grid.sglsl Normal file
View File

@@ -0,0 +1,49 @@
@vs vs
in vec2 pos;
out vec2 apos;
uniform mpara {
uniform vec2 offset;
uniform vec2 dimen;
};
void main()
{
apos = ((pos*0.5)*dimen) + offset;
gl_Position = vec4(pos, 0.f, 1.f);
}
@end
@fs fs
out vec4 frag_color;
in vec2 apos;
uniform fs_params {
uniform float thickness;
uniform float span;
uniform vec4 color;
};
void main()
{
float t = thickness / span;
t /= 2.0;
vec2 bpos;
bpos.x = mod(apos.x, span) / span;
bpos.y = mod(apos.y, span) / span;
bpos.x -= t;
bpos.y -= t;
float comp = min(bpos.x, bpos.y);
if (comp > t)
discard;
comp += t;
frag_color = color;
}
@end
@program grid vs fs

View File

@@ -1,28 +0,0 @@
#version 330
out vec4 frag_color;
in vec2 apos; /* Drawing coordinates of the grid */
uniform float thickness; /* thickness in pixels */
uniform float span;
uniform vec4 color;
void main(void)
{
float t = thickness / span;
t /= 2.0;
vec2 bpos;
bpos.x = mod(apos.x, span) / span;
bpos.y = mod(apos.y, span) / span;
bpos.x -= t;
bpos.y -= t;
float comp = min(bpos.x, bpos.y);
if (comp > t)
discard;
comp += t;
frag_color = color;
}

View File

@@ -1,18 +0,0 @@
#version 330
layout (location = 0) in vec2 pos;
out vec2 apos;
layout (std140) uniform Projection {
mat4 projection;
};
uniform vec2 offset;
uniform vec2 dimen;
void main()
{
apos = ((pos*0.5)*dimen) + offset;
gl_Position = vec4(pos, 0.f, 1.f);
}

View File

@@ -1,16 +1,40 @@
#version 330
@vs lvs
in vec2 apos;
in float adist;
in vec4 acolor;
in float aseglen;
in float asegspeed;
out float dist;
out vec4 fcolor;
out float seg_len;
out float seg_speed;
uniform lvs_params { mat4 proj; };
void main()
{
gl_Position = proj * vec4(apos, 0.0, 1.0);
fcolor = acolor;
dist = adist;
seg_len = aseglen;
seg_speed = asegspeed;
}
@end
@fs lfs
out vec4 color;
in float dist;
in vec4 fcolor;
in float seg_len;
in float seg_speed;
in float seg_len;
float pat = 0.5;
int pp = 0x0C24;
uniform float time;
uniform lfs_params { uniform float time; };
void main()
{
@@ -34,3 +58,6 @@ void main()
discard;
*/
}
@end
@program line lvs lfs

View File

@@ -1,22 +0,0 @@
#version 330
layout (location = 0) in vec2 apos;
layout (location = 1) in float adist;
layout (location = 2) in vec4 acolor;
layout (location = 3) in float aseglen;
layout (location = 4) in float asegspeed;
out float dist;
out vec4 fcolor;
out float seg_len;
out float seg_speed;
uniform mat4 proj;
void main()
{
gl_Position = proj * vec4(apos, 0.f, 1.f);
fcolor = acolor;
dist = adist;
seg_len = aseglen;
seg_speed = asegspeed;
}

View File

@@ -0,0 +1,40 @@
@vs vs
in vec4 vertex;
out vec2 TexCoords;
uniform vs_p { mat4 model; mat4 projection; };
void main()
{
TexCoords = vec2(vertex.x, 1.0 - vertex.y);
gl_Position = projection * model * vec4(vertex.xy, 0.0, 1.0);
}
@end
@fs fs
in vec2 TexCoords;
out vec4 color;
uniform texture2D texture_y;
uniform texture2D texture_cb;
uniform texture2D texture_cr;
uniform sampler smp;
mat4 rec601 = mat4(
1.16438, 0.00000, 1.59603, -0.87079,
1.16438, -0.39176, -0.81297, 0.52959,
1.16438, 2.01723, 0.00000, -1.08139,
0, 0, 0, 1
);
void main()
{
float y = texture(sampler2D(texture_y,smp), TexCoords).r;
float cb = texture(sampler2D(texture_cb,smp), TexCoords).r;
float cr = texture(sampler2D(texture_cr,smp), TexCoords).r;
color = vec4(y, cb, cr, 1.f) * rec601;
}
@end
@program mpeg2 vs fs

View File

@@ -0,0 +1,34 @@
@vs pointvs
in vec2 apos;
in vec4 acolor;
in float aradius;
uniform pvs_p { mat4 proj; };
out vec4 fcolor;
void main()
{
gl_Position = proj * vec4(apos, 0.0, 1.0);
fcolor = acolor;
gl_PointSize = aradius;
}
@end
@fs pointfs
out vec4 color;
in vec4 fcolor;
void main()
{
float d = length(gl_FragCoord.xy - vec2(0.5,0.5)); /* Should really pointcoord, normalized */
if (d >= 0.47)
discard;
color = fcolor;
}
@end
@program point pointvs pointfs

View File

@@ -1,13 +0,0 @@
#version 330 core
in vec4 fcolor;
out vec4 color;
void main()
{
float d = length(gl_PointCoord - vec2(0.5,0.5));
if (d >= 0.47)
discard;
color = fcolor;
}

View File

@@ -1,16 +0,0 @@
#version 330 core
layout (location = 0) in vec2 apos;
layout (location = 1) in vec4 acolor;
layout (location = 2) in float radius;
uniform mat4 proj;
out vec4 fcolor;
void main()
{
gl_Position = proj * vec4(apos, 0.0, 1.0);
fcolor = acolor;
gl_PointSize = radius;
}

View File

@@ -1,4 +1,4 @@
#version 330 core
@vs pvs
in vec2 apos;
in vec2 auv;
in vec4 acolor;
@@ -6,7 +6,7 @@ in vec4 acolor;
out vec4 color;
out vec2 uv;
uniform mat4 proj;
uniform pvs_params { mat4 proj; };
void main()
{
@@ -14,3 +14,17 @@ void main()
color = acolor;
uv = auv;
}
@end
@fs pfs
in vec4 color;
in vec2 uv;
out vec4 fcolor;
void main()
{
fcolor = color;
}
@end
@program poly pvs pfs

View File

@@ -1,10 +0,0 @@
#version 330 core
out vec4 fcolor;
in vec4 color;
in vec2 uv;
void main()
{
fcolor = color;
}

View File

@@ -1,58 +0,0 @@
#version 330 core
out vec4 FragColor;
in vec2 TexCoords;
uniform sampler2D screenTexture;
const float offset = 1.0 / 300.0;
void main()
{
FragColor = texture(screenTexture, TexCoords);
//Invert color
//FragColor = vec4(vec3(1.0 - texture(screenTexture, TexCoords)), 1.0);
//Grayscale
//FragColor = texture(screenTexture, TexCoords);
//float average = 0.2126 * FragColor.r + 0.7152 * FragColor.g + 0.0722 * FragColor.b;
//FragColor = vec4(average, average, average, 1.0);
//Blur
// vec2 offsets[9] = vec2[](
// vec2(-offset, offset), // top-left
// vec2( 0.0f, offset), // top-center
// vec2( offset, offset), // top-right
// vec2(-offset, 0.0f), // center-left
// vec2( 0.0f, 0.0f), // center-center
// vec2( offset, 0.0f), // center-right
// vec2(-offset, -offset), // bottom-left
// vec2( 0.0f, -offset), // bottom-center
// vec2( offset, -offset) // bottom-right
// );
// Sharpen kernel
// float kernel[9] = float[](
// -1, -1, -1,
// -1, 9, -1,
// -1, -1, -1
// );
// Blur kernel
// float kernel[9] = float[](
// 1.0 / 16, 2.0 / 16, 1.0 / 16,
// 2.0 / 16, 4.0 / 16, 2.0 / 16,
// 1.0 / 16, 2.0 / 16, 1.0 / 16
// );
// vec3 sampleTex[9];
// for(int i = 0; i < 9; i++)
// {
// sampleTex[i] = vec3(texture(screenTexture, TexCoords.st + offsets[i]));
// }
// vec3 col = vec3(0.0);
// for(int i = 0; i < 9; i++)
// col += sampleTex[i] * kernel[i];
// FragColor = vec4(col, 1.0);
}

View File

@@ -1,11 +0,0 @@
#version 330 core
layout (location = 0) in vec2 aPos;
layout (location = 1) in vec2 aTexCoords;
out vec2 TexCoords;
void main()
{
gl_Position = vec4(aPos.x, aPos.y, 0.0, 1.0);
TexCoords = aTexCoords;
}

View File

@@ -0,0 +1,25 @@
@vs svs
in vec3 aPos;
uniform vs_p {
mat4 lightSpaceMatrix;
mat4 model;
};
void main()
{
gl_Position = lightSpaceMatrix * model * vec4(aPos, 1.0);
}
@end
@fs sfs
out float frag_color;
void main()
{
// frag_color = encode_depth(gl_FragCoord.z);
frag_color = gl_FragCoord.z;
}
@end
@program shadow svs sfs

View File

@@ -1,8 +0,0 @@
#version 330 core
out float frag_color;
void main()
{
// frag_color = encode_depth(gl_FragCoord.z);
frag_color = gl_FragCoord.z;
}

View File

@@ -1,10 +0,0 @@
#version 330 core
layout (location = 0) in vec3 aPos;
uniform mat4 lightSpaceMatrix;
uniform mat4 model;
void main()
{
gl_Position = lightSpaceMatrix * model * vec4(aPos, 1.0);
}

View File

@@ -1,26 +0,0 @@
#version 330 core
layout (location = 0) in vec2 vert;
layout (location = 1) in vec2 vuv;
layout (location = 2) in vec4 vborder;
layout (location = 3) in vec2 vscale;
layout (location = 4) in vec4 vcolor;
out vec2 uv;
out vec4 border;
out vec2 scale;
out vec4 fcolor;
uniform mat4 projection;
void main()
{
gl_Position = projection * vec4(vert, 0.0, 1.0);
uv = vuv;
border = vborder;
scale = vscale;
fcolor = vcolor;
}

View File

@@ -0,0 +1,36 @@
@vs vs
in vec2 vertex;
in vec2 uv;
in vec4 vColor;
out vec2 texcoords;
out vec4 fcolor;
uniform vs_p { mat4 proj; };
void main()
{
fcolor = vColor;
texcoords = uv;
gl_Position = proj * vec4(vertex, 0.0, 1.0);
}
@end
@fs fs
in vec2 texcoords;
in vec4 fcolor;
out vec4 color;
uniform texture2D image;
uniform sampler smp;
void main()
{
color = fcolor * texture(sampler2D(image,smp), texcoords);
if (color.a <= 0.1f)
discard;
}
@end
@program sprite vs fs

View File

@@ -1,15 +0,0 @@
#version 330 core
in vec2 texcoords;
in vec4 fcolor;
out vec4 color;
uniform sampler2D image;
void main()
{
color = fcolor * texture(image, texcoords);
if (color.a <= 0.1f)
discard;
}

View File

@@ -1,16 +0,0 @@
#version 330 core
layout (location = 0) in vec2 vertex;
layout (location = 1) in vec2 uv;
layout (location = 2) in vec4 vColor;
out vec2 texcoords;
out vec4 fcolor;
uniform mat4 proj;
void main()
{
fcolor = vColor;
texcoords = uv;
gl_Position = proj * vec4(vertex, 0.0, 1.0);
}

76
source/shaders/text.sglsl Normal file
View File

@@ -0,0 +1,76 @@
@vs vs
in vec2 vert;
in vec2 pos;
in vec2 wh;
in vec2 uv;
in vec2 st;
in vec4 vColor;
out vec2 TexCoords;
out vec4 fColor;
out vec2 fst;
uniform vs_params { mat4 projection; };
void main()
{
gl_Position = projection * vec4(pos + (vert * wh), 0.0, 1.0);
TexCoords = uv + vec2(vert.x*st.x, st.y - vert.y*st.y);
fst = st / wh;
fColor = vColor;
}
@end
@fs fs
in vec2 TexCoords;
in vec4 fColor;
in vec2 fst;
out vec4 color;
uniform texture2D text;
uniform sampler smp;
float osize = 1.0;
void main()
{
float lettera = texture(sampler2D(text,smp),TexCoords).r;
if (lettera <= 0.1f)
{
vec2 uvpos = TexCoords - fst;
for (int x = 0; x < 3; x++) {
for (int y = 0; y < 3; y++) {
float pa = texture(sampler2D(text,smp), uvpos + (fst*vec2(x,y))).r;
if (pa > 0.1) {
color = vec4(0.0,0.0,0.0, fColor.a);
return;
}
}
}
discard;
}
// vec2 lsize = fst / textureSize(dtext,0).xy;
/* vec2 uvpos = TexCoords - fst;
for (int x = 0; x < 3; x++) {
for (int y = 0; 0 < 3; y++) {
float pa = texture(sampler2D(text,smp), uvpos + (fst * vec2(x,y))).r;
if (pa <= 0.1) {
color = vec4(0.0,0.0,0.0,fColor.a);
return;
}
}
}
*/
color = vec4(fColor.xyz, fColor.a);
}
@end
@program text vs fs

View File

@@ -1,23 +0,0 @@
#version 330 core
layout (location = 0) in vec2 vert;
layout (location = 1) in vec2 pos;
layout (location = 2) in vec2 wh;
layout (location = 3) in vec2 uv;
layout (location = 4) in vec2 st;
layout (location = 5) in vec4 vColor;
out vec2 TexCoords;
out vec4 fColor;
out vec2 fst;
uniform mat4 projection;
void main()
{
gl_Position = projection * vec4(pos + (vert * wh), 0.0, 1.0);
TexCoords = uv + vec2(vert.x*st.x, st.y - vert.y*st.y);
fst = st / wh;
fColor = vColor;
}

View File

@@ -1,22 +0,0 @@
#version 330 core
in vec2 TexCoords;
out vec4 color;
uniform sampler2D texture_y;
uniform sampler2D texture_cb;
uniform sampler2D texture_cr;
uniform vec3 spriteColor;
mat4 rec601 = mat4(
1.16438, 0.00000, 1.59603, -0.87079,
1.16438, -0.39176, -0.81297, 0.52959,
1.16438, 2.01723, 0.00000, -1.08139,
0, 0, 0, 1
);
void main() {
float y = texture2D(texture_y, TexCoords).r;
float cb = texture2D(texture_cb, TexCoords).r;
float cr = texture2D(texture_cr, TexCoords).r;
color = vec4(y, cb, cr, 1.f) * rec601 * vec4(spriteColor, 1.f);
}

View File

@@ -1,12 +0,0 @@
#version 330 core
layout (location = 0) in vec4 vertex;
out vec2 TexCoords;
uniform mat4 model;
uniform mat4 projection;
void main() {
TexCoords = vec2(vertex.x, 1.0 - vertex.y);
gl_Position = projection * model * vec4(vertex.xy, 0.0, 1.0);
}