| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | /* | ||
| 2 | * This file was automatically generated, do not edit. | ||
| 3 | */ | ||
| 4 | |||
| 5 | #include <geogram_gfx/GLUP/shaders/embedded_shaders.h> | ||
| 6 | #include <geogram_gfx/basic/common.h> | ||
| 7 | #include <geogram_gfx/basic/GLSL.h> | ||
| 8 | |||
| 9 | namespace GLUP { | ||
| 10 | ✗ | void register_embedded_shaders_GLUP() { | |
| 11 | ✗ | GEO::GLSL::register_GLSL_include_file("GLUP/constants.h", | |
| 12 | "const int GLUP_CLIP_STANDARD = 0; \n" | ||
| 13 | "const int GLUP_CLIP_WHOLE_CELLS = 1; \n" | ||
| 14 | "const int GLUP_CLIP_STRADDLING_CELLS = 2; \n" | ||
| 15 | "const int GLUP_CLIP_SLICE_CELLS = 3; \n" | ||
| 16 | " \n" | ||
| 17 | "const int GLUP_TEXTURE_1D = 1; \n" | ||
| 18 | "const int GLUP_TEXTURE_2D = 2; \n" | ||
| 19 | "const int GLUP_TEXTURE_3D = 3; \n" | ||
| 20 | " \n" | ||
| 21 | "const int GLUP_TEXTURE_REPLACE = 0; \n" | ||
| 22 | "const int GLUP_TEXTURE_MODULATE = 1; \n" | ||
| 23 | "const int GLUP_TEXTURE_ADD = 2; \n" | ||
| 24 | " \n" | ||
| 25 | "const int GLUP_PICK_PRIMITIVE = 1; \n" | ||
| 26 | "const int GLUP_PICK_CONSTANT = 2; \n" | ||
| 27 | " \n" | ||
| 28 | "const int GLUP_POINTS =0; \n" | ||
| 29 | "const int GLUP_LINES =1; \n" | ||
| 30 | "const int GLUP_TRIANGLES =2; \n" | ||
| 31 | "const int GLUP_QUADS =3; \n" | ||
| 32 | "const int GLUP_TETRAHEDRA =4; \n" | ||
| 33 | "const int GLUP_HEXAHEDRA =5; \n" | ||
| 34 | "const int GLUP_PRISMS =6; \n" | ||
| 35 | "const int GLUP_PYRAMIDS =7; \n" | ||
| 36 | "const int GLUP_CONNECTORS =8; \n" | ||
| 37 | "const int GLUP_SPHERES =9; \n" | ||
| 38 | "const int GLUP_THICK_LINES =10; \n" | ||
| 39 | " \n" | ||
| 40 | "const int GLUP_LIGHTING =0; \n" | ||
| 41 | "const int GLUP_VERTEX_COLORS =1; \n" | ||
| 42 | "const int GLUP_TEXTURING =2; \n" | ||
| 43 | "const int GLUP_DRAW_MESH =3; \n" | ||
| 44 | "const int GLUP_CLIPPING =4; \n" | ||
| 45 | "const int GLUP_INDIRECT_TEXTURING =5; \n" | ||
| 46 | "const int GLUP_VERTEX_NORMALS =6; \n" | ||
| 47 | "const int GLUP_PICKING =7; \n" | ||
| 48 | "const int GLUP_ALPHA_DISCARD =8; \n" | ||
| 49 | "const int GLUP_NORMAL_MAPPING =9; \n" | ||
| 50 | "const int GLUP_PRIMITIVE_FILTERING =10; \n" | ||
| 51 | ); | ||
| 52 | |||
| 53 | ✗ | GEO::GLSL::register_GLSL_include_file("GLUP/defs.h", | |
| 54 | "#ifdef GL_ES \n" | ||
| 55 | "#if __VERSION__ == 100 \n" | ||
| 56 | "#define GLUP_ES_100 \n" | ||
| 57 | "#endif \n" | ||
| 58 | "#endif \n" | ||
| 59 | " \n" | ||
| 60 | " \n" | ||
| 61 | "#ifdef GLUP_ES_100 \n" | ||
| 62 | "int glup_mod(in int x, in int y) { \n" | ||
| 63 | " return x - (x/y)*y; \n" | ||
| 64 | "} \n" | ||
| 65 | "#else \n" | ||
| 66 | "int glup_mod(in int x, in int y) { \n" | ||
| 67 | " return x % y; \n" | ||
| 68 | "} \n" | ||
| 69 | "#endif \n" | ||
| 70 | " \n" | ||
| 71 | " \n" | ||
| 72 | "// Definitions for GLUPES shaders \n" | ||
| 73 | "// These macro are used to have portable \n" | ||
| 74 | "// declarations with \n" | ||
| 75 | "// OpenGLES 2.0, GLSL 1.3 and GLSL 1.5, \n" | ||
| 76 | " \n" | ||
| 77 | "#ifdef GLUP_ES_100 \n" | ||
| 78 | "#ifdef GLUP_VERTEX_SHADER \n" | ||
| 79 | "#define glup_in attribute \n" | ||
| 80 | "#define glup_out varying \n" | ||
| 81 | "#elif defined GLUP_FRAGMENT_SHADER \n" | ||
| 82 | "#define glup_in varying \n" | ||
| 83 | "#endif \n" | ||
| 84 | "#define glup_flat \n" | ||
| 85 | "#define glup_id highp float \n" | ||
| 86 | "#else \n" | ||
| 87 | "#define glup_in in \n" | ||
| 88 | "#define glup_out out \n" | ||
| 89 | "#define glup_flat flat \n" | ||
| 90 | "#define glup_id highp int \n" | ||
| 91 | "#endif \n" | ||
| 92 | " \n" | ||
| 93 | "#ifdef GLUP_ES_100 \n" | ||
| 94 | "vec4 glup_texture(in sampler2D samp, in vec2 uv) { \n" | ||
| 95 | " return texture2D(samp, uv); \n" | ||
| 96 | "} \n" | ||
| 97 | "#else \n" | ||
| 98 | "vec4 glup_texture(in sampler2D samp, in vec2 uv) { \n" | ||
| 99 | " return texture(samp, uv); \n" | ||
| 100 | "} \n" | ||
| 101 | "#endif \n" | ||
| 102 | " \n" | ||
| 103 | "#ifdef GLUP_FRAGMENT_SHADER \n" | ||
| 104 | "#ifdef GLUP_ES_100 \n" | ||
| 105 | "#define glup_FragColor gl_FragColor \n" | ||
| 106 | "#ifdef GL_EXT_frag_depth \n" | ||
| 107 | "#define glup_FragDepth gl_FragDepthEXT \n" | ||
| 108 | "#else \n" | ||
| 109 | "float glup_FragDepth; // depth updates will be ignored \n" | ||
| 110 | "#endif \n" | ||
| 111 | "#else \n" | ||
| 112 | "out vec4 glup_FragColor; \n" | ||
| 113 | "#define glup_FragDepth gl_FragDepth \n" | ||
| 114 | "#endif \n" | ||
| 115 | "#endif \n" | ||
| 116 | ); | ||
| 117 | |||
| 118 | ✗ | GEO::GLSL::register_GLSL_include_file("GLUP/stdglup.h", | |
| 119 | "//import <GLUP/constants.h> \n" | ||
| 120 | "//import <GLUP/defs.h> \n" | ||
| 121 | ); | ||
| 122 | |||
| 123 | ✗ | GEO::GLSL::register_GLSL_include_file("GLUP/fragment_shader_utils.h", | |
| 124 | " \n" | ||
| 125 | " \n" | ||
| 126 | "#ifdef GLUP_ES_100 \n" | ||
| 127 | "// converts an integer into an ivec4. The components of \n" | ||
| 128 | "// the ivec4 contains the 4 bytes of the integer. \n" | ||
| 129 | "ivec4 int_to_ivec4(in int x) { \n" | ||
| 130 | " // TODO: we still have unsigned-signed conversion \n" | ||
| 131 | " // problems. Picking id in state should be unsigned. \n" | ||
| 132 | " if(x < 0) { \n" | ||
| 133 | " return ivec4(255,255,255,255); \n" | ||
| 134 | " } \n" | ||
| 135 | " int w = x; \n" | ||
| 136 | " int R = glup_mod(w, 256); \n" | ||
| 137 | " w /= 256; \n" | ||
| 138 | " int G = glup_mod(w, 256); \n" | ||
| 139 | " w /= 256; \n" | ||
| 140 | " int B = glup_mod(w, 256); \n" | ||
| 141 | " w /= 256; \n" | ||
| 142 | " int A = glup_mod(w, 256); \n" | ||
| 143 | " return ivec4(R,G,B,A); \n" | ||
| 144 | "} \n" | ||
| 145 | "#else \n" | ||
| 146 | "ivec4 int_to_ivec4(in int x) { \n" | ||
| 147 | " return ivec4( \n" | ||
| 148 | " x & 255, \n" | ||
| 149 | " (x >> 8) & 255, \n" | ||
| 150 | " (x >> 16) & 255, \n" | ||
| 151 | " (x >> 24) & 255 \n" | ||
| 152 | " ); \n" | ||
| 153 | "} \n" | ||
| 154 | "#endif \n" | ||
| 155 | " \n" | ||
| 156 | "// adds two 32 bits integers V1 and V2 represented \n" | ||
| 157 | "// as ivec4. \n" | ||
| 158 | "ivec4 ivec4_add(in ivec4 V1, in ivec4 V2) { \n" | ||
| 159 | " int R = V1.r + V2.r; \n" | ||
| 160 | " int carry = R/256; \n" | ||
| 161 | " R -= carry*256; \n" | ||
| 162 | " int G = V1.g + V2.g + carry; \n" | ||
| 163 | " carry = G/256; \n" | ||
| 164 | " G -= carry*256; \n" | ||
| 165 | " int B = V1.b + V2.b + carry; \n" | ||
| 166 | " carry = B/256; \n" | ||
| 167 | " B -= carry*256; \n" | ||
| 168 | " int A = V1.a + V2.a + carry; \n" | ||
| 169 | " return ivec4(R,G,B,A); \n" | ||
| 170 | "} \n" | ||
| 171 | " \n" | ||
| 172 | "// converts a 32 bit represented by an ivec4 \n" | ||
| 173 | "// into a color. \n" | ||
| 174 | "vec4 ivec4_to_vec4(in ivec4 V) { \n" | ||
| 175 | " return vec4( \n" | ||
| 176 | " float(V.r)/255.0, \n" | ||
| 177 | " float(V.g)/255.0, \n" | ||
| 178 | " float(V.b)/255.0, \n" | ||
| 179 | " float(V.a)/255.0 \n" | ||
| 180 | " ); \n" | ||
| 181 | "} \n" | ||
| 182 | " \n" | ||
| 183 | "// converts a 32 bit represented by an int \n" | ||
| 184 | "// into a color. \n" | ||
| 185 | "highp vec4 int_to_vec4(in int x) { \n" | ||
| 186 | " return ivec4_to_vec4(int_to_ivec4(x)); \n" | ||
| 187 | "} \n" | ||
| 188 | " \n" | ||
| 189 | "float min3(in float x, in float y, in float z) { \n" | ||
| 190 | " return min(min(x,y),z); \n" | ||
| 191 | "} \n" | ||
| 192 | " \n" | ||
| 193 | "float min4(in float x, in float y, in float z, in float w) { \n" | ||
| 194 | " return min(min(x,y),min(z,w)); \n" | ||
| 195 | "} \n" | ||
| 196 | " \n" | ||
| 197 | "float edge_factor1(in float bary) { \n" | ||
| 198 | " float d = fwidth(bary); \n" | ||
| 199 | " float a = smoothstep(0.0, d*GLUP.mesh_width, bary); \n" | ||
| 200 | " return a; \n" | ||
| 201 | "} \n" | ||
| 202 | " \n" | ||
| 203 | "float edge_factor3(in vec3 bary) { \n" | ||
| 204 | " vec3 d = fwidth(bary); \n" | ||
| 205 | " vec3 a = smoothstep( \n" | ||
| 206 | " vec3(0.0, 0.0, 0.0), d*GLUP.mesh_width, bary \n" | ||
| 207 | " ); \n" | ||
| 208 | " return min3(a.x, a.y ,a.z); \n" | ||
| 209 | "} \n" | ||
| 210 | " \n" | ||
| 211 | "float edge_factor4(in vec4 bary) { \n" | ||
| 212 | " vec4 d = fwidth(bary); \n" | ||
| 213 | " vec4 a = smoothstep( \n" | ||
| 214 | " vec4(0.0, 0.0, 0.0, 0.0), d*GLUP.mesh_width, bary \n" | ||
| 215 | " ); \n" | ||
| 216 | " return min4(a.x, a.y, a.z, a.w); \n" | ||
| 217 | "} \n" | ||
| 218 | " \n" | ||
| 219 | "vec4 glup_picking(in highp int primitive_id) { \n" | ||
| 220 | " vec4 result; \n" | ||
| 221 | " if(GLUP.picking_mode == GLUP_PICK_PRIMITIVE) { \n" | ||
| 222 | " ivec4 A4 = int_to_ivec4(primitive_id); \n" | ||
| 223 | " // TODO: this one will not work if GPU has lowprec fshaders \n" | ||
| 224 | " ivec4 B4 = int_to_ivec4(GLUP.base_picking_id); \n" | ||
| 225 | " result = ivec4_to_vec4(ivec4_add(A4,B4)); \n" | ||
| 226 | " } else { \n" | ||
| 227 | " result = int_to_vec4(GLUP.picking_id); \n" | ||
| 228 | " } \n" | ||
| 229 | " return result; \n" | ||
| 230 | "} \n" | ||
| 231 | " \n" | ||
| 232 | "vec4 glup_texturing(in vec4 color, in vec4 tex_coord) { \n" | ||
| 233 | " vec4 result = color; \n" | ||
| 234 | " vec4 tex_color; \n" | ||
| 235 | " if(GLUP.texture_type == GLUP_TEXTURE_1D) { \n" | ||
| 236 | " tex_color = glup_texture( \n" | ||
| 237 | " texture1Dsampler, tex_coord.xy \n" | ||
| 238 | " ); \n" | ||
| 239 | " } else if(GLUP.texture_type == GLUP_TEXTURE_2D) { \n" | ||
| 240 | " tex_color = glup_texture( \n" | ||
| 241 | " texture2Dsampler, tex_coord.xy \n" | ||
| 242 | " ); \n" | ||
| 243 | " } \n" | ||
| 244 | "#ifdef GLUP_NO_TEXTURE_3D \n" | ||
| 245 | " else { \n" | ||
| 246 | " tex_color = vec4(1.0, 0.0, 0.0, 1.0); \n" | ||
| 247 | " } \n" | ||
| 248 | "#else \n" | ||
| 249 | " else if(GLUP.texture_type == GLUP_TEXTURE_3D) { \n" | ||
| 250 | " tex_color = texture( \n" | ||
| 251 | " texture3Dsampler, tex_coord.xyz \n" | ||
| 252 | " ); \n" | ||
| 253 | " } \n" | ||
| 254 | "#endif \n" | ||
| 255 | " if(glupIsEnabled(GLUP_INDIRECT_TEXTURING)) { \n" | ||
| 256 | " tex_color = GLUP.texture_matrix * tex_color; \n" | ||
| 257 | " tex_color = glup_texture(texture1Dsampler, tex_color.xy); \n" | ||
| 258 | " } \n" | ||
| 259 | " if(GLUP.texture_mode == GLUP_TEXTURE_REPLACE) { \n" | ||
| 260 | " result = tex_color; \n" | ||
| 261 | " } else if(GLUP.texture_mode==GLUP_TEXTURE_MODULATE) { \n" | ||
| 262 | " result *= tex_color; \n" | ||
| 263 | " } else { \n" | ||
| 264 | " result += tex_color; \n" | ||
| 265 | " } \n" | ||
| 266 | " return result; \n" | ||
| 267 | "} \n" | ||
| 268 | " \n" | ||
| 269 | "vec4 glup_lighting(in vec4 color, in vec3 normal) { \n" | ||
| 270 | " vec4 result = color; \n" | ||
| 271 | " float diff = dot(normal,GLUP.light_vector); \n" | ||
| 272 | " if(diff > 0.0) { \n" | ||
| 273 | " result.rgb = diff*result.rgb + vec3(0.2, 0.2, 0.2); \n" | ||
| 274 | " if(GLUP.specular > 0.0) { \n" | ||
| 275 | " float spec = dot(normal,GLUP.light_half_vector); \n" | ||
| 276 | " if(spec > 0.0) { \n" | ||
| 277 | " spec = pow(spec, 30.0); \n" | ||
| 278 | " result.rgb += GLUP.specular*spec*vec3(1.0, 1.0, 1.0); \n" | ||
| 279 | " } \n" | ||
| 280 | " } \n" | ||
| 281 | " } else { \n" | ||
| 282 | " result.rgb = vec3(0.2, 0.2, 0.2); \n" | ||
| 283 | " } \n" | ||
| 284 | " return result; \n" | ||
| 285 | "} \n" | ||
| 286 | " \n" | ||
| 287 | " \n" | ||
| 288 | "void glup_alpha_discard() { \n" | ||
| 289 | " if(glupIsEnabled(GLUP_ALPHA_DISCARD)) { \n" | ||
| 290 | " if(glup_FragColor.a < GLUP.alpha_threshold) { \n" | ||
| 291 | " discard; \n" | ||
| 292 | " } \n" | ||
| 293 | " } \n" | ||
| 294 | "} \n" | ||
| 295 | " \n" | ||
| 296 | "void glup_primitive_filter(highp int primitive_id) { \n" | ||
| 297 | "#ifdef GLUP_PRIMITIVE_FILTER \n" | ||
| 298 | " if( \n" | ||
| 299 | " texelFetch( \n" | ||
| 300 | " texturePrimitiveFiltersampler, \n" | ||
| 301 | " GLUP.base_picking_id + primitive_id \n" | ||
| 302 | " ).r == 0u \n" | ||
| 303 | " ) { \n" | ||
| 304 | " discard; \n" | ||
| 305 | " } \n" | ||
| 306 | "#endif \n" | ||
| 307 | "} \n" | ||
| 308 | ); | ||
| 309 | |||
| 310 | ✗ | GEO::GLSL::register_GLSL_include_file("GLUP/fragment_ray_tracing.h", | |
| 311 | " \n" | ||
| 312 | "struct Ray { \n" | ||
| 313 | " vec3 O; // Origin \n" | ||
| 314 | " vec3 V; // Direction vector \n" | ||
| 315 | "}; \n" | ||
| 316 | " \n" | ||
| 317 | "// Notes: GLUP.viewport = [x0,y0,width,height] \n" | ||
| 318 | "// clip-space coordinates are in [-1,1] (not [0,1]) ! \n" | ||
| 319 | " \n" | ||
| 320 | "// Computes the ray that passes through the current fragment \n" | ||
| 321 | "// The ray is in world space. \n" | ||
| 322 | "Ray glup_primary_ray() { \n" | ||
| 323 | " vec4 near = vec4( \n" | ||
| 324 | " 2.0 * ( (gl_FragCoord.x - GLUP.viewport[0]) / GLUP.viewport[2] - 0.5), \n" | ||
| 325 | " 2.0 * ( (gl_FragCoord.y - GLUP.viewport[1]) / GLUP.viewport[3] - 0.5), \n" | ||
| 326 | " 0.0, \n" | ||
| 327 | " 1.0 \n" | ||
| 328 | " ); \n" | ||
| 329 | " near = GLUP.inverse_modelviewprojection_matrix * near ; \n" | ||
| 330 | " vec4 far = near + GLUP.inverse_modelviewprojection_matrix[2] ; \n" | ||
| 331 | " near.xyz /= near.w ; \n" | ||
| 332 | " far.xyz /= far.w ; \n" | ||
| 333 | " return Ray(near.xyz, far.xyz-near.xyz) ; \n" | ||
| 334 | "} \n" | ||
| 335 | " \n" | ||
| 336 | "// Updates fragment depth from a point in world space \n" | ||
| 337 | "void glup_update_depth(in vec3 M_world_space) { \n" | ||
| 338 | " vec4 M_clip_space = GLUP.modelviewprojection_matrix * vec4(M_world_space,1.0); \n" | ||
| 339 | " float z = 0.5*(1.0 + M_clip_space.z/M_clip_space.w); \n" | ||
| 340 | " glup_FragDepth = (1.0-z)*gl_DepthRange.near + z*gl_DepthRange.far; \n" | ||
| 341 | "} \n" | ||
| 342 | ); | ||
| 343 | |||
| 344 | ✗ | GEO::GLSL::register_GLSL_include_file("GLUP/portable_fragment_shader.h", | |
| 345 | "//import <GLUP/current_profile/fragment_shader_preamble.h> \n" | ||
| 346 | "//import <GLUP/defs.h> \n" | ||
| 347 | " \n" | ||
| 348 | "#if defined(GLUP150) || defined (GLUP440) \n" | ||
| 349 | "in VertexData { \n" | ||
| 350 | " vec4 color; \n" | ||
| 351 | " vec4 tex_coord; \n" | ||
| 352 | " vec3 normal; \n" | ||
| 353 | "} FragmentIn; \n" | ||
| 354 | "vec4 tex_coord = FragmentIn.tex_coord; \n" | ||
| 355 | "#elif defined(GLUPES2) \n" | ||
| 356 | "glup_in vec4 tex_coord; \n" | ||
| 357 | "#endif \n" | ||
| 358 | ); | ||
| 359 | |||
| 360 | ✗ | GEO::GLSL::register_GLSL_include_file("GLUP/ShaderToy.h", | |
| 361 | "//import <GLUP/portable_fragment_shader.h> \n" | ||
| 362 | " \n" | ||
| 363 | "uniform float iTime; \n" | ||
| 364 | "uniform float iFrame; \n" | ||
| 365 | "uniform vec4 iDate; \n" | ||
| 366 | "const vec3 iResolution=vec3(1024.0, 1024.0, 1.0); \n" | ||
| 367 | "const vec4 iMouse=vec4(0.0, 0.0, 0.0, 0.0); \n" | ||
| 368 | "uniform sampler2D iChannel0; \n" | ||
| 369 | "uniform sampler2D iChannel1; \n" | ||
| 370 | "uniform sampler2D iChannel2; \n" | ||
| 371 | "uniform sampler2D iChannel3; \n" | ||
| 372 | " \n" | ||
| 373 | "void mainImage(out vec4 fragColor, in vec2 fragCoord); \n" | ||
| 374 | " \n" | ||
| 375 | "void main(void) { \n" | ||
| 376 | " mainImage(glup_FragColor, 1024.0*tex_coord.xy); \n" | ||
| 377 | "} \n" | ||
| 378 | ); | ||
| 379 | |||
| 380 | ✗ | GEO::GLSL::register_GLSL_include_file("GLUPES/fragment_shader_utils.h", | |
| 381 | "//import <GLUP/fragment_shader_utils.h> \n" | ||
| 382 | " \n" | ||
| 383 | "float cell_edge_factor(in vec2 bary) { \n" | ||
| 384 | " return edge_factor1(1.0-(1.0 - bary.x)*(1.0 - bary.y)); \n" | ||
| 385 | "} \n" | ||
| 386 | " \n" | ||
| 387 | "float edge_factor(in vec4 bary) { \n" | ||
| 388 | " float e1,e2,e3,e4,e5,e6,e7,e8,e9,e10,e11,e12; \n" | ||
| 389 | " float r1,r2,r3; \n" | ||
| 390 | " if(glup_primitive == GLUP_TRIANGLES) { \n" | ||
| 391 | " return edge_factor3(bary.xyz); \n" | ||
| 392 | " } else if(glup_primitive == GLUP_QUADS) { \n" | ||
| 393 | " return edge_factor4(bary); \n" | ||
| 394 | " } else if(glup_primitive == GLUP_TETRAHEDRA) { \n" | ||
| 395 | " e1 = cell_edge_factor(bary.xy); \n" | ||
| 396 | " e2 = cell_edge_factor(bary.xz); \n" | ||
| 397 | " e3 = cell_edge_factor(bary.xw); \n" | ||
| 398 | " e4 = cell_edge_factor(bary.yz); \n" | ||
| 399 | " e5 = cell_edge_factor(bary.yw); \n" | ||
| 400 | " e6 = cell_edge_factor(bary.zw); \n" | ||
| 401 | " return min3(min(e1,e2),min(e3,e4),min(e5,e6)); \n" | ||
| 402 | " } else if(glup_primitive == GLUP_HEXAHEDRA) { \n" | ||
| 403 | " vec3 u = bary.xyz; \n" | ||
| 404 | " vec3 U = vec3(1.0, 1.0, 1.0) - u; \n" | ||
| 405 | " e1 = cell_edge_factor(vec2(u.x,u.y)); \n" | ||
| 406 | " e2 = cell_edge_factor(vec2(u.x,u.z)); \n" | ||
| 407 | " e3 = cell_edge_factor(vec2(u.x,U.y)); \n" | ||
| 408 | " e4 = cell_edge_factor(vec2(u.x,U.z)); \n" | ||
| 409 | " e5 = cell_edge_factor(vec2(U.x,u.y)); \n" | ||
| 410 | " e6 = cell_edge_factor(vec2(U.x,u.z)); \n" | ||
| 411 | " e7 = cell_edge_factor(vec2(U.x,U.y)); \n" | ||
| 412 | " e8 = cell_edge_factor(vec2(U.x,U.z)); \n" | ||
| 413 | " e9 = cell_edge_factor(vec2(u.y,u.z)); \n" | ||
| 414 | " e10 = cell_edge_factor(vec2(u.y,U.z)); \n" | ||
| 415 | " e11 = cell_edge_factor(vec2(U.y,u.z)); \n" | ||
| 416 | " e12 = cell_edge_factor(vec2(U.y,U.z)); \n" | ||
| 417 | " r1 = min4(e1,e2,e3,e4); \n" | ||
| 418 | " r2 = min4(e5,e6,e7,e8); \n" | ||
| 419 | " r3 = min4(e9,e10,e11,e12); \n" | ||
| 420 | " return min3(r1,r2,r3); \n" | ||
| 421 | " } else if(glup_primitive == GLUP_PRISMS) { \n" | ||
| 422 | " vec4 bary2 = vec4(bary.x, bary.y, bary.z, 1.0 - bary.w); \n" | ||
| 423 | " e1 = cell_edge_factor(bary.xw); \n" | ||
| 424 | " e2 = cell_edge_factor(bary.yw); \n" | ||
| 425 | " e3 = cell_edge_factor(bary.zw); \n" | ||
| 426 | " e4 = cell_edge_factor(bary2.xw); \n" | ||
| 427 | " e5 = cell_edge_factor(bary2.yw); \n" | ||
| 428 | " e6 = cell_edge_factor(bary2.zw); \n" | ||
| 429 | " e7 = cell_edge_factor(bary.xy); \n" | ||
| 430 | " e8 = cell_edge_factor(bary.yz); \n" | ||
| 431 | " e9 = cell_edge_factor(bary.zx); \n" | ||
| 432 | " return min(min3(e7,e8,e9), \n" | ||
| 433 | " min3(min(e1,e2), \n" | ||
| 434 | " min(e3,e4),min(e5,e6)) \n" | ||
| 435 | " ); \n" | ||
| 436 | " } \n" | ||
| 437 | " return 1.0; \n" | ||
| 438 | "} \n" | ||
| 439 | " \n" | ||
| 440 | "vec4 glup_draw_mesh(in vec4 color, in vec4 mesh_tex_coord) { \n" | ||
| 441 | "#ifdef GLUP_NO_MESH_TEX_COORDS \n" | ||
| 442 | " return color; \n" | ||
| 443 | "#else \n" | ||
| 444 | " return mix( \n" | ||
| 445 | " GLUP.mesh_color, color, edge_factor(mesh_tex_coord) \n" | ||
| 446 | " ); \n" | ||
| 447 | "#endif \n" | ||
| 448 | "} \n" | ||
| 449 | " \n" | ||
| 450 | "vec4 glup_shading( \n" | ||
| 451 | " in vec4 color, \n" | ||
| 452 | " in vec4 tex_coord, \n" | ||
| 453 | " in vec3 normal, \n" | ||
| 454 | " in highp int primitive_id, \n" | ||
| 455 | " in vec4 mesh_tex_coord \n" | ||
| 456 | ") { \n" | ||
| 457 | " if(glupIsEnabled(GLUP_PICKING)) { \n" | ||
| 458 | " return glup_picking(primitive_id); \n" | ||
| 459 | " } \n" | ||
| 460 | " vec4 result; \n" | ||
| 461 | " if(glupIsEnabled(GLUP_VERTEX_COLORS)) { \n" | ||
| 462 | " result = color; \n" | ||
| 463 | " } else { \n" | ||
| 464 | " result = gl_FrontFacing ? GLUP.front_color : GLUP.back_color; \n" | ||
| 465 | " } \n" | ||
| 466 | " if(glupIsEnabled(GLUP_TEXTURING) && !glupIsEnabled(GLUP_NORMAL_MAPPING)) { \n" | ||
| 467 | " result = glup_texturing(result, tex_coord); \n" | ||
| 468 | " } \n" | ||
| 469 | " if(glupIsEnabled(GLUP_LIGHTING)) { \n" | ||
| 470 | " result = glup_lighting(result, normal); \n" | ||
| 471 | " } \n" | ||
| 472 | " if( \n" | ||
| 473 | " glupIsEnabled(GLUP_DRAW_MESH) && ( \n" | ||
| 474 | " (glup_primitive_dimension == 2) || \n" | ||
| 475 | " !glupIsEnabled(GLUP_CLIPPING) || \n" | ||
| 476 | " GLUP.clipping_mode != GLUP_CLIP_SLICE_CELLS \n" | ||
| 477 | " ) \n" | ||
| 478 | " ) { \n" | ||
| 479 | " result = glup_draw_mesh(result, mesh_tex_coord); \n" | ||
| 480 | " } \n" | ||
| 481 | " return result; \n" | ||
| 482 | "} \n" | ||
| 483 | ); | ||
| 484 | |||
| 485 | ✗ | GEO::GLSL::register_GLSL_include_file("GLUPES/vertex_shader_state.h", | |
| 486 | "struct VSUniformState { \n" | ||
| 487 | " mat3 normal_matrix; \n" | ||
| 488 | " mat4 modelviewprojection_matrix; \n" | ||
| 489 | " mat4 modelview_matrix; \n" | ||
| 490 | " mat4 projection_matrix; \n" | ||
| 491 | " mat4 texture_matrix; \n" | ||
| 492 | " mat4 inverse_modelview_matrix; \n" | ||
| 493 | " mat4 inverse_projection_matrix; \n" | ||
| 494 | " mat4 inverse_modelviewprojection_matrix; \n" | ||
| 495 | " vec4 world_clip_plane; \n" | ||
| 496 | " float point_size; \n" | ||
| 497 | " vec4 viewport; \n" | ||
| 498 | " float mesh_width; \n" | ||
| 499 | "}; \n" | ||
| 500 | " \n" | ||
| 501 | "uniform VSUniformState GLUP_VS; \n" | ||
| 502 | ); | ||
| 503 | |||
| 504 | ✗ | GEO::GLSL::register_GLSL_include_file("GLUPES/fragment_shader_state.h", | |
| 505 | "struct UniformState { \n" | ||
| 506 | " bool vertex_colors_enabled; \n" | ||
| 507 | " \n" | ||
| 508 | " vec4 front_color; \n" | ||
| 509 | " vec4 back_color; \n" | ||
| 510 | " \n" | ||
| 511 | " bool draw_mesh_enabled; \n" | ||
| 512 | " vec4 mesh_color; \n" | ||
| 513 | " float mesh_width; \n" | ||
| 514 | " \n" | ||
| 515 | " bool lighting_enabled; \n" | ||
| 516 | " bool normal_mapping_enabled; \n" | ||
| 517 | " vec3 light_vector; \n" | ||
| 518 | " vec3 light_half_vector; \n" | ||
| 519 | " float specular; \n" | ||
| 520 | " \n" | ||
| 521 | " bool texturing_enabled; \n" | ||
| 522 | " bool indirect_texturing_enabled; \n" | ||
| 523 | " int texture_mode; \n" | ||
| 524 | " int texture_type; \n" | ||
| 525 | " \n" | ||
| 526 | " float cells_shrink; \n" | ||
| 527 | " \n" | ||
| 528 | " bool picking_enabled; \n" | ||
| 529 | " int picking_mode; \n" | ||
| 530 | " int picking_id; \n" | ||
| 531 | " int base_picking_id; \n" | ||
| 532 | " \n" | ||
| 533 | " bool clipping_enabled; \n" | ||
| 534 | " int clipping_mode; \n" | ||
| 535 | " vec4 clip_plane; \n" | ||
| 536 | " vec4 world_clip_plane; \n" | ||
| 537 | " \n" | ||
| 538 | " bool alpha_discard_enabled; \n" | ||
| 539 | " float alpha_threshold; \n" | ||
| 540 | " \n" | ||
| 541 | " mat4 texture_matrix; \n" | ||
| 542 | " mat4 modelviewprojection_matrix; \n" | ||
| 543 | " mat4 inverse_modelviewprojection_matrix; \n" | ||
| 544 | " mat3 normal_matrix; \n" | ||
| 545 | " \n" | ||
| 546 | " vec4 viewport; \n" | ||
| 547 | " \n" | ||
| 548 | " bool vertex_normals_enabled; \n" | ||
| 549 | " bool primitive_filtering_enabled; \n" | ||
| 550 | " bool thick_lines_enabled; \n" | ||
| 551 | "}; \n" | ||
| 552 | " \n" | ||
| 553 | "uniform UniformState GLUP; \n" | ||
| 554 | "uniform sampler2D texture1Dsampler; \n" | ||
| 555 | "uniform sampler2D texture2Dsampler; \n" | ||
| 556 | "#ifndef GLUP_NO_TEXTURE_3D \n" | ||
| 557 | "uniform sampler3D texture3Dsampler; \n" | ||
| 558 | "#endif \n" | ||
| 559 | " \n" | ||
| 560 | "// TODO: \n" | ||
| 561 | "// requires \n" | ||
| 562 | "// #version 140 or \n" | ||
| 563 | "// #extension GL_EXT_gpu_shader4 enable \n" | ||
| 564 | "// uniform samplerBuffer texturePrimitiveFiltersampler; \n" | ||
| 565 | ); | ||
| 566 | |||
| 567 | ✗ | GEO::GLSL::register_GLSL_include_file("GLUPES/points_vertex_shader.h", | |
| 568 | "//import <GLUP/current_profile/vertex_shader_preamble.h> \n" | ||
| 569 | "//import <GLUPES/vertex_shader_state.h> \n" | ||
| 570 | "//import <GLUP/stdglup.h> \n" | ||
| 571 | "//import <GLUP/current_profile/toggles.h> \n" | ||
| 572 | "//import <GLUP/current_profile/primitive.h> \n" | ||
| 573 | " \n" | ||
| 574 | "glup_in vec4 vertex_in; \n" | ||
| 575 | "glup_in vec4 color_in; \n" | ||
| 576 | "glup_in vec4 tex_coord_in; \n" | ||
| 577 | "glup_in highp float vertex_id_in; \n" | ||
| 578 | " \n" | ||
| 579 | "glup_flat glup_out vec4 color; \n" | ||
| 580 | "glup_flat glup_out vec4 tex_coord; \n" | ||
| 581 | "glup_flat glup_out vec3 center_world_space; \n" | ||
| 582 | "glup_flat glup_out float radius; \n" | ||
| 583 | "glup_flat glup_out glup_id primitive_id; \n" | ||
| 584 | " \n" | ||
| 585 | " \n" | ||
| 586 | "void main(void) { \n" | ||
| 587 | " \n" | ||
| 588 | " if(glupIsEnabled(GLUP_PICKING)) { \n" | ||
| 589 | "#ifdef GLUP_ES_100 \n" | ||
| 590 | " primitive_id = float(int(vertex_id_in + 0.5)) + 0.5; \n" | ||
| 591 | "#else \n" | ||
| 592 | " primitive_id = int(vertex_id_in + 0.5); \n" | ||
| 593 | "#endif \n" | ||
| 594 | " } \n" | ||
| 595 | " \n" | ||
| 596 | " if(glupIsEnabled(GLUP_VERTEX_COLORS)) { \n" | ||
| 597 | " color = color_in; \n" | ||
| 598 | " } \n" | ||
| 599 | " \n" | ||
| 600 | " if(glupIsEnabled(GLUP_TEXTURING)) { \n" | ||
| 601 | " if(glupIsEnabled(GLUP_INDIRECT_TEXTURING)) { \n" | ||
| 602 | " tex_coord = tex_coord_in; \n" | ||
| 603 | " } else { \n" | ||
| 604 | " tex_coord = GLUP_VS.texture_matrix * tex_coord_in; \n" | ||
| 605 | " } \n" | ||
| 606 | " } \n" | ||
| 607 | " \n" | ||
| 608 | " // note: WebGL does not have glPointSize() API function \n" | ||
| 609 | " // so the only way to set it is from the VS. \n" | ||
| 610 | " gl_PointSize = GLUP_VS.point_size; \n" | ||
| 611 | " gl_Position = GLUP_VS.modelviewprojection_matrix*vertex_in; \n" | ||
| 612 | " \n" | ||
| 613 | " center_world_space = vertex_in.xyz / vertex_in.w; \n" | ||
| 614 | " \n" | ||
| 615 | " vec4 P1 = GLUP_VS.inverse_modelviewprojection_matrix*vec4( \n" | ||
| 616 | " 0.0, 0.0, 0.0, 1.0 \n" | ||
| 617 | " ); \n" | ||
| 618 | " vec4 P2 = GLUP_VS.inverse_modelviewprojection_matrix*vec4( \n" | ||
| 619 | " GLUP_VS.point_size/GLUP_VS.viewport[2],0.0,0.0,1.0 \n" | ||
| 620 | " ); \n" | ||
| 621 | " radius = length(P1.xyz/P1.w-P2.xyz/P2.w); \n" | ||
| 622 | "} \n" | ||
| 623 | ); | ||
| 624 | |||
| 625 | ✗ | GEO::GLSL::register_GLSL_include_file("GLUPES/lines_fragment_shader.h", | |
| 626 | "//import <GLUP/current_profile/fragment_shader_preamble.h> \n" | ||
| 627 | "//import <GLUPES/fragment_shader_state.h> \n" | ||
| 628 | "//import <GLUP/stdglup.h> \n" | ||
| 629 | "//import <GLUP/current_profile/toggles.h> \n" | ||
| 630 | "//import <GLUP/current_profile/primitive.h> \n" | ||
| 631 | "//import <GLUPES/fragment_shader_utils.h> \n" | ||
| 632 | " \n" | ||
| 633 | "glup_in vec4 color; \n" | ||
| 634 | "glup_in vec4 tex_coord; \n" | ||
| 635 | "glup_in float clip_dist; \n" | ||
| 636 | "glup_flat glup_in glup_id primitive_id; \n" | ||
| 637 | " \n" | ||
| 638 | "void main() { \n" | ||
| 639 | " \n" | ||
| 640 | " if(glupIsEnabled(GLUP_CLIPPING) && (clip_dist < 0.0)) { \n" | ||
| 641 | " discard; \n" | ||
| 642 | " } \n" | ||
| 643 | " \n" | ||
| 644 | " if(glupIsEnabled(GLUP_PICKING)) { \n" | ||
| 645 | " glup_FragColor = glup_picking(int(primitive_id)); \n" | ||
| 646 | " return; \n" | ||
| 647 | " } \n" | ||
| 648 | " \n" | ||
| 649 | " vec4 result; \n" | ||
| 650 | " if(glupIsEnabled(GLUP_VERTEX_COLORS)) { \n" | ||
| 651 | " result = color; \n" | ||
| 652 | " } else { \n" | ||
| 653 | " result = GLUP.front_color; \n" | ||
| 654 | " } \n" | ||
| 655 | " if(glupIsEnabled(GLUP_TEXTURING)) { \n" | ||
| 656 | " result = glup_texturing(result, tex_coord); \n" | ||
| 657 | " } \n" | ||
| 658 | " glup_FragColor = result; \n" | ||
| 659 | " glup_alpha_discard(); \n" | ||
| 660 | "} \n" | ||
| 661 | ); | ||
| 662 | |||
| 663 | ✗ | GEO::GLSL::register_GLSL_include_file("GLUPES/thick_lines_vertex_shader.h", | |
| 664 | "//import <GLUP/current_profile/vertex_shader_preamble.h> \n" | ||
| 665 | "//import <GLUP/stdglup.h> \n" | ||
| 666 | "//import <GLUP/current_profile/toggles.h> \n" | ||
| 667 | "//import <GLUP/current_profile/primitive.h> \n" | ||
| 668 | "//import <GLUPES/vertex_shader_state.h> \n" | ||
| 669 | " \n" | ||
| 670 | "glup_in vec4 vertex_in; \n" | ||
| 671 | "glup_in vec4 color_in; \n" | ||
| 672 | "glup_in vec4 tex_coord_in; \n" | ||
| 673 | "glup_in vec4 normal_in; \n" | ||
| 674 | "glup_in highp float vertex_id_in; \n" | ||
| 675 | "glup_out float clip_dist; \n" | ||
| 676 | "glup_out vec4 color; \n" | ||
| 677 | "glup_out vec4 tex_coord; \n" | ||
| 678 | "glup_flat glup_out glup_id primitive_id; \n" | ||
| 679 | "glup_out float R; \n" | ||
| 680 | "glup_out vec2 p1_ndc; \n" | ||
| 681 | "glup_out vec2 p2_ndc; \n" | ||
| 682 | " \n" | ||
| 683 | " \n" | ||
| 684 | "void emit_vertex_2( \n" | ||
| 685 | " in vec4 p_world, in vec4 p_clip_space, \n" | ||
| 686 | " in vec2 offset, in float z_offset \n" | ||
| 687 | ") { \n" | ||
| 688 | " if(glupIsEnabled(GLUP_CLIPPING)) { \n" | ||
| 689 | " clip_dist = dot( \n" | ||
| 690 | " p_world, GLUP_VS.world_clip_plane \n" | ||
| 691 | " ); \n" | ||
| 692 | " } \n" | ||
| 693 | " gl_Position = p_clip_space / p_clip_space.w ; \n" | ||
| 694 | " gl_Position.x += offset.x; \n" | ||
| 695 | " gl_Position.y += offset.y; \n" | ||
| 696 | " gl_Position.z -= z_offset; \n" | ||
| 697 | " if(glupIsEnabled(GLUP_VERTEX_COLORS)) { \n" | ||
| 698 | " color = color_in; \n" | ||
| 699 | " } \n" | ||
| 700 | " if(glupIsEnabled(GLUP_TEXTURING)) { \n" | ||
| 701 | " if(glupIsEnabled(GLUP_INDIRECT_TEXTURING)) { \n" | ||
| 702 | " tex_coord = tex_coord_in; \n" | ||
| 703 | " } else { \n" | ||
| 704 | " tex_coord = GLUP_VS.texture_matrix * tex_coord_in; \n" | ||
| 705 | " } \n" | ||
| 706 | " } \n" | ||
| 707 | "} \n" | ||
| 708 | " \n" | ||
| 709 | " \n" | ||
| 710 | "void main() { \n" | ||
| 711 | " \n" | ||
| 712 | " R = 2.0*(GLUP_VS.mesh_width/(GLUP_VS.viewport[2]+GLUP_VS.viewport[3])); \n" | ||
| 713 | " \n" | ||
| 714 | " vec4 p1_clipspace = GLUP_VS.modelviewprojection_matrix * vertex_in; \n" | ||
| 715 | " vec4 p2_clipspace = GLUP_VS.modelviewprojection_matrix * normal_in; \n" | ||
| 716 | " \n" | ||
| 717 | " p1_ndc = p1_clipspace.xy / p1_clipspace.w; \n" | ||
| 718 | " p2_ndc = p2_clipspace.xy / p2_clipspace.w; \n" | ||
| 719 | " \n" | ||
| 720 | " if(glupIsEnabled(GLUP_PICKING)) { \n" | ||
| 721 | "#ifdef GLUP_ES_100 \n" | ||
| 722 | " // Note: we need to add 0.5, else there are some precision \n" | ||
| 723 | " // issues, and the integer mod() operation creates random \n" | ||
| 724 | " // values... \n" | ||
| 725 | " primitive_id = float( \n" | ||
| 726 | " int(vertex_id_in+0.5)/glup_primitive_nb_vertices \n" | ||
| 727 | " )+0.5; \n" | ||
| 728 | "#else \n" | ||
| 729 | " primitive_id = int(vertex_id_in + 0.5)/glup_primitive_nb_vertices; \n" | ||
| 730 | "#endif \n" | ||
| 731 | " } \n" | ||
| 732 | " \n" | ||
| 733 | " vec2 U = R*normalize(p2_ndc-p1_ndc); \n" | ||
| 734 | " vec2 V = vec2(U.y,-U.x); \n" | ||
| 735 | " \n" | ||
| 736 | " int v_local_id = glup_mod(int(vertex_id_in+0.5),4); \n" | ||
| 737 | " float z_offset = 0.2 * GLUP_VS.modelview_matrix[3][3] * R; \n" | ||
| 738 | " \n" | ||
| 739 | " if(v_local_id == 0) { \n" | ||
| 740 | " emit_vertex_2(vertex_in, p1_clipspace,-U-V, z_offset); \n" | ||
| 741 | " } else if(v_local_id == 1) { \n" | ||
| 742 | " emit_vertex_2(vertex_in, p1_clipspace,-U+V, z_offset); \n" | ||
| 743 | " } else if(v_local_id == 2) { \n" | ||
| 744 | " emit_vertex_2(normal_in, p2_clipspace, U-V, z_offset); \n" | ||
| 745 | " } else { \n" | ||
| 746 | " emit_vertex_2(normal_in, p2_clipspace, U+V, z_offset); \n" | ||
| 747 | " } \n" | ||
| 748 | " \n" | ||
| 749 | "} \n" | ||
| 750 | ); | ||
| 751 | |||
| 752 | ✗ | GEO::GLSL::register_GLSL_include_file("GLUPES/thick_lines_fragment_shader.h", | |
| 753 | "//import <GLUP/current_profile/fragment_shader_preamble.h> \n" | ||
| 754 | "//import <GLUPES/fragment_shader_state.h> \n" | ||
| 755 | "//import <GLUP/stdglup.h> \n" | ||
| 756 | "//import <GLUP/current_profile/toggles.h> \n" | ||
| 757 | "//import <GLUP/current_profile/primitive.h> \n" | ||
| 758 | "//import <GLUPES/fragment_shader_utils.h> \n" | ||
| 759 | " \n" | ||
| 760 | "glup_in float clip_dist; \n" | ||
| 761 | "glup_in vec4 color; \n" | ||
| 762 | "glup_in vec4 tex_coord; \n" | ||
| 763 | "glup_flat glup_in glup_id primitive_id; \n" | ||
| 764 | "glup_in float R; \n" | ||
| 765 | "glup_in vec2 p1_ndc; \n" | ||
| 766 | "glup_in vec2 p2_ndc; \n" | ||
| 767 | " \n" | ||
| 768 | "void main() { \n" | ||
| 769 | " \n" | ||
| 770 | " if(glupIsEnabled(GLUP_CLIPPING)) { \n" | ||
| 771 | " if(clip_dist < 0.0) { \n" | ||
| 772 | " discard; \n" | ||
| 773 | " } \n" | ||
| 774 | " } \n" | ||
| 775 | " \n" | ||
| 776 | " // Create nicer joints between overlapping thick lines by creating a \n" | ||
| 777 | " // small disk over the joints \n" | ||
| 778 | " \n" | ||
| 779 | " vec2 p_ndc = vec2( \n" | ||
| 780 | " 2.0 * ( (gl_FragCoord.x - GLUP.viewport[0]) / GLUP.viewport[2] - 0.5), \n" | ||
| 781 | " 2.0 * ( (gl_FragCoord.y - GLUP.viewport[1]) / GLUP.viewport[3] - 0.5) \n" | ||
| 782 | " ); \n" | ||
| 783 | " \n" | ||
| 784 | " vec2 U = p2_ndc - p1_ndc; \n" | ||
| 785 | " vec2 V1 = p_ndc - p1_ndc; \n" | ||
| 786 | " vec2 V2 = p_ndc - p2_ndc; \n" | ||
| 787 | " \n" | ||
| 788 | " if(dot(V1,U) < 0.0 && dot(V1,V1) > R*R) { \n" | ||
| 789 | " discard; \n" | ||
| 790 | " } \n" | ||
| 791 | " \n" | ||
| 792 | " if(dot(V2,U) > 0.0 && dot(V2,V2) > R*R) { \n" | ||
| 793 | " discard; \n" | ||
| 794 | " } \n" | ||
| 795 | " \n" | ||
| 796 | " if(glupIsEnabled(GLUP_PICKING)) { \n" | ||
| 797 | " glup_FragColor = glup_picking(int(primitive_id)); \n" | ||
| 798 | " return; \n" | ||
| 799 | " } \n" | ||
| 800 | " \n" | ||
| 801 | " vec4 result; \n" | ||
| 802 | " if(glupIsEnabled(GLUP_VERTEX_COLORS)) { \n" | ||
| 803 | " result = color; \n" | ||
| 804 | " } else { \n" | ||
| 805 | " result = GLUP.mesh_color; \n" | ||
| 806 | " } \n" | ||
| 807 | " \n" | ||
| 808 | " if(glupIsEnabled(GLUP_TEXTURING) && !glupIsEnabled(GLUP_NORMAL_MAPPING)) { \n" | ||
| 809 | " result = glup_texturing(result, tex_coord); \n" | ||
| 810 | " } \n" | ||
| 811 | " glup_FragColor = result; \n" | ||
| 812 | " glup_alpha_discard(); \n" | ||
| 813 | "} \n" | ||
| 814 | ); | ||
| 815 | |||
| 816 | ✗ | GEO::GLSL::register_GLSL_include_file("GLUPES/vertex_shader.h", | |
| 817 | "//import <GLUP/current_profile/vertex_shader_preamble.h> \n" | ||
| 818 | "//import <GLUP/stdglup.h> \n" | ||
| 819 | "//import <GLUP/current_profile/toggles.h> \n" | ||
| 820 | "//import <GLUP/current_profile/primitive.h> \n" | ||
| 821 | "//import <GLUPES/vertex_shader_state.h> \n" | ||
| 822 | " \n" | ||
| 823 | "glup_in vec4 vertex_in; \n" | ||
| 824 | "glup_in vec4 color_in; \n" | ||
| 825 | "glup_in vec4 tex_coord_in; \n" | ||
| 826 | "glup_in highp float vertex_id_in; \n" | ||
| 827 | "glup_out vec3 vertex_view_space; \n" | ||
| 828 | "glup_out float clip_dist; \n" | ||
| 829 | "glup_out vec4 color; \n" | ||
| 830 | "glup_out vec4 tex_coord; \n" | ||
| 831 | "glup_out vec4 mesh_tex_coord; \n" | ||
| 832 | "glup_flat glup_out glup_id primitive_id; \n" | ||
| 833 | " \n" | ||
| 834 | "#if GLUP_PRIMITIVE_DIMENSION==2 \n" | ||
| 835 | "glup_in vec4 normal_in; \n" | ||
| 836 | "glup_out vec3 normal; \n" | ||
| 837 | "#endif \n" | ||
| 838 | " \n" | ||
| 839 | "void main() { \n" | ||
| 840 | " \n" | ||
| 841 | " if(glupIsEnabled(GLUP_CLIPPING)) { \n" | ||
| 842 | " clip_dist = dot( \n" | ||
| 843 | " vertex_in, GLUP_VS.world_clip_plane \n" | ||
| 844 | " ); \n" | ||
| 845 | " } \n" | ||
| 846 | " \n" | ||
| 847 | " if(glupIsEnabled(GLUP_PICKING)) { \n" | ||
| 848 | "#ifdef GLUP_ES_100 \n" | ||
| 849 | " // Note: we need to add 0.5, else there are some precision \n" | ||
| 850 | " // issues, and the integer mod() operation creates random \n" | ||
| 851 | " // values... \n" | ||
| 852 | " primitive_id = float( \n" | ||
| 853 | " int(vertex_id_in+0.5)/glup_primitive_nb_vertices \n" | ||
| 854 | " )+0.5; \n" | ||
| 855 | "#else \n" | ||
| 856 | " primitive_id = int(vertex_id_in + 0.5)/glup_primitive_nb_vertices; \n" | ||
| 857 | "#endif \n" | ||
| 858 | " } \n" | ||
| 859 | " \n" | ||
| 860 | " if(glupIsEnabled(GLUP_LIGHTING)) { \n" | ||
| 861 | " vertex_view_space = (GLUP_VS.modelview_matrix * vertex_in).xyz; \n" | ||
| 862 | "#if GLUP_PRIMITIVE_DIMENSION==2 \n" | ||
| 863 | " if(glupIsEnabled(GLUP_VERTEX_NORMALS)) { \n" | ||
| 864 | " normal = GLUP_VS.normal_matrix*normal_in.xyz; \n" | ||
| 865 | " } \n" | ||
| 866 | "#endif \n" | ||
| 867 | " } \n" | ||
| 868 | " \n" | ||
| 869 | " if(glupIsEnabled(GLUP_VERTEX_COLORS)) { \n" | ||
| 870 | " color = color_in; \n" | ||
| 871 | " } \n" | ||
| 872 | " \n" | ||
| 873 | " if(glupIsEnabled(GLUP_TEXTURING)) { \n" | ||
| 874 | " if(glupIsEnabled(GLUP_INDIRECT_TEXTURING)) { \n" | ||
| 875 | " tex_coord = tex_coord_in; \n" | ||
| 876 | " } else { \n" | ||
| 877 | " tex_coord = GLUP_VS.texture_matrix * tex_coord_in; \n" | ||
| 878 | " } \n" | ||
| 879 | " } \n" | ||
| 880 | " \n" | ||
| 881 | " if(glupIsEnabled(GLUP_DRAW_MESH)) { \n" | ||
| 882 | " mesh_tex_coord = get_mesh_tex_coord(int(vertex_id_in + 0.5)); \n" | ||
| 883 | " } \n" | ||
| 884 | " \n" | ||
| 885 | " gl_Position = GLUP_VS.modelviewprojection_matrix * vertex_in; \n" | ||
| 886 | "} \n" | ||
| 887 | ); | ||
| 888 | |||
| 889 | ✗ | GEO::GLSL::register_GLSL_include_file("GLUPES/fragment_shader.h", | |
| 890 | "//import <GLUP/current_profile/fragment_shader_preamble.h> \n" | ||
| 891 | "//import <GLUPES/fragment_shader_state.h> \n" | ||
| 892 | "//import <GLUP/stdglup.h> \n" | ||
| 893 | "//import <GLUP/current_profile/toggles.h> \n" | ||
| 894 | "//import <GLUP/current_profile/primitive.h> \n" | ||
| 895 | "//import <GLUPES/fragment_shader_utils.h> \n" | ||
| 896 | " \n" | ||
| 897 | "glup_in vec3 vertex_view_space; \n" | ||
| 898 | "glup_in float clip_dist; \n" | ||
| 899 | "glup_in vec4 color; \n" | ||
| 900 | "glup_in vec4 tex_coord; \n" | ||
| 901 | "glup_in vec4 mesh_tex_coord; \n" | ||
| 902 | "glup_flat glup_in glup_id primitive_id; \n" | ||
| 903 | " \n" | ||
| 904 | "#if GLUP_PRIMITIVE_DIMENSION==2 \n" | ||
| 905 | "glup_in vec3 normal; \n" | ||
| 906 | "#endif \n" | ||
| 907 | " \n" | ||
| 908 | " \n" | ||
| 909 | "void main() { \n" | ||
| 910 | " \n" | ||
| 911 | " if(glupIsEnabled(GLUP_CLIPPING)) { \n" | ||
| 912 | " if(glup_primitive_dimension == 2) { \n" | ||
| 913 | " if(clip_dist < 0.0) { \n" | ||
| 914 | " discard; \n" | ||
| 915 | " } \n" | ||
| 916 | " } else if(glup_primitive_dimension == 3) { \n" | ||
| 917 | " if( \n" | ||
| 918 | " clip_dist < 0.0 && \n" | ||
| 919 | " GLUP.clipping_mode == GLUP_CLIP_STANDARD \n" | ||
| 920 | " ) { \n" | ||
| 921 | " discard; \n" | ||
| 922 | " } \n" | ||
| 923 | " } \n" | ||
| 924 | " } \n" | ||
| 925 | " \n" | ||
| 926 | " vec3 N; \n" | ||
| 927 | " if(glupIsEnabled(GLUP_LIGHTING)) { \n" | ||
| 928 | " if( \n" | ||
| 929 | " glupIsEnabled(GLUP_TEXTURING) && \n" | ||
| 930 | " glupIsEnabled(GLUP_NORMAL_MAPPING) \n" | ||
| 931 | " ) { \n" | ||
| 932 | " N = glup_texturing(vec4(1.0,1.0,1.0,1.0), tex_coord).xyz; \n" | ||
| 933 | " N = N-vec3(0.5,0.5,0.5); \n" | ||
| 934 | " N = normalize(GLUP.normal_matrix*N); \n" | ||
| 935 | " if(!gl_FrontFacing) { \n" | ||
| 936 | " N = -N; \n" | ||
| 937 | " } \n" | ||
| 938 | " } else { \n" | ||
| 939 | "#if GLUP_PRIMITIVE_DIMENSION==2 \n" | ||
| 940 | " if(glupIsEnabled(GLUP_VERTEX_NORMALS)) { \n" | ||
| 941 | " N = normalize(normal); \n" | ||
| 942 | " if(!gl_FrontFacing) { \n" | ||
| 943 | " N = -N; \n" | ||
| 944 | " } \n" | ||
| 945 | " } else \n" | ||
| 946 | "#endif \n" | ||
| 947 | " { \n" | ||
| 948 | " // Note: we still compute view space vertex \n" | ||
| 949 | " // in vertex shader, because we seemingly do \n" | ||
| 950 | " // not have sufficient precision to do the same \n" | ||
| 951 | " // trick as in GLUP_GLSL (i.e. going back to \n" | ||
| 952 | " // view space from clip space using projection \n" | ||
| 953 | " // matrix). \n" | ||
| 954 | " vec3 U = dFdx(vertex_view_space); \n" | ||
| 955 | " vec3 V = dFdy(vertex_view_space); \n" | ||
| 956 | " N = normalize(cross(U,V)); \n" | ||
| 957 | " } \n" | ||
| 958 | " } \n" | ||
| 959 | " } \n" | ||
| 960 | " \n" | ||
| 961 | " glup_FragColor = glup_shading( \n" | ||
| 962 | " color, tex_coord, N, int(primitive_id), mesh_tex_coord \n" | ||
| 963 | " ); \n" | ||
| 964 | " glup_alpha_discard(); \n" | ||
| 965 | "} \n" | ||
| 966 | ); | ||
| 967 | |||
| 968 | ✗ | GEO::GLSL::register_GLSL_include_file("GLUPES/spheres_vertex_shader.h", | |
| 969 | "//import <GLUP/current_profile/vertex_shader_preamble.h> \n" | ||
| 970 | "//import <GLUPES/vertex_shader_state.h> \n" | ||
| 971 | "//import <GLUP/stdglup.h> \n" | ||
| 972 | "//import <GLUP/current_profile/toggles.h> \n" | ||
| 973 | "//import <GLUP/current_profile/primitive.h> \n" | ||
| 974 | " \n" | ||
| 975 | "glup_in vec4 vertex_in; \n" | ||
| 976 | "glup_in vec4 color_in; \n" | ||
| 977 | "glup_in vec4 tex_coord_in; \n" | ||
| 978 | "glup_in highp float vertex_id_in; \n" | ||
| 979 | " \n" | ||
| 980 | "glup_flat glup_out vec4 color; \n" | ||
| 981 | "glup_flat glup_out vec4 tex_coord; \n" | ||
| 982 | "glup_flat glup_out vec3 center_world_space; \n" | ||
| 983 | "glup_flat glup_out float radius; \n" | ||
| 984 | "glup_flat glup_out glup_id primitive_id; \n" | ||
| 985 | " \n" | ||
| 986 | "vec4 row0(in mat4 M) { \n" | ||
| 987 | " return vec4(M[0][0], M[1][0], M[2][0], M[3][0]); \n" | ||
| 988 | "} \n" | ||
| 989 | " \n" | ||
| 990 | "vec4 row1(in mat4 M) { \n" | ||
| 991 | " return vec4(M[0][1], M[1][1], M[2][1], M[3][1]); \n" | ||
| 992 | "} \n" | ||
| 993 | " \n" | ||
| 994 | "vec4 row3(in mat4 M) { \n" | ||
| 995 | " return vec4(M[0][3], M[1][3], M[2][3], M[3][3]); \n" | ||
| 996 | "} \n" | ||
| 997 | " \n" | ||
| 998 | "// Reference: \n" | ||
| 999 | "// http://reality.cs.ucl.ac.uk/projects/quadrics/pbg06.pdf \n" | ||
| 1000 | "// Ported from Dmitry / Sam code \n" | ||
| 1001 | " \n" | ||
| 1002 | "void main(void) { \n" | ||
| 1003 | " \n" | ||
| 1004 | " if(glupIsEnabled(GLUP_PICKING)) { \n" | ||
| 1005 | "#ifdef GLUP_ES_100 \n" | ||
| 1006 | " primitive_id = float(int(vertex_id_in + 0.5)) + 0.5; \n" | ||
| 1007 | "#else \n" | ||
| 1008 | " primitive_id = int(vertex_id_in + 0.5); \n" | ||
| 1009 | "#endif \n" | ||
| 1010 | " } \n" | ||
| 1011 | " \n" | ||
| 1012 | " if(glupIsEnabled(GLUP_VERTEX_COLORS)) { \n" | ||
| 1013 | " color = color_in; \n" | ||
| 1014 | " } \n" | ||
| 1015 | " \n" | ||
| 1016 | " if(glupIsEnabled(GLUP_TEXTURING)) { \n" | ||
| 1017 | " if(glupIsEnabled(GLUP_INDIRECT_TEXTURING)) { \n" | ||
| 1018 | " tex_coord = tex_coord_in; \n" | ||
| 1019 | " } else { \n" | ||
| 1020 | " tex_coord = GLUP_VS.texture_matrix * tex_coord_in; \n" | ||
| 1021 | " } \n" | ||
| 1022 | " } \n" | ||
| 1023 | " \n" | ||
| 1024 | " float R = vertex_in.w; \n" | ||
| 1025 | " gl_Position = \n" | ||
| 1026 | " GLUP_VS.modelviewprojection_matrix*vec4(vertex_in.xyz,1.0); \n" | ||
| 1027 | " \n" | ||
| 1028 | " // TODO: optimize, directly compute r1,r2,r4 \n" | ||
| 1029 | " mat4 T = mat4( \n" | ||
| 1030 | " 1.0, 0.0, 0.0, 0.0, \n" | ||
| 1031 | " 0.0, 1.0, 0.0, 0.0, \n" | ||
| 1032 | " 0.0, 0.0, 1.0, 0.0, \n" | ||
| 1033 | " vertex_in.x/R, vertex_in.y/R, vertex_in.z/R, 1.0/R \n" | ||
| 1034 | " ); \n" | ||
| 1035 | " \n" | ||
| 1036 | " mat4 PMT = GLUP_VS.modelviewprojection_matrix * T; \n" | ||
| 1037 | " vec4 r1 = row0(PMT); \n" | ||
| 1038 | " vec4 r2 = row1(PMT); \n" | ||
| 1039 | " vec4 r4 = row3(PMT); \n" | ||
| 1040 | " \n" | ||
| 1041 | " float r1Dr4T = dot(r1.xyz,r4.xyz)-r1.w*r4.w; \n" | ||
| 1042 | " float r1Dr1T = dot(r1.xyz,r1.xyz)-r1.w*r1.w; \n" | ||
| 1043 | " float r4Dr4T = dot(r4.xyz,r4.xyz)-r4.w*r4.w; \n" | ||
| 1044 | " float r2Dr2T = dot(r2.xyz,r2.xyz)-r2.w*r2.w; \n" | ||
| 1045 | " float r2Dr4T = dot(r2.xyz,r4.xyz)-r2.w*r4.w; \n" | ||
| 1046 | " \n" | ||
| 1047 | " float discriminant_x = r1Dr4T*r1Dr4T-r4Dr4T*r1Dr1T; \n" | ||
| 1048 | " float discriminant_y = r2Dr4T*r2Dr4T-r4Dr4T*r2Dr2T; \n" | ||
| 1049 | " float screen = max(GLUP_VS.viewport[2], GLUP_VS.viewport[3]); \n" | ||
| 1050 | " gl_PointSize = sqrt(max(discriminant_x, discriminant_y)) * screen/(-r4Dr4T); \n" | ||
| 1051 | " \n" | ||
| 1052 | " center_world_space = vertex_in.xyz; \n" | ||
| 1053 | " radius = vertex_in.w; \n" | ||
| 1054 | "} \n" | ||
| 1055 | ); | ||
| 1056 | |||
| 1057 | ✗ | GEO::GLSL::register_GLSL_include_file("GLUPES/spheres_fragment_shader.h", | |
| 1058 | "//import <GLUP/current_profile/fragment_shader_preamble.h> \n" | ||
| 1059 | "//import <GLUPES/fragment_shader_state.h> \n" | ||
| 1060 | "//import <GLUP/stdglup.h> \n" | ||
| 1061 | "//import <GLUP/current_profile/toggles.h> \n" | ||
| 1062 | "//import <GLUP/current_profile/primitive.h> \n" | ||
| 1063 | "//import <GLUP/fragment_shader_utils.h> \n" | ||
| 1064 | "//import <GLUP/fragment_ray_tracing.h> \n" | ||
| 1065 | " \n" | ||
| 1066 | "glup_flat glup_in vec4 color; \n" | ||
| 1067 | "glup_flat glup_in vec4 tex_coord; \n" | ||
| 1068 | "glup_flat glup_in vec3 center_world_space; \n" | ||
| 1069 | "glup_flat glup_in float radius; \n" | ||
| 1070 | "glup_flat glup_in glup_id primitive_id; \n" | ||
| 1071 | " \n" | ||
| 1072 | "void main(void) { \n" | ||
| 1073 | " vec3 C = center_world_space; \n" | ||
| 1074 | " float r = radius; \n" | ||
| 1075 | " \n" | ||
| 1076 | " if(glupIsEnabled(GLUP_CLIPPING)) { \n" | ||
| 1077 | " if( \n" | ||
| 1078 | " glup_primitive == GLUP_POINTS || \n" | ||
| 1079 | " GLUP.clipping_mode == GLUP_CLIP_WHOLE_CELLS \n" | ||
| 1080 | " ) { \n" | ||
| 1081 | " if(dot(vec4(center_world_space,1.0),GLUP.world_clip_plane) < 0.0) { \n" | ||
| 1082 | " discard; \n" | ||
| 1083 | " } \n" | ||
| 1084 | " } else if(GLUP.clipping_mode == GLUP_CLIP_STRADDLING_CELLS) { \n" | ||
| 1085 | " float dist = \n" | ||
| 1086 | " abs(dot(vec4(center_world_space,1.0),GLUP.world_clip_plane)) / \n" | ||
| 1087 | " length(GLUP.world_clip_plane.xyz) ; \n" | ||
| 1088 | " if(dist > r) { \n" | ||
| 1089 | " discard; \n" | ||
| 1090 | " } \n" | ||
| 1091 | " } \n" | ||
| 1092 | " } \n" | ||
| 1093 | " \n" | ||
| 1094 | " Ray R = glup_primary_ray(); \n" | ||
| 1095 | " vec3 M,N; \n" | ||
| 1096 | " \n" | ||
| 1097 | " if( \n" | ||
| 1098 | " glup_primitive != GLUP_POINTS && \n" | ||
| 1099 | " glupIsEnabled(GLUP_CLIPPING) && \n" | ||
| 1100 | " GLUP.clipping_mode == GLUP_CLIP_SLICE_CELLS \n" | ||
| 1101 | " ) { \n" | ||
| 1102 | " N = GLUP.world_clip_plane.xyz; \n" | ||
| 1103 | " float w = GLUP.world_clip_plane.w; \n" | ||
| 1104 | " float t = -(w + dot(N,R.O)) / dot(N,R.V); \n" | ||
| 1105 | " M = R.O + t*R.V; \n" | ||
| 1106 | " if(dot(M-C,M-C) > r*r) { \n" | ||
| 1107 | " discard; \n" | ||
| 1108 | " } \n" | ||
| 1109 | " } else { \n" | ||
| 1110 | " // High-precision ray-sphere intersection \n" | ||
| 1111 | " // See Ray Tracing Gems, Chapter 7, \n" | ||
| 1112 | " // Precision Improvements for Ray-Sphere Intersection, \n" | ||
| 1113 | " // E. Haines, J. Gunther, T. Akenine-Moller \n" | ||
| 1114 | " vec3 D = R.O-C; \n" | ||
| 1115 | " float a = dot(R.V,R.V); \n" | ||
| 1116 | " \n" | ||
| 1117 | " float b_prime = -dot(D,R.V); \n" | ||
| 1118 | " vec3 H = D + (b_prime/a) * R.V; \n" | ||
| 1119 | " float delta = r*r - dot(H,H); \n" | ||
| 1120 | " if(delta < 0.0) { \n" | ||
| 1121 | " discard; \n" | ||
| 1122 | " } \n" | ||
| 1123 | " // Original article: q = b_prime + sign(b_prime)*sqrt(a*delta) \n" | ||
| 1124 | " // Don't know why they do that, here we know we want t1 \n" | ||
| 1125 | " float q = b_prime - sqrt(a*delta); \n" | ||
| 1126 | " float t = q/a; \n" | ||
| 1127 | " \n" | ||
| 1128 | " // Equivalent lower-precision version: \n" | ||
| 1129 | " /* \n" | ||
| 1130 | " float b = 2.0*dot(R.V,D); \n" | ||
| 1131 | " float c = dot(D,D)-r*r; \n" | ||
| 1132 | " float delta = b*b-4.0*a*c; \n" | ||
| 1133 | " if(delta < 0.0) { \n" | ||
| 1134 | " discard; \n" | ||
| 1135 | " } \n" | ||
| 1136 | " float t = (-b-sqrt(delta))/(2.0*a); \n" | ||
| 1137 | " */ \n" | ||
| 1138 | " \n" | ||
| 1139 | " M = R.O + t*R.V; \n" | ||
| 1140 | " N = M-C; \n" | ||
| 1141 | " } \n" | ||
| 1142 | " \n" | ||
| 1143 | " if( \n" | ||
| 1144 | " glup_primitive != GLUP_POINTS && \n" | ||
| 1145 | " glupIsEnabled(GLUP_CLIPPING) && \n" | ||
| 1146 | " GLUP.clipping_mode == GLUP_CLIP_STANDARD \n" | ||
| 1147 | " ) { \n" | ||
| 1148 | " if(dot(vec4(M,1.0),GLUP.world_clip_plane) < 0.0) { \n" | ||
| 1149 | " discard; \n" | ||
| 1150 | " } \n" | ||
| 1151 | " } \n" | ||
| 1152 | " \n" | ||
| 1153 | " glup_update_depth(M); \n" | ||
| 1154 | " \n" | ||
| 1155 | " if(glupIsEnabled(GLUP_PICKING)) { \n" | ||
| 1156 | " glup_FragColor = glup_picking(int(primitive_id)); \n" | ||
| 1157 | " return; \n" | ||
| 1158 | " } \n" | ||
| 1159 | " \n" | ||
| 1160 | " vec4 result; \n" | ||
| 1161 | " if(glupIsEnabled(GLUP_VERTEX_COLORS)) { \n" | ||
| 1162 | " result = color; \n" | ||
| 1163 | " } else { \n" | ||
| 1164 | " result = GLUP.front_color; \n" | ||
| 1165 | " } \n" | ||
| 1166 | " if(glupIsEnabled(GLUP_TEXTURING)) { \n" | ||
| 1167 | " result = glup_texturing(result, tex_coord); \n" | ||
| 1168 | " } \n" | ||
| 1169 | " if(glupIsEnabled(GLUP_LIGHTING)) { \n" | ||
| 1170 | " N = normalize(GLUP.normal_matrix*N); \n" | ||
| 1171 | " if( \n" | ||
| 1172 | " glup_primitive != GLUP_POINTS && \n" | ||
| 1173 | " glupIsEnabled(GLUP_CLIPPING) && \n" | ||
| 1174 | " GLUP.clipping_mode == GLUP_CLIP_SLICE_CELLS && \n" | ||
| 1175 | " N.z < 0.0 \n" | ||
| 1176 | " ) { \n" | ||
| 1177 | " N = -N; \n" | ||
| 1178 | " } \n" | ||
| 1179 | " result = glup_lighting(result, N); \n" | ||
| 1180 | " } \n" | ||
| 1181 | " glup_FragColor = result; \n" | ||
| 1182 | " glup_alpha_discard(); \n" | ||
| 1183 | "} \n" | ||
| 1184 | ); | ||
| 1185 | |||
| 1186 | ✗ | GEO::GLSL::register_GLSL_include_file("GLUPGLSL/state.h", | |
| 1187 | "layout(shared) \n" | ||
| 1188 | " uniform GLUPStateBlock { \n" | ||
| 1189 | " \n" | ||
| 1190 | " bool vertex_colors_enabled; \n" | ||
| 1191 | " \n" | ||
| 1192 | " vec4 front_color; \n" | ||
| 1193 | " vec4 back_color; \n" | ||
| 1194 | " \n" | ||
| 1195 | " bool draw_mesh_enabled; \n" | ||
| 1196 | " vec4 mesh_color; \n" | ||
| 1197 | " float mesh_width; \n" | ||
| 1198 | " \n" | ||
| 1199 | " bool lighting_enabled; \n" | ||
| 1200 | " bool vertex_normals_enabled; \n" | ||
| 1201 | " bool normal_mapping_enabled; \n" | ||
| 1202 | " vec3 light_vector; \n" | ||
| 1203 | " vec3 light_half_vector; \n" | ||
| 1204 | " float specular; \n" | ||
| 1205 | " \n" | ||
| 1206 | " bool texturing_enabled; \n" | ||
| 1207 | " bool indirect_texturing_enabled; \n" | ||
| 1208 | " int texture_mode; \n" | ||
| 1209 | " int texture_type; \n" | ||
| 1210 | " \n" | ||
| 1211 | " float cells_shrink; \n" | ||
| 1212 | " \n" | ||
| 1213 | " bool picking_enabled; \n" | ||
| 1214 | " int picking_mode; \n" | ||
| 1215 | " int picking_id; \n" | ||
| 1216 | " int base_picking_id; \n" | ||
| 1217 | " \n" | ||
| 1218 | " bool clipping_enabled; \n" | ||
| 1219 | " int clipping_mode; \n" | ||
| 1220 | " vec4 clip_plane; \n" | ||
| 1221 | " vec4 world_clip_plane; \n" | ||
| 1222 | " vec4 clip_clip_plane; \n" | ||
| 1223 | " \n" | ||
| 1224 | " bool alpha_discard_enabled; \n" | ||
| 1225 | " float alpha_threshold; \n" | ||
| 1226 | " \n" | ||
| 1227 | " bool primitive_filtering_enabled; \n" | ||
| 1228 | " \n" | ||
| 1229 | " mat4 modelviewprojection_matrix; \n" | ||
| 1230 | " mat4 modelview_matrix; \n" | ||
| 1231 | " mat4 projection_matrix; \n" | ||
| 1232 | " mat3 normal_matrix; \n" | ||
| 1233 | " mat4 texture_matrix; \n" | ||
| 1234 | " mat4 inverse_modelviewprojection_matrix; \n" | ||
| 1235 | " mat4 inverse_modelview_matrix; \n" | ||
| 1236 | " mat4 inverse_projection_matrix; \n" | ||
| 1237 | " vec4 viewport; \n" | ||
| 1238 | " \n" | ||
| 1239 | " float point_size; \n" | ||
| 1240 | "} GLUP; \n" | ||
| 1241 | " \n" | ||
| 1242 | "// Note: the 1D colormap is stored in a 2D texture, because \n" | ||
| 1243 | "// 1D textures are not supported by all OpenGL implementations \n" | ||
| 1244 | "uniform sampler2D texture1Dsampler; \n" | ||
| 1245 | "uniform sampler2D texture2Dsampler; \n" | ||
| 1246 | "uniform sampler3D texture3Dsampler; \n" | ||
| 1247 | " \n" | ||
| 1248 | "#define GLUP_PRIMITIVE_FILTER \n" | ||
| 1249 | "uniform usamplerBuffer texturePrimitiveFiltersampler; \n" | ||
| 1250 | ); | ||
| 1251 | |||
| 1252 | ✗ | GEO::GLSL::register_GLSL_include_file("GLUPGLSL/points_vertex_shader.h", | |
| 1253 | "//import <GLUP/current_profile/vertex_shader_preamble.h> \n" | ||
| 1254 | "//import <GLUPGLSL/state.h> \n" | ||
| 1255 | "//import <GLUP/stdglup.h> \n" | ||
| 1256 | "//import <GLUP/current_profile/toggles.h> \n" | ||
| 1257 | "//import <GLUP/current_profile/primitive.h> \n" | ||
| 1258 | " \n" | ||
| 1259 | "in vec4 vertex_in; \n" | ||
| 1260 | "in vec4 color_in; \n" | ||
| 1261 | "in vec4 tex_coord_in; \n" | ||
| 1262 | " \n" | ||
| 1263 | "out VertexData { \n" | ||
| 1264 | " vec4 color; \n" | ||
| 1265 | " vec4 tex_coord; \n" | ||
| 1266 | " vec3 center_world_space; \n" | ||
| 1267 | " float radius; \n" | ||
| 1268 | "} VertexOut; \n" | ||
| 1269 | " \n" | ||
| 1270 | "void main(void) { \n" | ||
| 1271 | " \n" | ||
| 1272 | " if(glupIsEnabled(GLUP_VERTEX_COLORS)) { \n" | ||
| 1273 | " VertexOut.color = color_in; \n" | ||
| 1274 | " } \n" | ||
| 1275 | " \n" | ||
| 1276 | " if(glupIsEnabled(GLUP_TEXTURING)) { \n" | ||
| 1277 | " if(glupIsEnabled(GLUP_INDIRECT_TEXTURING)) { \n" | ||
| 1278 | " VertexOut.tex_coord = tex_coord_in; \n" | ||
| 1279 | " } else { \n" | ||
| 1280 | " VertexOut.tex_coord = GLUP.texture_matrix * tex_coord_in; \n" | ||
| 1281 | " } \n" | ||
| 1282 | " } \n" | ||
| 1283 | " \n" | ||
| 1284 | " // note: WebGL does not have glPointSize() API function \n" | ||
| 1285 | " // so the only way to set it is from the VS. \n" | ||
| 1286 | " gl_PointSize = GLUP.point_size; \n" | ||
| 1287 | " gl_Position = GLUP.modelviewprojection_matrix*vertex_in; \n" | ||
| 1288 | " \n" | ||
| 1289 | " VertexOut.center_world_space = vertex_in.xyz / vertex_in.w; \n" | ||
| 1290 | " vec4 P1 = GLUP.inverse_modelviewprojection_matrix*vec4(0.0, 0.0, 0.0, 1.0); \n" | ||
| 1291 | " vec4 P2 = GLUP.inverse_modelviewprojection_matrix*vec4( \n" | ||
| 1292 | " GLUP.point_size/GLUP.viewport[2],0.0,0.0,1.0 \n" | ||
| 1293 | " ); \n" | ||
| 1294 | " VertexOut.radius = length(P1.xyz/P1.w-P2.xyz/P2.w); \n" | ||
| 1295 | "} \n" | ||
| 1296 | ); | ||
| 1297 | |||
| 1298 | ✗ | GEO::GLSL::register_GLSL_include_file("GLUPGLSL/lines_fragment_shader.h", | |
| 1299 | "//import <GLUP/current_profile/fragment_shader_preamble.h> \n" | ||
| 1300 | "//import <GLUPGLSL/state.h> \n" | ||
| 1301 | "//import <GLUP/stdglup.h> \n" | ||
| 1302 | "//import <GLUP/current_profile/toggles.h> \n" | ||
| 1303 | "//import <GLUP/current_profile/primitive.h> \n" | ||
| 1304 | "//import <GLUP/fragment_shader_utils.h> \n" | ||
| 1305 | " \n" | ||
| 1306 | "#ifndef GLUP_NO_GL_CLIPPING \n" | ||
| 1307 | "in float gl_ClipDistance[]; \n" | ||
| 1308 | "#endif \n" | ||
| 1309 | " \n" | ||
| 1310 | "in VertexData { \n" | ||
| 1311 | " vec4 color; \n" | ||
| 1312 | " vec4 tex_coord; \n" | ||
| 1313 | "} FragmentIn; \n" | ||
| 1314 | " \n" | ||
| 1315 | "void main() { \n" | ||
| 1316 | " \n" | ||
| 1317 | "#ifdef GLUP_GL_ES \n" | ||
| 1318 | "#ifndef GLUP_NO_GL_CLIPPING \n" | ||
| 1319 | " if(glupIsEnabled(GLUP_CLIPPING) && (gl_ClipDistance[0] < 0.0)) { \n" | ||
| 1320 | " discard; \n" | ||
| 1321 | " } \n" | ||
| 1322 | "#endif \n" | ||
| 1323 | "#endif \n" | ||
| 1324 | " \n" | ||
| 1325 | " if(glupIsEnabled(GLUP_PRIMITIVE_FILTERING)) { \n" | ||
| 1326 | " glup_primitive_filter(gl_PrimitiveID); \n" | ||
| 1327 | " } \n" | ||
| 1328 | " \n" | ||
| 1329 | " if(glupIsEnabled(GLUP_PICKING)) { \n" | ||
| 1330 | " glup_FragColor = glup_picking(gl_PrimitiveID); \n" | ||
| 1331 | " return; \n" | ||
| 1332 | " } \n" | ||
| 1333 | " \n" | ||
| 1334 | " vec4 result; \n" | ||
| 1335 | " if(glupIsEnabled(GLUP_VERTEX_COLORS)) { \n" | ||
| 1336 | " result = FragmentIn.color; \n" | ||
| 1337 | " } else { \n" | ||
| 1338 | " result = GLUP.front_color; \n" | ||
| 1339 | " } \n" | ||
| 1340 | " if(glupIsEnabled(GLUP_TEXTURING)) { \n" | ||
| 1341 | " result = glup_texturing(result, FragmentIn.tex_coord); \n" | ||
| 1342 | " } \n" | ||
| 1343 | " \n" | ||
| 1344 | " glup_FragColor = result; \n" | ||
| 1345 | " glup_alpha_discard(); \n" | ||
| 1346 | "} \n" | ||
| 1347 | ); | ||
| 1348 | |||
| 1349 | ✗ | GEO::GLSL::register_GLSL_include_file("GLUPGLSL/thick_lines_vertex_shader.h", | |
| 1350 | "//import <GLUP/current_profile/vertex_shader_preamble.h> \n" | ||
| 1351 | "//import <GLUPGLSL/state.h> \n" | ||
| 1352 | "//import <GLUP/stdglup.h> \n" | ||
| 1353 | "//import <GLUP/current_profile/toggles.h> \n" | ||
| 1354 | "//import <GLUP/current_profile/primitive.h> \n" | ||
| 1355 | " \n" | ||
| 1356 | "in vec4 vertex_in; \n" | ||
| 1357 | "in vec4 color_in; \n" | ||
| 1358 | "in vec4 tex_coord_in; \n" | ||
| 1359 | " \n" | ||
| 1360 | "out VertexData { \n" | ||
| 1361 | "#ifdef GLUP_GL_ES \n" | ||
| 1362 | " vec4 vertex_clip_space; \n" | ||
| 1363 | "#endif \n" | ||
| 1364 | " vec4 color; \n" | ||
| 1365 | " vec4 tex_coord; \n" | ||
| 1366 | "} VertexOut; \n" | ||
| 1367 | " \n" | ||
| 1368 | "void main(void) { \n" | ||
| 1369 | " if(glupIsEnabled(GLUP_VERTEX_COLORS)) { \n" | ||
| 1370 | " VertexOut.color = color_in; \n" | ||
| 1371 | " } \n" | ||
| 1372 | " if(glupIsEnabled(GLUP_TEXTURING)) { \n" | ||
| 1373 | " if(glupIsEnabled(GLUP_INDIRECT_TEXTURING)) { \n" | ||
| 1374 | " VertexOut.tex_coord = tex_coord_in; \n" | ||
| 1375 | " } else { \n" | ||
| 1376 | " VertexOut.tex_coord = \n" | ||
| 1377 | " GLUP.texture_matrix * tex_coord_in; \n" | ||
| 1378 | " } \n" | ||
| 1379 | " } \n" | ||
| 1380 | " gl_Position = GLUP.modelviewprojection_matrix * vertex_in; \n" | ||
| 1381 | "} \n" | ||
| 1382 | ); | ||
| 1383 | |||
| 1384 | ✗ | GEO::GLSL::register_GLSL_include_file("GLUPGLSL/thick_lines_geometry_shader.h", | |
| 1385 | "//import <GLUP/current_profile/geometry_shader_preamble.h> \n" | ||
| 1386 | "//import <GLUPGLSL/state.h> \n" | ||
| 1387 | "//import <GLUP/stdglup.h> \n" | ||
| 1388 | "//import <GLUP/current_profile/toggles.h> \n" | ||
| 1389 | "//import <GLUP/current_profile/primitive.h> \n" | ||
| 1390 | " \n" | ||
| 1391 | "// Send the two extremities of the segment and the radius to \n" | ||
| 1392 | "// the fragment shader (used to create nicer joints) \n" | ||
| 1393 | "out vec2 p1_ndc; \n" | ||
| 1394 | "out vec2 p2_ndc; \n" | ||
| 1395 | "out float R; \n" | ||
| 1396 | " \n" | ||
| 1397 | "void emit_vertex_2( \n" | ||
| 1398 | " in int i, in vec2 offset, in float z_offset, in bool do_clip \n" | ||
| 1399 | ") { \n" | ||
| 1400 | "#ifndef GLUP_NO_GL_CLIPPING \n" | ||
| 1401 | " if(glupIsEnabled(GLUP_CLIPPING)) { \n" | ||
| 1402 | " gl_ClipDistance[0] = \n" | ||
| 1403 | " clip_distance(vertex_clip_space_in(i),do_clip); \n" | ||
| 1404 | " } \n" | ||
| 1405 | "#endif \n" | ||
| 1406 | " gl_Position = vertex_clip_space_in(i) / vertex_clip_space_in(i).w ; \n" | ||
| 1407 | " gl_Position.x += offset.x; \n" | ||
| 1408 | " gl_Position.y += offset.y; \n" | ||
| 1409 | " gl_Position.z -= z_offset; \n" | ||
| 1410 | " VertexOut.vertex_clip_space = gl_Position; \n" | ||
| 1411 | " if(glupIsEnabled(GLUP_VERTEX_COLORS)) { \n" | ||
| 1412 | " VertexOut.color = color_in(i); \n" | ||
| 1413 | " } \n" | ||
| 1414 | " if(glupIsEnabled(GLUP_TEXTURING)) { \n" | ||
| 1415 | " VertexOut.tex_coord = tex_coord_in(i); \n" | ||
| 1416 | " } \n" | ||
| 1417 | " EmitVertex(); \n" | ||
| 1418 | "} \n" | ||
| 1419 | " \n" | ||
| 1420 | "void main() { \n" | ||
| 1421 | " gl_PrimitiveID = gl_PrimitiveIDIn; \n" | ||
| 1422 | " \n" | ||
| 1423 | " R = 2.0*(GLUP.mesh_width/(GLUP.viewport[2]+GLUP.viewport[3])); \n" | ||
| 1424 | " p1_ndc = vertex_clip_space_in(0).xy / vertex_clip_space_in(0).w; \n" | ||
| 1425 | " p2_ndc = vertex_clip_space_in(1).xy / vertex_clip_space_in(1).w; \n" | ||
| 1426 | " vec2 U = R*normalize(p2_ndc-p1_ndc); \n" | ||
| 1427 | " vec2 V = vec2(U.y,-U.x); \n" | ||
| 1428 | " float z_offset = 0.2 * GLUP.modelview_matrix[3][3] * R; \n" | ||
| 1429 | " emit_vertex_2(0,-U-V, z_offset, true); \n" | ||
| 1430 | " emit_vertex_2(0,-U+V, z_offset, true); \n" | ||
| 1431 | " emit_vertex_2(1, U-V, z_offset, true); \n" | ||
| 1432 | " emit_vertex_2(1, U+V, z_offset, true); \n" | ||
| 1433 | " EndPrimitive(); \n" | ||
| 1434 | "} \n" | ||
| 1435 | ); | ||
| 1436 | |||
| 1437 | ✗ | GEO::GLSL::register_GLSL_include_file("GLUPGLSL/thick_lines_fragment_shader.h", | |
| 1438 | "//import <GLUP/current_profile/fragment_shader_preamble.h> \n" | ||
| 1439 | "//import <GLUPGLSL/state.h> \n" | ||
| 1440 | "//import <GLUP/stdglup.h> \n" | ||
| 1441 | "//import <GLUP/current_profile/toggles.h> \n" | ||
| 1442 | "//import <GLUP/current_profile/primitive.h> \n" | ||
| 1443 | "//import <GLUP/fragment_shader_utils.h> \n" | ||
| 1444 | " \n" | ||
| 1445 | "#ifndef GLUP_NO_GL_CLIPPING \n" | ||
| 1446 | "in float gl_ClipDistance[]; \n" | ||
| 1447 | "#endif \n" | ||
| 1448 | " \n" | ||
| 1449 | "in VertexData { \n" | ||
| 1450 | " vec4 vertex_clip_space; \n" | ||
| 1451 | " vec4 color; \n" | ||
| 1452 | " vec4 tex_coord; \n" | ||
| 1453 | " vec4 mesh_tex_coord; \n" | ||
| 1454 | "} FragmentIn; \n" | ||
| 1455 | " \n" | ||
| 1456 | "in vec2 p1_ndc; \n" | ||
| 1457 | "in vec2 p2_ndc; \n" | ||
| 1458 | "in float R; \n" | ||
| 1459 | " \n" | ||
| 1460 | " \n" | ||
| 1461 | "void main() { \n" | ||
| 1462 | " \n" | ||
| 1463 | "#ifdef GLUP_GL_ES \n" | ||
| 1464 | "#ifndef GLUP_NO_GL_CLIPPING \n" | ||
| 1465 | " if(glupIsEnabled(GLUP_CLIPPING) && (gl_ClipDistance[0] < 0.0)) { \n" | ||
| 1466 | " discard; \n" | ||
| 1467 | " } \n" | ||
| 1468 | "#endif \n" | ||
| 1469 | "#endif \n" | ||
| 1470 | " \n" | ||
| 1471 | " // Create nicer joints between overlapping thick lines by creating a \n" | ||
| 1472 | " // small disk over the joints \n" | ||
| 1473 | " \n" | ||
| 1474 | " vec2 p_ndc = vec2( \n" | ||
| 1475 | " 2.0 * ( (gl_FragCoord.x - GLUP.viewport[0]) / GLUP.viewport[2] - 0.5), \n" | ||
| 1476 | " 2.0 * ( (gl_FragCoord.y - GLUP.viewport[1]) / GLUP.viewport[3] - 0.5) \n" | ||
| 1477 | " ); \n" | ||
| 1478 | " \n" | ||
| 1479 | " vec2 U = p2_ndc - p1_ndc; \n" | ||
| 1480 | " vec2 V1 = p_ndc - p1_ndc; \n" | ||
| 1481 | " vec2 V2 = p_ndc - p2_ndc; \n" | ||
| 1482 | " \n" | ||
| 1483 | " if(dot(V1,U) < 0 && dot(V1,V1) > R*R) { \n" | ||
| 1484 | " discard; \n" | ||
| 1485 | " } \n" | ||
| 1486 | " \n" | ||
| 1487 | " if(dot(V2,U) > 0 && dot(V2,V2) > R*R) { \n" | ||
| 1488 | " discard; \n" | ||
| 1489 | " } \n" | ||
| 1490 | " \n" | ||
| 1491 | " if(glupIsEnabled(GLUP_PRIMITIVE_FILTERING)) { \n" | ||
| 1492 | " glup_primitive_filter(gl_PrimitiveID); \n" | ||
| 1493 | " } \n" | ||
| 1494 | " \n" | ||
| 1495 | " if(glupIsEnabled(GLUP_PICKING)) { \n" | ||
| 1496 | " glup_FragColor = glup_picking(gl_PrimitiveID); \n" | ||
| 1497 | " return; \n" | ||
| 1498 | " } \n" | ||
| 1499 | " \n" | ||
| 1500 | " vec4 result; \n" | ||
| 1501 | " if(glupIsEnabled(GLUP_VERTEX_COLORS)) { \n" | ||
| 1502 | " result = FragmentIn.color; \n" | ||
| 1503 | " } else { \n" | ||
| 1504 | " result = GLUP.mesh_color; \n" | ||
| 1505 | " } \n" | ||
| 1506 | " \n" | ||
| 1507 | " if(glupIsEnabled(GLUP_TEXTURING) && !glupIsEnabled(GLUP_NORMAL_MAPPING)) { \n" | ||
| 1508 | " result = glup_texturing(result, FragmentIn.tex_coord); \n" | ||
| 1509 | " } \n" | ||
| 1510 | " glup_FragColor = result; \n" | ||
| 1511 | " glup_alpha_discard(); \n" | ||
| 1512 | "} \n" | ||
| 1513 | ); | ||
| 1514 | |||
| 1515 | ✗ | GEO::GLSL::register_GLSL_include_file("GLUPGLSL/vertex_shader.h", | |
| 1516 | "//import <GLUP/current_profile/vertex_shader_preamble.h> \n" | ||
| 1517 | "//import <GLUPGLSL/state.h> \n" | ||
| 1518 | "//import <GLUP/stdglup.h> \n" | ||
| 1519 | "//import <GLUP/current_profile/toggles.h> \n" | ||
| 1520 | "//import <GLUP/current_profile/primitive.h> \n" | ||
| 1521 | " \n" | ||
| 1522 | "in vec4 vertex_in; \n" | ||
| 1523 | "in vec4 color_in; \n" | ||
| 1524 | "in vec4 tex_coord_in; \n" | ||
| 1525 | " \n" | ||
| 1526 | "#if GLUP_PRIMITIVE_DIMENSION==2 \n" | ||
| 1527 | "in vec4 normal_in; \n" | ||
| 1528 | "#endif \n" | ||
| 1529 | " \n" | ||
| 1530 | "out VertexData { \n" | ||
| 1531 | "#ifdef GLUP_NO_GEOMETRY_SHADER \n" | ||
| 1532 | " vec4 vertex_clip_space; \n" | ||
| 1533 | "#endif \n" | ||
| 1534 | " vec4 color; \n" | ||
| 1535 | " vec4 tex_coord; \n" | ||
| 1536 | "#if GLUP_PRIMITIVE_DIMENSION==2 \n" | ||
| 1537 | " vec3 normal; \n" | ||
| 1538 | "# ifdef GLUP_NO_GEOMETRY_SHADER \n" | ||
| 1539 | " vec4 mesh_tex_coord; \n" | ||
| 1540 | "# endif \n" | ||
| 1541 | "#endif \n" | ||
| 1542 | "} VertexOut; \n" | ||
| 1543 | " \n" | ||
| 1544 | " \n" | ||
| 1545 | "void main(void) { \n" | ||
| 1546 | " if(glupIsEnabled(GLUP_VERTEX_COLORS)) { \n" | ||
| 1547 | " VertexOut.color = color_in; \n" | ||
| 1548 | " } \n" | ||
| 1549 | " if(glupIsEnabled(GLUP_TEXTURING)) { \n" | ||
| 1550 | " if(glupIsEnabled(GLUP_INDIRECT_TEXTURING)) { \n" | ||
| 1551 | " VertexOut.tex_coord = tex_coord_in; \n" | ||
| 1552 | " } else { \n" | ||
| 1553 | " VertexOut.tex_coord = \n" | ||
| 1554 | " GLUP.texture_matrix * tex_coord_in; \n" | ||
| 1555 | " } \n" | ||
| 1556 | " } \n" | ||
| 1557 | " \n" | ||
| 1558 | "#ifndef GLUP_NO_GL_CLIPPING \n" | ||
| 1559 | " if(glupIsEnabled(GLUP_CLIPPING)) { \n" | ||
| 1560 | " gl_ClipDistance[0] = dot( \n" | ||
| 1561 | " vertex_in, GLUP.world_clip_plane \n" | ||
| 1562 | " ); \n" | ||
| 1563 | " } else { \n" | ||
| 1564 | " gl_ClipDistance[0] = 0.0; \n" | ||
| 1565 | " } \n" | ||
| 1566 | "#endif \n" | ||
| 1567 | " \n" | ||
| 1568 | "#if GLUP_PRIMITIVE_DIMENSION==2 \n" | ||
| 1569 | " if( \n" | ||
| 1570 | " glupIsEnabled(GLUP_LIGHTING) && \n" | ||
| 1571 | " glupIsEnabled(GLUP_VERTEX_NORMALS) \n" | ||
| 1572 | " ) { \n" | ||
| 1573 | " VertexOut.normal = GLUP.normal_matrix * normal_in.xyz; \n" | ||
| 1574 | " } \n" | ||
| 1575 | " \n" | ||
| 1576 | "#endif \n" | ||
| 1577 | " gl_Position = GLUP.modelviewprojection_matrix * vertex_in; \n" | ||
| 1578 | " \n" | ||
| 1579 | "#if GLUP_PRIMITIVE_DIMENSION==2 \n" | ||
| 1580 | "# ifdef GLUP_NO_GEOMETRY_SHADER \n" | ||
| 1581 | " VertexOut.vertex_clip_space = gl_Position; \n" | ||
| 1582 | " if(glupIsEnabled(GLUP_DRAW_MESH)) { \n" | ||
| 1583 | " // Note: does not work with glDrawElements because gl_VertexID is \n" | ||
| 1584 | " // the element index ! \n" | ||
| 1585 | " int lv = gl_VertexID % glup_primitive_nb_vertices; \n" | ||
| 1586 | " VertexOut.mesh_tex_coord = vec4( \n" | ||
| 1587 | " float(lv == 0), \n" | ||
| 1588 | " float(lv == 1), \n" | ||
| 1589 | " float(lv == 2), \n" | ||
| 1590 | " float(lv == 3) \n" | ||
| 1591 | " ); \n" | ||
| 1592 | " } \n" | ||
| 1593 | "# endif \n" | ||
| 1594 | "#endif \n" | ||
| 1595 | "} \n" | ||
| 1596 | ); | ||
| 1597 | |||
| 1598 | ✗ | GEO::GLSL::register_GLSL_include_file("GLUPGLSL/gather_vertex_shader.h", | |
| 1599 | "//import <GLUP/current_profile/vertex_shader_preamble.h> \n" | ||
| 1600 | "//import <GLUPGLSL/state.h> \n" | ||
| 1601 | "//import <GLUP/stdglup.h> \n" | ||
| 1602 | "//import <GLUP/current_profile/toggles.h> \n" | ||
| 1603 | "//import <GLUP/current_profile/primitive.h> \n" | ||
| 1604 | " \n" | ||
| 1605 | "in vec4 vertex_in[glup_nb_vertices_per_GL_v]; \n" | ||
| 1606 | "in vec4 color_in[glup_nb_vertices_per_GL_v]; \n" | ||
| 1607 | "in vec4 tex_coord_in[glup_nb_vertices_per_GL_v]; \n" | ||
| 1608 | " \n" | ||
| 1609 | "out GVertexData { \n" | ||
| 1610 | " vec4 other_vertex_clip_space[glup_nb_vertices_per_GL_v-1]; \n" | ||
| 1611 | " vec4 color[glup_nb_vertices_per_GL_v]; \n" | ||
| 1612 | " vec4 tex_coord[glup_nb_vertices_per_GL_v]; \n" | ||
| 1613 | "} VertexOut; \n" | ||
| 1614 | " \n" | ||
| 1615 | " \n" | ||
| 1616 | "void main(void) { \n" | ||
| 1617 | " for(int i=0; i<glup_nb_vertices_per_GL_v; ++i) { \n" | ||
| 1618 | " if(glupIsEnabled(GLUP_VERTEX_COLORS)) { \n" | ||
| 1619 | " VertexOut.color[i] = color_in[i]; \n" | ||
| 1620 | " } \n" | ||
| 1621 | " if(glupIsEnabled(GLUP_TEXTURING)) { \n" | ||
| 1622 | " if(glupIsEnabled(GLUP_INDIRECT_TEXTURING)) { \n" | ||
| 1623 | " VertexOut.tex_coord[i] = tex_coord_in[i]; \n" | ||
| 1624 | " } else { \n" | ||
| 1625 | " VertexOut.tex_coord[i] = GLUP.texture_matrix * tex_coord_in[i]; \n" | ||
| 1626 | " } \n" | ||
| 1627 | " } \n" | ||
| 1628 | " } \n" | ||
| 1629 | " \n" | ||
| 1630 | " for(int i=1; i<glup_nb_vertices_per_GL_v; ++i) { \n" | ||
| 1631 | " VertexOut.other_vertex_clip_space[i-1] = \n" | ||
| 1632 | " GLUP.modelviewprojection_matrix * vertex_in[i]; \n" | ||
| 1633 | " } \n" | ||
| 1634 | " \n" | ||
| 1635 | " gl_Position = GLUP.modelviewprojection_matrix * vertex_in[0]; \n" | ||
| 1636 | "} \n" | ||
| 1637 | ); | ||
| 1638 | |||
| 1639 | ✗ | GEO::GLSL::register_GLSL_include_file("GLUPGLSL/fragment_shader.h", | |
| 1640 | "//import <GLUP/current_profile/fragment_shader_preamble.h> \n" | ||
| 1641 | "//import <GLUPGLSL/state.h> \n" | ||
| 1642 | "//import <GLUP/stdglup.h> \n" | ||
| 1643 | "//import <GLUP/current_profile/toggles.h> \n" | ||
| 1644 | "//import <GLUP/current_profile/primitive.h> \n" | ||
| 1645 | "//import <GLUP/fragment_shader_utils.h> \n" | ||
| 1646 | " \n" | ||
| 1647 | "#ifndef GLUP_NO_GL_CLIPPING \n" | ||
| 1648 | "in float gl_ClipDistance[]; \n" | ||
| 1649 | "#endif \n" | ||
| 1650 | " \n" | ||
| 1651 | "in VertexData { \n" | ||
| 1652 | " vec4 vertex_clip_space; \n" | ||
| 1653 | " vec4 color; \n" | ||
| 1654 | " vec4 tex_coord; \n" | ||
| 1655 | "#if GLUP_PRIMITIVE_DIMENSION==2 \n" | ||
| 1656 | " vec3 normal; \n" | ||
| 1657 | "#endif \n" | ||
| 1658 | " vec4 mesh_tex_coord; \n" | ||
| 1659 | "} FragmentIn; \n" | ||
| 1660 | " \n" | ||
| 1661 | " \n" | ||
| 1662 | "bool is_triangle(in vec4 mesh_tex_coord) { \n" | ||
| 1663 | " if( \n" | ||
| 1664 | " !glupIsEnabled(GLUP_CLIPPING) || \n" | ||
| 1665 | " GLUP.clipping_mode != GLUP_CLIP_SLICE_CELLS \n" | ||
| 1666 | " ) { \n" | ||
| 1667 | " switch(glup_primitive) { \n" | ||
| 1668 | " case GLUP_TRIANGLES: \n" | ||
| 1669 | " return true; \n" | ||
| 1670 | " case GLUP_QUADS: \n" | ||
| 1671 | " return false; \n" | ||
| 1672 | " case GLUP_TETRAHEDRA: \n" | ||
| 1673 | " return true; \n" | ||
| 1674 | " case GLUP_HEXAHEDRA: \n" | ||
| 1675 | " return false; \n" | ||
| 1676 | " } \n" | ||
| 1677 | " } \n" | ||
| 1678 | " return ( \n" | ||
| 1679 | " (mesh_tex_coord.x + \n" | ||
| 1680 | " mesh_tex_coord.y + \n" | ||
| 1681 | " mesh_tex_coord.z + \n" | ||
| 1682 | " mesh_tex_coord.w) < 1.5 \n" | ||
| 1683 | " ); \n" | ||
| 1684 | "} \n" | ||
| 1685 | " \n" | ||
| 1686 | "float edge_factor(in vec4 mesh_tex_coord) { \n" | ||
| 1687 | " if(is_triangle(mesh_tex_coord)) { \n" | ||
| 1688 | " return edge_factor3(mesh_tex_coord.xyz); \n" | ||
| 1689 | " } else { \n" | ||
| 1690 | " return edge_factor4(mesh_tex_coord); \n" | ||
| 1691 | " } \n" | ||
| 1692 | "} \n" | ||
| 1693 | " \n" | ||
| 1694 | "vec4 glup_draw_mesh(in vec4 color, in vec4 mesh_tex_coord) { \n" | ||
| 1695 | " return mix( \n" | ||
| 1696 | " GLUP.mesh_color, color, edge_factor(mesh_tex_coord) \n" | ||
| 1697 | " ); \n" | ||
| 1698 | "} \n" | ||
| 1699 | " \n" | ||
| 1700 | "void main() { \n" | ||
| 1701 | " \n" | ||
| 1702 | "#ifdef GLUP_GL_ES \n" | ||
| 1703 | "#ifndef GLUP_NO_GL_CLIPPING \n" | ||
| 1704 | " if(glupIsEnabled(GLUP_CLIPPING) && (gl_ClipDistance[0] < 0.0)) { \n" | ||
| 1705 | " discard; \n" | ||
| 1706 | " } \n" | ||
| 1707 | "#endif \n" | ||
| 1708 | "#endif \n" | ||
| 1709 | " \n" | ||
| 1710 | " if(glupIsEnabled(GLUP_PRIMITIVE_FILTERING)) { \n" | ||
| 1711 | " glup_primitive_filter(gl_PrimitiveID); \n" | ||
| 1712 | " } \n" | ||
| 1713 | " \n" | ||
| 1714 | " if(glupIsEnabled(GLUP_PICKING)) { \n" | ||
| 1715 | " glup_FragColor = glup_picking(gl_PrimitiveID); \n" | ||
| 1716 | " return; \n" | ||
| 1717 | " } \n" | ||
| 1718 | " \n" | ||
| 1719 | " vec4 result; \n" | ||
| 1720 | " if(glupIsEnabled(GLUP_VERTEX_COLORS)) { \n" | ||
| 1721 | " result = FragmentIn.color; \n" | ||
| 1722 | " } else { \n" | ||
| 1723 | " result = gl_FrontFacing ? GLUP.front_color : GLUP.back_color; \n" | ||
| 1724 | " } \n" | ||
| 1725 | " \n" | ||
| 1726 | " if(glupIsEnabled(GLUP_TEXTURING) && !glupIsEnabled(GLUP_NORMAL_MAPPING)) { \n" | ||
| 1727 | " result = glup_texturing(result, FragmentIn.tex_coord); \n" | ||
| 1728 | " } \n" | ||
| 1729 | " if(glupIsEnabled(GLUP_LIGHTING)) { \n" | ||
| 1730 | " vec3 N; \n" | ||
| 1731 | " if( \n" | ||
| 1732 | " glupIsEnabled(GLUP_TEXTURING) && \n" | ||
| 1733 | " glupIsEnabled(GLUP_NORMAL_MAPPING) \n" | ||
| 1734 | " ){ \n" | ||
| 1735 | " N = glup_texturing(vec4(1.0,1.0,1.0,1.0), FragmentIn.tex_coord).xyz; \n" | ||
| 1736 | " N = N-vec3(0.5,0.5,0.5); \n" | ||
| 1737 | " N = normalize(GLUP.normal_matrix*N); \n" | ||
| 1738 | " if(!gl_FrontFacing) { \n" | ||
| 1739 | " N = -N; \n" | ||
| 1740 | " } \n" | ||
| 1741 | " } else { \n" | ||
| 1742 | "#if GLUP_PRIMITIVE_DIMENSION==2 \n" | ||
| 1743 | " if(glupIsEnabled(GLUP_VERTEX_NORMALS)) { \n" | ||
| 1744 | " N = normalize(FragmentIn.normal); \n" | ||
| 1745 | " if(!gl_FrontFacing) { \n" | ||
| 1746 | " N = -N; \n" | ||
| 1747 | " } \n" | ||
| 1748 | " } else \n" | ||
| 1749 | "#endif \n" | ||
| 1750 | " { \n" | ||
| 1751 | " vec3 U = dFdx(FragmentIn.vertex_clip_space.xyz); \n" | ||
| 1752 | " vec3 V = dFdy(FragmentIn.vertex_clip_space.xyz); \n" | ||
| 1753 | " \n" | ||
| 1754 | " mat3 M = transpose( \n" | ||
| 1755 | " mat3( \n" | ||
| 1756 | " GLUP.projection_matrix[0].xyz, \n" | ||
| 1757 | " GLUP.projection_matrix[1].xyz, \n" | ||
| 1758 | " GLUP.projection_matrix[2].xyz \n" | ||
| 1759 | " ) \n" | ||
| 1760 | " ); \n" | ||
| 1761 | " N = -normalize(M*cross(U,V)); \n" | ||
| 1762 | " } \n" | ||
| 1763 | " } \n" | ||
| 1764 | " result = glup_lighting(result, N); \n" | ||
| 1765 | " } \n" | ||
| 1766 | " if(glupIsEnabled(GLUP_DRAW_MESH)) { \n" | ||
| 1767 | " result = glup_draw_mesh(result, FragmentIn.mesh_tex_coord); \n" | ||
| 1768 | " } \n" | ||
| 1769 | " glup_FragColor = result; \n" | ||
| 1770 | " glup_alpha_discard(); \n" | ||
| 1771 | "} \n" | ||
| 1772 | ); | ||
| 1773 | |||
| 1774 | ✗ | GEO::GLSL::register_GLSL_include_file("GLUPGLSL/geometry_shader_preamble.h", | |
| 1775 | "//import <GLUP/current_profile/geometry_shader_preamble.h> \n" | ||
| 1776 | "//import <GLUPGLSL/state.h> \n" | ||
| 1777 | "//import <GLUP/stdglup.h> \n" | ||
| 1778 | "//import <GLUP/current_profile/toggles.h> \n" | ||
| 1779 | "//import <GLUP/current_profile/primitive.h> \n" | ||
| 1780 | " \n" | ||
| 1781 | " \n" | ||
| 1782 | "#if defined(GLUP_TESS_GATHER) \n" | ||
| 1783 | " \n" | ||
| 1784 | "in GTVertexData { \n" | ||
| 1785 | " vec4 vertex_clip_space[glup_nb_vertices_per_GL_v]; \n" | ||
| 1786 | " vec4 color[glup_nb_vertices_per_GL_v]; \n" | ||
| 1787 | " vec4 tex_coord[glup_nb_vertices_per_GL_v]; \n" | ||
| 1788 | "#ifndef GLUP_TESS_MULTI_VERTEX \n" | ||
| 1789 | " bool discard_me; \n" | ||
| 1790 | "#endif \n" | ||
| 1791 | "} VertexIn[]; \n" | ||
| 1792 | " \n" | ||
| 1793 | "#elif defined(GLUP_VERTEX_GATHER) \n" | ||
| 1794 | " \n" | ||
| 1795 | "in GVertexData { \n" | ||
| 1796 | " vec4 other_vertex_clip_space[glup_nb_vertices_per_GL_v-1]; \n" | ||
| 1797 | " vec4 color[glup_nb_vertices_per_GL_v]; \n" | ||
| 1798 | " vec4 tex_coord[glup_nb_vertices_per_GL_v]; \n" | ||
| 1799 | "} VertexIn[]; \n" | ||
| 1800 | " \n" | ||
| 1801 | "#else \n" | ||
| 1802 | " \n" | ||
| 1803 | "in VertexData { \n" | ||
| 1804 | " vec4 color; \n" | ||
| 1805 | " vec4 tex_coord; \n" | ||
| 1806 | "#if GLUP_PRIMITIVE_DIMENSION==2 \n" | ||
| 1807 | " vec3 normal; \n" | ||
| 1808 | "#endif \n" | ||
| 1809 | "} VertexIn[]; \n" | ||
| 1810 | " \n" | ||
| 1811 | "#endif \n" | ||
| 1812 | " \n" | ||
| 1813 | "out VertexData { \n" | ||
| 1814 | " vec4 vertex_clip_space; \n" | ||
| 1815 | " vec4 color; \n" | ||
| 1816 | " vec4 tex_coord; \n" | ||
| 1817 | "#if GLUP_PRIMITIVE_DIMENSION==2 \n" | ||
| 1818 | " vec3 normal; \n" | ||
| 1819 | "#endif \n" | ||
| 1820 | " vec4 mesh_tex_coord; \n" | ||
| 1821 | "} VertexOut; \n" | ||
| 1822 | " \n" | ||
| 1823 | "#ifndef GLUP_NO_GL_CLIPPING \n" | ||
| 1824 | "out float gl_ClipDistance[]; \n" | ||
| 1825 | "#endif \n" | ||
| 1826 | " \n" | ||
| 1827 | "//****** Data abstraction ************** \n" | ||
| 1828 | " \n" | ||
| 1829 | "#if defined(GLUP_VERTEX_GATHER) || defined(GLUP_TESS_GATHER) \n" | ||
| 1830 | " \n" | ||
| 1831 | "# if defined(GLUP_VERTEX_GATHER) \n" | ||
| 1832 | "vec4 vertex_clip_space_in(in int i) { \n" | ||
| 1833 | " int i0 = i / glup_nb_vertices_per_GL_v; \n" | ||
| 1834 | " int i1 = i % glup_nb_vertices_per_GL_v; \n" | ||
| 1835 | " return (i1==0) ? gl_in[i0].gl_Position : \n" | ||
| 1836 | " VertexIn[i0].other_vertex_clip_space[i1-1]; \n" | ||
| 1837 | "} \n" | ||
| 1838 | "# else \n" | ||
| 1839 | "vec4 vertex_clip_space_in(in int i) { \n" | ||
| 1840 | " int i0 = i / glup_nb_vertices_per_GL_v; \n" | ||
| 1841 | " int i1 = i % glup_nb_vertices_per_GL_v; \n" | ||
| 1842 | " return VertexIn[i0].vertex_clip_space[i1]; \n" | ||
| 1843 | "} \n" | ||
| 1844 | "# endif \n" | ||
| 1845 | " \n" | ||
| 1846 | "vec4 color_in(in int i) { \n" | ||
| 1847 | " int i0 = i / glup_nb_vertices_per_GL_v; \n" | ||
| 1848 | " int i1 = i % glup_nb_vertices_per_GL_v; \n" | ||
| 1849 | " return VertexIn[i0].color[i1]; \n" | ||
| 1850 | "} \n" | ||
| 1851 | " \n" | ||
| 1852 | "vec4 tex_coord_in(in int i) { \n" | ||
| 1853 | " int i0 = i / glup_nb_vertices_per_GL_v; \n" | ||
| 1854 | " int i1 = i % glup_nb_vertices_per_GL_v; \n" | ||
| 1855 | " return VertexIn[i0].tex_coord[i1]; \n" | ||
| 1856 | "} \n" | ||
| 1857 | " \n" | ||
| 1858 | "bool prim_is_discarded() { \n" | ||
| 1859 | "#if defined(GLUP_TESS_GATHER) && !defined(GLUP_TESS_MULTI_VERTEX) \n" | ||
| 1860 | " return VertexIn[0].discard_me; \n" | ||
| 1861 | "#endif \n" | ||
| 1862 | " return false; \n" | ||
| 1863 | "} \n" | ||
| 1864 | " \n" | ||
| 1865 | "#else \n" | ||
| 1866 | " \n" | ||
| 1867 | "vec4 vertex_clip_space_in(in int i) { \n" | ||
| 1868 | " return gl_in[i].gl_Position; \n" | ||
| 1869 | "} \n" | ||
| 1870 | " \n" | ||
| 1871 | "vec4 color_in(in int i) { \n" | ||
| 1872 | " return VertexIn[i].color; \n" | ||
| 1873 | "} \n" | ||
| 1874 | " \n" | ||
| 1875 | "vec4 tex_coord_in(in int i) { \n" | ||
| 1876 | " return VertexIn[i].tex_coord; \n" | ||
| 1877 | "} \n" | ||
| 1878 | " \n" | ||
| 1879 | "#if GLUP_PRIMITIVE_DIMENSION==2 \n" | ||
| 1880 | "vec3 normal_in(in int i) { \n" | ||
| 1881 | " return VertexIn[i].normal; \n" | ||
| 1882 | "} \n" | ||
| 1883 | "#endif \n" | ||
| 1884 | " \n" | ||
| 1885 | "bool prim_is_discarded() { \n" | ||
| 1886 | " return false; \n" | ||
| 1887 | "} \n" | ||
| 1888 | " \n" | ||
| 1889 | "#endif \n" | ||
| 1890 | " \n" | ||
| 1891 | "// **** Utilities **************************** \n" | ||
| 1892 | " \n" | ||
| 1893 | "vec4 vertex_clip_space[glup_primitive_nb_vertices]; \n" | ||
| 1894 | " \n" | ||
| 1895 | "void get_vertices() { \n" | ||
| 1896 | " for(int v=0; v<glup_primitive_nb_vertices; ++v) { \n" | ||
| 1897 | " vertex_clip_space[v] = vertex_clip_space_in(v); \n" | ||
| 1898 | " } \n" | ||
| 1899 | " if(GLUP.cells_shrink != 0.0) { \n" | ||
| 1900 | " vec4 g = vec4(0.0, 0.0, 0.0, 0.0); \n" | ||
| 1901 | " for(int i=0; i<glup_primitive_nb_vertices; ++i) { \n" | ||
| 1902 | " g += vertex_clip_space[i]; \n" | ||
| 1903 | " } \n" | ||
| 1904 | " g /= float(glup_primitive_nb_vertices); \n" | ||
| 1905 | " float s = GLUP.cells_shrink; \n" | ||
| 1906 | " for(int i=0; i<glup_primitive_nb_vertices; ++i) { \n" | ||
| 1907 | " vertex_clip_space[i] = mix(vertex_clip_space[i], g, s); \n" | ||
| 1908 | " } \n" | ||
| 1909 | " } \n" | ||
| 1910 | "} \n" | ||
| 1911 | " \n" | ||
| 1912 | "float clip_distance(in vec4 V, in bool do_clip) { \n" | ||
| 1913 | " return do_clip?dot(V,GLUP.clip_clip_plane):1.0; \n" | ||
| 1914 | "} \n" | ||
| 1915 | " \n" | ||
| 1916 | "bool cell_is_clipped() { \n" | ||
| 1917 | " if(prim_is_discarded()) { \n" | ||
| 1918 | " return true; \n" | ||
| 1919 | " } \n" | ||
| 1920 | " if( \n" | ||
| 1921 | " (glup_primitive_dimension != 3) || \n" | ||
| 1922 | " !glupIsEnabled(GLUP_CLIPPING) || \n" | ||
| 1923 | " (GLUP.clipping_mode==GLUP_CLIP_STANDARD) || \n" | ||
| 1924 | " (GLUP.clipping_mode==GLUP_CLIP_SLICE_CELLS) \n" | ||
| 1925 | " ) { \n" | ||
| 1926 | " return false; \n" | ||
| 1927 | " } \n" | ||
| 1928 | " int count = 0; \n" | ||
| 1929 | " for(int i=0; i<glup_primitive_nb_vertices; ++i) { \n" | ||
| 1930 | " count += int(clip_distance(vertex_clip_space_in(i),true) >= 0.0); \n" | ||
| 1931 | " } \n" | ||
| 1932 | " if( \n" | ||
| 1933 | " (GLUP.clipping_mode==GLUP_CLIP_WHOLE_CELLS) && (count == 0) \n" | ||
| 1934 | " ) { \n" | ||
| 1935 | " return true; \n" | ||
| 1936 | " } \n" | ||
| 1937 | " if( \n" | ||
| 1938 | " (GLUP.clipping_mode==GLUP_CLIP_STRADDLING_CELLS) && \n" | ||
| 1939 | " ((count==0) || (count==glup_primitive_nb_vertices)) \n" | ||
| 1940 | " ) { \n" | ||
| 1941 | " return true; \n" | ||
| 1942 | " } \n" | ||
| 1943 | " \n" | ||
| 1944 | " // Should not happen ??? (first test would have returned) \n" | ||
| 1945 | " // But if I do not say that, straddling cells \n" | ||
| 1946 | " // do not work ??? (WTF?) GLSL compiler bug ? \n" | ||
| 1947 | " if(GLUP.clipping_mode==GLUP_CLIP_SLICE_CELLS) { \n" | ||
| 1948 | " return true; \n" | ||
| 1949 | " } \n" | ||
| 1950 | " \n" | ||
| 1951 | " return false; \n" | ||
| 1952 | "} \n" | ||
| 1953 | " \n" | ||
| 1954 | "void emit_vertex(in int i, in vec4 mesh_tex_coord, in bool do_clip) { \n" | ||
| 1955 | "#ifndef GLUP_NO_GL_CLIPPING \n" | ||
| 1956 | " if(glupIsEnabled(GLUP_CLIPPING)) { \n" | ||
| 1957 | " gl_ClipDistance[0] = clip_distance(vertex_clip_space_in(i),do_clip); \n" | ||
| 1958 | " } \n" | ||
| 1959 | "#endif \n" | ||
| 1960 | " gl_Position = vertex_clip_space[i]; \n" | ||
| 1961 | " VertexOut.vertex_clip_space = gl_Position; \n" | ||
| 1962 | " if(glupIsEnabled(GLUP_VERTEX_COLORS)) { \n" | ||
| 1963 | " VertexOut.color = color_in(i); \n" | ||
| 1964 | " } \n" | ||
| 1965 | " if(glupIsEnabled(GLUP_TEXTURING)) { \n" | ||
| 1966 | " VertexOut.tex_coord = tex_coord_in(i); \n" | ||
| 1967 | " } \n" | ||
| 1968 | "#if GLUP_PRIMITIVE_DIMENSION==2 \n" | ||
| 1969 | " if( \n" | ||
| 1970 | " glupIsEnabled(GLUP_LIGHTING) && \n" | ||
| 1971 | " glupIsEnabled(GLUP_VERTEX_NORMALS)) { \n" | ||
| 1972 | " VertexOut.normal = normal_in(i); \n" | ||
| 1973 | " } \n" | ||
| 1974 | "#endif \n" | ||
| 1975 | " if(glupIsEnabled(GLUP_DRAW_MESH)) { \n" | ||
| 1976 | " VertexOut.mesh_tex_coord = mesh_tex_coord; \n" | ||
| 1977 | " } \n" | ||
| 1978 | " EmitVertex(); \n" | ||
| 1979 | "} \n" | ||
| 1980 | " \n" | ||
| 1981 | "void draw_triangle(in int i1, in int i2, in int i3, in bool do_clip) { \n" | ||
| 1982 | " emit_vertex(i1, vec4(1.0, 0.0, 0.0, 0.0), do_clip); \n" | ||
| 1983 | " emit_vertex(i2, vec4(0.0, 1.0, 0.0, 0.0), do_clip); \n" | ||
| 1984 | " emit_vertex(i3, vec4(0.0, 0.0, 1.0, 0.0), do_clip); \n" | ||
| 1985 | " EndPrimitive(); \n" | ||
| 1986 | "} \n" | ||
| 1987 | " \n" | ||
| 1988 | "void draw_quad(in int i1, in int i2, in int i3, in int i4, in bool do_clip) { \n" | ||
| 1989 | " emit_vertex(i1, vec4(0.0, 1.0, 0.0, 1.0), do_clip); \n" | ||
| 1990 | " emit_vertex(i2, vec4(1.0, 0.0, 0.0, 1.0), do_clip); \n" | ||
| 1991 | " emit_vertex(i3, vec4(0.0, 1.0, 1.0, 0.0), do_clip); \n" | ||
| 1992 | " emit_vertex(i4, vec4(1.0, 0.0, 1.0, 0.0), do_clip); \n" | ||
| 1993 | " EndPrimitive(); \n" | ||
| 1994 | "} \n" | ||
| 1995 | ); | ||
| 1996 | |||
| 1997 | ✗ | GEO::GLSL::register_GLSL_include_file("GLUPGLSL/tess_evaluation_shader.h", | |
| 1998 | "//import <GLUP/current_profile/tess_evaluation_shader_preamble.h> \n" | ||
| 1999 | "//import <GLUPGLSL/state.h> \n" | ||
| 2000 | "//import <GLUP/stdglup.h> \n" | ||
| 2001 | "//import <GLUP/current_profile/toggles.h> \n" | ||
| 2002 | "//import <GLUP/current_profile/primitive.h> \n" | ||
| 2003 | " \n" | ||
| 2004 | "layout(isolines) in; \n" | ||
| 2005 | " \n" | ||
| 2006 | "in VertexData { \n" | ||
| 2007 | " vec4 color; \n" | ||
| 2008 | " vec4 tex_coord; \n" | ||
| 2009 | "} VertexIn[]; \n" | ||
| 2010 | " \n" | ||
| 2011 | "out GTVertexData { \n" | ||
| 2012 | " vec4 vertex_clip_space[glup_nb_vertices_per_GL_v]; \n" | ||
| 2013 | " vec4 color[glup_nb_vertices_per_GL_v]; \n" | ||
| 2014 | " vec4 tex_coord[glup_nb_vertices_per_GL_v]; \n" | ||
| 2015 | "#ifndef GLUP_TESS_MULTI_VERTEX \n" | ||
| 2016 | " bool discard_me; \n" | ||
| 2017 | "#endif \n" | ||
| 2018 | "} VertexOut; \n" | ||
| 2019 | " \n" | ||
| 2020 | "#ifdef GLUP_TESS_MULTI_VERTEX \n" | ||
| 2021 | " \n" | ||
| 2022 | "void main() { \n" | ||
| 2023 | " int i0 = int(gl_TessCoord.x + 0.5); \n" | ||
| 2024 | " for(int i1=0; i1<glup_nb_vertices_per_GL_v; ++i1) { \n" | ||
| 2025 | " int i = i0*glup_nb_vertices_per_GL_v + i1; \n" | ||
| 2026 | " VertexOut.vertex_clip_space[i1] = gl_in[i].gl_Position; \n" | ||
| 2027 | " } \n" | ||
| 2028 | " if(glupIsEnabled(GLUP_VERTEX_COLORS)) { \n" | ||
| 2029 | " for(int i1=0; i1<glup_nb_vertices_per_GL_v; ++i1) { \n" | ||
| 2030 | " int i = i0*glup_nb_vertices_per_GL_v + i1; \n" | ||
| 2031 | " VertexOut.color[i1] = VertexIn[i].color; \n" | ||
| 2032 | " } \n" | ||
| 2033 | " } \n" | ||
| 2034 | " if(glupIsEnabled(GLUP_TEXTURING)) { \n" | ||
| 2035 | " for(int i1=0; i1<glup_nb_vertices_per_GL_v; ++i1) { \n" | ||
| 2036 | " int i = i0*glup_nb_vertices_per_GL_v + i1; \n" | ||
| 2037 | " VertexOut.tex_coord[i1] = VertexIn[i].tex_coord; \n" | ||
| 2038 | " } \n" | ||
| 2039 | " } \n" | ||
| 2040 | "} \n" | ||
| 2041 | "#else \n" | ||
| 2042 | " \n" | ||
| 2043 | "void main() { \n" | ||
| 2044 | " VertexOut.discard_me = (gl_TessCoord.x > 0.5); \n" | ||
| 2045 | " if(VertexOut.discard_me) { \n" | ||
| 2046 | " return; \n" | ||
| 2047 | " } \n" | ||
| 2048 | " for(int i=0; i<glup_primitive_nb_vertices; ++i) { \n" | ||
| 2049 | " VertexOut.vertex_clip_space[i] = gl_in[i].gl_Position; \n" | ||
| 2050 | " } \n" | ||
| 2051 | " if(glupIsEnabled(GLUP_VERTEX_COLORS)) { \n" | ||
| 2052 | " for(int i=0; i<glup_primitive_nb_vertices; ++i) { \n" | ||
| 2053 | " VertexOut.color[i] = VertexIn[i].color; \n" | ||
| 2054 | " } \n" | ||
| 2055 | " } \n" | ||
| 2056 | " if(glupIsEnabled(GLUP_TEXTURING)) { \n" | ||
| 2057 | " for(int i=0; i<glup_primitive_nb_vertices; ++i) { \n" | ||
| 2058 | " VertexOut.tex_coord[i] = VertexIn[i].tex_coord; \n" | ||
| 2059 | " } \n" | ||
| 2060 | " } \n" | ||
| 2061 | "} \n" | ||
| 2062 | " \n" | ||
| 2063 | "#endif \n" | ||
| 2064 | ); | ||
| 2065 | |||
| 2066 | ✗ | GEO::GLSL::register_GLSL_include_file("GLUPGLSL/marching_cells.h", | |
| 2067 | "//import <GLUP/current_profile/marching_cells.h> \n" | ||
| 2068 | " \n" | ||
| 2069 | "int compute_config() { \n" | ||
| 2070 | " int result = 0; \n" | ||
| 2071 | " for(int v=0; v<cell_nb_vertices; ++v) { \n" | ||
| 2072 | " if(dot(vertex_clip_space_in(v),GLUP.clip_clip_plane) > 0.0) { \n" | ||
| 2073 | " result = result | (1 << v); \n" | ||
| 2074 | " } \n" | ||
| 2075 | " } \n" | ||
| 2076 | " return result; \n" | ||
| 2077 | "} \n" | ||
| 2078 | " \n" | ||
| 2079 | "void emit_isect_vertex(in int i, in vec4 mesh_tex_coord) { \n" | ||
| 2080 | "#ifndef GLUP_NO_GL_CLIPPING \n" | ||
| 2081 | " gl_ClipDistance[0] = 1.0; \n" | ||
| 2082 | "#endif \n" | ||
| 2083 | " gl_Position = isect_point_clip_space[i]; \n" | ||
| 2084 | " if(glupIsEnabled(GLUP_VERTEX_COLORS)) { \n" | ||
| 2085 | " VertexOut.color = isect_color[i]; \n" | ||
| 2086 | " } \n" | ||
| 2087 | " if(glupIsEnabled(GLUP_TEXTURING)) { \n" | ||
| 2088 | " VertexOut.tex_coord = isect_tex_coord[i]; \n" | ||
| 2089 | " } \n" | ||
| 2090 | " if(glupIsEnabled(GLUP_DRAW_MESH)) { \n" | ||
| 2091 | " VertexOut.mesh_tex_coord = mesh_tex_coord; \n" | ||
| 2092 | " } \n" | ||
| 2093 | " if(glupIsEnabled(GLUP_LIGHTING)) { \n" | ||
| 2094 | " VertexOut.vertex_clip_space = gl_Position; \n" | ||
| 2095 | " } \n" | ||
| 2096 | " EmitVertex(); \n" | ||
| 2097 | "} \n" | ||
| 2098 | " \n" | ||
| 2099 | "void isect_triangle( \n" | ||
| 2100 | " in int i, in vec4 mtexi, \n" | ||
| 2101 | " in int j, in vec4 mtexj, \n" | ||
| 2102 | " in int k, in vec4 mtexk \n" | ||
| 2103 | ") { \n" | ||
| 2104 | " emit_isect_vertex(i,mtexi); \n" | ||
| 2105 | " emit_isect_vertex(j,mtexj); \n" | ||
| 2106 | " emit_isect_vertex(k,mtexk); \n" | ||
| 2107 | "} \n" | ||
| 2108 | " \n" | ||
| 2109 | "void draw_marching_cell() { \n" | ||
| 2110 | " int config = compute_config(); \n" | ||
| 2111 | " \n" | ||
| 2112 | " \n" | ||
| 2113 | " if(config_size(config) == 0) { \n" | ||
| 2114 | " return; \n" | ||
| 2115 | " } \n" | ||
| 2116 | " \n" | ||
| 2117 | " compute_intersections(); \n" | ||
| 2118 | " int size = config_size(config); \n" | ||
| 2119 | " \n" | ||
| 2120 | " // Using instead if(glupIsEnabled(GLUP_DRAW_MESH)) crashes on NVidia driver \n" | ||
| 2121 | " // so I directly test the state variable (a little bit less efficient, but \n" | ||
| 2122 | " // does not crash) -> probably an NVidia GLSL compiler bug (crashes in \n" | ||
| 2123 | " // memcpy when calling glLinkProgram()). \n" | ||
| 2124 | " if(GLUP.draw_mesh_enabled) { \n" | ||
| 2125 | " // Single triangle: mesh tex coords are standard tri mesh tex coord. \n" | ||
| 2126 | " if(size == 3) { \n" | ||
| 2127 | " isect_triangle( \n" | ||
| 2128 | " config_edge(config,0), vec4(1.0, 0.0, 0.0, 0.0), \n" | ||
| 2129 | " config_edge(config,1), vec4(0.0, 1.0, 0.0, 0.0), \n" | ||
| 2130 | " config_edge(config,2), vec4(0.0, 0.0, 1.0, 0.0) \n" | ||
| 2131 | " ); \n" | ||
| 2132 | " } else { \n" | ||
| 2133 | " // First triangle: draw mesh only on first wedge \n" | ||
| 2134 | " // (let's pretend it is a wedge of a quad) \n" | ||
| 2135 | " isect_triangle( \n" | ||
| 2136 | " config_edge(config,0), vec4(0.0, 1.0, 0.0, 1.0), \n" | ||
| 2137 | " config_edge(config,1), vec4(1.0, 0.0, 0.0, 1.0), \n" | ||
| 2138 | " config_edge(config,2), vec4(1.0, 0.0, 1.0, 0.0) \n" | ||
| 2139 | " ); \n" | ||
| 2140 | " // Middle triangles: draw mesh only on [i,i+1] \n" | ||
| 2141 | " // (let's pretend that vertex i is the quad center) \n" | ||
| 2142 | " for(int i=2; i+2<size; ++i) { \n" | ||
| 2143 | " isect_triangle( \n" | ||
| 2144 | " config_edge(config,0), vec4(0.5, 0.5, 0.5, 0.5), \n" | ||
| 2145 | " config_edge(config,i), vec4(0.0, 1.0, 0.0, 1.0), \n" | ||
| 2146 | " config_edge(config,i+1), vec4(1.0, 0.0, 0.0, 1.0) \n" | ||
| 2147 | " ); \n" | ||
| 2148 | " } \n" | ||
| 2149 | " // Last triangle: draw mesh only on last wedge \n" | ||
| 2150 | " // (let's pretend it is a wedge of a quad) \n" | ||
| 2151 | " isect_triangle( \n" | ||
| 2152 | " config_edge(config,0), vec4(0.0, 1.0, 0.0, 1.0), \n" | ||
| 2153 | " config_edge(config,size-2), vec4(1.0, 0.0, 1.0, 0.0), \n" | ||
| 2154 | " config_edge(config,size-1), vec4(1.0, 0.0, 0.0, 1.0) \n" | ||
| 2155 | " ); \n" | ||
| 2156 | " } \n" | ||
| 2157 | " } else { \n" | ||
| 2158 | " for(int i=1; i+1<size; ++i) { \n" | ||
| 2159 | " isect_triangle( \n" | ||
| 2160 | " config_edge(config,0), vec4(0.0, 0.0, 0.0, 0.0), \n" | ||
| 2161 | " config_edge(config,i), vec4(0.0, 0.0, 0.0, 0.0), \n" | ||
| 2162 | " config_edge(config,i+1), vec4(0.0, 0.0, 0.0, 0.0) \n" | ||
| 2163 | " ); \n" | ||
| 2164 | " } \n" | ||
| 2165 | " } \n" | ||
| 2166 | "} \n" | ||
| 2167 | " \n" | ||
| 2168 | "bool compute_clip_coords() { \n" | ||
| 2169 | " return ( \n" | ||
| 2170 | " glupIsEnabled(GLUP_CLIPPING) && \n" | ||
| 2171 | " GLUP.clipping_mode==GLUP_CLIP_STANDARD \n" | ||
| 2172 | " ); \n" | ||
| 2173 | "} \n" | ||
| 2174 | " \n" | ||
| 2175 | "bool draw_clipped_cell() { \n" | ||
| 2176 | " if(cell_is_clipped()) { \n" | ||
| 2177 | " return true; \n" | ||
| 2178 | " } \n" | ||
| 2179 | " gl_PrimitiveID = gl_PrimitiveIDIn; \n" | ||
| 2180 | " get_vertices(); \n" | ||
| 2181 | " if( \n" | ||
| 2182 | " glupIsEnabled(GLUP_CLIPPING) && \n" | ||
| 2183 | " GLUP.clipping_mode == GLUP_CLIP_SLICE_CELLS \n" | ||
| 2184 | " ) { \n" | ||
| 2185 | " draw_marching_cell(); \n" | ||
| 2186 | " return true; \n" | ||
| 2187 | " } \n" | ||
| 2188 | " return false; \n" | ||
| 2189 | "} \n" | ||
| 2190 | ); | ||
| 2191 | |||
| 2192 | ✗ | GEO::GLSL::register_GLSL_include_file("GLUPGLSL/spheres_vertex_shader.h", | |
| 2193 | "//import <GLUP/current_profile/vertex_shader_preamble.h> \n" | ||
| 2194 | "//import <GLUPGLSL/state.h> \n" | ||
| 2195 | "//import <GLUP/stdglup.h> \n" | ||
| 2196 | "//import <GLUP/current_profile/toggles.h> \n" | ||
| 2197 | "//import <GLUP/current_profile/primitive.h> \n" | ||
| 2198 | " \n" | ||
| 2199 | "in vec4 vertex_in; \n" | ||
| 2200 | "in vec4 color_in; \n" | ||
| 2201 | "in vec4 tex_coord_in; \n" | ||
| 2202 | " \n" | ||
| 2203 | "out VertexData { \n" | ||
| 2204 | " vec4 color; \n" | ||
| 2205 | " vec4 tex_coord; \n" | ||
| 2206 | " vec3 center_world_space; \n" | ||
| 2207 | " float radius; \n" | ||
| 2208 | "} VertexOut; \n" | ||
| 2209 | " \n" | ||
| 2210 | "// Reference: \n" | ||
| 2211 | "// http://reality.cs.ucl.ac.uk/projects/quadrics/pbg06.pdf \n" | ||
| 2212 | "// Ported from Dmitry / Sam code \n" | ||
| 2213 | " \n" | ||
| 2214 | "vec4 row(in mat4 M, in int i) { \n" | ||
| 2215 | " return vec4(M[0][i], M[1][i], M[2][i], M[3][i]); \n" | ||
| 2216 | "} \n" | ||
| 2217 | " \n" | ||
| 2218 | "void main(void) { \n" | ||
| 2219 | " \n" | ||
| 2220 | " if(glupIsEnabled(GLUP_VERTEX_COLORS)) { \n" | ||
| 2221 | " VertexOut.color = color_in; \n" | ||
| 2222 | " } \n" | ||
| 2223 | " \n" | ||
| 2224 | " if(glupIsEnabled(GLUP_TEXTURING)) { \n" | ||
| 2225 | " if(glupIsEnabled(GLUP_INDIRECT_TEXTURING)) { \n" | ||
| 2226 | " VertexOut.tex_coord = tex_coord_in; \n" | ||
| 2227 | " } else { \n" | ||
| 2228 | " VertexOut.tex_coord = GLUP.texture_matrix * tex_coord_in; \n" | ||
| 2229 | " } \n" | ||
| 2230 | " } \n" | ||
| 2231 | " \n" | ||
| 2232 | " float R = vertex_in.w; \n" | ||
| 2233 | " gl_Position = \n" | ||
| 2234 | " GLUP.modelviewprojection_matrix*vec4(vertex_in.xyz,1.0); \n" | ||
| 2235 | " \n" | ||
| 2236 | " // TODO: optimize: directly compute r1,r2,r4 \n" | ||
| 2237 | " mat4 T = mat4( \n" | ||
| 2238 | " 1.0, 0.0, 0.0, 0.0, \n" | ||
| 2239 | " 0.0, 1.0, 0.0, 0.0, \n" | ||
| 2240 | " 0.0, 0.0, 1.0, 0.0, \n" | ||
| 2241 | " vertex_in.x/R, vertex_in.y/R, vertex_in.z/R, 1.0/R \n" | ||
| 2242 | " ); \n" | ||
| 2243 | " \n" | ||
| 2244 | " mat4 PMT = GLUP.modelviewprojection_matrix * T; \n" | ||
| 2245 | " vec4 r1 = row(PMT,0); \n" | ||
| 2246 | " vec4 r2 = row(PMT,1); \n" | ||
| 2247 | " vec4 r4 = row(PMT,3); \n" | ||
| 2248 | " \n" | ||
| 2249 | " float r1Dr4T = dot(r1.xyz,r4.xyz)-r1.w*r4.w; \n" | ||
| 2250 | " float r1Dr1T = dot(r1.xyz,r1.xyz)-r1.w*r1.w; \n" | ||
| 2251 | " float r4Dr4T = dot(r4.xyz,r4.xyz)-r4.w*r4.w; \n" | ||
| 2252 | " float r2Dr2T = dot(r2.xyz,r2.xyz)-r2.w*r2.w; \n" | ||
| 2253 | " float r2Dr4T = dot(r2.xyz,r4.xyz)-r2.w*r4.w; \n" | ||
| 2254 | " \n" | ||
| 2255 | " float discriminant_x = r1Dr4T*r1Dr4T-r4Dr4T*r1Dr1T; \n" | ||
| 2256 | " float discriminant_y = r2Dr4T*r2Dr4T-r4Dr4T*r2Dr2T; \n" | ||
| 2257 | " float screen = max(GLUP.viewport[2], GLUP.viewport[3]); \n" | ||
| 2258 | " \n" | ||
| 2259 | " gl_PointSize = sqrt(max(discriminant_x,discriminant_y)) * screen/(-r4Dr4T); \n" | ||
| 2260 | " \n" | ||
| 2261 | " VertexOut.center_world_space = vertex_in.xyz; \n" | ||
| 2262 | " VertexOut.radius = R; \n" | ||
| 2263 | "} \n" | ||
| 2264 | ); | ||
| 2265 | |||
| 2266 | ✗ | GEO::GLSL::register_GLSL_include_file("GLUPGLSL/spheres_fragment_shader.h", | |
| 2267 | "//import <GLUP/current_profile/fragment_shader_preamble.h> \n" | ||
| 2268 | "//import <GLUPGLSL/state.h> \n" | ||
| 2269 | "//import <GLUP/stdglup.h> \n" | ||
| 2270 | "//import <GLUP/current_profile/toggles.h> \n" | ||
| 2271 | "//import <GLUP/current_profile/primitive.h> \n" | ||
| 2272 | "//import <GLUP/fragment_shader_utils.h> \n" | ||
| 2273 | "//import <GLUP/fragment_ray_tracing.h> \n" | ||
| 2274 | " \n" | ||
| 2275 | "in VertexData { \n" | ||
| 2276 | " vec4 color; \n" | ||
| 2277 | " vec4 tex_coord; \n" | ||
| 2278 | " vec3 center_world_space; \n" | ||
| 2279 | " float radius; \n" | ||
| 2280 | "} FragmentIn; \n" | ||
| 2281 | " \n" | ||
| 2282 | "void main(void) { \n" | ||
| 2283 | " \n" | ||
| 2284 | " vec3 C = FragmentIn.center_world_space; \n" | ||
| 2285 | " float r = FragmentIn.radius; \n" | ||
| 2286 | " \n" | ||
| 2287 | " if(glupIsEnabled(GLUP_CLIPPING)) { \n" | ||
| 2288 | " if( \n" | ||
| 2289 | " glup_primitive == GLUP_POINTS || \n" | ||
| 2290 | " GLUP.clipping_mode == GLUP_CLIP_WHOLE_CELLS \n" | ||
| 2291 | " ) { \n" | ||
| 2292 | " if(dot(vec4(C,1.0),GLUP.world_clip_plane) < 0.0) { \n" | ||
| 2293 | " discard; \n" | ||
| 2294 | " } \n" | ||
| 2295 | " } else if(GLUP.clipping_mode == GLUP_CLIP_STRADDLING_CELLS) { \n" | ||
| 2296 | " float dist = \n" | ||
| 2297 | " abs(dot(vec4(C,1.0),GLUP.world_clip_plane)) / \n" | ||
| 2298 | " length(GLUP.world_clip_plane.xyz) ; \n" | ||
| 2299 | " if(dist > r) { \n" | ||
| 2300 | " discard; \n" | ||
| 2301 | " } \n" | ||
| 2302 | " } \n" | ||
| 2303 | " } \n" | ||
| 2304 | " \n" | ||
| 2305 | " Ray R = glup_primary_ray(); \n" | ||
| 2306 | " vec3 M,N; \n" | ||
| 2307 | " \n" | ||
| 2308 | " if( \n" | ||
| 2309 | " glup_primitive != GLUP_POINTS && \n" | ||
| 2310 | " glupIsEnabled(GLUP_CLIPPING) && \n" | ||
| 2311 | " GLUP.clipping_mode == GLUP_CLIP_SLICE_CELLS \n" | ||
| 2312 | " ) { \n" | ||
| 2313 | " N = GLUP.world_clip_plane.xyz; \n" | ||
| 2314 | " float w = GLUP.world_clip_plane.w; \n" | ||
| 2315 | " float t = -(w + dot(N,R.O)) / dot(N,R.V); \n" | ||
| 2316 | " M = R.O + t*R.V; \n" | ||
| 2317 | " if(dot(M-C,M-C) > r*r) { \n" | ||
| 2318 | " discard; \n" | ||
| 2319 | " } \n" | ||
| 2320 | " } else { \n" | ||
| 2321 | " // High-precision ray-sphere intersection \n" | ||
| 2322 | " // See Ray Tracing Gems, Chapter 7, \n" | ||
| 2323 | " // Precision Improvements for Ray-Sphere Intersection, \n" | ||
| 2324 | " // E. Haines, J. Gunther, T. Akenine-Moller \n" | ||
| 2325 | " vec3 D = R.O-C; \n" | ||
| 2326 | " float a = dot(R.V,R.V); \n" | ||
| 2327 | " float b_prime = -dot(D,R.V); \n" | ||
| 2328 | " vec3 H = D + (b_prime/a) * R.V; \n" | ||
| 2329 | " float delta = r*r - dot(H,H); \n" | ||
| 2330 | " if(delta < 0.0) { \n" | ||
| 2331 | " discard; \n" | ||
| 2332 | " } \n" | ||
| 2333 | " // Original article: q = b_prime + sign(b_prime)*sqrt(a*delta) \n" | ||
| 2334 | " // Don't know why they do that, here we know we want t1 \n" | ||
| 2335 | " float q = b_prime - sqrt(a*delta); \n" | ||
| 2336 | " float t = q/a; \n" | ||
| 2337 | " \n" | ||
| 2338 | " /* \n" | ||
| 2339 | " // Equivalent lower-precision version: \n" | ||
| 2340 | " float a = dot(R.V,R.V); \n" | ||
| 2341 | " float b = 2.0*dot(R.V,D); \n" | ||
| 2342 | " float c = dot(D,D)-r*r; \n" | ||
| 2343 | " float delta = b*b-4.0*a*c; \n" | ||
| 2344 | " if(delta < 0.0) { \n" | ||
| 2345 | " discard; \n" | ||
| 2346 | " } \n" | ||
| 2347 | " float t = (-b-sqrt(delta))/(2.0*a); \n" | ||
| 2348 | " */ \n" | ||
| 2349 | " \n" | ||
| 2350 | " M = R.O + t*R.V; \n" | ||
| 2351 | " N = M-C; \n" | ||
| 2352 | " } \n" | ||
| 2353 | " \n" | ||
| 2354 | " if( \n" | ||
| 2355 | " glup_primitive != GLUP_POINTS && \n" | ||
| 2356 | " glupIsEnabled(GLUP_CLIPPING) && \n" | ||
| 2357 | " GLUP.clipping_mode == GLUP_CLIP_STANDARD \n" | ||
| 2358 | " ) { \n" | ||
| 2359 | " if(dot(vec4(M,1.0),GLUP.world_clip_plane) < 0.0) { \n" | ||
| 2360 | " discard; \n" | ||
| 2361 | " } \n" | ||
| 2362 | " } \n" | ||
| 2363 | " \n" | ||
| 2364 | " glup_update_depth(M); \n" | ||
| 2365 | " \n" | ||
| 2366 | " if(glupIsEnabled(GLUP_PRIMITIVE_FILTERING)) { \n" | ||
| 2367 | " glup_primitive_filter(gl_PrimitiveID); \n" | ||
| 2368 | " } \n" | ||
| 2369 | " \n" | ||
| 2370 | " if(glupIsEnabled(GLUP_PICKING)) { \n" | ||
| 2371 | " glup_FragColor = glup_picking(gl_PrimitiveID); \n" | ||
| 2372 | " return; \n" | ||
| 2373 | " } \n" | ||
| 2374 | " \n" | ||
| 2375 | " vec4 result; \n" | ||
| 2376 | " if(glupIsEnabled(GLUP_VERTEX_COLORS)) { \n" | ||
| 2377 | " result = FragmentIn.color; \n" | ||
| 2378 | " } else { \n" | ||
| 2379 | " result = GLUP.front_color; \n" | ||
| 2380 | " } \n" | ||
| 2381 | " if(glupIsEnabled(GLUP_TEXTURING)) { \n" | ||
| 2382 | " result = glup_texturing(result, FragmentIn.tex_coord); \n" | ||
| 2383 | " } \n" | ||
| 2384 | " if(glupIsEnabled(GLUP_LIGHTING)) { \n" | ||
| 2385 | " N = normalize(GLUP.normal_matrix*N); \n" | ||
| 2386 | " if( \n" | ||
| 2387 | " glup_primitive != GLUP_POINTS && \n" | ||
| 2388 | " glupIsEnabled(GLUP_CLIPPING) && \n" | ||
| 2389 | " GLUP.clipping_mode == GLUP_CLIP_SLICE_CELLS && \n" | ||
| 2390 | " N.z < 0.0 \n" | ||
| 2391 | " ) { \n" | ||
| 2392 | " N = -N; \n" | ||
| 2393 | " } \n" | ||
| 2394 | " result = glup_lighting(result, N); \n" | ||
| 2395 | " } \n" | ||
| 2396 | " glup_FragColor = result; \n" | ||
| 2397 | " glup_alpha_discard(); \n" | ||
| 2398 | "} \n" | ||
| 2399 | ); | ||
| 2400 | |||
| 2401 | ✗ | } | |
| 2402 | ✗ | void register_embedded_shaders_fullscreen() { | |
| 2403 | ✗ | GEO::GLSL::register_GLSL_include_file("fullscreen/ambient_occlusion_fragment_shader.h", | |
| 2404 | "//import <fullscreen/current_profile/fragment_shader_preamble.h> \n" | ||
| 2405 | "//import <GLUP/defs.h> \n" | ||
| 2406 | " \n" | ||
| 2407 | "glup_in vec2 tex_coord; \n" | ||
| 2408 | " \n" | ||
| 2409 | "// Max radius to be used around pixel to estimate occlusion \n" | ||
| 2410 | "uniform float max_radius; \n" | ||
| 2411 | " \n" | ||
| 2412 | "// Multiplicative factor between two consecutive steps. \n" | ||
| 2413 | "uniform float step_mul; \n" | ||
| 2414 | " \n" | ||
| 2415 | "uniform sampler2D depth_texture; \n" | ||
| 2416 | "uniform sampler2D random_texture; \n" | ||
| 2417 | " \n" | ||
| 2418 | "const float PI = 3.14159265; \n" | ||
| 2419 | " \n" | ||
| 2420 | "uniform mat4 mat_proj_inv; \n" | ||
| 2421 | "uniform float shadows_gamma; \n" | ||
| 2422 | "uniform float shadows_intensity; \n" | ||
| 2423 | "uniform float depth_cueing; \n" | ||
| 2424 | "uniform float nb_directions; \n" | ||
| 2425 | " \n" | ||
| 2426 | "#ifdef GL_ES \n" | ||
| 2427 | " \n" | ||
| 2428 | "uniform vec2 depth_tex_size; \n" | ||
| 2429 | "uniform vec2 random_tex_size; \n" | ||
| 2430 | " \n" | ||
| 2431 | "#define width float(depth_tex_size.x) \n" | ||
| 2432 | "#define height float(depth_tex_size.y) \n" | ||
| 2433 | " \n" | ||
| 2434 | "#define r_width float(random_tex_size.x) \n" | ||
| 2435 | "#define r_height float(random_tex_size.y) \n" | ||
| 2436 | " \n" | ||
| 2437 | "#else \n" | ||
| 2438 | " \n" | ||
| 2439 | "// Size of depth buffer \n" | ||
| 2440 | "float width = float(textureSize(depth_texture,0).x); \n" | ||
| 2441 | "float height = float(textureSize(depth_texture,0).y); \n" | ||
| 2442 | " \n" | ||
| 2443 | "// Size of random pattern \n" | ||
| 2444 | "float r_width = float(textureSize(random_texture,0).x); \n" | ||
| 2445 | "float r_height = float(textureSize(random_texture,0).y); \n" | ||
| 2446 | " \n" | ||
| 2447 | "#endif \n" | ||
| 2448 | " \n" | ||
| 2449 | "//------------------------------------------------- \n" | ||
| 2450 | "// Map 2D coordinate into world space. \n" | ||
| 2451 | "//------------------------------------------------- \n" | ||
| 2452 | " \n" | ||
| 2453 | "vec3 get_obj_coords(in vec2 where, in sampler2D texture) { \n" | ||
| 2454 | " vec4 p = vec4(where, glup_texture(texture, where).x, 1.); \n" | ||
| 2455 | " // Map [0,1] to [-1,1] \n" | ||
| 2456 | " p.xyz = p.xyz * 2. - 1.; \n" | ||
| 2457 | " p = mat_proj_inv * p; \n" | ||
| 2458 | " if (p.w != 0.) { \n" | ||
| 2459 | " p.xyz /= p.w; \n" | ||
| 2460 | " } \n" | ||
| 2461 | " return vec3(p); \n" | ||
| 2462 | "} \n" | ||
| 2463 | " \n" | ||
| 2464 | "//------------------------------------------------- \n" | ||
| 2465 | "// Computes depth coordinate in world space. \n" | ||
| 2466 | "//------------------------------------------------- \n" | ||
| 2467 | " \n" | ||
| 2468 | "float get_obj_z(in vec2 where, in sampler2D texture) { \n" | ||
| 2469 | " float depth = glup_texture(texture, where).x; \n" | ||
| 2470 | " // For background points, return infinite value. \n" | ||
| 2471 | " if (depth >= 1.) { \n" | ||
| 2472 | " return -10000.; \n" | ||
| 2473 | " } \n" | ||
| 2474 | " // Map from range 0 to 1 to range -1 to 1 \n" | ||
| 2475 | " depth = depth * 2. - 1.; \n" | ||
| 2476 | " float z = (depth * mat_proj_inv[2][2] + mat_proj_inv[3][2]) / \n" | ||
| 2477 | " (depth * mat_proj_inv[2][3] + mat_proj_inv[3][3]); \n" | ||
| 2478 | " return z; \n" | ||
| 2479 | "} \n" | ||
| 2480 | " \n" | ||
| 2481 | "//------------------------------------------------- \n" | ||
| 2482 | "// Tests whether a point falls outside a texture \n" | ||
| 2483 | "//------------------------------------------------- \n" | ||
| 2484 | " \n" | ||
| 2485 | "bool outside(in vec2 point) { \n" | ||
| 2486 | " return ( \n" | ||
| 2487 | " point.x > 1. || point.x < 0.|| \n" | ||
| 2488 | " point.y > 1. || point.y < 0. \n" | ||
| 2489 | " ); \n" | ||
| 2490 | "} \n" | ||
| 2491 | " \n" | ||
| 2492 | "//------------------------------------------------- \n" | ||
| 2493 | "// Horizon point \n" | ||
| 2494 | "//------------------------------------------------- \n" | ||
| 2495 | " \n" | ||
| 2496 | "vec2 horizon_point(in vec2 from, in vec2 dir) { \n" | ||
| 2497 | " vec2 result; \n" | ||
| 2498 | " float horizon_delta = -100000.0; \n" | ||
| 2499 | " float from_z = get_obj_z(from, depth_texture); \n" | ||
| 2500 | " float step = (1.0 / width); \n" | ||
| 2501 | " float r = 2.0 * step; \n" | ||
| 2502 | " vec2 cur_point = from + r * dir; \n" | ||
| 2503 | " \n" | ||
| 2504 | "#ifdef GL_ES \n" | ||
| 2505 | " for(int i=0; i<100; ++i) { \n" | ||
| 2506 | " if(!outside(cur_point)) { \n" | ||
| 2507 | "#else \n" | ||
| 2508 | " while (!outside(cur_point)) { \n" | ||
| 2509 | "#endif \n" | ||
| 2510 | " float z; \n" | ||
| 2511 | " z = get_obj_z(cur_point, depth_texture); \n" | ||
| 2512 | " \n" | ||
| 2513 | " float delta_z = (z - from_z) / r; \n" | ||
| 2514 | " if( delta_z > horizon_delta) { \n" | ||
| 2515 | " horizon_delta = delta_z; \n" | ||
| 2516 | " result = cur_point; \n" | ||
| 2517 | " } \n" | ||
| 2518 | " if(r > max_radius) { \n" | ||
| 2519 | " break; \n" | ||
| 2520 | " } \n" | ||
| 2521 | " r += step; \n" | ||
| 2522 | " step *= step_mul; \n" | ||
| 2523 | " cur_point = from + r * dir; \n" | ||
| 2524 | " } \n" | ||
| 2525 | " \n" | ||
| 2526 | "#ifdef GL_ES \n" | ||
| 2527 | " } \n" | ||
| 2528 | "#endif \n" | ||
| 2529 | " \n" | ||
| 2530 | " return result; \n" | ||
| 2531 | " } \n" | ||
| 2532 | " \n" | ||
| 2533 | "//----------------------------------------------------------------------------- \n" | ||
| 2534 | "// Computes the angle between the horizon and the specified vector \n" | ||
| 2535 | "// in the specified direction. \n" | ||
| 2536 | "// The vector needs to be normalized \n" | ||
| 2537 | "//----------------------------------------------------------------------------- \n" | ||
| 2538 | " \n" | ||
| 2539 | " float horizon_angle(in vec2 from, in vec3 from3D, in vec2 dir, in vec3 normal) { \n" | ||
| 2540 | " vec3 horizon = \n" | ||
| 2541 | " get_obj_coords(horizon_point(from, dir), depth_texture) - from3D; \n" | ||
| 2542 | " return acos ( dot(normal, horizon) / length(horizon) ); \n" | ||
| 2543 | " } \n" | ||
| 2544 | " \n" | ||
| 2545 | "//------------------------------------------------------------------------------ \n" | ||
| 2546 | "// Generates an image-space noise. \n" | ||
| 2547 | "//------------------------------------------------------------------------------ \n" | ||
| 2548 | " \n" | ||
| 2549 | " float my_noise() { \n" | ||
| 2550 | " float x = tex_coord.x * width / r_width; \n" | ||
| 2551 | " float y = tex_coord.y * height / r_height; \n" | ||
| 2552 | " return glup_texture(random_texture, vec2(x,y)).x; \n" | ||
| 2553 | " } \n" | ||
| 2554 | " \n" | ||
| 2555 | " float ambient_occlusion(in vec2 from) { \n" | ||
| 2556 | " float angle_step = 2.0 * PI / (nb_directions); \n" | ||
| 2557 | " float cur_angle = my_noise() * 2. * PI ; \n" | ||
| 2558 | " float occlusion_factor = 0.0; \n" | ||
| 2559 | " vec3 from3D = get_obj_coords(from, depth_texture); \n" | ||
| 2560 | "#ifdef GL_ES \n" | ||
| 2561 | " for (int i=0; i < 7; i++) { \n" | ||
| 2562 | "#else \n" | ||
| 2563 | " for (int i=0; i < nb_directions; i++) { \n" | ||
| 2564 | "#endif \n" | ||
| 2565 | " vec2 dir = vec2(cos(cur_angle), sin(cur_angle)); \n" | ||
| 2566 | " float h_angle = horizon_angle(from, from3D, dir, vec3(0., 0., 1.)); \n" | ||
| 2567 | " cur_angle += angle_step; \n" | ||
| 2568 | " occlusion_factor += h_angle; \n" | ||
| 2569 | " } \n" | ||
| 2570 | " return occlusion_factor / (float(nb_directions) * (PI / 2.0)); \n" | ||
| 2571 | " } \n" | ||
| 2572 | " \n" | ||
| 2573 | " float compute_depth_cueing(vec2 uv) { \n" | ||
| 2574 | " if(depth_cueing == 0.0) { \n" | ||
| 2575 | " return 0.0; \n" | ||
| 2576 | " } \n" | ||
| 2577 | " float depth = glup_texture(depth_texture,tex_coord).x; \n" | ||
| 2578 | " return depth < 1.0 ? depth_cueing * depth : 0.0; \n" | ||
| 2579 | " } \n" | ||
| 2580 | " \n" | ||
| 2581 | " void main() { \n" | ||
| 2582 | " float g = 1.0; \n" | ||
| 2583 | " if(glup_texture(depth_texture, tex_coord).x < 1.0) { \n" | ||
| 2584 | " g = ambient_occlusion(tex_coord); \n" | ||
| 2585 | " g = shadows_intensity * \n" | ||
| 2586 | " pow(g, shadows_gamma) - compute_depth_cueing(tex_coord); \n" | ||
| 2587 | " } \n" | ||
| 2588 | " glup_FragColor.rgb = vec3(0.0,0.0,0.0); \n" | ||
| 2589 | " glup_FragColor.a = 1.0 - g; \n" | ||
| 2590 | " } \n" | ||
| 2591 | ); | ||
| 2592 | |||
| 2593 | ✗ | GEO::GLSL::register_GLSL_include_file("fullscreen/blur_fragment_shader.h", | |
| 2594 | "//import <fullscreen/current_profile/fragment_shader_preamble.h> \n" | ||
| 2595 | "//import <GLUP/stdglup.h> \n" | ||
| 2596 | " \n" | ||
| 2597 | "glup_in vec2 tex_coord; \n" | ||
| 2598 | " \n" | ||
| 2599 | "uniform sampler2D source_tex; \n" | ||
| 2600 | " \n" | ||
| 2601 | "uniform float blur_width; \n" | ||
| 2602 | "uniform bool vertical; \n" | ||
| 2603 | " \n" | ||
| 2604 | "const float PI = 3.14159265; \n" | ||
| 2605 | " \n" | ||
| 2606 | "#ifdef GL_ES \n" | ||
| 2607 | "uniform vec2 source_tex_size; \n" | ||
| 2608 | "#define width float(source_tex_size.x); \n" | ||
| 2609 | "#define height float(source_tex_size.y); \n" | ||
| 2610 | "#else \n" | ||
| 2611 | "float width = float(textureSize(source_tex,0).x); \n" | ||
| 2612 | "float height = float(textureSize(source_tex,0).y); \n" | ||
| 2613 | "#endif \n" | ||
| 2614 | " \n" | ||
| 2615 | "// 1D Gaussian distribution, s is standard deviation \n" | ||
| 2616 | "float gaussian(in float x, in float s) { \n" | ||
| 2617 | " return exp(-x * x / (2.0 * s * s)) / (s * sqrt(2.0 * PI)); \n" | ||
| 2618 | "} \n" | ||
| 2619 | " \n" | ||
| 2620 | "void compute_blur() { \n" | ||
| 2621 | " int n = int(floor(3.0 * blur_width) - 1.0); \n" | ||
| 2622 | " float sum = 0.0; \n" | ||
| 2623 | " \n" | ||
| 2624 | "#ifdef GL_ES \n" | ||
| 2625 | " for(int i = -5; i <= 5; i++) { \n" | ||
| 2626 | "#else \n" | ||
| 2627 | " for(int i = -n; i <= n; i++) { \n" | ||
| 2628 | "#endif \n" | ||
| 2629 | " float weight = gaussian(float(i), blur_width); \n" | ||
| 2630 | " sum += weight; \n" | ||
| 2631 | " } \n" | ||
| 2632 | " \n" | ||
| 2633 | " vec2 cur_pix_coords; \n" | ||
| 2634 | " vec4 cur_pix_tex; \n" | ||
| 2635 | " vec4 final_pix_tex = vec4(0.0); \n" | ||
| 2636 | " \n" | ||
| 2637 | "#ifdef GL_ES \n" | ||
| 2638 | " for(int i = -5; i <= 5; i++) { \n" | ||
| 2639 | "#else \n" | ||
| 2640 | " for(int i = -n; i <= n; i++) { \n" | ||
| 2641 | "#endif \n" | ||
| 2642 | " float x_offset, y_offset; \n" | ||
| 2643 | " if (vertical) { \n" | ||
| 2644 | " x_offset = 0.0; \n" | ||
| 2645 | " y_offset = float(i); \n" | ||
| 2646 | " } else { \n" | ||
| 2647 | " x_offset = float(i); \n" | ||
| 2648 | " y_offset = 0.0; \n" | ||
| 2649 | " } \n" | ||
| 2650 | " \n" | ||
| 2651 | " x_offset = x_offset / width; \n" | ||
| 2652 | " y_offset = y_offset / height; \n" | ||
| 2653 | " \n" | ||
| 2654 | " float weight = gaussian(float(i), blur_width) / sum; \n" | ||
| 2655 | " cur_pix_coords = vec2(x_offset, y_offset) + tex_coord; \n" | ||
| 2656 | " cur_pix_tex = glup_texture(source_tex, cur_pix_coords); \n" | ||
| 2657 | " final_pix_tex += cur_pix_tex * weight; \n" | ||
| 2658 | " } \n" | ||
| 2659 | " glup_FragColor.rgb = final_pix_tex.rgb; \n" | ||
| 2660 | " } \n" | ||
| 2661 | " \n" | ||
| 2662 | " void main() { \n" | ||
| 2663 | " compute_blur(); \n" | ||
| 2664 | " } \n" | ||
| 2665 | ); | ||
| 2666 | |||
| 2667 | ✗ | GEO::GLSL::register_GLSL_include_file("fullscreen/depth_dependent_blur_fragment_shader.h", | |
| 2668 | "//import <fullscreen/current_profile/fragment_shader_preamble.h> \n" | ||
| 2669 | "//import <GLUP/defs.h> \n" | ||
| 2670 | " \n" | ||
| 2671 | "glup_in vec2 tex_coord; \n" | ||
| 2672 | " \n" | ||
| 2673 | "uniform sampler2D source_tex; \n" | ||
| 2674 | "uniform sampler2D depth_tex; \n" | ||
| 2675 | " \n" | ||
| 2676 | "uniform float blur_width; \n" | ||
| 2677 | "uniform bool vertical; \n" | ||
| 2678 | " \n" | ||
| 2679 | "const float PI = 3.14159265; \n" | ||
| 2680 | "const float threshold = 0.005; \n" | ||
| 2681 | " \n" | ||
| 2682 | "#ifdef GL_ES \n" | ||
| 2683 | "uniform vec2 source_tex_size; \n" | ||
| 2684 | "#define width float(source_tex_size.x); \n" | ||
| 2685 | "#define height float(source_tex_size.y); \n" | ||
| 2686 | "#else \n" | ||
| 2687 | "float width = float(textureSize(source_tex,0).x); \n" | ||
| 2688 | "float height = float(textureSize(source_tex,0).y); \n" | ||
| 2689 | "#endif \n" | ||
| 2690 | " \n" | ||
| 2691 | "// 1D Gaussian distribution, s is standard deviation \n" | ||
| 2692 | "float gaussian(in float x, in float s) { \n" | ||
| 2693 | " return exp(-x * x / (2.0 * s * s)) / (s * sqrt(2.0 * PI)); \n" | ||
| 2694 | "} \n" | ||
| 2695 | " \n" | ||
| 2696 | "float get_z_coeff(in vec2 pos) { \n" | ||
| 2697 | " float zCoef = glup_texture(depth_tex, pos).r; \n" | ||
| 2698 | " zCoef = 3.0 * (zCoef - 0.1) ; \n" | ||
| 2699 | " return zCoef; \n" | ||
| 2700 | "} \n" | ||
| 2701 | " \n" | ||
| 2702 | "float get_z_dist(in vec2 center_pos, in vec2 other_pos) { \n" | ||
| 2703 | " return abs(get_z_coeff(center_pos) - get_z_coeff(other_pos)); \n" | ||
| 2704 | "} \n" | ||
| 2705 | " \n" | ||
| 2706 | "void compute_blur() { \n" | ||
| 2707 | " int n = int(floor(3.0 * blur_width) - 1.0); \n" | ||
| 2708 | " float sum = 0.0; \n" | ||
| 2709 | " int i; \n" | ||
| 2710 | " \n" | ||
| 2711 | " vec2 cur_pix_coords; \n" | ||
| 2712 | " vec4 cur_pix_tex; \n" | ||
| 2713 | " vec4 final_pix_tex = vec4(0.0); \n" | ||
| 2714 | " \n" | ||
| 2715 | " // Calculate the sum of weights for the blur \n" | ||
| 2716 | "#ifdef GL_ES \n" | ||
| 2717 | " for(int i = -5; i <= 5; i++) { \n" | ||
| 2718 | "#else \n" | ||
| 2719 | " for(int i = -n; i <= n; i++) { \n" | ||
| 2720 | "#endif \n" | ||
| 2721 | " float x_offset, y_offset; \n" | ||
| 2722 | " if (vertical) { \n" | ||
| 2723 | " x_offset = 0.0; \n" | ||
| 2724 | " y_offset = float(i); \n" | ||
| 2725 | " } else { \n" | ||
| 2726 | " x_offset = float(i); \n" | ||
| 2727 | " y_offset = 0.0; \n" | ||
| 2728 | " } \n" | ||
| 2729 | " \n" | ||
| 2730 | " x_offset = x_offset / width; \n" | ||
| 2731 | " y_offset = y_offset / height; \n" | ||
| 2732 | " \n" | ||
| 2733 | " cur_pix_coords = vec2(x_offset, y_offset) + tex_coord; \n" | ||
| 2734 | " \n" | ||
| 2735 | " if(get_z_dist(tex_coord, cur_pix_coords) <= threshold) { \n" | ||
| 2736 | " float weight = gaussian(float(i), blur_width); \n" | ||
| 2737 | " sum += weight; \n" | ||
| 2738 | " } \n" | ||
| 2739 | " } \n" | ||
| 2740 | " \n" | ||
| 2741 | " // Calculate the blurred color \n" | ||
| 2742 | "#ifdef GL_ES \n" | ||
| 2743 | " for(int i = -5; i <= 5; i++) { \n" | ||
| 2744 | "#else \n" | ||
| 2745 | " for(int i = -n; i <= n; i++) { \n" | ||
| 2746 | "#endif \n" | ||
| 2747 | " float x_offset, y_offset; \n" | ||
| 2748 | " if (vertical) { \n" | ||
| 2749 | " x_offset = 0.0; \n" | ||
| 2750 | " y_offset = float(i); \n" | ||
| 2751 | " } else { \n" | ||
| 2752 | " x_offset = float(i); \n" | ||
| 2753 | " y_offset = 0.0; \n" | ||
| 2754 | " } \n" | ||
| 2755 | " \n" | ||
| 2756 | " x_offset = x_offset / width; \n" | ||
| 2757 | " y_offset = y_offset / height; \n" | ||
| 2758 | " \n" | ||
| 2759 | " cur_pix_coords = vec2(x_offset, y_offset) + tex_coord; \n" | ||
| 2760 | " \n" | ||
| 2761 | " if(get_z_dist(tex_coord, cur_pix_coords) <= threshold) { \n" | ||
| 2762 | " cur_pix_tex = glup_texture(source_tex, cur_pix_coords); \n" | ||
| 2763 | " float weight = gaussian(float(i), blur_width) / sum; \n" | ||
| 2764 | " final_pix_tex += cur_pix_tex * weight; \n" | ||
| 2765 | " } \n" | ||
| 2766 | " } \n" | ||
| 2767 | " glup_FragColor.rgb = final_pix_tex.rgb; \n" | ||
| 2768 | " } \n" | ||
| 2769 | " \n" | ||
| 2770 | " void main() { \n" | ||
| 2771 | " compute_blur(); \n" | ||
| 2772 | " } \n" | ||
| 2773 | ); | ||
| 2774 | |||
| 2775 | ✗ | GEO::GLSL::register_GLSL_include_file("fullscreen/unsharp_masking_fragment_shader.h", | |
| 2776 | "//import <fullscreen/current_profile/fragment_shader_preamble.h> \n" | ||
| 2777 | "//import <GLUP/defs.h> \n" | ||
| 2778 | " \n" | ||
| 2779 | "glup_in vec2 tex_coord; \n" | ||
| 2780 | " \n" | ||
| 2781 | "uniform sampler2D blur_texture; \n" | ||
| 2782 | "uniform sampler2D depth_texture; \n" | ||
| 2783 | " \n" | ||
| 2784 | "uniform bool do_positive_shadows; // = false; \n" | ||
| 2785 | "uniform float shadows_gamma ; // = 0.8; \n" | ||
| 2786 | "uniform float shadows_intensity ; // = 1.0; \n" | ||
| 2787 | "uniform bool shadows_halo ; // = false; \n" | ||
| 2788 | " \n" | ||
| 2789 | "float equalize_shadow(float x) { \n" | ||
| 2790 | " return pow(x, shadows_gamma); \n" | ||
| 2791 | "} \n" | ||
| 2792 | " \n" | ||
| 2793 | "float unsharp_masking(vec2 uv) { \n" | ||
| 2794 | " float orig_depth = glup_texture(depth_texture,uv).x; \n" | ||
| 2795 | " if(!shadows_halo && orig_depth == 1.0) { orig_depth = 0.5; } \n" | ||
| 2796 | " float smoothed_depth = glup_texture(blur_texture,uv).x; \n" | ||
| 2797 | " float result = smoothed_depth-orig_depth; \n" | ||
| 2798 | " if(result < 0.0) { \n" | ||
| 2799 | " result = -equalize_shadow(-result); \n" | ||
| 2800 | " } else { \n" | ||
| 2801 | " if(do_positive_shadows) { \n" | ||
| 2802 | " result = equalize_shadow(result); \n" | ||
| 2803 | " } else { \n" | ||
| 2804 | " result = 0.0; \n" | ||
| 2805 | " } \n" | ||
| 2806 | " } \n" | ||
| 2807 | " return -100.0 * shadows_intensity * result; \n" | ||
| 2808 | "} \n" | ||
| 2809 | " \n" | ||
| 2810 | "void compute_unsharp_masking() { \n" | ||
| 2811 | " float shadow = unsharp_masking(tex_coord); \n" | ||
| 2812 | " if(!do_positive_shadows || shadow > 0.0) { \n" | ||
| 2813 | " glup_FragColor.rgb = vec3(0.0, 0.0, 0.0) ; \n" | ||
| 2814 | " glup_FragColor.a = shadow; \n" | ||
| 2815 | " } else { \n" | ||
| 2816 | " glup_FragColor.rgb = vec3(1.0, 1.0, 1.0) ; \n" | ||
| 2817 | " glup_FragColor.a = -shadow; \n" | ||
| 2818 | " } \n" | ||
| 2819 | "} \n" | ||
| 2820 | " \n" | ||
| 2821 | "void main() { \n" | ||
| 2822 | " compute_unsharp_masking(); \n" | ||
| 2823 | "} \n" | ||
| 2824 | ); | ||
| 2825 | |||
| 2826 | ✗ | GEO::GLSL::register_GLSL_include_file("fullscreen/vertex_shader.h", | |
| 2827 | "//import <fullscreen/current_profile/vertex_shader_preamble.h> \n" | ||
| 2828 | "//import <GLUP/stdglup.h> \n" | ||
| 2829 | " \n" | ||
| 2830 | "glup_in vec2 vertex_in; \n" | ||
| 2831 | "glup_in vec2 tex_coord_in; \n" | ||
| 2832 | "glup_out vec2 tex_coord; \n" | ||
| 2833 | " \n" | ||
| 2834 | "void main() { \n" | ||
| 2835 | " tex_coord = tex_coord_in; \n" | ||
| 2836 | " gl_Position = vec4(vertex_in, 0.0, 1.0); \n" | ||
| 2837 | "} \n" | ||
| 2838 | ); | ||
| 2839 | |||
| 2840 | ✗ | } | |
| 2841 | } | ||
| 2842 |