update helpers/location to 'frosted' ui
[carveJwlIkooP6JGAAIwe30JlM.git] / world_render.h
index 32a15baeddd6e0bdf84769f41f2c88b4ec73adc0..846e2d83f7f53694147231ca09a02b2246a3caaf 100644 (file)
 /*
- * 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
-
-#include "world.h"
-
-vg_tex2d tex_terrain_colours = { .path = "textures/gradients.qoi",
-                                 .flags = VG_TEXTURE_CLAMP|VG_TEXTURE_NEAREST };
-
-vg_tex2d tex_terrain_noise = { .path = "textures/garbage.qoi",
-                                 .flags = VG_TEXTURE_NEAREST };
-
-vg_tex2d tex_alphatest = { .path = "textures/alphatest.qoi",
-                                 .flags = VG_TEXTURE_NEAREST };
-
-vg_tex2d tex_graffiti = { .path = "textures/graffitibox.qoi",
-                                 .flags = VG_TEXTURE_NEAREST };
-
-static void world_render_init(void)
-{
-   vg_info( "Loading default world textures\n" );
-
-   vg_acquire_thread_sync();
-   {
-      vg_tex2d_init( (vg_tex2d *[]){ &tex_terrain_colours, 
-                                     &tex_terrain_noise,
-                                     &tex_alphatest,
-                                     &tex_graffiti }, 4 );
-   }
-   vg_release_thread_sync();
-}
-
-static void world_render_free(void*_)
-{
-   vg_tex2d_free( (vg_tex2d *[]){ &tex_terrain_colours, 
-                                  &tex_terrain_noise,
-                                  &tex_alphatest,
-                                  &tex_graffiti }, 4 );
-}
-
-
-
-static void render_world_depth( m4x4f projection, m4x3f camera );
-
-
+#pragma once
 
+#define WORLD_CUBEMAP_RES 32
 
-/*
- * Rendering
- */
-
-static void bind_terrain_textures(void)
-{
-   vg_tex2d_bind( &tex_terrain_noise, 0 );
-   vg_tex2d_bind( &tex_terrain_colours, 1 );
-}
-
-static void render_world_vb( m4x4f projection, v3f camera )
+#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
 {
-   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 );
-   bind_terrain_textures();
+   GLuint tex_terrain_noise;
 
-   shader_vblend_uPv( projection );
-   shader_vblend_uMdl( identity_matrix );
-   shader_vblend_uCamera( camera );
+   /* rendering */
+   glmesh skydome;
 
-   scene_bind( &world.geo );
-   mdl_draw_submesh( &world.sm_geo_vb );
+   double sky_time, sky_rate, sky_target_rate;
 
-   mesh_bind( &world.cars );
-
-#if 0
-   for( int i=0; i<vg_list_size(world.van_man); i++ )
-   {
-      shader_vblend_uMdl( world.van_man[i].transform );
-      mdl_draw_submesh( &world.car_holden );
+   /* water rendering */
+   struct{
+      struct framebuffer fbreflect, fbdepth;
    }
-#endif
-}
-
-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 );
-
-   vg_tex2d_bind( &tex_terrain_noise, 0 );
-   vg_tex2d_bind( &tex_alphatest, 1 );
-
-   shader_alphatest_uPv( projection );
-   shader_alphatest_uMdl( identity_matrix );
-   shader_alphatest_uCamera( camera );
-
-   glDisable(GL_CULL_FACE);
-   scene_bind( &world.foliage );
-   mdl_draw_submesh( &world.sm_foliage_alphatest );
-
-   vg_tex2d_bind( &tex_graffiti, 1 );
-   mdl_draw_submesh( &world.sm_graffiti );
-
-   glEnable(GL_CULL_FACE);
-}
-
-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 );
-   bind_terrain_textures();
-
-   shader_terrain_uPv( projection );
-   shader_terrain_uMdl( identity_matrix );
-   shader_terrain_uCamera( camera );
-
-   scene_bind( &world.geo );
-   mdl_draw_submesh( &world.sm_terrain );
-   mdl_draw_submesh( &world.sm_geo_std_oob );
-   mdl_draw_submesh( &world.sm_geo_std );
-   mdl_draw_submesh( &world.sm_subworld );
-
-   /* TODO: Dont draw in reflection */
-   glDisable(GL_CULL_FACE);
-   scene_bind( &world.foliage );
-   mdl_draw_submesh( &world.sm_foliage_main );
-   glEnable(GL_CULL_FACE);
-}
-
-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 );
-}
-
-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 );
-}
-
-static void render_world_gates( m4x4f projection, v3f playerco, m4x3f camera )
-{
-   float closest = INFINITY;
-   int   id = 0;
-
-   for( int i=0; i<world.routes.gate_count; i++ )
-   {
-      struct route_gate *rg = &world.routes.gates[i];
-      float dist = v3_dist2( rg->gate.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.routes.gates[id].gate, playerco, camera );
-   v3_lerp( world.render_gate_pos, 
-            world.routes.gates[id].gate.co[0],
-            1.0f,
-            world.render_gate_pos );
-}
-
-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;
-
-   for( int i=0; i<world.routes.route_count; i++ )
-   {
-      float dist = v3_dist2( world.routes.routes[i].scoreboard_transform[3],
-                              camera[3] );
-
-      if( dist < min_dist )
-      {
-         min_dist = dist;
-         closest = i;
-      }
+   timer_texts[4];
+   u32 timer_text_count;
+
+   struct text_particle{
+      rigidbody rb;
+      m4x3f mlocal;
+      ent_glyph *glyph;
+      v4f colour;
+      m4x3f mdl;
+      f32 radius;
    }
-
-   sfd_render( &world.sfd.tester, projection, camera[3], 
-         world.routes.routes[closest].scoreboard_transform );
-}
-
-static void render_world_depth( m4x4f projection, m4x3f camera )
-{
-   m4x3f identity_matrix;
-   m4x3_identity( identity_matrix );
-
-   shader_gpos_use();
-   shader_gpos_uCamera( camera[3] );
-   shader_gpos_uPv( projection );
-   shader_gpos_uMdl( identity_matrix );
-   
-   scene_bind( &world.geo );
-   scene_draw( &world.geo );
-
-#if 0
-   glDisable(GL_CULL_FACE);
-   scene_bind( &world.foliage );
-   scene_draw( &world.foliage );
-   glEnable(GL_CULL_FACE);
-#endif
+   text_particles[6*4];
+   u32 text_particle_count;
 }
+extern world_render;
+
+void world_render_init(void);
+
+void world_prerender( world_instance *world );
+void world_link_lighting_ub( world_instance *world, GLuint shader );
+void world_bind_position_texture( world_instance *world, 
+                                  GLuint shader, GLuint location,
+                                  int slot );
+void world_bind_light_array( world_instance *world,
+                             GLuint shader, GLuint location, 
+                             int slot );
+void world_bind_light_index( world_instance *world,
+                             GLuint shader, GLuint location,
+                             int slot );
+void render_world_position( world_instance *world, vg_camera *cam );
+void render_world_depth( world_instance *world, vg_camera *cam );
+void render_world( world_instance *world, vg_camera *cam,
+                   int stenciled, int viewing_from_gate, 
+                   int with_water, int with_cubemaps );
+void render_world_cubemaps( world_instance *world );
+void bind_terrain_noise(void);
+void render_world_override( world_instance *world,
+                            world_instance *lighting_source,
+                            m4x3f mmdl,
+                            vg_camera *cam,
+                            ent_spawn *dest_spawn, v4f map_info );
+void render_world_gates( world_instance *world, vg_camera *cam );
+void imgui_world_light_edit( world_instance *world );
+
+#define WORLD_BIND_LIGHT_BUFFERS_UB0_TEX234( WORLD, SHADER )            \
+   world_link_lighting_ub( WORLD, _shader_##SHADER.id );                \
+   world_bind_position_texture( WORLD, _shader_##SHADER.id,             \
+                                _uniform_##SHADER##_g_world_depth, 2 ); \
+   world_bind_light_array( WORLD, _shader_##SHADER.id,                  \
+                           _uniform_##SHADER##_uLightsArray, 3 );       \
+   world_bind_light_index( WORLD, _shader_##SHADER.id,                  \
+                           _uniform_##SHADER##_uLightsIndex, 4 );
 
-#endif /* WORLD_RENDER_H */