2 * Copyright (C) 2021-2023 Mt.ZERO Software, Harry Godden - All Rights Reserved
6 #include "world_render.h"
10 #include "ent_miniworld.h"
11 #include "player_remote.h"
12 #include "ent_skateshop.h"
14 #include "shaders/model_entity.h"
16 struct world_render world_render
;
18 static int ccmd_set_time( int argc
, const char *argv
[] ){
19 world_instance
*world
= world_current_instance();
21 world
->time
= atof( argv
[0] );
23 vg_error( "Usage set_time <0-1.0> (current time: %f)\n", world
->time
);
27 static void async_world_render_init( void *payload
, u32 size
){
28 vg_info( "Allocate uniform buffers\n" );
29 for( int i
=0; i
<k_world_max
; i
++ ){
30 world_instance
*world
= &world_static
.instances
[i
];
31 world
->ubo_bind_point
= i
;
33 glGenBuffers( 1, &world
->ubo_lighting
);
34 glBindBuffer( GL_UNIFORM_BUFFER
, world
->ubo_lighting
);
35 glBufferData( GL_UNIFORM_BUFFER
, sizeof(struct ub_world_lighting
),
36 NULL
, GL_DYNAMIC_DRAW
);
38 glBindBufferBase( GL_UNIFORM_BUFFER
, i
, world
->ubo_lighting
);
42 vg_info( "Allocate frame buffers\n" );
43 for( int i
=0; i
<k_world_max
; i
++ ){
44 world_instance
*world
= &world_static
.instances
[i
];
45 struct framebuffer
*fb
= &world
->heightmap
;
47 fb
->display_name
= NULL
;
51 fb
->resolution_div
= 0;
53 fb
->attachments
[0].display_name
= NULL
;
54 fb
->attachments
[0].purpose
= k_framebuffer_attachment_type_texture
;
55 fb
->attachments
[0].internalformat
= GL_RG16F
;
56 fb
->attachments
[0].format
= GL_RG
;
57 fb
->attachments
[0].type
= GL_FLOAT
;
58 fb
->attachments
[0].attachment
= GL_COLOR_ATTACHMENT0
;
60 fb
->attachments
[1].purpose
= k_framebuffer_attachment_type_none
;
61 fb
->attachments
[2].purpose
= k_framebuffer_attachment_type_none
;
62 fb
->attachments
[3].purpose
= k_framebuffer_attachment_type_none
;
63 fb
->attachments
[4].purpose
= k_framebuffer_attachment_type_none
;
65 render_fb_allocate( fb
);
69 void world_render_init(void)
71 VG_VAR_F32( k_day_length
);
72 VG_VAR_I32( k_debug_light_indices
);
73 VG_VAR_I32( k_debug_light_complexity
);
74 VG_VAR_I32( k_light_preview
);
75 VG_VAR_I32( k_light_editor
);
76 vg_console_reg_cmd( "set_time", ccmd_set_time
, NULL
);
78 world_render
.sky_rate
= 1.0;
79 world_render
.sky_target_rate
= 1.0;
81 vg_info( "Loading world resources\n" );
82 vg_linear_clear( vg_mem
.scratch
);
85 mdl_open( &msky
, "models/rs_skydome.mdl", vg_mem
.scratch
);
86 mdl_load_metadata_block( &msky
, vg_mem
.scratch
);
87 mdl_async_load_glmesh( &msky
, &world_render
.skydome
, NULL
);
90 vg_info( "Loading default world textures\n" );
91 vg_tex2d_load_qoi_async_file( "textures/garbage.qoi",
92 VG_TEX2D_NEAREST
|VG_TEX2D_REPEAT
,
93 &world_render
.tex_terrain_noise
);
95 vg_async_call( async_world_render_init
, NULL
, 0 );
99 * standard uniform bindings
100 * ----------------------------------------------------------------------------
102 void world_link_lighting_ub( world_instance
*world
, GLuint shader
)
104 GLuint idx
= glGetUniformBlockIndex( shader
, "ub_world_lighting" );
105 glUniformBlockBinding( shader
, idx
, world
->ubo_bind_point
);
108 void world_bind_position_texture( world_instance
*world
,
109 GLuint shader
, GLuint location
,
112 render_fb_bind_texture( &world
->heightmap
, 0, slot
);
113 glUniform1i( location
, slot
);
116 void world_bind_light_array( world_instance
*world
,
117 GLuint shader
, GLuint location
,
120 glActiveTexture( GL_TEXTURE0
+ slot
);
121 glBindTexture( GL_TEXTURE_BUFFER
, world
->tex_light_entities
);
122 glUniform1i( location
, slot
);
125 void world_bind_light_index( world_instance
*world
,
126 GLuint shader
, GLuint location
,
129 glActiveTexture( GL_TEXTURE0
+ slot
);
130 glBindTexture( GL_TEXTURE_3D
, world
->tex_light_cubes
);
131 glUniform1i( location
, slot
);
134 void bind_terrain_noise(void)
136 glActiveTexture( GL_TEXTURE0
);
137 glBindTexture( GL_TEXTURE_2D
, world_render
.tex_terrain_noise
);
141 * Get OpenGL texture name from texture ID.
143 static GLuint
world_get_texture( world_instance
*world
, u32 id
){
144 if( id
& 0x80000000 ) return skaterift
.rt_textures
[id
& ~0x80000000];
145 else return world
->textures
[ id
];
149 static void bindpoint_diffuse_texture1( world_instance
*world
,
150 struct world_surface
*mat
){
151 glActiveTexture( GL_TEXTURE1
);
152 glBindTexture( GL_TEXTURE_2D
,
153 world_get_texture(world
,mat
->info
.tex_diffuse
) );
159 * ----------------------------------------------------------------------------
165 enum mdl_shader shader
;
166 enum world_geo_type geo_type
;
168 void (*fn_bind
)( world_instance
*world
, struct world_surface
*mat
);
169 void (*fn_set_mdl
)( m4x3f mdl
);
170 void (*fn_set_uPvmPrev
)( m4x4f pvm
);
171 void (*fn_set_uNormalMtx
)( m3x3f mnorm
);
174 void render_world_depth( world_instance
*world
, vg_camera
*cam
);
177 * Render a run of submeshes, only of those which match material_id
179 static void world_render_submeshes( world_instance
*world
,
180 struct world_pass
*pass
,
181 mdl_transform
*transform
,
182 u32 start
, u32 count
, u32 material_id
)
184 for( u32 k
=0; k
<count
; k
++ )
186 mdl_submesh
*sm
= mdl_arritm( &world
->meta
.submeshs
, start
+k
);
187 if( sm
->material_id
!= material_id
)
191 mdl_transform_m4x3( transform
, mmdl
);
194 m4x3_expand( mmdl
, m4mdl
);
195 m4x4_mul( pass
->cam
->mtx_prev
.pv
, m4mdl
, m4mdl
);
197 pass
->fn_set_mdl( mmdl
);
198 pass
->fn_set_uPvmPrev( m4mdl
);
200 mdl_draw_submesh( sm
);
205 * Render props attached to this material
207 static void world_render_props( world_instance
*world
, u32 material_id
,
208 struct world_pass
*pass
)
210 struct world_surface
*mat
= &world
->surfaces
[ material_id
];
211 if( !(mat
->flags
& WORLD_SURFACE_HAS_PROPS
) ) return;
213 pass
->fn_bind( world
, mat
);
215 for( u32 j
=0; j
<mdl_arrcount( &world
->ent_prop
); j
++ ){
216 ent_prop
*prop
= mdl_arritm( &world
->ent_prop
, j
);
217 if( prop
->flags
& 0x1 ) continue;
219 world_render_submeshes( world
, pass
, &prop
->transform
,
220 prop
->submesh_start
, prop
->submesh_count
, material_id
);
225 * Render traffic models attactched to this material
227 static void world_render_traffic( world_instance
*world
, u32 material_id
,
228 struct world_pass
*pass
)
230 struct world_surface
*mat
= &world
->surfaces
[ material_id
];
231 if( !(mat
->flags
& WORLD_SURFACE_HAS_TRAFFIC
) ) return;
233 pass
->fn_bind( world
, mat
);
235 for( u32 j
=0; j
<mdl_arrcount( &world
->ent_traffic
); j
++ ){
236 ent_traffic
*traffic
= mdl_arritm( &world
->ent_traffic
, j
);
238 world_render_submeshes( world
, pass
, &traffic
->transform
,
239 traffic
->submesh_start
, traffic
->submesh_count
,
245 * Iterate and render all materials which match the passes shader and geometry
246 * type. Includes props/traffic.
248 static void world_render_pass( world_instance
*world
, struct world_pass
*pass
)
250 for( int i
=0; i
<world
->surface_count
; i
++ )
252 struct world_surface
*mat
= &world
->surfaces
[i
];
254 if( mat
->info
.shader
== pass
->shader
)
258 if( pass
->geo_type
== k_world_geo_type_solid
)
264 world_render_traffic( world
, i
, pass
);
265 world_render_props( world
, i
, pass
);
266 sm
= &mat
->sm_no_collide
;
269 if( !sm
->indice_count
)
273 m4x3_identity( mmdl
);
274 pass
->fn_set_mdl( mmdl
);
275 pass
->fn_set_uPvmPrev( pass
->cam
->mtx_prev
.pv
);
276 pass
->fn_bind( world
, mat
);
277 mdl_draw_submesh( sm
);
283 * Specific shader instructions
284 * ----------------------------------------------------------------------------
287 static void world_render_both_stages( world_instance
*world
,
288 struct world_pass
*pass
)
290 mesh_bind( &world
->mesh_geo
);
291 pass
->geo_type
= k_world_geo_type_solid
;
292 world_render_pass( world
, pass
);
294 glDisable( GL_CULL_FACE
);
295 mesh_bind( &world
->mesh_no_collide
);
296 pass
->geo_type
= k_world_geo_type_nonsolid
;
297 world_render_pass( world
, pass
);
298 glEnable( GL_CULL_FACE
);
301 static void bindpoint_world_vb( world_instance
*world
,
302 struct world_surface
*mat
)
304 struct shader_props_vertex_blend
*props
= mat
->info
.props
.compiled
;
306 glActiveTexture( GL_TEXTURE1
);
307 glBindTexture( GL_TEXTURE_2D
, world_get_texture(world
, props
->tex_diffuse
) );
310 shader_scene_vertex_blend_uOffset( props
->blend_offset
);
314 static void render_world_vb( world_instance
*world
, vg_camera
*cam
)
316 shader_scene_vertex_blend_use();
317 shader_scene_vertex_blend_uTexGarbage(0);
318 shader_scene_vertex_blend_uTexGradients(1);
319 WORLD_BIND_LIGHT_BUFFERS_UB0_TEX234( world
, scene_vertex_blend
);
321 glActiveTexture( GL_TEXTURE0
);
322 glBindTexture( GL_TEXTURE_2D
, world_render
.tex_terrain_noise
);
324 shader_scene_vertex_blend_uPv( cam
->mtx
.pv
);
325 shader_scene_vertex_blend_uCamera( cam
->transform
[3] );
327 struct world_pass pass
=
329 .shader
= k_shader_standard_vertex_blend
,
331 .fn_bind
= bindpoint_world_vb
,
332 .fn_set_mdl
= shader_scene_vertex_blend_uMdl
,
333 .fn_set_uPvmPrev
= shader_scene_vertex_blend_uPvmPrev
,
336 world_render_both_stages( world
, &pass
);
339 static void world_shader_standard_bind( world_instance
*world
, vg_camera
*cam
)
341 shader_scene_standard_use();
342 shader_scene_standard_uTexGarbage(0);
343 shader_scene_standard_uTexMain(1);
344 shader_scene_standard_uPv( cam
->mtx
.pv
);
345 WORLD_BIND_LIGHT_BUFFERS_UB0_TEX234( world
, scene_standard
);
347 bind_terrain_noise();
348 shader_scene_standard_uCamera( cam
->transform
[3] );
351 static void bindpoint_standard( world_instance
*world
,
352 struct world_surface
*mat
)
354 struct shader_props_standard
*props
= mat
->info
.props
.compiled
;
356 glActiveTexture( GL_TEXTURE1
);
357 glBindTexture( GL_TEXTURE_2D
, world_get_texture(world
, props
->tex_diffuse
) );
360 static void render_world_standard( world_instance
*world
, vg_camera
*cam
)
362 world_shader_standard_bind( world
, cam
);
363 struct world_pass pass
=
365 .shader
= k_shader_standard
,
367 .fn_bind
= bindpoint_standard
,
368 .fn_set_mdl
= shader_scene_standard_uMdl
,
369 .fn_set_uPvmPrev
= shader_scene_standard_uPvmPrev
,
372 world_render_both_stages( world
, &pass
);
375 static void bindpoint_world_cubemapped( world_instance
*world
,
376 struct world_surface
*mat
)
378 struct shader_props_cubemapped
*props
= mat
->info
.props
.compiled
;
380 glActiveTexture( GL_TEXTURE1
);
381 glBindTexture( GL_TEXTURE_2D
,
382 world_get_texture( world
,props
->tex_diffuse
) );
384 u32 cubemap_id
= props
->cubemap_entity
,
387 if( mdl_entity_id_type( cubemap_id
) == k_ent_cubemap
)
389 cubemap_index
= mdl_entity_id_id( cubemap_id
);
392 ent_cubemap
*cm
= mdl_arritm( &world
->ent_cubemap
, cubemap_index
);
393 glActiveTexture( GL_TEXTURE10
);
394 glBindTexture( GL_TEXTURE_CUBE_MAP
, cm
->texture_id
);
396 shader_scene_cubemapped_uColour( props
->tint
);
399 static void bindpoint_world_cubemapped_disabled( world_instance
*world
,
400 struct world_surface
*mat
)
402 struct shader_props_cubemapped
*props
= mat
->info
.props
.compiled
;
404 glActiveTexture( GL_TEXTURE1
);
405 glBindTexture( GL_TEXTURE_2D
,
406 world_get_texture( world
, props
->tex_diffuse
) );
409 static void render_world_cubemapped( world_instance
*world
, vg_camera
*cam
,
412 if( !mdl_arrcount( &world
->ent_cubemap
) )
417 world_shader_standard_bind( world
, cam
);
419 struct world_pass pass
=
421 .shader
= k_shader_cubemap
,
423 .fn_bind
= bindpoint_world_cubemapped_disabled
,
424 .fn_set_mdl
= shader_scene_standard_uMdl
,
425 .fn_set_uPvmPrev
= shader_scene_standard_uPvmPrev
,
428 world_render_both_stages( world
, &pass
);
432 shader_scene_cubemapped_use();
433 shader_scene_cubemapped_uTexGarbage(0);
434 shader_scene_cubemapped_uTexMain(1);
435 shader_scene_cubemapped_uTexCubemap(10);
436 shader_scene_cubemapped_uPv( cam
->mtx
.pv
);
438 WORLD_BIND_LIGHT_BUFFERS_UB0_TEX234( world
, scene_cubemapped
);
440 bind_terrain_noise();
441 shader_scene_cubemapped_uCamera( cam
->transform
[3] );
443 struct world_pass pass
=
445 .shader
= k_shader_cubemap
,
447 .fn_bind
= bindpoint_world_cubemapped
,
448 .fn_set_mdl
= shader_scene_cubemapped_uMdl
,
449 .fn_set_uPvmPrev
= shader_scene_cubemapped_uPvmPrev
,
452 world_render_both_stages( world
, &pass
);
456 static void render_world_alphatest( world_instance
*world
, vg_camera
*cam
)
458 shader_scene_standard_alphatest_use();
459 shader_scene_standard_alphatest_uTexGarbage(0);
460 shader_scene_standard_alphatest_uTexMain(1);
461 shader_scene_standard_alphatest_uPv( cam
->mtx
.pv
);
463 WORLD_BIND_LIGHT_BUFFERS_UB0_TEX234( world
, scene_standard_alphatest
);
465 bind_terrain_noise();
466 shader_scene_standard_alphatest_uCamera( cam
->transform
[3] );
467 glDisable(GL_CULL_FACE
);
469 struct world_pass pass
=
471 .shader
= k_shader_standard_cutout
,
473 .fn_bind
= bindpoint_standard
,
474 .fn_set_mdl
= shader_scene_standard_alphatest_uMdl
,
475 .fn_set_uPvmPrev
= shader_scene_standard_alphatest_uPvmPrev
,
478 world_render_both_stages( world
, &pass
);
479 glEnable(GL_CULL_FACE
);
482 static void render_world_foliage( world_instance
*world
, vg_camera
*cam
)
484 shader_scene_foliage_use();
485 shader_scene_foliage_uTexGarbage(0);
486 shader_scene_foliage_uTexMain(1);
487 shader_scene_foliage_uPv( cam
->mtx
.pv
);
488 shader_scene_foliage_uTime( vg
.time
);
490 WORLD_BIND_LIGHT_BUFFERS_UB0_TEX234( world
, scene_foliage
);
491 bind_terrain_noise();
493 shader_scene_foliage_uCamera( cam
->transform
[3] );
494 glDisable(GL_CULL_FACE
);
495 struct world_pass pass
=
497 .shader
= k_shader_foliage
,
499 .fn_bind
= bindpoint_standard
,
500 .fn_set_mdl
= shader_scene_foliage_uMdl
,
501 .fn_set_uPvmPrev
= shader_scene_foliage_uPvmPrev
,
503 world_render_both_stages( world
, &pass
);
504 glEnable(GL_CULL_FACE
);
507 static void world_render_challenges( world_instance
*world
,
508 struct world_pass
*pass
, v3f pos
)
511 if( skaterift
.activity
== k_skaterift_replay
) return;
512 if( world
!= world_current_instance() ) return;
517 u32 objective_list
[ 32 ],
518 challenge_list
[ 16 ];
520 v2f objective_uv_offsets
[ 32 ];
522 u32 objective_count
= 0,
525 ent_challenge
*active_challenge
= NULL
;
527 if( mdl_entity_id_type( world_static
.focused_entity
) == k_ent_challenge
){
528 if( (skaterift
.activity
== k_skaterift_default
) &&
529 world_static
.challenge_target
){
533 if( !((skaterift
.activity
!= k_skaterift_ent_focus
) &&
534 !world_static
.challenge_target
) ){
535 world_instance
*challenge_world
= world_current_instance();
536 u32 index
= mdl_entity_id_id( world_static
.focused_entity
);
537 active_challenge
= mdl_arritm(&challenge_world
->ent_challenge
, index
);
541 if( active_challenge
){
542 shader_scene_fxglow_uUvOffset( (v2f
){ 8.0f
/256.0f
, 0.0f
} );
543 challenge_list
[ challenge_count
++ ] = world_static
.focused_entity
;
545 u32 next
= active_challenge
->first
;
546 while( mdl_entity_id_type(next
) == k_ent_objective
){
547 u32 index
= mdl_entity_id_id( next
);
548 objective_list
[ objective_count
++ ] = index
;
550 ent_objective
*objective
= mdl_arritm( &world
->ent_objective
, index
);
551 next
= objective
->id_next
;
557 shader_scene_fxglow_uUvOffset( (v2f
){ 0.0f
, 0.0f
} );
559 bh_iter_init_range( 0, &it
, pos
, radius
+10.0f
);
561 while( bh_next( world
->entity_bh
, &it
, &idx
) ){
562 u32 id
= world
->entity_list
[ idx
],
563 type
= mdl_entity_id_type( id
),
564 index
= mdl_entity_id_id( id
);
566 if( type
== k_ent_objective
) {
567 if( objective_count
< vg_list_size(objective_list
) )
568 objective_list
[ objective_count
++ ] = index
;
570 else if( type
== k_ent_challenge
){
571 if( challenge_count
< vg_list_size(challenge_list
) )
572 challenge_list
[ challenge_count
++ ] = index
;
577 /* render objectives */
578 glDisable( GL_CULL_FACE
);
579 mesh_bind( &world
->mesh_no_collide
);
580 u32 last_material
= 0;
581 for( u32 i
=0; i
<objective_count
; i
++ )
583 u32 index
= objective_list
[ i
];
584 ent_objective
*objective
= mdl_arritm( &world
->ent_objective
, index
);
585 if( (objective
->flags
& k_ent_objective_hidden
) &&
586 !active_challenge
) continue;
592 u32 passed
= objective
->flags
& k_ent_objective_passed
;
593 f32 target
= passed
? 0.0f
: 1.0f
;
594 vg_slewf(&objective
->transform
.s
[0], target
, vg
.time_frame_delta
*4.0f
);
595 scale
= vg_smoothstepf( objective
->transform
.s
[0] );
597 if( (objective
== world_static
.challenge_target
) || passed
)
598 shader_scene_fxglow_uUvOffset( (v2f
){ 16.0f
/256.0f
, 0.0f
} );
600 shader_scene_fxglow_uUvOffset( (v2f
){ 8.0f
/256.0f
, 0.0f
} );
604 f32 dist
= v3_dist( objective
->transform
.co
, pos
) * (1.0f
/radius
);
605 scale
= vg_smoothstepf( vg_clampf( 5.0f
-dist
*5.0f
, 0.0f
,1.0f
) );
609 q_m3x3( objective
->transform
.q
, mmdl
);
610 m3x3_scalef( mmdl
, scale
);
611 v3_copy( objective
->transform
.co
, mmdl
[3] );
612 shader_scene_fxglow_uMdl( mmdl
);
614 for( u32 j
=0; j
<objective
->submesh_count
; j
++ )
616 mdl_submesh
*sm
= mdl_arritm( &world
->meta
.submeshs
,
617 objective
->submesh_start
+ j
);
619 if( sm
->material_id
!= last_material
)
621 last_material
= sm
->material_id
;
622 pass
->fn_bind( world
, &world
->surfaces
[sm
->material_id
] );
624 mdl_draw_submesh( sm
);
629 font3d_bind( &gui
.font
, k_font_shader_world
, 0, world
, &skaterift
.cam
);
633 for( u32 i
=0; i
<mdl_arrcount(&world
->ent_challenge
); i
++ )
635 ent_challenge
*challenge
= mdl_arritm( &world
->ent_challenge
, i
);
636 if( challenge
->status
) count
++;
641 vg_strnull( &str
, buf
, sizeof(buf
) );
642 vg_strcati32( &str
, count
);
643 vg_strcatch( &str
, '/' );
644 vg_strcati32( &str
, mdl_arrcount(&world
->ent_challenge
) );
646 f32 w
= font3d_string_width( 1, buf
);
648 m3x3_identity( mlocal
);
649 mlocal
[3][0] = -w
*0.5f
;
653 for( u32 i
=0; i
<challenge_count
; i
++ )
655 u32 index
= challenge_list
[ i
];
656 ent_challenge
*challenge
= mdl_arritm( &world
->ent_challenge
, index
);
658 mdl_transform_m4x3( &challenge
->transform
, mmdl
);
659 m4x3_mul( mmdl
, mlocal
, mmdl
);
661 vg_line_point( challenge
->transform
.co
, 0.25f
, VG__RED
);
663 f32 dist
= v3_dist( challenge
->transform
.co
, pos
) * (1.0f
/radius
),
664 scale
= vg_smoothstepf( vg_clampf( 10.0f
-dist
*10.0f
, 0.0f
,1.0f
) ),
667 if( challenge
->status
)
670 shader_scene_font_uOpacity( scale
);
671 shader_scene_font_uColourize( colour
);
672 font3d_simple_draw( 1, buf
, &skaterift
.cam
, mmdl
);
676 static void bindpoint_fxglow( world_instance
*world
,
677 struct world_surface
*mat
)
679 struct shader_props_standard
*props
= mat
->info
.props
.compiled
;
681 glActiveTexture( GL_TEXTURE1
);
682 glBindTexture( GL_TEXTURE_2D
, world_get_texture(world
, props
->tex_diffuse
) );
685 static void render_world_fxglow( world_instance
*host_world
,
686 world_instance
*world
, vg_camera
*cam
,
688 int generic
, int challenges
, int regions
)
690 shader_scene_fxglow_use();
691 shader_scene_fxglow_uUvOffset( (v2f
){ 0.0f
, 0.0f
} );
692 shader_scene_fxglow_uTexMain(1);
693 shader_scene_fxglow_uPv( cam
->mtx
.pv
);
694 WORLD_BIND_LIGHT_BUFFERS_UB0_TEX234( world
, scene_fxglow
);
696 shader_scene_fxglow_uCamera( cam
->transform
[3] );
697 glDisable(GL_CULL_FACE
);
699 struct world_pass pass
=
701 .shader
= k_shader_fxglow
,
703 .fn_bind
= bindpoint_fxglow
,
704 .fn_set_mdl
= shader_scene_fxglow_uMdl
,
705 .fn_set_uPvmPrev
= shader_scene_fxglow_uPvmPrev
,
709 world_render_both_stages( world
, &pass
);
712 mesh_bind( &world
->mesh_no_collide
);
714 u32 last_material
= 0;
715 for( u32 i
=0; i
<mdl_arrcount(&world
->ent_region
); i
++ ){
716 shader_scene_fxglow_uUvOffset( (v2f
){ 0.0f
, 0.0f
} );
717 ent_region
*region
= mdl_arritm( &world
->ent_region
, i
);
720 if( region
->flags
& k_ent_route_flag_achieve_gold
)
722 else if( region
->flags
& k_ent_route_flag_achieve_silver
)
725 shader_scene_fxglow_uUvOffset( (v2f
){ (8.0f
/256.0f
)*offset
, 0.0f
} );
728 mdl_transform_m4x3( ®ion
->transform
, mmdl
);
729 m4x3_mul( world_mmdl
, mmdl
, mmdl
);
730 shader_scene_fxglow_uMdl( mmdl
);
732 for( u32 j
=0; j
<region
->submesh_count
; j
++ )
734 mdl_submesh
*sm
= mdl_arritm( &world
->meta
.submeshs
,
735 region
->submesh_start
+ j
);
737 if( sm
->material_id
!= last_material
)
739 last_material
= sm
->material_id
;
740 pass
.fn_bind( world
, &world
->surfaces
[sm
->material_id
] );
742 mdl_draw_submesh( sm
);
748 world_render_challenges( world
, &pass
, cam
->pos
);
750 glEnable(GL_CULL_FACE
);
753 static void bindpoint_terrain( world_instance
*world
,
754 struct world_surface
*mat
)
756 struct shader_props_terrain
*props
= mat
->info
.props
.compiled
;
758 glActiveTexture( GL_TEXTURE1
);
759 glBindTexture( GL_TEXTURE_2D
, world_get_texture(world
, props
->tex_diffuse
) );
760 shader_scene_terrain_uBlendOffset( props
->blend_offset
);
761 shader_scene_terrain_uSandColour( props
->sand_colour
);
764 static void bindpoint_override( world_instance
*world
,
765 struct world_surface
*mat
)
767 if( mat
->info
.flags
& k_material_flag_collision
)
769 shader_scene_override_uAlphatest(0);
773 glActiveTexture( GL_TEXTURE1
);
774 glBindTexture( GL_TEXTURE_2D
, world_get_texture(world
, mat
->alpha_tex
) );
775 shader_scene_override_uAlphatest(1);
779 static void render_terrain( world_instance
*world
, vg_camera
*cam
)
781 shader_scene_terrain_use();
782 shader_scene_terrain_uTexGarbage(0);
783 shader_scene_terrain_uTexGradients(1);
785 WORLD_BIND_LIGHT_BUFFERS_UB0_TEX234( world
, scene_terrain
);
786 glActiveTexture( GL_TEXTURE0
);
787 glBindTexture( GL_TEXTURE_2D
, world_render
.tex_terrain_noise
);
789 shader_scene_terrain_uPv( cam
->mtx
.pv
);
790 shader_scene_terrain_uCamera( cam
->transform
[3] );
792 struct world_pass pass
=
794 .shader
= k_shader_terrain_blend
,
796 .fn_bind
= bindpoint_terrain
,
797 .fn_set_mdl
= shader_scene_terrain_uMdl
,
798 .fn_set_uPvmPrev
= shader_scene_terrain_uPvmPrev
,
801 world_render_both_stages( world
, &pass
);
804 static void render_sky( world_instance
*world
, vg_camera
*cam
)
807 * Modify matrix to remove clipping and view translation
814 m4x4_copy( cam
->mtx
.v
, v
);
815 m4x4_copy( cam
->mtx_prev
.v
, v_prev
);
817 for( int i
=0; i
<3; i
++ ){
819 v3_normalize(v_prev
[i
]);
822 v3_zero( v_prev
[3] );
824 m4x4_copy( cam
->mtx
.p
, pv
);
825 m4x4_copy( cam
->mtx_prev
.p
, pv_prev
);
826 m4x4_reset_clipping( pv
, 100.0f
, 0.1f
);
827 m4x4_reset_clipping( pv_prev
, 100.0f
, 0.1f
);
829 m4x4_mul( pv
, v
, pv
);
830 m4x4_mul( pv_prev
, v_prev
, pv_prev
);
832 m4x3f identity_matrix
;
833 m4x3_identity( identity_matrix
);
838 if( world
->skybox
== k_skybox_default
){
839 shader_model_sky_use();
840 shader_model_sky_uMdl( identity_matrix
);
841 shader_model_sky_uPv( pv
);
842 shader_model_sky_uPvmPrev( pv_prev
);
843 shader_model_sky_uTexGarbage(0);
844 world_link_lighting_ub( world
, _shader_model_sky
.id
);
846 glActiveTexture( GL_TEXTURE0
);
847 glBindTexture( GL_TEXTURE_2D
, world_render
.tex_terrain_noise
);
849 else if( world
->skybox
== k_skybox_space
){
850 shader_model_sky_space_use();
852 shader_model_sky_space_uMdl( identity_matrix
);
853 shader_model_sky_space_uPv( pv
);
854 shader_model_sky_space_uPvmPrev( pv_prev
);
855 shader_model_sky_space_uTexGarbage(0);
856 world_link_lighting_ub( world
, _shader_model_sky_space
.id
);
858 glActiveTexture( GL_TEXTURE0
);
859 glBindTexture( GL_TEXTURE_2D
, world_render
.tex_terrain_noise
);
862 vg_fatal_error( "Programming error\n" );
865 glDepthMask( GL_FALSE
);
866 glDisable( GL_DEPTH_TEST
);
868 mesh_bind( &world_render
.skydome
);
869 mesh_draw( &world_render
.skydome
);
871 glEnable( GL_DEPTH_TEST
);
872 glDepthMask( GL_TRUE
);
875 void render_world_gates( world_instance
*world
, vg_camera
*cam
)
877 float closest
= INFINITY
;
878 struct ent_gate
*gate
= NULL
;
880 for( u32 i
=0; i
<mdl_arrcount(&world
->ent_gate
); i
++ ){
881 ent_gate
*gi
= mdl_arritm( &world
->ent_gate
, i
);
883 if( !(gi
->flags
& k_ent_gate_nonlocal
) )
884 if( !(gi
->flags
& k_ent_gate_linked
) )
887 float dist
= v3_dist2( gi
->co
[0], cam
->transform
[3] );
889 vg_line_point( gi
->co
[0], 0.25f
, VG__BLUE
);
891 if( dist
< closest
){
897 world
->rendering_gate
= gate
;
900 if( gate
->flags
& k_ent_gate_locked
){
901 world
->rendering_gate
= NULL
;
905 if( gate
->flags
& k_ent_gate_nonlocal
){
906 if( !(gate
->flags
& k_ent_gate_linked
) ||
907 (world_static
.load_state
!= k_world_loader_none
) ){
908 world
->rendering_gate
= NULL
;
909 render_gate_unlinked( world
, gate
, cam
);
913 world_instance
*dest_world
= &world_static
.instances
[ gate
->target
];
914 render_gate( world
, dest_world
, gate
, cam
);
917 render_gate( world
, world
, gate
, cam
);
921 void world_prerender( world_instance
*world
)
923 if( mdl_arrcount( &world
->ent_light
) ){
924 f32 rate
= vg_maxf(0.1f
, fabsf(k_day_length
)) * vg_signf(k_day_length
);
925 world
->time
+= vg
.time_frame_delta
* (1.0/(rate
*60.0));
931 if( world
->info
.flags
& 0x1 ){
932 world
->time
= world
->info
.timezone
;
935 struct ub_world_lighting
*state
= &world
->ub_lighting
;
937 state
->g_time
= world
->time
;
938 state
->g_realtime
= vg
.time_real
;
939 state
->g_debug_indices
= k_debug_light_indices
;
940 state
->g_light_preview
= k_light_preview
;
941 state
->g_debug_complexity
= k_debug_light_complexity
;
942 state
->g_time_of_day
= vg_fractf( world
->time
);
944 if( vg
.quality_profile
== k_quality_profile_high
)
945 state
->g_shadow_samples
= 8;
946 else if( vg
.quality_profile
== k_quality_profile_low
)
947 state
->g_shadow_samples
= 2;
949 state
->g_shadow_samples
= 0;
951 state
->g_day_phase
= cosf( state
->g_time_of_day
* VG_PIf
* 2.0f
);
952 state
->g_sunset_phase
= cosf( state
->g_time_of_day
* VG_PIf
* 4.0f
+ VG_PIf
);
954 state
->g_day_phase
= state
->g_day_phase
* 0.5f
+ 0.5f
;
955 state
->g_sunset_phase
= powf( state
->g_sunset_phase
* 0.5f
+ 0.5f
, 6.0f
);
957 float a
= state
->g_time_of_day
* VG_PIf
* 2.0f
;
958 state
->g_sun_dir
[0] = sinf( a
);
959 state
->g_sun_dir
[1] = cosf( a
);
960 state
->g_sun_dir
[2] = 0.2f
;
961 v3_normalize( state
->g_sun_dir
);
963 world
->probabilities
[ k_probability_curve_constant
] = 1.0f
;
964 float dp
= state
->g_day_phase
;
966 world
->probabilities
[ k_probability_curve_wildlife_day
] =
967 (dp
*dp
*0.8f
+state
->g_sunset_phase
)*0.8f
;
968 world
->probabilities
[ k_probability_curve_wildlife_night
] =
969 1.0f
-powf(fabsf((state
->g_time_of_day
-0.5f
)*5.0f
),5.0f
);
971 glBindBuffer( GL_UNIFORM_BUFFER
, world
->ubo_lighting
);
972 glBufferSubData( GL_UNIFORM_BUFFER
, 0,
973 sizeof(struct ub_world_lighting
), &world
->ub_lighting
);
976 static void render_other_entities( world_instance
*world
, vg_camera
*cam
)
980 bh_iter_init_range( 0, &it
, cam
->pos
, radius
+10.0f
);
988 while( bh_next( world
->entity_bh
, &it
, &idx
) ){
989 u32 id
= world
->entity_list
[ idx
],
990 type
= mdl_entity_id_type( id
),
991 index
= mdl_entity_id_id( id
);
993 if( type
== k_ent_glider
)
995 if( glider_count
< vg_list_size(glider_list
) )
996 glider_list
[ glider_count
++ ] = index
;
998 else if( type
== k_ent_npc
)
1000 if( npc_count
< vg_list_size(npc_list
) )
1001 npc_list
[ npc_count
++ ] = index
;
1005 shader_model_entity_use();
1006 shader_model_entity_uTexMain( 0 );
1007 shader_model_entity_uCamera( cam
->transform
[3] );
1008 shader_model_entity_uPv( cam
->mtx
.pv
);
1009 WORLD_BIND_LIGHT_BUFFERS_UB0_TEX234( world
, model_entity
);
1011 for( u32 j
=0; j
<glider_count
; j
++ )
1013 ent_glider
*glider
= mdl_arritm( &world
->ent_glider
, glider_list
[j
] );
1015 if( !(glider
->flags
& 0x1) )
1019 mdl_transform_m4x3( &glider
->transform
, mdl
);
1021 f32 dist
= v3_dist( glider
->transform
.co
, cam
->pos
) * (1.0f
/radius
),
1022 scale
= vg_smoothstepf( vg_clampf( 5.0f
-dist
*5.0f
, 0.0f
,1.0f
) );
1023 m3x3_scalef( mdl
, scale
);
1025 render_glider_model( cam
, world
, mdl
, k_board_shader_entity
);
1028 for( u32 j
=0; j
<npc_count
; j
++ )
1030 u32 index
= npc_list
[j
];
1031 ent_npc
*npc
= mdl_arritm( &world
->ent_npc
, npc_list
[j
] );
1033 npc_render( npc
, world
, cam
);
1037 void render_world( world_instance
*world
, vg_camera
*cam
,
1038 int stenciled
, int viewing_from_gate
,
1039 int with_water
, int with_cubemaps
)
1042 glClear( GL_DEPTH_BUFFER_BIT
);
1043 glStencilFunc( GL_EQUAL
, 1, 0xFF );
1044 glStencilMask( 0x00 );
1045 glEnable( GL_CULL_FACE
);
1046 glEnable( GL_STENCIL_TEST
);
1049 glStencilMask( 0xFF );
1050 glStencilFunc( GL_ALWAYS
, 1, 0xFF );
1051 glDisable( GL_STENCIL_TEST
);
1054 render_sky( world
, cam
);
1057 m4x3_identity(identity
);
1058 render_world_routes( world
, world
, identity
, cam
, viewing_from_gate
, 0 );
1059 render_world_standard( world
, cam
);
1060 render_world_cubemapped( world
, cam
, with_cubemaps
);
1062 render_world_vb( world
, cam
);
1063 render_world_alphatest( world
, cam
);
1064 render_world_foliage( world
, cam
);
1065 render_terrain( world
, cam
);
1067 if( !viewing_from_gate
){
1068 world_entity_focus_render();
1072 float min_dist
= INFINITY
;
1074 if( mdl_arrcount( &world
->ent_route
) ){
1075 for( u32 i
=0; i
<mdl_arrcount( &world
->ent_route
); i
++ ){
1076 ent_route
*route
= mdl_arritm( &world
->ent_route
, i
);
1077 float dist
= v3_dist2( route
->board_transform
[3], cam
->pos
);
1079 if( dist
< min_dist
){
1085 ent_route
*route
= mdl_arritm( &world
->ent_route
, closest
);
1086 sfd_render( world
, cam
, route
->board_transform
);
1090 if( !viewing_from_gate
){
1092 if( mdl_entity_id_type(world_static
.focused_entity
) == k_ent_challenge
)
1093 greyout
= world_static
.focus_strength
;
1095 if( greyout
> 0.0f
){
1096 glDrawBuffers( 1, (GLenum
[]){ GL_COLOR_ATTACHMENT0
} );
1098 glDisable(GL_DEPTH_TEST
);
1099 glDepthMask(GL_FALSE
);
1100 glBlendFunc(GL_SRC_ALPHA
, GL_ONE_MINUS_SRC_ALPHA
);
1101 glBlendEquation(GL_FUNC_ADD
);
1103 shader_blitcolour_use();
1104 shader_blitcolour_uColour( (v4f
){ 0.5f
, 0.5f
, 0.5f
, greyout
*0.56f
} );
1107 glDisable(GL_BLEND
);
1108 glEnable(GL_DEPTH_TEST
);
1109 glDepthMask(GL_TRUE
);
1110 glDrawBuffers( 2, (GLenum
[]){ GL_COLOR_ATTACHMENT0
,
1111 GL_COLOR_ATTACHMENT1
} );
1114 render_world_fxglow( world
, world
, cam
, NULL
, 1, 1, 0 );
1118 render_water_texture( world
, cam
);
1119 render_fb_bind( gpipeline
.fb_main
, 1 );
1123 glStencilFunc( GL_EQUAL
, 1, 0xFF );
1124 glStencilMask( 0x00 );
1125 glEnable( GL_CULL_FACE
);
1126 glEnable( GL_STENCIL_TEST
);
1130 render_water_surface( world
, cam
);
1133 render_remote_players( world
, cam
);
1134 render_other_entities( world
, cam
);
1135 ent_miniworld_render( world
, cam
);
1138 glStencilMask( 0xFF );
1139 glStencilFunc( GL_ALWAYS
, 1, 0xFF );
1140 glDisable( GL_STENCIL_TEST
);
1145 static void render_world_override_pass( world_instance
*world
,
1146 struct world_pass
*pass
,
1147 m4x3f mmdl
, m3x3f mnormal
,
1150 for( int i
=0; i
<world
->surface_count
; i
++ )
1152 struct world_surface
*mat
= &world
->surfaces
[i
];
1153 if( mat
->info
.flags
& k_material_flag_ghosts
) continue;
1156 if( pass
->geo_type
== k_world_geo_type_solid
)
1159 sm
= &mat
->sm_no_collide
;
1161 if( !sm
->indice_count
)
1164 pass
->fn_set_mdl( mmdl
);
1165 pass
->fn_set_uNormalMtx( mnormal
);
1166 pass
->fn_set_uPvmPrev( mpvm_prev
);
1167 pass
->fn_bind( world
, mat
);
1168 mdl_draw_submesh( sm
);
1172 void render_world_override( world_instance
*world
,
1173 world_instance
*lighting_source
,
1176 ent_spawn
*dest_spawn
, v4f map_info
)
1178 struct world_pass pass
=
1181 .fn_bind
= bindpoint_override
,
1182 .fn_set_mdl
= shader_scene_override_uMdl
,
1183 .fn_set_uPvmPrev
= shader_scene_override_uPvmPrev
,
1184 .fn_set_uNormalMtx
= shader_scene_override_uNormalMtx
,
1185 .shader
= k_shader_override
1188 shader_scene_override_use();
1189 shader_scene_override_uTexGarbage(0);
1190 shader_scene_override_uTexMain(1);
1191 shader_scene_override_uPv( pass
.cam
->mtx
.pv
);
1192 shader_scene_override_uMapInfo( map_info
);
1194 WORLD_BIND_LIGHT_BUFFERS_UB0_TEX234( lighting_source
, scene_override
);
1195 bind_terrain_noise();
1197 shader_scene_override_uCamera( pass
.cam
->transform
[3] );
1200 m4x3_expand( mmdl
, mpvm_prev
);
1201 m4x4_mul( cam
->mtx_prev
.pv
, mpvm_prev
, mpvm_prev
);
1204 m3x3_inv( mmdl
, mnormal
);
1205 m3x3_transpose( mnormal
, mnormal
);
1206 v3_normalize( mnormal
[0] );
1207 v3_normalize( mnormal
[1] );
1208 v3_normalize( mnormal
[2] );
1210 v4f uPlayerPos
, uSpawnPos
;
1211 v4_zero( uPlayerPos
);
1212 v4_zero( uSpawnPos
);
1214 v3_copy( world
->player_co
, uPlayerPos
);
1216 if( dest_spawn
&& (v3_dist2(dest_spawn
->transform
.co
,uPlayerPos
) > 0.1f
) )
1217 v3_copy( dest_spawn
->transform
.co
, uSpawnPos
);
1219 v3_add( uPlayerPos
, (v3f
){0,-1,0}, uSpawnPos
);
1221 uPlayerPos
[3] = v3_dist(uPlayerPos
,uSpawnPos
);
1222 uSpawnPos
[3] = 1.0f
/uPlayerPos
[3];
1224 shader_scene_override_uPlayerPos( uPlayerPos
);
1225 shader_scene_override_uSpawnPos( uSpawnPos
);
1228 glDisable( GL_CULL_FACE
);
1229 mesh_bind( &world
->mesh_geo
);
1230 pass
.geo_type
= k_world_geo_type_solid
;
1231 render_world_override_pass( world
, &pass
, mmdl
, mnormal
, mpvm_prev
);
1232 mesh_bind( &world
->mesh_no_collide
);
1233 pass
.geo_type
= k_world_geo_type_nonsolid
;
1234 render_world_override_pass( world
, &pass
, mmdl
, mnormal
, mpvm_prev
);
1235 glEnable( GL_CULL_FACE
);
1237 render_world_fxglow( world
, world
, cam
, mmdl
, 0, 0, 1 );
1240 static void render_cubemap_side( world_instance
*world
, ent_cubemap
*cm
,
1243 glFramebufferTexture2D( GL_FRAMEBUFFER
, GL_COLOR_ATTACHMENT0
,
1244 GL_TEXTURE_CUBE_MAP_POSITIVE_X
+ side
, cm
->texture_id
, 0 );
1245 glClear( GL_DEPTH_BUFFER_BIT
);
1248 { -1.0f
, 0.0f
, 0.0f
},
1249 { 1.0f
, 0.0f
, 0.0f
},
1250 { 0.0f
, -1.0f
, 0.0f
},
1251 { 0.0f
, 1.0f
, 0.0f
},
1252 { 0.0f
, 0.0f
, -1.0f
},
1253 { 0.0f
, 0.0f
, 1.0f
}
1256 { 0.0f
, -1.0f
, 0.0f
},
1257 { 0.0f
, -1.0f
, 0.0f
},
1258 { 0.0f
, 0.0f
, 1.0f
},
1259 { 0.0f
, 0.0f
, -1.0f
},
1260 { 0.0f
, -1.0f
, 0.0f
},
1261 { 0.0f
, -1.0f
, 0.0f
}
1264 v3_zero( cam
.angles
);
1265 v3_copy( cm
->co
, cam
.pos
);
1267 v3_copy( forward
[side
], cam
.transform
[2] );
1268 v3_copy( up
[side
], cam
.transform
[1] );
1269 v3_cross( up
[side
], forward
[side
], cam
.transform
[0] );
1270 v3_copy( cm
->co
, cam
.transform
[3] );
1271 m4x3_invert_affine( cam
.transform
, cam
.transform_inverse
);
1273 vg_camera_update_view( &cam
);
1278 m4x4_copy( cam
.mtx
.p
, cam
.mtx_prev
.p
);
1279 m4x4_projection( cam
.mtx
.p
, cam
.fov
, 1.0f
, cam
.nearz
, cam
.farz
);
1280 vg_camera_finalize( &cam
);
1281 vg_camera_finalize( &cam
);
1283 render_world( world
, &cam
, 0, 1, 1, 0 );
1286 void render_world_cubemaps( world_instance
*world
)
1288 if( world
->cubemap_cooldown
)
1289 world
->cubemap_cooldown
--;
1291 world
->cubemap_cooldown
= 60;
1293 glViewport( 0, 0, WORLD_CUBEMAP_RES
, WORLD_CUBEMAP_RES
);
1294 for( u32 i
=0; i
<mdl_arrcount( &world
->ent_cubemap
); i
++ ){
1295 ent_cubemap
*cm
= mdl_arritm( &world
->ent_cubemap
, i
);
1296 glBindFramebuffer( GL_FRAMEBUFFER
, cm
->framebuffer_id
);
1298 world
->cubemap_side
++;
1299 if( world
->cubemap_side
>= 6 )
1300 world
->cubemap_side
= 0;
1302 render_cubemap_side( world
, cm
, world
->cubemap_side
);
1309 * ---------------------------------------------
1312 void render_world_depth( world_instance
*world
, vg_camera
*cam
)
1314 m4x3f identity_matrix
;
1315 m4x3_identity( identity_matrix
);
1317 shader_scene_depth_use();
1318 shader_scene_depth_uCamera( cam
->transform
[3] );
1319 shader_scene_depth_uPv( cam
->mtx
.pv
);
1320 shader_scene_depth_uPvmPrev( cam
->mtx_prev
.pv
);
1321 shader_scene_depth_uMdl( identity_matrix
);
1322 world_link_lighting_ub( world
, _shader_scene_depth
.id
);
1324 mesh_bind( &world
->mesh_geo
);
1325 mesh_draw( &world
->mesh_geo
);
1328 void render_world_position( world_instance
*world
, vg_camera
*cam
)
1330 m4x3f identity_matrix
;
1331 m4x3_identity( identity_matrix
);
1333 shader_scene_position_use();
1334 shader_scene_position_uCamera( cam
->transform
[3] );
1335 shader_scene_position_uPv( cam
->mtx
.pv
);
1336 shader_scene_position_uPvmPrev( cam
->mtx_prev
.pv
);
1337 shader_scene_position_uMdl( identity_matrix
);
1338 world_link_lighting_ub( world
, _shader_scene_position
.id
);
1340 mesh_bind( &world
->mesh_geo
);
1341 mesh_draw( &world
->mesh_geo
);
1344 struct ui_enum_opt skybox_setting_options
[] = {
1345 { 0, "g_daysky_colour" },
1346 { 1, "g_nightsky_colour" },
1347 { 2, "g_sunset_colour" },
1348 { 3, "g_ambient_colour" },
1349 { 4, "g_sun_colour" },
1352 static f32
*skybox_prop_location( world_instance
*world
, i32 index
){
1354 case 0: return world
->ub_lighting
.g_daysky_colour
; break;
1355 case 1: return world
->ub_lighting
.g_nightsky_colour
; break;
1356 case 2: return world
->ub_lighting
.g_sunset_colour
; break;
1357 case 3: return world
->ub_lighting
.g_ambient_colour
; break;
1358 case 4: return world
->ub_lighting
.g_sun_colour
; break;
1359 default: return NULL
;
1363 void imgui_world_light_edit( world_instance
*world
)
1365 ui_rect panel
= { vg
.window_x
-400, 0, 400, vg
.window_y
};
1366 ui_fill( panel
, ui_colour( k_ui_bg
+1 ) );
1367 ui_outline( panel
, 1, ui_colour( k_ui_bg
+7 ), 0 );
1368 ui_rect_pad( panel
, (ui_px
[2]){ 8, 8 } );
1369 vg_ui
.wants_mouse
= 1;
1371 static i32 option_to_edit
= 0;
1372 ui_enum( panel
, "option", skybox_setting_options
, 5, &option_to_edit
);
1373 ui_colourpicker( panel
, "colour",
1374 skybox_prop_location( world
, option_to_edit
) );
1376 if( ui_button( panel
, "save tweaker file ('/tmp/tweaker.txt')\n" ) == 1 ){
1377 FILE *fp
= fopen( "/tmp/tweaker.txt", "w" );
1379 for( i32 i
=0; i
<5; i
++ ){
1380 struct ui_enum_opt
*opt
= &skybox_setting_options
[i
];
1381 f32
*val
= skybox_prop_location( world
, i
);
1382 fprintf( fp
, "%s = {%.3ff, %.3ff, %.3ff, %.3ff},\n",
1383 opt
->alias
, val
[0], val
[1], val
[2], val
[3] );