1 #ifndef SHADER_point_map_H
2 #define SHADER_point_map_H
3 static void shader_point_map_link(void);
4 static void shader_point_map_register(void);
5 static struct vg_shader _shader_point_map
= {
7 .link
= shader_point_map_link
,
10 .orig_file
= "shaders/cloud.vs",
12 "layout (location=0) in vec4 a_co;\n"
13 "layout (location=1) in vec4 a_colour;\n"
16 "const float k_motion_lerp_amount = 0.01;\n"
20 "out vec3 aMotionVec0;\n"
21 "out vec3 aMotionVec1;\n"
23 "void vs_motion_out( vec4 vproj0, vec4 vproj1 )\n"
25 " // This magically solves some artifacting errors!\n"
27 " vproj1 = vproj0*(1.0-k_motion_lerp_amount) + vproj1*k_motion_lerp_amount;\n"
29 " aMotionVec0 = vec3( vproj0.xy, vproj0.w );\n"
30 " aMotionVec1 = vec3( vproj1.xy, vproj1.w );\n"
35 "uniform mat4x3 uMdl;\n"
36 "uniform mat3 uNormMtx;\n"
38 "uniform mat4 uPvmPrev;\n"
39 "uniform vec4 uAnim;\n"
42 "out vec3 aWorldCo;\n"
45 "vec2 rand_hash22( vec2 p )\n"
47 " vec3 p3 = fract(vec3(p.xyx) * 213.8976123);\n"
48 " p3 += dot(p3, p3.yzx+19.19);\n"
49 " return fract(vec2((p3.x + p3.y)*p3.z, (p3.x+p3.z)*p3.y));\n"
52 "vec3 gridify( vec3 p, float s, float t )\n"
55 " vec2 r2 = rand_hash22(p.xz);\n"
56 " vec3 grid = (vec3(floor(co.x),co.y,floor(co.z))+vec3(0.5,0.0,0.5)) * (1.0/s);\n"
58 " float t1 = 1.0-t;\n"
62 " return mix( p, grid, t1 ) + t2*vec3(0.0,r2.y*r2.y*0.2,0.0);\n"
67 " vec3 co = gridify( a_co.xyz, uAnim.x, uAnim.y );\n"
69 " vec3 world_pos0 = uMdl * vec4( co, 1.0 );\n"
70 " vec4 vproj0 = uPv * vec4( world_pos0, 1.0 );\n"
71 " vec4 vproj1 = uPvmPrev * vec4( co, 1.0 );\n"
73 " float scaler = smoothstep(0.6,0.58,length(co.xz));\n"
75 " vs_motion_out( vproj0, vproj1 );\n"
77 " gl_Position = vproj0;\n"
78 " gl_PointSize = (9.0*scaler) / (gl_Position.z + 0.01);\n"
79 " aWorldCo = world_pos0;\n"
80 " aColour = a_colour*scaler*(1.0-uAnim.y*uAnim.y);\n"
86 .orig_file
= "shaders/cloud.fs",
88 "out vec4 FragColor;\n"
91 "const float k_motion_lerp_amount = 0.01;\n"
95 "layout (location = 1) out vec2 oMotionVec;\n"
97 "in vec3 aMotionVec0;\n"
98 "in vec3 aMotionVec1;\n"
100 "void compute_motion_vectors()\n"
102 " // Write motion vectors\n"
103 " vec2 vmotion0 = aMotionVec0.xy / aMotionVec0.z;\n"
104 " vec2 vmotion1 = aMotionVec1.xy / aMotionVec1.z;\n"
106 " oMotionVec = (vmotion1-vmotion0) * (1.0/k_motion_lerp_amount);\n"
111 "uniform vec3 uCamera;\n"
115 "in vec3 aWorldCo;\n"
119 " vec2 ssuv = gl_FragCoord.xy;\n"
120 " vec3 vDither = vec3( dot( vec2( 171.0, 231.0 ), ssuv) );\n"
121 " float dither = fract( vDither.g / 71.0 ) - 0.5;\n"
123 " float diff = length(gl_PointCoord.xy-vec2(0.5));\n"
124 " if( diff+dither>0.5 )discard;\n"
126 " compute_motion_vectors();\n"
127 " FragColor = aColour;\n"
132 static GLuint _uniform_point_map_uMdl
;
133 static GLuint _uniform_point_map_uNormMtx
;
134 static GLuint _uniform_point_map_uPv
;
135 static GLuint _uniform_point_map_uPvmPrev
;
136 static GLuint _uniform_point_map_uAnim
;
137 static GLuint _uniform_point_map_uCamera
;
138 static void shader_point_map_uMdl(m4x3f m
){
139 glUniformMatrix4x3fv(_uniform_point_map_uMdl
,1,GL_FALSE
,(float*)m
);
141 static void shader_point_map_uNormMtx(m3x3f m
){
142 glUniformMatrix3fv(_uniform_point_map_uNormMtx
,1,GL_FALSE
,(float*)m
);
144 static void shader_point_map_uPv(m4x4f m
){
145 glUniformMatrix4fv(_uniform_point_map_uPv
,1,GL_FALSE
,(float*)m
);
147 static void shader_point_map_uPvmPrev(m4x4f m
){
148 glUniformMatrix4fv(_uniform_point_map_uPvmPrev
,1,GL_FALSE
,(float*)m
);
150 static void shader_point_map_uAnim(v4f v
){
151 glUniform4fv(_uniform_point_map_uAnim
,1,v
);
153 static void shader_point_map_uCamera(v3f v
){
154 glUniform3fv(_uniform_point_map_uCamera
,1,v
);
156 static void shader_point_map_register(void){
157 vg_shader_register( &_shader_point_map
);
159 static void shader_point_map_use(void){ glUseProgram(_shader_point_map
.id
); }
160 static void shader_point_map_link(void){
161 _uniform_point_map_uMdl
= glGetUniformLocation( _shader_point_map
.id
, "uMdl" );
162 _uniform_point_map_uNormMtx
= glGetUniformLocation( _shader_point_map
.id
, "uNormMtx" );
163 _uniform_point_map_uPv
= glGetUniformLocation( _shader_point_map
.id
, "uPv" );
164 _uniform_point_map_uPvmPrev
= glGetUniformLocation( _shader_point_map
.id
, "uPvmPrev" );
165 _uniform_point_map_uAnim
= glGetUniformLocation( _shader_point_map
.id
, "uAnim" );
166 _uniform_point_map_uCamera
= glGetUniformLocation( _shader_point_map
.id
, "uCamera" );
168 #endif /* SHADER_point_map_H */