add shaders

This commit is contained in:
John Alanbrook 2024-05-30 17:12:54 -05:00
parent cb30231c2f
commit 10678e8bcc
9 changed files with 268 additions and 0 deletions

51
shaders/base.cg Normal file
View file

@ -0,0 +1,51 @@
#blend mix
#primitive triangle
#cull none
#depth off
@vs vs
in vec3 a_pos;
in vec2 a_uv;
out vec2 uv;
#define PI 3.141592
vec3 pos;
uniform mat4 projection;
uniform mat4 view;
uniform mat4 vp;
uniform mat4 model;
@include_block vert
void main()
{
pos = a_pos;
uv = a_uv;
vert();
gl_Position = vp * model * vec4(pos, 1.0);
}
@end
@fs fs
in vec2 uv;
out vec4 color;
#define PI 3.141592
texture2D diffuse;
sampler smp;
@include_block frag
void main()
{
frag();
}
@end
@program sprite vs fs

61
shaders/basetext.cg Normal file
View file

@ -0,0 +1,61 @@
#depth off
@vs vs
in vec2 a_pos;
in vec2 a_uv;
struct letter {
vec2 pos;
vec2 wh;
vec2 uv;
vec2 st;
vec4 color;
};
readonly buffer ssbo {
letter ls[];
};
out vec2 uv;
out vec2 fuv;
out vec4 color0;
vec2 pos;
uniform mat4 vp;
@include_block vert
void main()
{
letter l = ls[gl_InstanceIndex];
fuv = l.uv + vec2(a_pos.x*l.st.x, l.st.y - a_pos.y*l.st.y);
uv = a_uv;
color0 = l.color;
pos = l.pos+(a_pos*l.wh);
vert();
gl_Position = vp * vec4(pos, 0.0, 1.0);
}
@end
@fs fs
in vec2 uv;
in vec2 fuv;
in vec4 color0;
out vec4 color;
texture2D text;
sampler smp;
@include_block frag
void main()
{
float lettera = texture(sampler2D(text,smp),fuv).r;
if (lettera < 0.1f) discard;
frag();
}
@end
@program text vs fs

44
shaders/circle.cg Normal file
View file

@ -0,0 +1,44 @@
#blend mix
#primitive triangle
#cull none
#depth off
@vs vert
in vec3 a_pos;
uniform float radius;
uniform vec2 coord;
uniform mat4 vp;
out vec2 coords;
out float rad;
void main() {
vec3 pos = a_pos;
pos.xy -= 0.5;
pos.xy *= 2;
coords = pos.xy;
pos *= radius;
pos.xy += coord;
rad = radius;
gl_Position = vp * vec4(pos,1);
}
@end
@fs frag
in vec2 coords;
in float rad;
uniform vec4 shade;
out vec4 color;
void main() {
float px = 1/rad;
float R = 1;
float R2 = 0.90;
float dist = sqrt(dot(coords,coords));
float sm = 1 - smoothstep(R-px,R,dist);
float sm2 = smoothstep(R2-px,R2,dist);
float alpha = sm*sm2;
color = vec4(shade.xyz, alpha*alpha);
}
@end
@program circle vert frag

25
shaders/poly.cg Normal file
View file

@ -0,0 +1,25 @@
#depth off
#primitive triangle
#cull none
#blend mix
@vs vs
in vec3 a_pos;
uniform mat4 vp;
uniform mat4 model;
void main() {
gl_Position = vp * model * vec4(a_pos, 1);
}
@end
@fs fs
uniform vec4 shade;
out vec4 color;
void main() {
color = shade;
}
@end
@program sprite vs fs

42
shaders/postbase.cg Normal file
View file

@ -0,0 +1,42 @@
#cull back
@vs vs
in vec3 a_pos;
in vec2 a_uv;
out vec2 uv;
void main()
{
vec3 pos = a_pos;
pos -= 0.5;
pos *= 2;
uv = a_uv;
gl_Position = vec4(pos.xy, 0, 1.0);
}
@end
@fs fs
in vec2 uv;
out vec4 color;
#define PI 3.141592
@image_sample_type diffuse unfilterable_float
texture2D diffuse;
@sampler_type smp nonfiltering
sampler smp;
uniform vec2 mouse;
uniform float time;
@include_block frag
void main()
{
frag();
}
@end
@program p vs fs

8
shaders/simplepost.cg Normal file
View file

@ -0,0 +1,8 @@
@block frag
void frag()
{
color = texture(sampler2D(diffuse,smp),uv);
}
@end
#include <postbase.cg>

24
shaders/sprite.cg Normal file
View file

@ -0,0 +1,24 @@
@block vert
uniform vec4 mixcolor;
uniform vec4 emissive;
uniform vec4 rect;
uniform vec2 offset;
uniform vec2 diffuse_size;
void vert()
{
pos *= vec3(diffuse_size * rect.zw,1);
uv = (uv*rect.zw)+rect.xy;
}
@end
@block frag
uniform vec4 shade;
void frag()
{
color = texture(sampler2D(diffuse,smp), uv);
if (color.a < 0.1) discard;
color *= shade;
}
@end
#include <base.cg>

3
shaders/stdvert.cg Normal file
View file

@ -0,0 +1,3 @@
@block vert
void vert(){}
@end

10
shaders/text_base.cg Normal file
View file

@ -0,0 +1,10 @@
#include <stdvert.cg>
@block frag
void frag()
{
color = color0;
}
@end
#include <basetext.cg>