X-Git-Url: https://harrygodden.com/git/?a=blobdiff_plain;f=world_render.h;h=846e2d83f7f53694147231ca09a02b2246a3caaf;hb=5fa590f62aa7e62a8b6b07e10556c2ecc54cdca6;hp=8398a60cd526b5dfb2369bf894e694cdf42d0cf5;hpb=23a1be081ab9e378cba49a23b8ed4d4082b580c1;p=carveJwlIkooP6JGAAIwe30JlM.git diff --git a/world_render.h b/world_render.h index 8398a60..846e2d8 100644 --- a/world_render.h +++ b/world_render.h @@ -1,299 +1,101 @@ /* - * Copyright (C) 2021-2022 Mt.ZERO Software, Harry Godden - All Rights Reserved + * Copyright (C) 2021-2024 Mt.ZERO Software, Harry Godden - All Rights Reserved */ -#ifndef WORLD_RENDER_H -#define WORLD_RENDER_H +#pragma once -#include "world.h" - -vg_tex2d tex_terrain_noise = { .path = "textures/garbage.qoi", - .flags = VG_TEXTURE_NEAREST }; - -VG_STATIC void world_render_init(void) -{ - vg_info( "Loading default world textures\n" ); - - vg_acquire_thread_sync(); - { - vg_tex2d_init( (vg_tex2d *[]){ &tex_terrain_noise }, 1 ); - } - vg_release_thread_sync(); -} - -VG_STATIC void render_world_depth( m4x4f projection, m4x3f camera ); - -/* - * Rendering - */ +#define WORLD_CUBEMAP_RES 32 -VG_STATIC void bind_terrain_noise(void) -{ - vg_tex2d_bind( &tex_terrain_noise, 0 ); -} - -VG_STATIC void world_render_if( enum mdl_shader shader, - enum geo_type geo_type, - void (*bind_point)(struct world_material *mat)) +#include "vg/vg_camera.h" +#include "world.h" +#include "shaders/scene_standard.h" +#include "shaders/scene_standard_alphatest.h" +#include "shaders/scene_foliage.h" +#include "shaders/scene_override.h" +#include "shaders/scene_cubemapped.h" +#include "shaders/scene_vertex_blend.h" +#include "shaders/scene_terrain.h" +#include "shaders/scene_fxglow.h" +#include "shaders/scene_depth.h" +#include "shaders/scene_position.h" +#include "shaders/scene_font.h" +#include "shaders/model_sky.h" +#include "shaders/model_sky_space.h" + +static const float k_world_light_cube_size = 8.0f; + +struct world_render { - - for( int i=0; iinfo.shader == shader ) - { - mdl_submesh *sm; + GLuint tex_terrain_noise; - if( geo_type == k_geo_type_solid ) - sm = &mat->sm_geo; - else - sm = &mat->sm_no_collide; + /* rendering */ + glmesh skydome; - if( !sm->indice_count ) - continue; + double sky_time, sky_rate, sky_target_rate; - bind_point( mat ); - mdl_draw_submesh( sm ); - } + /* water rendering */ + struct{ + struct framebuffer fbreflect, fbdepth; } -} - -VG_STATIC void world_render_both_stages( enum mdl_shader shader, - void (*bind_point)(struct world_material *mat)) -{ - mesh_bind( &world.mesh_geo ); - world_render_if( shader, k_geo_type_solid, bind_point ); - mesh_bind( &world.mesh_no_collide ); - world_render_if( shader, k_geo_type_nonsolid, bind_point ); -} - -VG_STATIC void bindpoint_diffuse_texture1( struct world_material *mat ) -{ - glActiveTexture( GL_TEXTURE1 ); - glBindTexture( GL_TEXTURE_2D, world.textures[ mat->info.tex_diffuse ] ); -} - -VG_STATIC void render_world_vb( m4x4f projection, v3f camera ) -{ - m4x3f identity_matrix; - m4x3_identity( identity_matrix ); - - shader_vblend_use(); - shader_vblend_uTexGarbage(0); - shader_vblend_uTexGradients(1); - shader_link_standard_ub( _shader_vblend.id, 2 ); - vg_tex2d_bind( &tex_terrain_noise, 0 ); - - shader_vblend_uPv( projection ); - shader_vblend_uMdl( identity_matrix ); - shader_vblend_uCamera( camera ); - - world_render_both_stages( k_shader_standard_vertex_blend, - bindpoint_diffuse_texture1 ); -} - -VG_STATIC void render_world_standard( m4x4f projection, v3f camera ) -{ - m4x3f identity_matrix; - m4x3_identity( identity_matrix ); - - shader_standard_use(); - shader_standard_uTexGarbage(0); - shader_standard_uTexMain(1); - shader_link_standard_ub( _shader_standard.id, 2 ); - bind_terrain_noise(); - - shader_standard_uPv( projection ); - shader_standard_uMdl( identity_matrix ); - shader_standard_uCamera( camera ); - - world_render_both_stages( k_shader_standard, - bindpoint_diffuse_texture1 ); -} - -VG_STATIC void render_world_alphatest( m4x4f projection, v3f camera ) -{ - m4x3f identity_matrix; - m4x3_identity( identity_matrix ); - - shader_alphatest_use(); - shader_alphatest_uTexGarbage(0); - shader_alphatest_uTexMain(1); - shader_link_standard_ub( _shader_alphatest.id, 2 ); - bind_terrain_noise(); - - shader_alphatest_uPv( projection ); - shader_alphatest_uMdl( identity_matrix ); - shader_alphatest_uCamera( camera ); - - glDisable(GL_CULL_FACE); - - world_render_both_stages( k_shader_standard_cutout, - bindpoint_diffuse_texture1 ); - - glEnable(GL_CULL_FACE); -} - -VG_STATIC void bindpoint_terrain( struct world_material *mat ) -{ - glActiveTexture( GL_TEXTURE1 ); - glBindTexture( GL_TEXTURE_2D, world.textures[ mat->info.tex_diffuse ] ); - - shader_terrain_uSandColour( mat->info.colour ); - shader_terrain_uBlendOffset( mat->info.colour1 ); -} - -VG_STATIC void render_terrain( m4x4f projection, v3f camera ) -{ - m4x3f identity_matrix; - m4x3_identity( identity_matrix ); - - shader_terrain_use(); - shader_terrain_uTexGarbage(0); - shader_terrain_uTexGradients(1); - shader_link_standard_ub( _shader_terrain.id, 2 ); - - vg_tex2d_bind( &tex_terrain_noise, 0 ); - - shader_terrain_uPv( projection ); - shader_terrain_uMdl( identity_matrix ); - shader_terrain_uCamera( camera ); - - world_render_both_stages( k_shader_terrain_blend, bindpoint_terrain ); -} - -VG_STATIC void render_lowerdome( m4x3f camera ) -{ - m4x4f projection, full; - pipeline_projection( projection, 0.4f, 1000.0f ); - - m4x3f inverse; - m3x3_transpose( camera, inverse ); - v3_copy((v3f){0.0f,0.0f,0.0f}, inverse[3]); - m4x3_expand( inverse, full ); - m4x4_mul( projection, full, full ); - - m4x3f identity_matrix; - m4x3_identity( identity_matrix ); - - shader_planeinf_use(); - shader_planeinf_uMdl(identity_matrix); - shader_planeinf_uPv(full); - shader_planeinf_uCamera(camera[3]); - shader_planeinf_uPlane( (v4f){0.0f,1.0f,0.0f,0.0f} ); - - mdl_draw_submesh( &world.dome_lower ); -} - -VG_STATIC void render_sky(m4x3f camera) -{ - m4x4f projection, full; - pipeline_projection( projection, 0.4f, 1000.0f ); - - m4x3f inverse; - m3x3_transpose( camera, inverse ); - v3_copy((v3f){0.0f,0.0f,0.0f}, inverse[3]); - m4x3_expand( inverse, full ); - m4x4_mul( projection, full, full ); - - m4x3f identity_matrix; - m4x3_identity( identity_matrix ); - - shader_sky_use(); - shader_sky_uMdl(identity_matrix); - shader_sky_uPv(full); - shader_sky_uTexGarbage(0); - shader_sky_uTime( world.sky_time ); - - vg_tex2d_bind( &tex_terrain_noise, 0 ); - - glDepthMask( GL_FALSE ); - glDisable( GL_DEPTH_TEST ); - - mesh_bind( &world.skydome ); - mdl_draw_submesh( &world.dome_upper ); - - glEnable( GL_DEPTH_TEST ); - glDepthMask( GL_TRUE ); -} - -VG_STATIC void render_world_gates( m4x4f projection, v3f playerco, m4x3f camera ) -{ - if( !world.gate_count ) - return; - - float closest = INFINITY; - int id = 0; - - for( int i=0; igate.co[0], camera[3] ); - - if( dist < closest ) - { - closest = dist; - id = i; - } + water; + + v3f render_gate_pos; + struct timer_text{ + char text[8]; + m4x3f transform; + ent_gate *gate; + ent_route *route; } - - render_gate( &world.gates[id].gate, playerco, camera ); - v3_lerp( world.render_gate_pos, - world.gates[id].gate.co[0], - 1.0f, - world.render_gate_pos ); -} - -VG_STATIC void render_world( m4x4f projection, m4x3f camera ) -{ - render_sky( camera ); - render_world_routes( projection, camera[3] ); - render_world_vb( projection, camera[3] ); - render_world_alphatest( projection, camera[3] ); - render_terrain( projection, camera[3] ); - - int closest = 0; - float min_dist = INFINITY; - - if( !world.route_count ) - return; - - for( int i=0; i