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_norm;\n"
14 "layout (location=2) in vec4 a_colour;\n"
17 "const float k_motion_lerp_amount = 0.01;\n"
21 "out vec3 aMotionVec0;\n"
22 "out vec3 aMotionVec1;\n"
24 "void vs_motion_out( vec4 vproj0, vec4 vproj1 )\n"
26 " // This magically solves some artifacting errors!\n"
28 " vproj1 = vproj0*(1.0-k_motion_lerp_amount) + vproj1*k_motion_lerp_amount;\n"
30 " aMotionVec0 = vec3( vproj0.xy, vproj0.w );\n"
31 " aMotionVec1 = vec3( vproj1.xy, vproj1.w );\n"
36 "uniform mat4x3 uMdl;\n"
37 "uniform mat3 uNormMtx;\n"
39 "uniform mat4 uPvmPrev;\n"
40 "uniform vec2 uTime;\n"
41 "uniform vec4 uTransform;\n"
45 "out vec3 aWorldCo;\n"
48 "vec2 rand_hash22( vec2 p )\n"
50 " vec3 p3 = fract(vec3(p.xyx) * 213.8976123);\n"
51 " p3 += dot(p3, p3.yzx+19.19);\n"
52 " return fract(vec2((p3.x + p3.y)*p3.z, (p3.x+p3.z)*p3.y));\n"
55 "vec3 mapP( vec3 p )\n"
58 " float t = max(0.0,uTime.y);\n"
60 " vec3 lco = p * 20.0;\n"
61 " vec3 grid = vec3(floor(lco.x),lco.y,floor(lco.z));//fract(p);\n"
63 " return mix(p,grid * (1.0/20.0), t)*vec3(1.0+t,1.0-t,1.0+t);\n"
68 " vec3 mco = a_co.xyz * uTransform.w + uTransform.xyz;\n"
71 " vec3 center = vec3(0.5);\n"
72 " vec3 lco = mapP(mco-center);\n"
73 " mco = lco + center;\n"
75 " vec3 world_pos0 = uMdl * vec4( mco, 1.0 );\n"
76 " vec4 vproj0 = uPv * vec4( world_pos0, 1.0 );\n"
77 " vec4 vproj1 = uPvmPrev * vec4( mco, 1.0 );\n"
79 " float t = max(0.0,uTime.y);\n"
80 " float scaler = smoothstep(0.6,0.58,length(lco.xz*vec2(0.7,1.0)));\n"
82 " vs_motion_out( vproj0, vproj1 );\n"
84 " gl_Position = vproj0;\n"
85 " gl_PointSize = (8.0*uTransform.w*scaler) / (gl_Position.z + 0.01);\n"
86 " aWorldCo = world_pos0;\n"
87 " aColour = a_colour*scaler*(0.3+a_co.y);\n"
89 " aNorm = uNormMtx * a_norm.xyz;\n"
94 .orig_file
= "shaders/cloud.fs",
96 "out vec4 FragColor;\n"
99 "const float k_motion_lerp_amount = 0.01;\n"
103 "layout (location = 1) out vec2 oMotionVec;\n"
105 "in vec3 aMotionVec0;\n"
106 "in vec3 aMotionVec1;\n"
108 "void compute_motion_vectors()\n"
110 " // Write motion vectors\n"
111 " vec2 vmotion0 = aMotionVec0.xy / aMotionVec0.z;\n"
112 " vec2 vmotion1 = aMotionVec1.xy / aMotionVec1.z;\n"
114 " oMotionVec = (vmotion1-vmotion0) * (1.0/k_motion_lerp_amount);\n"
119 "uniform vec3 uCamera;\n"
124 "in vec3 aWorldCo;\n"
128 " vec2 ssuv = gl_FragCoord.xy;\n"
129 " vec3 vDither = vec3( dot( vec2( 171.0, 231.0 ), ssuv) );\n"
130 " float dither = fract( vDither.g / 71.0 ) - 0.5;\n"
132 " float diff = length(gl_PointCoord.xy-vec2(0.5));\n"
136 " compute_motion_vectors();\n"
137 " FragColor = aColour;\n"
142 static GLuint _uniform_point_map_uMdl
;
143 static GLuint _uniform_point_map_uNormMtx
;
144 static GLuint _uniform_point_map_uPv
;
145 static GLuint _uniform_point_map_uPvmPrev
;
146 static GLuint _uniform_point_map_uTime
;
147 static GLuint _uniform_point_map_uTransform
;
148 static GLuint _uniform_point_map_uCamera
;
149 static void shader_point_map_uMdl(m4x3f m
){
150 glUniformMatrix4x3fv(_uniform_point_map_uMdl
,1,GL_FALSE
,(float*)m
);
152 static void shader_point_map_uNormMtx(m3x3f m
){
153 glUniformMatrix3fv(_uniform_point_map_uNormMtx
,1,GL_FALSE
,(float*)m
);
155 static void shader_point_map_uPv(m4x4f m
){
156 glUniformMatrix4fv(_uniform_point_map_uPv
,1,GL_FALSE
,(float*)m
);
158 static void shader_point_map_uPvmPrev(m4x4f m
){
159 glUniformMatrix4fv(_uniform_point_map_uPvmPrev
,1,GL_FALSE
,(float*)m
);
161 static void shader_point_map_uTime(v2f v
){
162 glUniform2fv(_uniform_point_map_uTime
,1,v
);
164 static void shader_point_map_uTransform(v4f v
){
165 glUniform4fv(_uniform_point_map_uTransform
,1,v
);
167 static void shader_point_map_uCamera(v3f v
){
168 glUniform3fv(_uniform_point_map_uCamera
,1,v
);
170 static void shader_point_map_register(void){
171 vg_shader_register( &_shader_point_map
);
173 static void shader_point_map_use(void){ glUseProgram(_shader_point_map
.id
); }
174 static void shader_point_map_link(void){
175 _uniform_point_map_uMdl
= glGetUniformLocation( _shader_point_map
.id
, "uMdl" );
176 _uniform_point_map_uNormMtx
= glGetUniformLocation( _shader_point_map
.id
, "uNormMtx" );
177 _uniform_point_map_uPv
= glGetUniformLocation( _shader_point_map
.id
, "uPv" );
178 _uniform_point_map_uPvmPrev
= glGetUniformLocation( _shader_point_map
.id
, "uPvmPrev" );
179 _uniform_point_map_uTime
= glGetUniformLocation( _shader_point_map
.id
, "uTime" );
180 _uniform_point_map_uTransform
= glGetUniformLocation( _shader_point_map
.id
, "uTransform" );
181 _uniform_point_map_uCamera
= glGetUniformLocation( _shader_point_map
.id
, "uCamera" );
183 #endif /* SHADER_point_map_H */