33 static void scene_init( scene
*pscene
)
36 pscene
->indices
= NULL
;
37 pscene
->vertex_count
= 0;
38 pscene
->indice_count
= 0;
39 pscene
->shadowers
= NULL
;
40 pscene
->shadower_count
= 0;
41 pscene
->shadower_cap
= 0;
42 pscene
->submesh
.indice_start
= 0;
43 pscene
->submesh
.indice_count
= 0;
45 v3_fill( pscene
->bbx
[0], 999999.9f
);
46 v3_fill( pscene
->bbx
[1], -999999.9f
);
48 static int noise_ready
= 0;
53 u8
*buf
= malloc( 256*256*2 );
55 for( int i
=0; i
<256*256; i
++ )
61 for( int y
=0; y
<256; y
++ )
63 for( int x
=0; x
<256; x
++ )
65 u8
*pr
= &buf
[(y
*256+x
)*2],
66 *pg
= &buf
[(((y
+17)&0xff)*256+((x
+37)&0xff))*2+1];
71 /* TODO: This texture should be delted somewhere */
72 glGenTextures( 1, &tex_dual_noise
);
73 glBindTexture( GL_TEXTURE_2D
, tex_dual_noise
);
74 glTexImage2D( GL_TEXTURE_2D
, 0, GL_RG
, 256, 256, 0, GL_RG
,
75 GL_UNSIGNED_BYTE
, buf
);
84 /* https://www.shadertoy.com/view/4sfGzS */
85 #define SHADER_VALUE_NOISE_3D \
86 "uniform sampler2D uTexNoise;" \
88 "float noise( vec3 x )" \
90 "vec3 i = floor(x);" \
91 "vec3 f = fract(x);" \
92 "f = f*f*(3.0-2.0*f);" \
93 "vec2 uv = (i.xy+vec2(37.0,17.0)*i.z) + f.xy;" \
94 "vec2 rg = texture( uTexNoise, (uv+0.5)/256.0).yx;"\
95 "return mix( rg.x, rg.y, f.z );" \
98 "const mat3 m = mat3( 0.00, 0.80, 0.60," \
99 "-0.80, 0.36, -0.48," \
100 "-0.60, -0.48, 0.64 );" \
102 "float fractalNoise( vec3 x )" \
106 "f = 0.5000*noise( q ); q = m*q*2.01;" \
107 "f += 0.2500*noise( q ); q = m*q*2.02;" \
108 "f += 0.1250*noise( q ); q = m*q*2.03;" \
109 "f += 0.0625*noise( q ); q = m*q*2.01;" \
113 SHADER_DEFINE( shader_debug_vcol
,
115 /*Include*/ VERTEX_STANDARD_ATTRIBUTES
118 "uniform mat4x3 uMdl;"
119 "uniform float uTime;"
120 "uniform float uSwayAmt;"
127 "vec3 compute_sway( vec3 pos )"
129 "vec4 sines = vec4( sin(uTime + pos.x)*1.0,"
130 "sin(uTime*1.2 + pos.z*2.0)*1.1,"
131 "sin(uTime*2.33)*0.5,"
132 "sin(uTime*0.6 + pos.x*0.3)*1.3 );"
134 "vec3 offset = vec3( sines.x+sines.y*sines.w, 0.0, sines.x+sines.z );"
135 "return pos + offset*a_colour.r*uSwayAmt;"
140 "vec3 swaypos = compute_sway( a_co );"
141 "gl_Position = uPv * vec4(uMdl * vec4(swaypos,1.0), 1.0 );"
142 "aColour = a_colour;"
144 "aNorm = normalize(mat3(uMdl) * a_norm);"
148 "out vec4 FragColor;"
151 "uniform sampler2D uTexMain;"
152 "uniform sampler2D uTexGradients;"
154 /*Include*/ SHADER_VALUE_NOISE_3D
163 "vec4 colour = vec4(1.0,0.0,0.5,1.0);"
164 "vec4 diffuse = texture( uTexMain, aUv );"
168 "colour = vec4(aNorm * 0.5 + 0.5, 1.0);"
176 "float light = dot(aNorm, vec3(0.2,0.8,0.1));"
177 "vec3 grid3 = fract(aCo);"
179 "colour = vec4(vec3(light)*(1.0-grid3*0.3),1.0);"
183 "colour = vec4( aUv, 0.0, 1.0 );"
187 "if( diffuse.a < 0.45 ) discard;"
192 "float r1 = fractalNoise(aCo);"
193 "colour = vec4( vec3(r1), 1.0 );"
197 "if( diffuse.a < 0.2 ) discard;"
198 "float lighting = 1.0 - aColour.g*0.8;"
200 "float light1 = max(0.0,dot(-vec3(0.5,-0.8,0.25), aNorm));"
201 "float light2 = max(0.0,dot(-vec3(-0.8,0.5,-0.25), aNorm));"
202 "vec3 lt = vec3(0.2,0.2,0.2 ) + "
203 "vec3(1.0,1.0,0.9)*light1 + "
204 "vec3(0.1,0.3,0.4 )*light2;"
207 "colour = vec4(vec3(pow(lighting,1.6)*(diffuse.r*0.7+0.5)),1.0);"
208 "colour = vec4(colour.rgb*lt,1.0);"
210 "vec2 gradUV = vec2(lighting*1.9,aColour.b*0.8);"
211 "vec4 gradient_sample = texture( uTexGradients, gradUV );"
212 "colour = colour*gradient_sample;"
216 "if( diffuse.a < 0.45 ) discard;"
217 "float light = 1.0 - aColour.g;"
218 "light = pow(light,1.6)*(diffuse.r*0.7+0.5);"
219 "float r1 = fractalNoise(aCo*0.01);"
221 "vec2 gradUV = vec2(light*1.9,r1+aColour.b);"
222 "vec4 gradient_sample = texture( uTexGradients, gradUV );"
223 "colour = gradient_sample*light;"
226 "FragColor = colour;"
229 UNIFORMS({ "uPv", "uMode", "uTexMain", "uTexGradients", "uTexNoise", \
230 "uTime", "uSwayAmt", "uMdl" })
233 SHADER_DEFINE( shader_standard_lit
,
235 /*Include*/ VERTEX_STANDARD_ATTRIBUTES
238 "uniform mat4x3 uMdl;"
247 "gl_Position = uPv * vec4( uMdl * vec4(a_co,1.0), 1.0 );"
248 "aColour = a_colour;"
250 "aNorm = mat3(uMdl) * a_norm;"
254 "out vec4 FragColor;"
256 "uniform sampler2D uTexMain;"
257 "uniform vec4 uColour;"
266 "vec3 diffuse = texture( uTexMain, aUv ).rgb;"
268 "float light1 = max(0.0,dot(-vec3(0.5,-0.8,0.25), aNorm));"
269 "float light2 = max(0.0,dot(-vec3(-0.8,0.5,-0.25), aNorm));"
270 "diffuse += vec3(0.2,0.2,0.2 ) + "
271 "vec3(1.0,1.0,0.9)*light1 + "
272 "vec3(0.1,0.3,0.4 )*light2;"
274 "FragColor = vec4((diffuse*uColour.rgb),"
275 "aColour.a*uColour.a);"
278 UNIFORMS({ "uColour","uTexMain","uPv","uMdl" })
281 SHADER_DEFINE( shader_unlit
,
283 /*Include*/ VERTEX_STANDARD_ATTRIBUTES
286 "uniform mat4x3 uMdl;"
295 "gl_Position = uPv * vec4(uMdl * vec4(a_co,1.0), 1.0);"
296 "aColour = a_colour;"
298 "aNorm = mat3(uMdl) * a_norm;"
302 "out vec4 FragColor;"
304 "uniform sampler2D uTexMain;"
305 "uniform vec4 uColour;"
314 "vec3 diffuse = texture( uTexMain, aUv ).rgb;"
315 "FragColor = vec4(pow(diffuse,vec3(1.0)),1.0);"
318 UNIFORMS({ "uTexMain", "uPv", "uMdl" })
321 static void *buffer_reserve( void *buffer
, u32 count
, u32
*cap
, u32 amount
,
324 if( count
+amount
> *cap
)
326 *cap
= VG_MAX( (*cap
)*2, (*cap
)+amount
);
328 return realloc( buffer
, (*cap
) * emsize
);
335 * Append a model into the scene with a given transform
337 static void scene_add_model( scene
*pscene
, model
*mdl
, submodel
*submodel
,
338 v3f pos
, float yaw
, float scale
)
340 pscene
->verts
= buffer_reserve( pscene
->verts
, pscene
->vertex_count
,
341 &pscene
->vertex_cap
, submodel
->vertex_count
, sizeof(model_vert
) );
342 pscene
->indices
= buffer_reserve( pscene
->indices
, pscene
->indice_count
,
343 &pscene
->indice_cap
, submodel
->indice_count
, sizeof(u32
) );
345 if( submodel
->sdf_type
)
347 pscene
->shadowers
= buffer_reserve( pscene
->shadowers
,
348 pscene
->shadower_count
, &pscene
->shadower_cap
, 1,
349 sizeof( struct shadower
));
351 struct shadower
*shadower
=
352 &pscene
->shadowers
[ pscene
->shadower_count
++ ];
354 shadower
->sdf
= submodel
->sdf
;
355 shadower
->sdf_type
= submodel
->sdf_type
;
357 v2_muls( shadower
->sdf
.info
, scale
, shadower
->sdf
.info
);
358 v3_muls( shadower
->sdf
.origin
, scale
, shadower
->sdf
.origin
);
359 v3_add( pos
, shadower
->sdf
.origin
, shadower
->sdf
.origin
);
362 /* Transform and place vertices */
363 model_vert
*src_verts
= submodel_vert_data( mdl
, submodel
);
364 u32
*src_indices
= submodel_indice_data( mdl
, submodel
);
367 m4x3_identity( mtx
);
368 m4x3_translate( mtx
, pos
);
369 m4x3_rotate_y( mtx
, yaw
);
370 m4x3_scale( mtx
, scale
);
373 box_copy( submodel
->bbx
, bbxnew
);
374 m4x3_transform_aabb( mtx
, bbxnew
);
375 box_concat( pscene
->bbx
, bbxnew
);
378 m4x3_to_3x3( mtx
, rotation
);
380 float rand_hue
= vg_randf();
382 for( u32 i
=0; i
<submodel
->vertex_count
; i
++ )
384 model_vert
*pvert
= &pscene
->verts
[ pscene
->vertex_count
+i
],
385 *src
= &src_verts
[ i
];
387 m4x3_mulv( mtx
, src
->co
, pvert
->co
);
388 m3x3_mulv( rotation
, src
->norm
, pvert
->norm
);
390 v4_copy( src
->colour
, pvert
->colour
);
391 v2_copy( src
->uv
, pvert
->uv
);
393 float rel_y
= src
->co
[1] / submodel
->bbx
[1][1];
394 pvert
->colour
[0] = rel_y
;
395 pvert
->colour
[2] = rand_hue
;
398 for( u32 i
=0; i
<submodel
->indice_count
; i
++ )
400 u32
*pidx
= &pscene
->indices
[ pscene
->indice_count
+i
];
401 *pidx
= src_indices
[i
] + pscene
->vertex_count
;
404 pscene
->vertex_count
+= submodel
->vertex_count
;
405 pscene
->indice_count
+= submodel
->indice_count
;
408 static void scene_copy_slice( scene
*pscene
, submodel
*sm
)
410 sm
->indice_start
= pscene
->submesh
.indice_start
;
411 sm
->indice_count
= pscene
->indice_count
- sm
->indice_start
;
413 pscene
->submesh
.indice_start
= pscene
->indice_count
;
416 static void scene_shadow_sphere( scene
*pscene
, v3f sphere
,
417 v4f params
, v3f lightdir
)
419 for( int i
=0; i
<pscene
->vertex_count
; i
++ )
421 model_vert
*vert
= &pscene
->verts
[i
];
424 v3_sub( sphere
, vert
->co
, delta
);
426 float d
= v3_dot( lightdir
, delta
);
429 v3_muls( lightdir
, d
, closest
);
430 float dist
= v3_dist( closest
, delta
),
431 shading
= vg_maxf( dist
- params
[0], 0.0f
);
433 shading
= vg_minf( shading
* params
[1], 1.0f
);
434 vert
->colour
[1] *= shading
;
438 static void scene_shadow_gradient( scene
*pscene
, int comp
,
439 float start
, float length
)
441 float scale
= 1.0f
/ length
;
443 for( int i
=0; i
<pscene
->vertex_count
; i
++ )
445 model_vert
*vert
= &pscene
->verts
[i
];
446 float shading
= start
+ vert
->co
[comp
] * scale
;
448 vert
->colour
[1] = shading
;
453 static int sample_scene_height( scene
*pscene
, v3f pos
, v3f norm
)
455 for( int i
=0; i
<pscene
->indice_count
/3; i
++ )
457 u32
*tri
= &pscene
->indices
[i
*3];
459 float *pA
= pscene
->verts
[tri
[0]].co
,
460 *pB
= pscene
->verts
[tri
[1]].co
,
461 *pC
= pscene
->verts
[tri
[2]].co
;
464 if( triangle_raycast( pA
, pB
, pC
, pos
, &height
))
471 v3_sub( pA
, pB
, v0
);
472 v3_sub( pC
, pB
, v1
);
473 v3_cross( v1
, v0
, norm
);
474 v3_normalize( norm
);
483 static void sample_scene_normal( scene
*pscene
, v3f pos
, v3f normal
)
485 for( int i
=0; i
<pscene
->indice_count
/3; i
++ )
487 u32
*tri
= &pscene
->indices
[i
*3];
490 if( triangle_raycast(
491 pscene
->verts
[ tri
[0] ].co
,
492 pscene
->verts
[ tri
[1] ].co
,
493 pscene
->verts
[ tri
[2] ].co
, pos
, &height
))
497 v3_sub( pscene
->verts
[ tri
[1] ].co
,
498 pscene
->verts
[ tri
[0] ].co
,
501 v3_sub( pscene
->verts
[ tri
[2] ].co
,
502 pscene
->verts
[ tri
[0] ].co
,
505 v3_cross( v0
, v1
, normal
);
506 v3_normalize( normal
);
517 * Experimental SDF based shadows
519 * https://iquilezles.org/articles/distfunctions/
521 static float sd_cone( v3f co
, sdf_primative
*prim
)
523 float bound
= prim
->info
[1]*1.75f
;
524 if( v3_dist2( prim
->origin
, co
) > bound
*bound
)
528 v3_sub( co
, prim
->origin
, p
);
530 float h
= prim
->info
[1];
531 v2f c
= { prim
->info
[2], prim
->info
[3] };
534 v2_muls( (v2f
){ c
[0]/c
[1], -1.0f
}, h
, q
);
536 w
[0] = v2_length( (v2f
){ p
[0], p
[2] } );
539 v2_muladds( w
, q
, -vg_clampf( v2_dot(w
,q
)/v2_dot(q
,q
), 0.0f
, 1.0f
), a
);
540 v2_muladd( w
, q
, (v2f
){ vg_clampf( w
[0]/q
[0], 0.0f
, 1.0f
), 1.0f
}, b
);
542 float k
= vg_signf( q
[1] ),
543 d
= vg_minf( v2_dot( a
,a
), v2_dot( b
,b
) ),
544 s
= vg_maxf( k
*(w
[0]*q
[1]-w
[1]*q
[0]), k
*(w
[1]-q
[1]) );
546 return sqrtf(d
)*vg_signf(s
);
549 #define CACHE_AMBIENT_SHAPES
551 static float scene_ambient_sample( scene
*pscene
, v3f pos
, v3f dir
)
555 #ifdef CACHE_AMBIENT_SHAPES
556 static struct shadower
*local_shadowers
[32];
557 static int local_shadower_count
= 0;
558 static v3f local_shadower_last
= { -99999.9f
, -999999.9f
, -9999999.9f
};
560 if( v3_dist2( pos
, local_shadower_last
) > 10.0f
*10.0f
)
562 local_shadower_count
= 0;
563 v3_copy( pos
, local_shadower_last
);
565 for( int k
=0; k
<pscene
->shadower_count
; k
++ )
567 struct shadower
*shadower
= &pscene
->shadowers
[k
];
569 if( sd_cone( pos
, &shadower
->sdf
) <= 20.0f
)
571 local_shadowers
[ local_shadower_count
++ ] = shadower
;
572 if( local_shadower_count
== vg_list_size( local_shadowers
) )
579 for( int j
=0; j
<5; j
++ )
582 v3_muladds( pos
, dir
, 1.5f
*(float)j
, tracepos
);
584 float mindist
= 99999.9f
;
586 #ifndef CACHE_AMBIENT_SHAPES
588 for( int k
=0; k
<pscene
->shadower_count
; k
++ ){
589 struct shadower
*shadower
= &pscene
->shadowers
[k
];
592 for( int k
=0; k
<local_shadower_count
; k
++ ){
593 struct shadower
*shadower
= local_shadowers
[k
];
596 float dist
= vg_maxf( 0.0f
, sd_cone( tracepos
, &shadower
->sdf
));
597 mindist
= vg_minf( mindist
, dist
);
601 accum
+= vg_clampf( 1.0f
- mindist
, 0.0f
, 1.0f
)*0.2f
;
608 #define JUST_DO_EVERY_VERT
610 static void scene_compute_occlusion( scene
*pscene
)
612 v3f sundir
= { 0.2f
, 0.9f
, 0.2f
};
613 v3_normalize( sundir
);
615 /* TODO: Make this sample grid be dynamically required.
617 * 1. Only resample the light grid (1x1x1), when a vertex is outside the
620 * 2. Reorder all vertices so that each group of vertices that fit in a
621 * cube are next to eachother in the buffer. This will save cache
624 * for the sorting algorithm, i think we can already assume that *most
625 * vertices will be quite close to eachother. so instead of doing an
626 * exhaustive search we can reorder 1k chunks at a time.
630 v3_sub( pscene
->bbx
[1], pscene
->bbx
[0], sample_area
);
631 v3_ceil( sample_area
, sample_area
);
632 int ax
= sample_area
[0],
637 float *samplegrid
= malloc( ax
*ay
*az
* sizeof(float) );
639 for( int x
=0; x
<ax
; x
++ ){
640 for( int y
=0; y
<ay
; y
++ ){
641 for( int z
=0; z
<az
; z
++ )
643 v3f sample_pos
= { x
,y
,z
};
644 v3_add( pscene
->bbx
[0], sample_pos
, sample_pos
);
645 float accum
= scene_ambient_sample( pscene
, sample_pos
, sundir
);
647 samplegrid
[x
+ y
*ax
+ z
*ax
*ay
] = accum
;
650 v3i cube_pos
= { -999999, -999999, -999999 };
651 int cube_resamples
= 0, hits
= 0, misses
= 0;
653 float s0
=0.0f
,s1
=0.0f
,s2
=0.0f
,s3
=0.0f
,s4
=0.0f
,s5
=0.0f
,s6
=0.0f
,s7
=0.0f
;
656 for( int i
=0; i
<pscene
->vertex_count
; i
++ )
658 model_vert
*vert
= &pscene
->verts
[i
];
662 v3_sub( vert
->co
, pscene
->bbx
[0], q
);
664 v3_copy( vert
->co
, q
);
674 #ifndef JUST_DO_EVERY_VERT
684 s0
= samplegrid
[ x
+ y
*ax
+ z
*ax
*ay
],
685 s1
= samplegrid
[(x
+1) + y
*ax
+ z
*ax
*ay
],
686 s2
= samplegrid
[ x
+ (y
+1)*ax
+ z
*ax
*ay
],
687 s3
= samplegrid
[(x
+1) + (y
+1)*ax
+ z
*ax
*ay
],
688 s4
= samplegrid
[ x
+ y
*ax
+ (z
+1)*ax
*ay
],
689 s5
= samplegrid
[(x
+1) + y
*ax
+ (z
+1)*ax
*ay
],
690 s6
= samplegrid
[ x
+ (y
+1)*ax
+ (z
+1)*ax
*ay
],
691 s7
= samplegrid
[(x
+1) + (y
+1)*ax
+ (z
+1)*ax
*ay
],
693 if( x
!=cube_pos
[0] || y
!=cube_pos
[1] || z
!=cube_pos
[2] )
699 s0
= scene_ambient_sample( pscene
, (v3f
){ x
,y
,z
}, sundir
);
700 s1
= scene_ambient_sample( pscene
, (v3f
){ x
+1,y
,z
}, sundir
);
701 s2
= scene_ambient_sample( pscene
, (v3f
){ x
,y
+1,z
}, sundir
);
702 s3
= scene_ambient_sample( pscene
, (v3f
){ x
+1,y
+1,z
}, sundir
);
703 s4
= scene_ambient_sample( pscene
, (v3f
){ x
,y
,z
+1 }, sundir
);
704 s5
= scene_ambient_sample( pscene
, (v3f
){ x
+1,y
,z
+1 }, sundir
);
705 s6
= scene_ambient_sample( pscene
, (v3f
){ x
,y
+1,z
+1 }, sundir
);
706 s7
= scene_ambient_sample( pscene
, (v3f
){ x
+1,y
+1,z
+1 }, sundir
);
717 s0_s1
= vg_lerpf( s0
, s1
, q
[0] ),
718 s2_s3
= vg_lerpf( s2
, s3
, q
[0] ),
719 s4_s5
= vg_lerpf( s4
, s5
, q
[0] ),
720 s6_s7
= vg_lerpf( s6
, s7
, q
[0] ),
722 s0s1_s2s3
= vg_lerpf( s0_s1
, s2_s3
, q
[1] ),
723 s4s5_s6s7
= vg_lerpf( s4_s5
, s6_s7
, q
[1] ),
724 s0s1s2s3_s4s5s6s7
= vg_lerpf( s0s1_s2s3
, s4s5_s6s7
, q
[2] );
726 vert
->colour
[1] = s0s1s2s3_s4s5s6s7
;
728 vert
->colour
[1] = scene_ambient_sample( pscene
, vert
->co
, sundir
);
733 int cube_resamples
= -1, misses
= 0, hits
= 0;
736 int static_samples
= ax
*ay
*az
,
737 vertex_samples
= pscene
->vertex_count
;
739 if( cube_resamples
< static_samples
)
740 vg_success( "Walking cube beat static grid (%d<%d. %d)!\n",
741 cube_resamples
, static_samples
, vertex_samples
);
743 vg_warn( "Walking cube was worse than static grid (%d<%d. %d).\n",
744 cube_resamples
, static_samples
, vertex_samples
);
746 vg_info( "Hits; %d, misses: %d\n", hits
, misses
);
754 for( int i
=0; i
<pscene
->vertex_count
; i
++ )
756 model_vert
*vert
= &pscene
->verts
[i
];
759 for( int j
=0; j
<5; j
++ )
762 v3_copy( vert
->co
, tracepos
);
763 v3_muladds( tracepos
, sundir
, 1.5f
*(float)j
, tracepos
);
765 float mindist
= 99999.9f
;
767 for( int k
=0; k
<pscene
->shadower_count
; k
++ )
769 struct shadower
*shadower
= &pscene
->shadowers
[k
];
770 float dist
= vg_maxf( 0.0f
, sd_cone( tracepos
, &shadower
->sdf
));
771 mindist
= vg_minf( mindist
, dist
);
774 accum
+= vg_clampf( 1.0f
- mindist
, 0.0f
, 1.0f
)*0.2f
;
777 vert
->colour
[1] = vg_minf( accum
, 1.0f
);
781 static void scene_upload( scene
*pscene
)
783 mesh_upload( &pscene
->mesh
,
784 pscene
->verts
, pscene
->vertex_count
,
785 pscene
->indices
, pscene
->indice_count
);
787 vg_info( "Scene upload\n" );
788 vg_info( " indices:%u\n", pscene
->indice_count
);
789 vg_info( " verts:%u\n", pscene
->vertex_count
);
792 float scene_tree_sway
= 0.1f
;
794 static void scene_foliage_shader_use(void)
796 SHADER_USE( shader_debug_vcol
);
798 glUniformMatrix4fv( SHADER_UNIFORM( shader_debug_vcol
, "uPv" ),
799 1, GL_FALSE
, (float *)vg_pv
);
801 glUniform1i( SHADER_UNIFORM( shader_debug_vcol
, "uMode" ), debugview
);
802 glUniform1i( SHADER_UNIFORM( shader_debug_vcol
, "uTexMain" ), 0 );
804 glUniform1i( SHADER_UNIFORM( shader_debug_vcol
, "uTexGradients" ), 1 );
805 vg_tex2d_bind( &tex_gradients
, 1 );
807 glUniform1i( SHADER_UNIFORM( shader_debug_vcol
, "uTexNoise" ), 2 );
808 glActiveTexture( GL_TEXTURE2
);
809 glBindTexture( GL_TEXTURE_2D
, tex_dual_noise
);
811 glUniform1f( SHADER_UNIFORM( shader_debug_vcol
, "uTime" ), vg_time
);
812 glUniform1f( SHADER_UNIFORM( shader_debug_vcol
, "uSwayAmt" ),
816 static void scene_bind( scene
*pscene
)
818 mesh_bind( &pscene
->mesh
);
821 static void scene_draw( scene
*pscene
)
823 mesh_drawn( 0, pscene
->indice_count
);
826 static void scene_debugsdf( scene
*pscene
)
828 for( int i
=0; i
<pscene
->shadower_count
; i
++ )
830 struct shadower
*shadower
= &pscene
->shadowers
[i
];
833 v3_copy( shadower
->sdf
.origin
, base
);
834 base
[1] -= shadower
->sdf
.info
[1];
835 v3_copy( base
, side
);
836 side
[0] += shadower
->sdf
.info
[0];
838 vg_line2( shadower
->sdf
.origin
, base
, 0xff00ff00, 0xff0000ff );
839 vg_line2( side
, base
, 0xff00ff00, 0xff0000ff );
840 vg_line( side
, shadower
->sdf
.origin
, 0xff00ff00 );
843 v3f p0
= { pscene
->bbx
[0][0], pscene
->bbx
[0][1], pscene
->bbx
[0][2] },
844 p1
= { pscene
->bbx
[0][0], pscene
->bbx
[1][1], pscene
->bbx
[0][2] },
845 p2
= { pscene
->bbx
[1][0], pscene
->bbx
[1][1], pscene
->bbx
[0][2] },
846 p3
= { pscene
->bbx
[1][0], pscene
->bbx
[0][1], pscene
->bbx
[0][2] },
848 p4
= { pscene
->bbx
[0][0], pscene
->bbx
[0][1], pscene
->bbx
[1][2] },
849 p5
= { pscene
->bbx
[0][0], pscene
->bbx
[1][1], pscene
->bbx
[1][2] },
850 p6
= { pscene
->bbx
[1][0], pscene
->bbx
[1][1], pscene
->bbx
[1][2] },
851 p7
= { pscene
->bbx
[1][0], pscene
->bbx
[0][1], pscene
->bbx
[1][2] };
853 u32 col
= 0xffff00c8;
854 vg_line( p0
, p1
, col
);
855 vg_line( p1
, p2
, col
);
856 vg_line( p2
, p3
, col
);
857 vg_line( p3
, p0
, col
);
859 vg_line( p4
, p5
, col
);
860 vg_line( p5
, p6
, col
);
861 vg_line( p6
, p7
, col
);
862 vg_line( p7
, p4
, col
);
864 vg_line( p0
, p4
, col
);
865 vg_line( p1
, p5
, col
);
866 vg_line( p2
, p6
, col
);
867 vg_line( p3
, p7
, col
);
870 static void scene_register(void)
872 SHADER_INIT( shader_debug_vcol
);
873 SHADER_INIT( shader_standard_lit
);
874 SHADER_INIT( shader_unlit
);