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
124 "uniform mat4x3 uMdl;"
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 * vec4(uMdl * vec4(swaypos,1.0), 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
244 "uniform mat4x3 uMdl;"
253 "gl_Position = uPv * vec4( uMdl * vec4(a_co,1.0), 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 "float light1 = max(0.0,dot(-vec3(0.5,-0.8,0.25), aNorm));"
273 "float light2 = max(0.0,dot(-vec3(-0.8,0.5,-0.25), aNorm));"
275 "vec3 diffuse = texture( uTexMain, aUv +vec2(0.0,light1)*0.1 ).rgb;"
278 "float light1 = max(0.0,dot(-vec3(0.5,-0.8,0.25), aNorm));"
279 "float light2 = max(0.0,dot(-vec3(-0.8,0.5,-0.25), aNorm));"
280 "diffuse += vec3(0.2,0.2,0.2 ) + "
281 "vec3(1.0,1.0,0.9)*light1 + "
282 "vec3(0.1,0.3,0.4 )*light2;"
284 "FragColor = vec4((diffuse*uColour.rgb),"
285 "aColour.a*uColour.a);"
287 "FragColor = vec4(diffuse,1.0);"
290 UNIFORMS({ "uColour","uTexMain","uPv","uMdl" })
293 SHADER_DEFINE( shader_unlit
,
295 /*Include*/ VERTEX_STANDARD_ATTRIBUTES
298 "uniform mat4x3 uMdl;"
307 "gl_Position = uPv * vec4(uMdl * vec4(a_co,1.0), 1.0);"
308 "aColour = a_colour;"
310 "aNorm = mat3(uMdl) * a_norm;"
314 "out vec4 FragColor;"
316 "uniform sampler2D uTexMain;"
317 "uniform vec4 uColour;"
326 "vec3 diffuse = texture( uTexMain, aUv ).rgb;"
327 "FragColor = vec4(pow(diffuse,vec3(1.0)),1.0);"
330 UNIFORMS({ "uTexMain", "uPv", "uMdl" })
333 static void *buffer_reserve( void *buffer
, u32 count
, u32
*cap
, u32 amount
,
336 if( count
+amount
> *cap
)
338 *cap
= VG_MAX( (*cap
)*2, (*cap
)+amount
);
340 return realloc( buffer
, (*cap
) * emsize
);
347 * Append a model into the scene with a given transform
349 static void scene_add_model( scene
*pscene
, model
*mdl
, submodel
*submodel
,
350 v3f pos
, float yaw
, float scale
)
352 pscene
->verts
= buffer_reserve( pscene
->verts
, pscene
->vertex_count
,
353 &pscene
->vertex_cap
, submodel
->vertex_count
, sizeof(model_vert
) );
354 pscene
->indices
= buffer_reserve( pscene
->indices
, pscene
->indice_count
,
355 &pscene
->indice_cap
, submodel
->indice_count
, sizeof(u32
) );
357 if( submodel
->sdf_type
)
359 pscene
->shadowers
= buffer_reserve( pscene
->shadowers
,
360 pscene
->shadower_count
, &pscene
->shadower_cap
, 1,
361 sizeof( struct shadower
));
363 struct shadower
*shadower
=
364 &pscene
->shadowers
[ pscene
->shadower_count
++ ];
366 shadower
->sdf
= submodel
->sdf
;
367 shadower
->sdf_type
= submodel
->sdf_type
;
369 v2_muls( shadower
->sdf
.info
, scale
, shadower
->sdf
.info
);
370 v3_muls( shadower
->sdf
.origin
, scale
, shadower
->sdf
.origin
);
371 v3_add( pos
, shadower
->sdf
.origin
, shadower
->sdf
.origin
);
374 /* Transform and place vertices */
375 model_vert
*src_verts
= submodel_vert_data( mdl
, submodel
);
376 u32
*src_indices
= submodel_indice_data( mdl
, submodel
);
379 m4x3_identity( mtx
);
380 m4x3_translate( mtx
, pos
);
381 m4x3_rotate_y( mtx
, yaw
);
382 m4x3_scale( mtx
, scale
);
385 box_copy( submodel
->bbx
, bbxnew
);
386 m4x3_transform_aabb( mtx
, bbxnew
);
387 box_concat( pscene
->bbx
, bbxnew
);
390 m4x3_to_3x3( mtx
, rotation
);
392 float rand_hue
= vg_randf();
394 for( u32 i
=0; i
<submodel
->vertex_count
; i
++ )
396 model_vert
*pvert
= &pscene
->verts
[ pscene
->vertex_count
+i
],
397 *src
= &src_verts
[ i
];
399 m4x3_mulv( mtx
, src
->co
, pvert
->co
);
400 m3x3_mulv( rotation
, src
->norm
, pvert
->norm
);
402 v4_copy( src
->colour
, pvert
->colour
);
403 v2_copy( src
->uv
, pvert
->uv
);
405 float rel_y
= src
->co
[1] / submodel
->bbx
[1][1];
406 pvert
->colour
[0] = rel_y
;
407 pvert
->colour
[2] = rand_hue
;
410 for( u32 i
=0; i
<submodel
->indice_count
; i
++ )
412 u32
*pidx
= &pscene
->indices
[ pscene
->indice_count
+i
];
413 *pidx
= src_indices
[i
] + pscene
->vertex_count
;
416 pscene
->vertex_count
+= submodel
->vertex_count
;
417 pscene
->indice_count
+= submodel
->indice_count
;
420 static void scene_copy_slice( scene
*pscene
, submodel
*sm
)
422 sm
->indice_start
= pscene
->submesh
.indice_start
;
423 sm
->indice_count
= pscene
->indice_count
- sm
->indice_start
;
425 pscene
->submesh
.indice_start
= pscene
->indice_count
;
428 static void scene_shadow_sphere( scene
*pscene
, v3f sphere
,
429 v4f params
, v3f lightdir
)
431 for( int i
=0; i
<pscene
->vertex_count
; i
++ )
433 model_vert
*vert
= &pscene
->verts
[i
];
436 v3_sub( sphere
, vert
->co
, delta
);
438 float d
= v3_dot( lightdir
, delta
);
441 v3_muls( lightdir
, d
, closest
);
442 float dist
= v3_dist( closest
, delta
),
443 shading
= vg_maxf( dist
- params
[0], 0.0f
);
445 shading
= vg_minf( shading
* params
[1], 1.0f
);
446 vert
->colour
[1] *= shading
;
450 static void scene_shadow_gradient( scene
*pscene
, int comp
,
451 float start
, float length
)
453 float scale
= 1.0f
/ length
;
455 for( int i
=0; i
<pscene
->vertex_count
; i
++ )
457 model_vert
*vert
= &pscene
->verts
[i
];
458 float shading
= start
+ vert
->co
[comp
] * scale
;
460 vert
->colour
[1] = shading
;
465 static int sample_scene_height( scene
*pscene
, v3f pos
, v3f norm
)
467 for( int i
=0; i
<pscene
->indice_count
/3; i
++ )
469 u32
*tri
= &pscene
->indices
[i
*3];
471 float *pA
= pscene
->verts
[tri
[0]].co
,
472 *pB
= pscene
->verts
[tri
[1]].co
,
473 *pC
= pscene
->verts
[tri
[2]].co
;
476 if( triangle_raycast( pA
, pB
, pC
, pos
, &height
))
483 v3_sub( pA
, pB
, v0
);
484 v3_sub( pC
, pB
, v1
);
485 v3_cross( v1
, v0
, norm
);
486 v3_normalize( norm
);
495 static void sample_scene_normal( scene
*pscene
, v3f pos
, v3f normal
)
497 for( int i
=0; i
<pscene
->indice_count
/3; i
++ )
499 u32
*tri
= &pscene
->indices
[i
*3];
502 if( triangle_raycast(
503 pscene
->verts
[ tri
[0] ].co
,
504 pscene
->verts
[ tri
[1] ].co
,
505 pscene
->verts
[ tri
[2] ].co
, pos
, &height
))
509 v3_sub( pscene
->verts
[ tri
[1] ].co
,
510 pscene
->verts
[ tri
[0] ].co
,
513 v3_sub( pscene
->verts
[ tri
[2] ].co
,
514 pscene
->verts
[ tri
[0] ].co
,
517 v3_cross( v0
, v1
, normal
);
518 v3_normalize( normal
);
529 * Experimental SDF based shadows
531 * https://iquilezles.org/articles/distfunctions/
533 static float sd_cone( v3f co
, sdf_primative
*prim
)
535 float bound
= prim
->info
[1]*1.75f
;
536 if( v3_dist2( prim
->origin
, co
) > bound
*bound
)
540 v3_sub( co
, prim
->origin
, p
);
542 float h
= prim
->info
[1];
543 v2f c
= { prim
->info
[2], prim
->info
[3] };
546 v2_muls( (v2f
){ c
[0]/c
[1], -1.0f
}, h
, q
);
548 w
[0] = v2_length( (v2f
){ p
[0], p
[2] } );
551 v2_muladds( w
, q
, -vg_clampf( v2_dot(w
,q
)/v2_dot(q
,q
), 0.0f
, 1.0f
), a
);
552 v2_muladd( w
, q
, (v2f
){ vg_clampf( w
[0]/q
[0], 0.0f
, 1.0f
), 1.0f
}, b
);
554 float k
= vg_signf( q
[1] ),
555 d
= vg_minf( v2_dot( a
,a
), v2_dot( b
,b
) ),
556 s
= vg_maxf( k
*(w
[0]*q
[1]-w
[1]*q
[0]), k
*(w
[1]-q
[1]) );
558 return sqrtf(d
)*vg_signf(s
);
561 #define CACHE_AMBIENT_SHAPES
563 static float scene_ambient_sample( scene
*pscene
, v3f pos
, v3f dir
)
567 #ifdef CACHE_AMBIENT_SHAPES
568 static struct shadower
*local_shadowers
[32];
569 static int local_shadower_count
= 0;
570 static v3f local_shadower_last
= { -99999.9f
, -999999.9f
, -9999999.9f
};
572 if( v3_dist2( pos
, local_shadower_last
) > 10.0f
*10.0f
)
574 local_shadower_count
= 0;
575 v3_copy( pos
, local_shadower_last
);
577 for( int k
=0; k
<pscene
->shadower_count
; k
++ )
579 struct shadower
*shadower
= &pscene
->shadowers
[k
];
581 if( sd_cone( pos
, &shadower
->sdf
) <= 20.0f
)
583 local_shadowers
[ local_shadower_count
++ ] = shadower
;
584 if( local_shadower_count
== vg_list_size( local_shadowers
) )
591 for( int j
=0; j
<5; j
++ )
594 v3_muladds( pos
, dir
, 1.5f
*(float)j
, tracepos
);
596 float mindist
= 99999.9f
;
598 #ifndef CACHE_AMBIENT_SHAPES
600 for( int k
=0; k
<pscene
->shadower_count
; k
++ ){
601 struct shadower
*shadower
= &pscene
->shadowers
[k
];
604 for( int k
=0; k
<local_shadower_count
; k
++ ){
605 struct shadower
*shadower
= local_shadowers
[k
];
608 float dist
= vg_maxf( 0.0f
, sd_cone( tracepos
, &shadower
->sdf
));
609 mindist
= vg_minf( mindist
, dist
);
613 accum
+= vg_clampf( 1.0f
- mindist
, 0.0f
, 1.0f
)*0.2f
;
620 #define JUST_DO_EVERY_VERT
622 static void scene_compute_occlusion( scene
*pscene
)
624 v3f sundir
= { 0.2f
, 0.9f
, 0.2f
};
625 v3_normalize( sundir
);
627 /* TODO: Make this sample grid be dynamically required.
629 * 1. Only resample the light grid (1x1x1), when a vertex is outside the
632 * 2. Reorder all vertices so that each group of vertices that fit in a
633 * cube are next to eachother in the buffer. This will save cache
636 * for the sorting algorithm, i think we can already assume that *most
637 * vertices will be quite close to eachother. so instead of doing an
638 * exhaustive search we can reorder 1k chunks at a time.
642 v3_sub( pscene
->bbx
[1], pscene
->bbx
[0], sample_area
);
643 v3_ceil( sample_area
, sample_area
);
644 int ax
= sample_area
[0],
649 float *samplegrid
= malloc( ax
*ay
*az
* sizeof(float) );
651 for( int x
=0; x
<ax
; x
++ ){
652 for( int y
=0; y
<ay
; y
++ ){
653 for( int z
=0; z
<az
; z
++ )
655 v3f sample_pos
= { x
,y
,z
};
656 v3_add( pscene
->bbx
[0], sample_pos
, sample_pos
);
657 float accum
= scene_ambient_sample( pscene
, sample_pos
, sundir
);
659 samplegrid
[x
+ y
*ax
+ z
*ax
*ay
] = accum
;
662 v3i cube_pos
= { -999999, -999999, -999999 };
663 int cube_resamples
= 0, hits
= 0, misses
= 0;
665 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
;
668 for( int i
=0; i
<pscene
->vertex_count
; i
++ )
670 model_vert
*vert
= &pscene
->verts
[i
];
674 v3_sub( vert
->co
, pscene
->bbx
[0], q
);
676 v3_copy( vert
->co
, q
);
686 #ifndef JUST_DO_EVERY_VERT
696 s0
= samplegrid
[ x
+ y
*ax
+ z
*ax
*ay
],
697 s1
= samplegrid
[(x
+1) + y
*ax
+ z
*ax
*ay
],
698 s2
= samplegrid
[ x
+ (y
+1)*ax
+ z
*ax
*ay
],
699 s3
= samplegrid
[(x
+1) + (y
+1)*ax
+ z
*ax
*ay
],
700 s4
= samplegrid
[ x
+ y
*ax
+ (z
+1)*ax
*ay
],
701 s5
= samplegrid
[(x
+1) + y
*ax
+ (z
+1)*ax
*ay
],
702 s6
= samplegrid
[ x
+ (y
+1)*ax
+ (z
+1)*ax
*ay
],
703 s7
= samplegrid
[(x
+1) + (y
+1)*ax
+ (z
+1)*ax
*ay
],
705 if( x
!=cube_pos
[0] || y
!=cube_pos
[1] || z
!=cube_pos
[2] )
711 s0
= scene_ambient_sample( pscene
, (v3f
){ x
,y
,z
}, sundir
);
712 s1
= scene_ambient_sample( pscene
, (v3f
){ x
+1,y
,z
}, sundir
);
713 s2
= scene_ambient_sample( pscene
, (v3f
){ x
,y
+1,z
}, sundir
);
714 s3
= scene_ambient_sample( pscene
, (v3f
){ x
+1,y
+1,z
}, sundir
);
715 s4
= scene_ambient_sample( pscene
, (v3f
){ x
,y
,z
+1 }, sundir
);
716 s5
= scene_ambient_sample( pscene
, (v3f
){ x
+1,y
,z
+1 }, sundir
);
717 s6
= scene_ambient_sample( pscene
, (v3f
){ x
,y
+1,z
+1 }, sundir
);
718 s7
= scene_ambient_sample( pscene
, (v3f
){ x
+1,y
+1,z
+1 }, sundir
);
729 s0_s1
= vg_lerpf( s0
, s1
, q
[0] ),
730 s2_s3
= vg_lerpf( s2
, s3
, q
[0] ),
731 s4_s5
= vg_lerpf( s4
, s5
, q
[0] ),
732 s6_s7
= vg_lerpf( s6
, s7
, q
[0] ),
734 s0s1_s2s3
= vg_lerpf( s0_s1
, s2_s3
, q
[1] ),
735 s4s5_s6s7
= vg_lerpf( s4_s5
, s6_s7
, q
[1] ),
736 s0s1s2s3_s4s5s6s7
= vg_lerpf( s0s1_s2s3
, s4s5_s6s7
, q
[2] );
738 vert
->colour
[1] = s0s1s2s3_s4s5s6s7
;
740 vert
->colour
[1] = scene_ambient_sample( pscene
, vert
->co
, sundir
);
745 int cube_resamples
= -1, misses
= 0, hits
= 0;
748 int static_samples
= ax
*ay
*az
,
749 vertex_samples
= pscene
->vertex_count
;
751 if( cube_resamples
< static_samples
)
752 vg_success( "Walking cube beat static grid (%d<%d. %d)!\n",
753 cube_resamples
, static_samples
, vertex_samples
);
755 vg_warn( "Walking cube was worse than static grid (%d<%d. %d).\n",
756 cube_resamples
, static_samples
, vertex_samples
);
758 vg_info( "Hits; %d, misses: %d\n", hits
, misses
);
766 for( int i
=0; i
<pscene
->vertex_count
; i
++ )
768 model_vert
*vert
= &pscene
->verts
[i
];
771 for( int j
=0; j
<5; j
++ )
774 v3_copy( vert
->co
, tracepos
);
775 v3_muladds( tracepos
, sundir
, 1.5f
*(float)j
, tracepos
);
777 float mindist
= 99999.9f
;
779 for( int k
=0; k
<pscene
->shadower_count
; k
++ )
781 struct shadower
*shadower
= &pscene
->shadowers
[k
];
782 float dist
= vg_maxf( 0.0f
, sd_cone( tracepos
, &shadower
->sdf
));
783 mindist
= vg_minf( mindist
, dist
);
786 accum
+= vg_clampf( 1.0f
- mindist
, 0.0f
, 1.0f
)*0.2f
;
789 vert
->colour
[1] = vg_minf( accum
, 1.0f
);
793 static void scene_upload( scene
*pscene
)
795 mesh_upload( &pscene
->mesh
,
796 pscene
->verts
, pscene
->vertex_count
,
797 pscene
->indices
, pscene
->indice_count
);
799 vg_info( "Scene upload\n" );
800 vg_info( " indices:%u\n", pscene
->indice_count
);
801 vg_info( " verts:%u\n", pscene
->vertex_count
);
804 float scene_tree_sway
= 0.1f
;
806 static void scene_foliage_shader_use(void)
808 SHADER_USE( shader_debug_vcol
);
810 glUniformMatrix4fv( SHADER_UNIFORM( shader_debug_vcol
, "uPv" ),
811 1, GL_FALSE
, (float *)vg_pv
);
813 glUniform1i( SHADER_UNIFORM( shader_debug_vcol
, "uMode" ), debugview
);
814 glUniform1i( SHADER_UNIFORM( shader_debug_vcol
, "uTexMain" ), 0 );
816 glUniform1i( SHADER_UNIFORM( shader_debug_vcol
, "uTexGradients" ), 1 );
817 vg_tex2d_bind( &tex_gradients
, 1 );
819 glUniform1i( SHADER_UNIFORM( shader_debug_vcol
, "uTexNoise" ), 2 );
820 glActiveTexture( GL_TEXTURE2
);
821 glBindTexture( GL_TEXTURE_2D
, tex_dual_noise
);
823 glUniform1f( SHADER_UNIFORM( shader_debug_vcol
, "uTime" ), vg_time
);
824 glUniform1f( SHADER_UNIFORM( shader_debug_vcol
, "uSwayAmt" ),
828 static void scene_bind( scene
*pscene
)
830 mesh_bind( &pscene
->mesh
);
833 static void scene_draw( scene
*pscene
)
835 mesh_drawn( 0, pscene
->indice_count
);
838 static void scene_debugsdf( scene
*pscene
)
840 for( int i
=0; i
<pscene
->shadower_count
; i
++ )
842 struct shadower
*shadower
= &pscene
->shadowers
[i
];
845 v3_copy( shadower
->sdf
.origin
, base
);
846 base
[1] -= shadower
->sdf
.info
[1];
847 v3_copy( base
, side
);
848 side
[0] += shadower
->sdf
.info
[0];
850 vg_line2( shadower
->sdf
.origin
, base
, 0xff00ff00, 0xff0000ff );
851 vg_line2( side
, base
, 0xff00ff00, 0xff0000ff );
852 vg_line( side
, shadower
->sdf
.origin
, 0xff00ff00 );
855 v3f p0
= { pscene
->bbx
[0][0], pscene
->bbx
[0][1], pscene
->bbx
[0][2] },
856 p1
= { pscene
->bbx
[0][0], pscene
->bbx
[1][1], pscene
->bbx
[0][2] },
857 p2
= { pscene
->bbx
[1][0], pscene
->bbx
[1][1], pscene
->bbx
[0][2] },
858 p3
= { pscene
->bbx
[1][0], pscene
->bbx
[0][1], pscene
->bbx
[0][2] },
860 p4
= { pscene
->bbx
[0][0], pscene
->bbx
[0][1], pscene
->bbx
[1][2] },
861 p5
= { pscene
->bbx
[0][0], pscene
->bbx
[1][1], pscene
->bbx
[1][2] },
862 p6
= { pscene
->bbx
[1][0], pscene
->bbx
[1][1], pscene
->bbx
[1][2] },
863 p7
= { pscene
->bbx
[1][0], pscene
->bbx
[0][1], pscene
->bbx
[1][2] };
865 u32 col
= 0xffff00c8;
866 vg_line( p0
, p1
, col
);
867 vg_line( p1
, p2
, col
);
868 vg_line( p2
, p3
, col
);
869 vg_line( p3
, p0
, col
);
871 vg_line( p4
, p5
, col
);
872 vg_line( p5
, p6
, col
);
873 vg_line( p6
, p7
, col
);
874 vg_line( p7
, p4
, col
);
876 vg_line( p0
, p4
, col
);
877 vg_line( p1
, p5
, col
);
878 vg_line( p2
, p6
, col
);
879 vg_line( p3
, p7
, col
);
882 static void scene_register(void)
884 SHADER_INIT( shader_debug_vcol
);
885 SHADER_INIT( shader_standard_lit
);
886 SHADER_INIT( shader_unlit
);