6 vg_tex2d tex_terrain_colours
= { .path
= "textures/gradients.qoi",
7 .flags
= VG_TEXTURE_CLAMP
|VG_TEXTURE_NEAREST
};
9 vg_tex2d tex_terrain_noise
= { .path
= "textures/garbage.qoi",
10 .flags
= VG_TEXTURE_NEAREST
};
12 vg_tex2d tex_alphatest
= { .path
= "textures/alphatest.qoi",
13 .flags
= VG_TEXTURE_NEAREST
};
15 vg_tex2d tex_graffiti
= { .path
= "textures/graffitibox.qoi",
16 .flags
= VG_TEXTURE_NEAREST
};
18 static void world_render_init(void)
20 vg_tex2d_init( (vg_tex2d
*[]){ &tex_terrain_colours
,
28 static void render_world_depth( m4x4f projection
, m4x3f camera
);
37 static void bind_terrain_textures(void)
39 vg_tex2d_bind( &tex_terrain_noise
, 0 );
40 vg_tex2d_bind( &tex_terrain_colours
, 1 );
43 static void render_world_vb( m4x4f projection
, v3f camera
)
45 m4x3f identity_matrix
;
46 m4x3_identity( identity_matrix
);
49 shader_vblend_uTexGarbage(0);
50 shader_vblend_uTexGradients(1);
51 shader_link_standard_ub( _shader_vblend
.id
, 2 );
52 bind_terrain_textures();
54 shader_vblend_uPv( projection
);
55 shader_vblend_uMdl( identity_matrix
);
56 shader_vblend_uCamera( camera
);
58 scene_bind( &world
.geo
);
59 mdl_draw_submesh( &world
.sm_geo_vb
);
61 mesh_bind( &world
.cars
);
64 for( int i
=0; i
<vg_list_size(world
.van_man
); i
++ )
66 shader_vblend_uMdl( world
.van_man
[i
].transform
);
67 mdl_draw_submesh( &world
.car_holden
);
72 static void render_world_alphatest( m4x4f projection
, v3f camera
)
74 m4x3f identity_matrix
;
75 m4x3_identity( identity_matrix
);
77 shader_alphatest_use();
78 shader_alphatest_uTexGarbage(0);
79 shader_alphatest_uTexMain(1);
80 shader_link_standard_ub( _shader_alphatest
.id
, 2 );
82 vg_tex2d_bind( &tex_terrain_noise
, 0 );
83 vg_tex2d_bind( &tex_alphatest
, 1 );
85 shader_alphatest_uPv( projection
);
86 shader_alphatest_uMdl( identity_matrix
);
87 shader_alphatest_uCamera( camera
);
89 glDisable(GL_CULL_FACE
);
90 scene_bind( &world
.foliage
);
91 mdl_draw_submesh( &world
.sm_foliage_alphatest
);
93 vg_tex2d_bind( &tex_graffiti
, 1 );
94 mdl_draw_submesh( &world
.sm_graffiti
);
96 glEnable(GL_CULL_FACE
);
99 static void render_terrain( m4x4f projection
, v3f camera
)
101 m4x3f identity_matrix
;
102 m4x3_identity( identity_matrix
);
104 shader_terrain_use();
105 shader_terrain_uTexGarbage(0);
106 shader_terrain_uTexGradients(1);
107 shader_link_standard_ub( _shader_terrain
.id
, 2 );
108 bind_terrain_textures();
110 shader_terrain_uPv( projection
);
111 shader_terrain_uMdl( identity_matrix
);
112 shader_terrain_uCamera( camera
);
114 scene_bind( &world
.geo
);
115 mdl_draw_submesh( &world
.sm_terrain
);
116 mdl_draw_submesh( &world
.sm_geo_std_oob
);
117 mdl_draw_submesh( &world
.sm_geo_std
);
118 mdl_draw_submesh( &world
.sm_subworld
);
120 /* TODO: Dont draw in reflection */
121 glDisable(GL_CULL_FACE
);
122 scene_bind( &world
.foliage
);
123 mdl_draw_submesh( &world
.sm_foliage_main
);
124 glEnable(GL_CULL_FACE
);
127 static void render_lowerdome( m4x3f camera
)
129 m4x4f projection
, full
;
130 pipeline_projection( projection
, 0.4f
, 1000.0f
);
133 m3x3_transpose( camera
, inverse
);
134 v3_copy((v3f
){0.0f
,0.0f
,0.0f
}, inverse
[3]);
135 m4x3_expand( inverse
, full
);
136 m4x4_mul( projection
, full
, full
);
138 m4x3f identity_matrix
;
139 m4x3_identity( identity_matrix
);
141 shader_planeinf_use();
142 shader_planeinf_uMdl(identity_matrix
);
143 shader_planeinf_uPv(full
);
144 shader_planeinf_uCamera(camera
[3]);
145 shader_planeinf_uPlane( (v4f
){0.0f
,1.0f
,0.0f
,0.0f
} );
147 mdl_draw_submesh( &world
.dome_lower
);
150 static void render_sky(m4x3f camera
)
152 m4x4f projection
, full
;
153 pipeline_projection( projection
, 0.4f
, 1000.0f
);
156 m3x3_transpose( camera
, inverse
);
157 v3_copy((v3f
){0.0f
,0.0f
,0.0f
}, inverse
[3]);
158 m4x3_expand( inverse
, full
);
159 m4x4_mul( projection
, full
, full
);
161 m4x3f identity_matrix
;
162 m4x3_identity( identity_matrix
);
165 shader_sky_uMdl(identity_matrix
);
166 shader_sky_uPv(full
);
167 shader_sky_uTexGarbage(0);
168 shader_sky_uTime( vg_time
);
170 vg_tex2d_bind( &tex_terrain_noise
, 0 );
172 glDepthMask( GL_FALSE
);
173 glDisable( GL_DEPTH_TEST
);
175 mesh_bind( &world
.skydome
);
176 mdl_draw_submesh( &world
.dome_upper
);
178 glEnable( GL_DEPTH_TEST
);
179 glDepthMask( GL_TRUE
);
182 static void render_world_gates( m4x4f projection
, v3f playerco
, m4x3f camera
)
184 float closest
= INFINITY
;
187 for( int i
=0; i
<world
.routes
.gate_count
; i
++ )
189 struct route_gate
*rg
= &world
.routes
.gates
[i
];
190 float dist
= v3_dist2( rg
->gate
.co
[0], camera
[3] );
199 render_gate( &world
.routes
.gates
[id
].gate
, playerco
, camera
);
200 v3_lerp( world
.render_gate_pos
,
201 world
.routes
.gates
[id
].gate
.co
[0],
203 world
.render_gate_pos
);
206 static void render_world( m4x4f projection
, m4x3f camera
)
208 render_sky( camera
);
209 render_world_routes( projection
, camera
[3] );
210 render_world_vb( projection
, camera
[3] );
211 render_world_alphatest( projection
, camera
[3] );
212 render_terrain( projection
, camera
[3] );
215 float min_dist
= INFINITY
;
217 for( int i
=0; i
<world
.routes
.route_count
; i
++ )
219 float dist
= v3_dist2( world
.routes
.routes
[i
].scoreboard_transform
[3],
222 if( dist
< min_dist
)
229 sfd_render( &world
.sfd
.tester
, projection
, camera
[3],
230 world
.routes
.routes
[closest
].scoreboard_transform
);
233 static void render_world_depth( m4x4f projection
, m4x3f camera
)
235 m4x3f identity_matrix
;
236 m4x3_identity( identity_matrix
);
239 shader_gpos_uCamera( camera
[3] );
240 shader_gpos_uPv( projection
);
241 shader_gpos_uMdl( identity_matrix
);
243 scene_bind( &world
.geo
);
244 scene_draw( &world
.geo
);
247 glDisable(GL_CULL_FACE
);
248 scene_bind( &world
.foliage
);
249 scene_draw( &world
.foliage
);
250 glEnable(GL_CULL_FACE
);
254 #endif /* WORLD_RENDER_H */