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 #define VERTEX_STANDARD_ATTRIBUTES \
114 "layout (location=0) in vec3 a_co;" \
115 "layout (location=1) in vec3 a_norm;" \
116 "layout (location=2) in vec4 a_colour;" \
117 "layout (location=3) in vec2 a_uv;"
119 SHADER_DEFINE( shader_debug_vcol
,
121 /*Include*/ VERTEX_STANDARD_ATTRIBUTES
125 "uniform float uTime;"
126 "uniform float uSwayAmt;"
133 "vec3 compute_sway( vec3 pos )"
135 "vec4 sines = vec4( sin(uTime + pos.x)*1.0,"
136 "sin(uTime*1.2 + pos.z*2.0)*1.1,"
137 "sin(uTime*2.33)*0.5,"
138 "sin(uTime*0.6 + pos.x*0.3)*1.3 );"
140 "vec3 offset = vec3( sines.x+sines.y*sines.w, 0.0, sines.x+sines.z );"
141 "return pos + offset*a_colour.r*uSwayAmt;"
146 "vec3 swaypos = compute_sway( a_co );"
147 "gl_Position = uPv * uMdl * vec4( swaypos, 1.0 );"
148 "aColour = a_colour;"
150 "aNorm = normalize(mat3(uMdl) * a_norm);"
154 "out vec4 FragColor;"
157 "uniform sampler2D uTexMain;"
158 "uniform sampler2D uTexGradients;"
160 /*Include*/ SHADER_VALUE_NOISE_3D
169 "vec4 colour = vec4(1.0,0.0,0.5,1.0);"
170 "vec4 diffuse = texture( uTexMain, aUv );"
174 "colour = vec4(aNorm * 0.5 + 0.5, 1.0);"
182 "float light = dot(aNorm, vec3(0.2,0.8,0.1));"
183 "vec3 grid3 = fract(aCo);"
185 "colour = vec4(vec3(light)*(1.0-grid3*0.3),1.0);"
189 "colour = vec4( aUv, 0.0, 1.0 );"
193 "if( diffuse.a < 0.45 ) discard;"
198 "float r1 = fractalNoise(aCo);"
199 "colour = vec4( vec3(r1), 1.0 );"
203 "if( diffuse.a < 0.2 ) discard;"
204 "float lighting = 1.0 - aColour.g*0.8;"
206 "float light1 = max(0.0,dot(-vec3(0.5,-0.8,0.25), aNorm));"
207 "float light2 = max(0.0,dot(-vec3(-0.8,0.5,-0.25), aNorm));"
208 "vec3 lt = vec3(0.2,0.2,0.2 ) + "
209 "vec3(1.0,1.0,0.9)*light1 + "
210 "vec3(0.1,0.3,0.4 )*light2;"
213 "colour = vec4(vec3(pow(lighting,1.6)*(diffuse.r*0.7+0.5)),1.0);"
214 "colour = vec4(colour.rgb*lt,1.0);"
216 "vec2 gradUV = vec2(lighting*1.9,aColour.b*0.8);"
217 "vec4 gradient_sample = texture( uTexGradients, gradUV );"
218 "colour = colour*gradient_sample;"
222 "if( diffuse.a < 0.45 ) discard;"
223 "float light = 1.0 - aColour.g;"
224 "light = pow(light,1.6)*(diffuse.r*0.7+0.5);"
225 "float r1 = fractalNoise(aCo*0.01);"
227 "vec2 gradUV = vec2(light*1.9,r1+aColour.b);"
228 "vec4 gradient_sample = texture( uTexGradients, gradUV );"
229 "colour = gradient_sample*light;"
232 "FragColor = colour;"
235 UNIFORMS({ "uPv", "uMode", "uTexMain", "uTexGradients", "uTexNoise", \
236 "uTime", "uSwayAmt", "uMdl" })
239 SHADER_DEFINE( shader_standard_lit
,
241 /*Include*/ VERTEX_STANDARD_ATTRIBUTES
253 "gl_Position = uPv * uMdl * vec4( a_co, 1.0 );"
254 "aColour = a_colour;"
256 "aNorm = mat3(uMdl) * a_norm;"
260 "out vec4 FragColor;"
262 "uniform sampler2D uTexMain;"
263 "uniform vec4 uColour;"
272 "vec3 diffuse = texture( uTexMain, aUv ).rgb;"
274 "float light1 = max(0.0,dot(-vec3(0.5,-0.8,0.25), aNorm));"
275 "float light2 = max(0.0,dot(-vec3(-0.8,0.5,-0.25), aNorm));"
276 "diffuse += vec3(0.2,0.2,0.2 ) + "
277 "vec3(1.0,1.0,0.9)*light1 + "
278 "vec3(0.1,0.3,0.4 )*light2;"
280 "FragColor = vec4((diffuse*uColour.rgb),"
281 "aColour.a*uColour.a);"
284 UNIFORMS({ "uColour","uTexMain","uPv","uMdl" })
287 SHADER_DEFINE( shader_unlit
,
289 /*Include*/ VERTEX_STANDARD_ATTRIBUTES
301 "gl_Position = uPv * uMdl * vec4( a_co, 1.0 );"
302 "aColour = a_colour;"
304 "aNorm = mat3(uMdl) * a_norm;"
308 "out vec4 FragColor;"
310 "uniform sampler2D uTexMain;"
311 "uniform vec4 uColour;"
320 "vec3 diffuse = texture( uTexMain, aUv ).rgb;"
321 "FragColor = vec4(pow(diffuse,vec3(1.0)),1.0);"
324 UNIFORMS({ "uTexMain", "uPv", "uMdl" })
327 static void *buffer_reserve( void *buffer
, u32 count
, u32
*cap
, u32 amount
,
330 if( count
+amount
> *cap
)
332 *cap
= VG_MAX( (*cap
)*2, (*cap
)+amount
);
334 return realloc( buffer
, (*cap
) * emsize
);
341 * Append a model into the scene with a given transform
343 static void scene_add_model( scene
*pscene
, model
*mdl
, submodel
*submodel
,
344 v3f pos
, float yaw
, float scale
)
346 pscene
->verts
= buffer_reserve( pscene
->verts
, pscene
->vertex_count
,
347 &pscene
->vertex_cap
, submodel
->vertex_count
, sizeof(model_vert
) );
348 pscene
->indices
= buffer_reserve( pscene
->indices
, pscene
->indice_count
,
349 &pscene
->indice_cap
, submodel
->indice_count
, sizeof(u32
) );
351 if( submodel
->sdf_type
)
353 pscene
->shadowers
= buffer_reserve( pscene
->shadowers
,
354 pscene
->shadower_count
, &pscene
->shadower_cap
, 1,
355 sizeof( struct shadower
));
357 struct shadower
*shadower
=
358 &pscene
->shadowers
[ pscene
->shadower_count
++ ];
360 shadower
->sdf
= submodel
->sdf
;
361 shadower
->sdf_type
= submodel
->sdf_type
;
363 v2_muls( shadower
->sdf
.info
, scale
, shadower
->sdf
.info
);
364 v3_muls( shadower
->sdf
.origin
, scale
, shadower
->sdf
.origin
);
365 v3_add( pos
, shadower
->sdf
.origin
, shadower
->sdf
.origin
);
368 /* Transform and place vertices */
369 model_vert
*src_verts
= submodel_vert_data( mdl
, submodel
);
370 u32
*src_indices
= submodel_indice_data( mdl
, submodel
);
373 m4x3_identity( mtx
);
374 m4x3_translate( mtx
, pos
);
375 m4x3_rotate_y( mtx
, yaw
);
376 m4x3_scale( mtx
, scale
);
379 box_copy( submodel
->bbx
, bbxnew
);
380 m4x3_transform_aabb( mtx
, bbxnew
);
381 box_concat( pscene
->bbx
, bbxnew
);
384 m4x3_to_3x3( mtx
, rotation
);
386 float rand_hue
= vg_randf();
388 for( u32 i
=0; i
<submodel
->vertex_count
; i
++ )
390 model_vert
*pvert
= &pscene
->verts
[ pscene
->vertex_count
+i
],
391 *src
= &src_verts
[ i
];
393 m4x3_mulv( mtx
, src
->co
, pvert
->co
);
394 m3x3_mulv( rotation
, src
->norm
, pvert
->norm
);
396 v4_copy( src
->colour
, pvert
->colour
);
397 v2_copy( src
->uv
, pvert
->uv
);
399 float rel_y
= src
->co
[1] / submodel
->bbx
[1][1];
400 pvert
->colour
[0] = rel_y
;
401 pvert
->colour
[2] = rand_hue
;
404 for( u32 i
=0; i
<submodel
->indice_count
; i
++ )
406 u32
*pidx
= &pscene
->indices
[ pscene
->indice_count
+i
];
407 *pidx
= src_indices
[i
] + pscene
->vertex_count
;
410 pscene
->vertex_count
+= submodel
->vertex_count
;
411 pscene
->indice_count
+= submodel
->indice_count
;
414 static void scene_copy_slice( scene
*pscene
, submodel
*sm
)
416 sm
->indice_start
= pscene
->submesh
.indice_start
;
417 sm
->indice_count
= pscene
->indice_count
- sm
->indice_start
;
419 pscene
->submesh
.indice_start
= pscene
->indice_count
;
422 static void scene_shadow_sphere( scene
*pscene
, v3f sphere
,
423 v4f params
, v3f lightdir
)
425 for( int i
=0; i
<pscene
->vertex_count
; i
++ )
427 model_vert
*vert
= &pscene
->verts
[i
];
430 v3_sub( sphere
, vert
->co
, delta
);
432 float d
= v3_dot( lightdir
, delta
);
435 v3_muls( lightdir
, d
, closest
);
436 float dist
= v3_dist( closest
, delta
),
437 shading
= vg_maxf( dist
- params
[0], 0.0f
);
439 shading
= vg_minf( shading
* params
[1], 1.0f
);
440 vert
->colour
[1] *= shading
;
444 static void scene_shadow_gradient( scene
*pscene
, int comp
,
445 float start
, float length
)
447 float scale
= 1.0f
/ length
;
449 for( int i
=0; i
<pscene
->vertex_count
; i
++ )
451 model_vert
*vert
= &pscene
->verts
[i
];
452 float shading
= start
+ vert
->co
[comp
] * scale
;
454 vert
->colour
[1] = shading
;
459 static int sample_scene_height( scene
*pscene
, v3f pos
, v3f norm
)
461 for( int i
=0; i
<pscene
->indice_count
/3; i
++ )
463 u32
*tri
= &pscene
->indices
[i
*3];
465 float *pA
= pscene
->verts
[tri
[0]].co
,
466 *pB
= pscene
->verts
[tri
[1]].co
,
467 *pC
= pscene
->verts
[tri
[2]].co
;
470 if( triangle_raycast( pA
, pB
, pC
, pos
, &height
))
477 v3_sub( pA
, pB
, v0
);
478 v3_sub( pC
, pB
, v1
);
479 v3_cross( v1
, v0
, norm
);
480 v3_normalize( norm
);
489 static void sample_scene_normal( scene
*pscene
, v3f pos
, v3f normal
)
491 for( int i
=0; i
<pscene
->indice_count
/3; i
++ )
493 u32
*tri
= &pscene
->indices
[i
*3];
496 if( triangle_raycast(
497 pscene
->verts
[ tri
[0] ].co
,
498 pscene
->verts
[ tri
[1] ].co
,
499 pscene
->verts
[ tri
[2] ].co
, pos
, &height
))
503 v3_sub( pscene
->verts
[ tri
[1] ].co
,
504 pscene
->verts
[ tri
[0] ].co
,
507 v3_sub( pscene
->verts
[ tri
[2] ].co
,
508 pscene
->verts
[ tri
[0] ].co
,
511 v3_cross( v0
, v1
, normal
);
512 v3_normalize( normal
);
523 * Experimental SDF based shadows
525 * https://iquilezles.org/articles/distfunctions/
527 static float sd_cone( v3f co
, sdf_primative
*prim
)
529 float bound
= prim
->info
[1]*1.75f
;
530 if( v3_dist2( prim
->origin
, co
) > bound
*bound
)
534 v3_sub( co
, prim
->origin
, p
);
536 float h
= prim
->info
[1];
537 v2f c
= { prim
->info
[2], prim
->info
[3] };
540 v2_muls( (v2f
){ c
[0]/c
[1], -1.0f
}, h
, q
);
542 w
[0] = v2_length( (v2f
){ p
[0], p
[2] } );
545 v2_muladds( w
, q
, -vg_clampf( v2_dot(w
,q
)/v2_dot(q
,q
), 0.0f
, 1.0f
), a
);
546 v2_muladd( w
, q
, (v2f
){ vg_clampf( w
[0]/q
[0], 0.0f
, 1.0f
), 1.0f
}, b
);
548 float k
= vg_signf( q
[1] ),
549 d
= vg_minf( v2_dot( a
,a
), v2_dot( b
,b
) ),
550 s
= vg_maxf( k
*(w
[0]*q
[1]-w
[1]*q
[0]), k
*(w
[1]-q
[1]) );
552 return sqrtf(d
)*vg_signf(s
);
555 #define CACHE_AMBIENT_SHAPES
557 static float scene_ambient_sample( scene
*pscene
, v3f pos
, v3f dir
)
561 #ifdef CACHE_AMBIENT_SHAPES
562 static struct shadower
*local_shadowers
[32];
563 static int local_shadower_count
= 0;
564 static v3f local_shadower_last
= { -99999.9f
, -999999.9f
, -9999999.9f
};
566 if( v3_dist2( pos
, local_shadower_last
) > 10.0f
*10.0f
)
568 local_shadower_count
= 0;
569 v3_copy( pos
, local_shadower_last
);
571 for( int k
=0; k
<pscene
->shadower_count
; k
++ )
573 struct shadower
*shadower
= &pscene
->shadowers
[k
];
575 if( sd_cone( pos
, &shadower
->sdf
) <= 20.0f
)
577 local_shadowers
[ local_shadower_count
++ ] = shadower
;
578 if( local_shadower_count
== vg_list_size( local_shadowers
) )
585 for( int j
=0; j
<5; j
++ )
588 v3_muladds( pos
, dir
, 1.5f
*(float)j
, tracepos
);
590 float mindist
= 99999.9f
;
592 #ifndef CACHE_AMBIENT_SHAPES
594 for( int k
=0; k
<pscene
->shadower_count
; k
++ ){
595 struct shadower
*shadower
= &pscene
->shadowers
[k
];
598 for( int k
=0; k
<local_shadower_count
; k
++ ){
599 struct shadower
*shadower
= local_shadowers
[k
];
602 float dist
= vg_maxf( 0.0f
, sd_cone( tracepos
, &shadower
->sdf
));
603 mindist
= vg_minf( mindist
, dist
);
607 accum
+= vg_clampf( 1.0f
- mindist
, 0.0f
, 1.0f
)*0.2f
;
614 #define JUST_DO_EVERY_VERT
616 static void scene_compute_occlusion( scene
*pscene
)
618 v3f sundir
= { 0.2f
, 0.9f
, 0.2f
};
619 v3_normalize( sundir
);
621 /* TODO: Make this sample grid be dynamically required.
623 * 1. Only resample the light grid (1x1x1), when a vertex is outside the
626 * 2. Reorder all vertices so that each group of vertices that fit in a
627 * cube are next to eachother in the buffer. This will save cache
630 * for the sorting algorithm, i think we can already assume that *most
631 * vertices will be quite close to eachother. so instead of doing an
632 * exhaustive search we can reorder 1k chunks at a time.
636 v3_sub( pscene
->bbx
[1], pscene
->bbx
[0], sample_area
);
637 v3_ceil( sample_area
, sample_area
);
638 int ax
= sample_area
[0],
643 float *samplegrid
= malloc( ax
*ay
*az
* sizeof(float) );
645 for( int x
=0; x
<ax
; x
++ ){
646 for( int y
=0; y
<ay
; y
++ ){
647 for( int z
=0; z
<az
; z
++ )
649 v3f sample_pos
= { x
,y
,z
};
650 v3_add( pscene
->bbx
[0], sample_pos
, sample_pos
);
651 float accum
= scene_ambient_sample( pscene
, sample_pos
, sundir
);
653 samplegrid
[x
+ y
*ax
+ z
*ax
*ay
] = accum
;
656 v3i cube_pos
= { -999999, -999999, -999999 };
657 int cube_resamples
= 0, hits
= 0, misses
= 0;
659 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
;
662 for( int i
=0; i
<pscene
->vertex_count
; i
++ )
664 model_vert
*vert
= &pscene
->verts
[i
];
668 v3_sub( vert
->co
, pscene
->bbx
[0], q
);
670 v3_copy( vert
->co
, q
);
680 #ifndef JUST_DO_EVERY_VERT
690 s0
= samplegrid
[ x
+ y
*ax
+ z
*ax
*ay
],
691 s1
= samplegrid
[(x
+1) + y
*ax
+ z
*ax
*ay
],
692 s2
= samplegrid
[ x
+ (y
+1)*ax
+ z
*ax
*ay
],
693 s3
= samplegrid
[(x
+1) + (y
+1)*ax
+ z
*ax
*ay
],
694 s4
= samplegrid
[ x
+ y
*ax
+ (z
+1)*ax
*ay
],
695 s5
= samplegrid
[(x
+1) + y
*ax
+ (z
+1)*ax
*ay
],
696 s6
= samplegrid
[ x
+ (y
+1)*ax
+ (z
+1)*ax
*ay
],
697 s7
= samplegrid
[(x
+1) + (y
+1)*ax
+ (z
+1)*ax
*ay
],
699 if( x
!=cube_pos
[0] || y
!=cube_pos
[1] || z
!=cube_pos
[2] )
705 s0
= scene_ambient_sample( pscene
, (v3f
){ x
,y
,z
}, sundir
);
706 s1
= scene_ambient_sample( pscene
, (v3f
){ x
+1,y
,z
}, sundir
);
707 s2
= scene_ambient_sample( pscene
, (v3f
){ x
,y
+1,z
}, sundir
);
708 s3
= scene_ambient_sample( pscene
, (v3f
){ x
+1,y
+1,z
}, sundir
);
709 s4
= scene_ambient_sample( pscene
, (v3f
){ x
,y
,z
+1 }, sundir
);
710 s5
= scene_ambient_sample( pscene
, (v3f
){ x
+1,y
,z
+1 }, sundir
);
711 s6
= scene_ambient_sample( pscene
, (v3f
){ x
,y
+1,z
+1 }, sundir
);
712 s7
= scene_ambient_sample( pscene
, (v3f
){ x
+1,y
+1,z
+1 }, sundir
);
723 s0_s1
= vg_lerpf( s0
, s1
, q
[0] ),
724 s2_s3
= vg_lerpf( s2
, s3
, q
[0] ),
725 s4_s5
= vg_lerpf( s4
, s5
, q
[0] ),
726 s6_s7
= vg_lerpf( s6
, s7
, q
[0] ),
728 s0s1_s2s3
= vg_lerpf( s0_s1
, s2_s3
, q
[1] ),
729 s4s5_s6s7
= vg_lerpf( s4_s5
, s6_s7
, q
[1] ),
730 s0s1s2s3_s4s5s6s7
= vg_lerpf( s0s1_s2s3
, s4s5_s6s7
, q
[2] );
732 vert
->colour
[1] = s0s1s2s3_s4s5s6s7
;
734 vert
->colour
[1] = scene_ambient_sample( pscene
, vert
->co
, sundir
);
739 int cube_resamples
= -1, misses
= 0, hits
= 0;
742 int static_samples
= ax
*ay
*az
,
743 vertex_samples
= pscene
->vertex_count
;
745 if( cube_resamples
< static_samples
)
746 vg_success( "Walking cube beat static grid (%d<%d. %d)!\n",
747 cube_resamples
, static_samples
, vertex_samples
);
749 vg_warn( "Walking cube was worse than static grid (%d<%d. %d).\n",
750 cube_resamples
, static_samples
, vertex_samples
);
752 vg_info( "Hits; %d, misses: %d\n", hits
, misses
);
760 for( int i
=0; i
<pscene
->vertex_count
; i
++ )
762 model_vert
*vert
= &pscene
->verts
[i
];
765 for( int j
=0; j
<5; j
++ )
768 v3_copy( vert
->co
, tracepos
);
769 v3_muladds( tracepos
, sundir
, 1.5f
*(float)j
, tracepos
);
771 float mindist
= 99999.9f
;
773 for( int k
=0; k
<pscene
->shadower_count
; k
++ )
775 struct shadower
*shadower
= &pscene
->shadowers
[k
];
776 float dist
= vg_maxf( 0.0f
, sd_cone( tracepos
, &shadower
->sdf
));
777 mindist
= vg_minf( mindist
, dist
);
780 accum
+= vg_clampf( 1.0f
- mindist
, 0.0f
, 1.0f
)*0.2f
;
783 vert
->colour
[1] = vg_minf( accum
, 1.0f
);
787 static void scene_upload( scene
*pscene
)
789 mesh_upload( &pscene
->mesh
,
790 pscene
->verts
, pscene
->vertex_count
,
791 pscene
->indices
, pscene
->indice_count
);
793 vg_info( "Scene upload\n" );
794 vg_info( " indices:%u\n", pscene
->indice_count
);
795 vg_info( " verts:%u\n", pscene
->vertex_count
);
798 float scene_tree_sway
= 0.1f
;
800 static void scene_foliage_shader_use(void)
802 SHADER_USE( shader_debug_vcol
);
804 glUniformMatrix4fv( SHADER_UNIFORM( shader_debug_vcol
, "uPv" ),
805 1, GL_FALSE
, (float *)vg_pv
);
807 glUniform1i( SHADER_UNIFORM( shader_debug_vcol
, "uMode" ), debugview
);
808 glUniform1i( SHADER_UNIFORM( shader_debug_vcol
, "uTexMain" ), 0 );
810 glUniform1i( SHADER_UNIFORM( shader_debug_vcol
, "uTexGradients" ), 1 );
811 vg_tex2d_bind( &tex_gradients
, 1 );
813 glUniform1i( SHADER_UNIFORM( shader_debug_vcol
, "uTexNoise" ), 2 );
814 glActiveTexture( GL_TEXTURE2
);
815 glBindTexture( GL_TEXTURE_2D
, tex_dual_noise
);
817 glUniform1f( SHADER_UNIFORM( shader_debug_vcol
, "uTime" ), vg_time
);
818 glUniform1f( SHADER_UNIFORM( shader_debug_vcol
, "uSwayAmt" ),
822 static void scene_bind( scene
*pscene
)
824 mesh_bind( &pscene
->mesh
);
827 static void scene_draw( scene
*pscene
)
829 mesh_drawn( 0, pscene
->indice_count
);
832 static void scene_debugsdf( scene
*pscene
)
834 for( int i
=0; i
<pscene
->shadower_count
; i
++ )
836 struct shadower
*shadower
= &pscene
->shadowers
[i
];
839 v3_copy( shadower
->sdf
.origin
, base
);
840 base
[1] -= shadower
->sdf
.info
[1];
841 v3_copy( base
, side
);
842 side
[0] += shadower
->sdf
.info
[0];
844 vg_line2( shadower
->sdf
.origin
, base
, 0xff00ff00, 0xff0000ff );
845 vg_line2( side
, base
, 0xff00ff00, 0xff0000ff );
846 vg_line( side
, shadower
->sdf
.origin
, 0xff00ff00 );
849 v3f p0
= { pscene
->bbx
[0][0], pscene
->bbx
[0][1], pscene
->bbx
[0][2] },
850 p1
= { pscene
->bbx
[0][0], pscene
->bbx
[1][1], pscene
->bbx
[0][2] },
851 p2
= { pscene
->bbx
[1][0], pscene
->bbx
[1][1], pscene
->bbx
[0][2] },
852 p3
= { pscene
->bbx
[1][0], pscene
->bbx
[0][1], pscene
->bbx
[0][2] },
854 p4
= { pscene
->bbx
[0][0], pscene
->bbx
[0][1], pscene
->bbx
[1][2] },
855 p5
= { pscene
->bbx
[0][0], pscene
->bbx
[1][1], pscene
->bbx
[1][2] },
856 p6
= { pscene
->bbx
[1][0], pscene
->bbx
[1][1], pscene
->bbx
[1][2] },
857 p7
= { pscene
->bbx
[1][0], pscene
->bbx
[0][1], pscene
->bbx
[1][2] };
859 u32 col
= 0xffff00c8;
860 vg_line( p0
, p1
, col
);
861 vg_line( p1
, p2
, col
);
862 vg_line( p2
, p3
, col
);
863 vg_line( p3
, p0
, col
);
865 vg_line( p4
, p5
, col
);
866 vg_line( p5
, p6
, col
);
867 vg_line( p6
, p7
, col
);
868 vg_line( p7
, p4
, col
);
870 vg_line( p0
, p4
, col
);
871 vg_line( p1
, p5
, col
);
872 vg_line( p2
, p6
, col
);
873 vg_line( p3
, p7
, col
);
876 static void scene_register(void)
878 SHADER_INIT( shader_debug_vcol
);
879 SHADER_INIT( shader_standard_lit
);
880 SHADER_INIT( shader_unlit
);