3 static void shader_trail_link(void);
4 static void shader_trail_register(void);
5 static struct vg_shader _shader_trail
= {
7 .link
= shader_trail_link
,
10 .orig_file
= "shaders/trail.vs",
12 "layout (location=0) in vec4 a_co;\n"
15 "const float k_motion_lerp_amount = 0.01;\n"
19 "out vec3 aMotionVec0;\n"
20 "out vec3 aMotionVec1;\n"
22 "void vs_motion_out( vec4 vproj0, vec4 vproj1 )\n"
24 " // This magically solves some artifacting errors!\n"
26 " vproj1 = vproj0*(1.0-k_motion_lerp_amount) + vproj1*k_motion_lerp_amount;\n"
28 " aMotionVec0 = vec3( vproj0.xy, vproj0.w );\n"
29 " aMotionVec1 = vec3( vproj1.xy, vproj1.w );\n"
35 "uniform mat4 uPvPrev;\n"
40 " vec4 vproj0 = uPv * vec4( a_co.xyz, 1.0 );\n"
41 " vec4 vproj1 = uPvPrev * vec4( a_co.xyz, 1.0 );\n"
42 " vs_motion_out( vproj0, vproj1 );\n"
44 " gl_Position = vproj0;\n"
50 .orig_file
= "shaders/trail.fs",
52 "layout (location = 0) out vec4 oColour;\n"
54 "uniform vec4 uColour;\n"
57 "const float k_motion_lerp_amount = 0.01;\n"
61 "layout (location = 1) out vec2 oMotionVec;\n"
63 "in vec3 aMotionVec0;\n"
64 "in vec3 aMotionVec1;\n"
66 "void compute_motion_vectors()\n"
68 " // Write motion vectors\n"
69 " vec2 vmotion0 = aMotionVec0.xy / aMotionVec0.z;\n"
70 " vec2 vmotion1 = aMotionVec1.xy / aMotionVec1.z;\n"
72 " oMotionVec = (vmotion1-vmotion0) * (1.0/k_motion_lerp_amount);\n"
78 " compute_motion_vectors();\n"
80 " vec2 ssuv = gl_FragCoord.xy;\n"
81 " vec3 vDither = vec3( dot( vec2( 171.0, 231.0 ), ssuv) );\n"
82 " float dither = fract( vDither.g / 71.0 ) - 0.5;\n"
84 " if( aAlpha+dither<0.5 )\n"
87 " oColour = vec4( uColour.rgb, uColour.a * aAlpha );\n"
92 static GLuint _uniform_trail_uPv
;
93 static GLuint _uniform_trail_uPvPrev
;
94 static GLuint _uniform_trail_uColour
;
95 static void shader_trail_uPv(m4x4f m
){
96 glUniformMatrix4fv(_uniform_trail_uPv
,1,GL_FALSE
,(float*)m
);
98 static void shader_trail_uPvPrev(m4x4f m
){
99 glUniformMatrix4fv(_uniform_trail_uPvPrev
,1,GL_FALSE
,(float*)m
);
101 static void shader_trail_uColour(v4f v
){
102 glUniform4fv(_uniform_trail_uColour
,1,v
);
104 static void shader_trail_register(void){
105 vg_shader_register( &_shader_trail
);
107 static void shader_trail_use(void){ glUseProgram(_shader_trail
.id
); }
108 static void shader_trail_link(void){
109 _uniform_trail_uPv
= glGetUniformLocation( _shader_trail
.id
, "uPv" );
110 _uniform_trail_uPvPrev
= glGetUniformLocation( _shader_trail
.id
, "uPvPrev" );
111 _uniform_trail_uColour
= glGetUniformLocation( _shader_trail
.id
, "uColour" );
113 #endif /* SHADER_trail_H */