shader overrides
authorhgn <hgodden00@gmail.com>
Thu, 23 Nov 2023 07:56:44 +0000 (07:56 +0000)
committerhgn <hgodden00@gmail.com>
Thu, 23 Nov 2023 07:56:44 +0000 (07:56 +0000)
ent_miniworld.c
maps_src/dev_hub/main.mdl
maps_src/mp_mtzero/main.mdl
maps_src/mp_spawn/main.mdl
shaders/scene_override.fs
shaders/scene_override.h
skaterift.c
world.h
world_entity.c
world_render.c
world_render.h

index af4d66810164b8b98d054719608effa45bd09118..e425fa2da2212d24651e1cf91a0f56496c23ee81 100644 (file)
@@ -87,7 +87,7 @@ static void ent_miniworld_render( world_instance *host_world, camera *cam ){
       return;
 
    render_world_override( dest_world, host_world, global_miniworld.mmdl, cam,
-                          NULL, 0.0f );
+                          NULL, (v4f){-10000.0f,10000.0f,0.0f,0.0f} );
    render_world_routes( dest_world, host_world, 
                         global_miniworld.mmdl, cam, 0, 1 );
 
index 4eecbcaa1d11de15079809d61c09500b07af41fd..49a245ef1d089420f80ceae1fd7c19a9e863f6b3 100644 (file)
Binary files a/maps_src/dev_hub/main.mdl and b/maps_src/dev_hub/main.mdl differ
index fd22f643d97b500bcf9b5e5827c9321b27e80753..40e488eaa5fe885e69f04add5e3b2a8c28c43624 100644 (file)
Binary files a/maps_src/mp_mtzero/main.mdl and b/maps_src/mp_mtzero/main.mdl differ
index e195aa6b97d9c8a2c3a022cfbcbc51dd6b04530b..c42dc1bd4172d0c26e9171f12aed12c22f4d105e 100644 (file)
Binary files a/maps_src/mp_spawn/main.mdl and b/maps_src/mp_spawn/main.mdl differ
index 237fe6b49adfc2055ed3673e1004c50311543d6a..42e97b47fab9168214df4fa5844f087efd87d6e0 100644 (file)
@@ -6,7 +6,7 @@ uniform vec4 uPlane;
 uniform vec4 uPlayerPos; /* w: distance to uSpawnPos */
 uniform vec4 uSpawnPos;  /* w: inverse distance to uPlayerPos */
 uniform bool uAlphatest;
-uniform float uIsoAmt;
+uniform vec4 uMapInfo; /* x: min, y: max, z: iso line amount */
 
 #include "common_scene.glsl"
 #include "motion_vectors_fs.glsl"
@@ -28,7 +28,11 @@ void main(){
    float dither = fract( vDither.g / 71.0 ) - 0.5;
 
    float dcam = (-8.0+distance( aCo, uCamera ))/4.0;
-   if( min(aCo.y*0.5 + dither, dcam + dither) < 0.51 ) discard;
+   float dy0 = aCo.y - uMapInfo.x;
+   float dy1 = uMapInfo.y - aCo.y;
+
+   if( min(min(dy0,dy1)*0.5, dcam) + dither < 0.51 ) 
+      discard;
 
    compute_motion_vectors();
 
@@ -67,10 +71,10 @@ void main(){
 
    vfrag += emit;
 
-   if( uIsoAmt > 0.0 ){
+   if( uMapInfo.z > 0.0 ){
       float height = fract( aCo.y * 0.1 );
       float lg = 2.0*length(vec2(dFdx(height), dFdy(height)));
-      vfrag *= 1.0f+(lg*0.2*uIsoAmt);
+      vfrag *= 1.0f+(lg*0.2*uMapInfo.z);
    }
 
    oColour = vec4( vfrag, 1.0 );
index 6ef67c9f589686f2e0c878ab987ac4ef9d5aebfe..602cda4d88053c4127c72b19910acff6cac1b9f4 100644 (file)
@@ -71,7 +71,7 @@ static struct vg_shader _shader_scene_override = {
 "uniform vec4 uPlayerPos; /* w: distance to uSpawnPos */\n"
 "uniform vec4 uSpawnPos;  /* w: inverse distance to uPlayerPos */\n"
 "uniform bool uAlphatest;\n"
-"uniform float uIsoAmt;\n"
+"uniform vec4 uMapInfo; /* x: min, y: max, z: iso line amount */\n"
 "\n"
 "#line       1        1 \n"
 "// :D\n"
@@ -518,10 +518,10 @@ static struct vg_shader _shader_scene_override = {
 "\n"
 "   vfrag += emit;\n"
 "\n"
-"   if( uIsoAmt > 0.0 ){\n"
+"   if( uMapInfo.z > 0.0 ){\n"
 "      float height = fract( aCo.y * 0.1 );\n"
 "      float lg = 2.0*length(vec2(dFdx(height), dFdy(height)));\n"
-"      vfrag *= 1.0f+(lg*0.2*uIsoAmt);\n"
+"      vfrag *= 1.0f+(lg*0.2*uMapInfo.z);\n"
 "   }\n"
 "\n"
 "   oColour = vec4( vfrag, 1.0 );\n"
@@ -541,7 +541,7 @@ static GLuint _uniform_scene_override_uPlane;
 static GLuint _uniform_scene_override_uPlayerPos;
 static GLuint _uniform_scene_override_uSpawnPos;
 static GLuint _uniform_scene_override_uAlphatest;
-static GLuint _uniform_scene_override_uIsoAmt;
+static GLuint _uniform_scene_override_uMapInfo;
 static GLuint _uniform_scene_override_g_world_depth;
 static GLuint _uniform_scene_override_uLightsArray;
 static GLuint _uniform_scene_override_uLightsIndex;
@@ -578,8 +578,8 @@ static void shader_scene_override_uSpawnPos(v4f v){
 static void shader_scene_override_uAlphatest(int b){
    glUniform1i(_uniform_scene_override_uAlphatest,b);
 }
-static void shader_scene_override_uIsoAmt(float f){
-   glUniform1f(_uniform_scene_override_uIsoAmt,f);
+static void shader_scene_override_uMapInfo(v4f v){
+   glUniform4fv(_uniform_scene_override_uMapInfo,1,v);
 }
 static void shader_scene_override_g_world_depth(int i){
    glUniform1i(_uniform_scene_override_g_world_depth,i);
@@ -600,7 +600,7 @@ static void shader_scene_override_link(void){
    _uniform_scene_override_uPlayerPos = glGetUniformLocation( _shader_scene_override.id, "uPlayerPos" );
    _uniform_scene_override_uSpawnPos = glGetUniformLocation( _shader_scene_override.id, "uSpawnPos" );
    _uniform_scene_override_uAlphatest = glGetUniformLocation( _shader_scene_override.id, "uAlphatest" );
-   _uniform_scene_override_uIsoAmt = glGetUniformLocation( _shader_scene_override.id, "uIsoAmt" );
+   _uniform_scene_override_uMapInfo = glGetUniformLocation( _shader_scene_override.id, "uMapInfo" );
    _uniform_scene_override_g_world_depth = glGetUniformLocation( _shader_scene_override.id, "g_world_depth" );
    _uniform_scene_override_uLightsArray = glGetUniformLocation( _shader_scene_override.id, "uLightsArray" );
    _uniform_scene_override_uLightsIndex = glGetUniformLocation( _shader_scene_override.id, "uLightsIndex" );
index c23d022fec2911716c2d79bc3cb4b8efb888f5e0..2bc0e4c7f1384cd7011aee2b4f3a2cedf1dd3349 100644 (file)
@@ -464,7 +464,8 @@ static void render_scene(void){
       m4x3f identity;
       m4x3_identity( identity );
       render_world_override( world, world, identity, &skaterift.cam, 
-                             respawn_chooser.spawn, 1.0f );
+                             respawn_chooser.spawn, 
+                             (v4f){world->tar_min, world->tar_max, 1.0f, 0.0f});
       render_world_routes( world, world, identity, &skaterift.cam, 0, 1 );
       return;
    }
diff --git a/world.h b/world.h
index 0a67abf855df6d9216424243f9730770e945acda..02355013aaf362ac621ddb5cd0839a33c865bd8f 100644 (file)
--- a/world.h
+++ b/world.h
@@ -85,6 +85,7 @@ struct world_instance {
    water;
 
    f64 time;
+   f32 tar_min, tar_max;
 
    /* STD140 */
    struct ub_world_lighting{
index 146683669bc4e5d7512b600c9bb74a8eeaee505c..cbe7432a54aacc1e70b3cc31462d795af348e9c8 100644 (file)
@@ -212,6 +212,19 @@ static void world_gen_entities_init( world_instance *world ){
 
    world->entity_bh = bh_create( world->heap, &bh_system_entity_list, world,
                                  indexed_count, 2 );
+
+   world->tar_min = world->entity_bh->nodes[0].bbx[0][1];
+   world->tar_max = world->entity_bh->nodes[0].bbx[1][1] + 20.0f;
+
+   for( u32 i=0; i<mdl_arrcount(&world->ent_marker); i++ ){
+      ent_marker *marker = mdl_arritm( &world->ent_marker, i );
+
+      if( MDL_CONST_PSTREQ( &world->meta, marker->pstr_alias, "tar_min" ) )
+         world->tar_min = marker->transform.co[1];
+
+      if( MDL_CONST_PSTREQ( &world->meta, marker->pstr_alias, "tar_max" ) )
+         world->tar_max = marker->transform.co[1];
+   }
 }
 
 static
index 3f87a12d1ebdcbdd85a3801a6c798facb5fdd707..04db5a008a123f8314a8447272c88c8007ebaaf7 100644 (file)
@@ -985,7 +985,7 @@ static void render_world_override( world_instance *world,
                                    world_instance *lighting_source,
                                    m4x3f mmdl,
                                    camera *cam,
-                                   ent_spawn *dest_spawn, f32 iso_amt ){
+                                   ent_spawn *dest_spawn, v4f map_info ){
    struct world_pass pass = {
       .cam = cam,
       .fn_bind_textures = bindpoint_override,
@@ -999,7 +999,7 @@ static void render_world_override( world_instance *world,
    shader_scene_override_uTexGarbage(0);
    shader_scene_override_uTexMain(1);
    shader_scene_override_uPv( pass.cam->mtx.pv );
-   shader_scene_override_uIsoAmt( iso_amt );
+   shader_scene_override_uMapInfo( map_info );
 
    WORLD_BIND_LIGHT_BUFFERS_UB0_TEX234( lighting_source, scene_override );
    bind_terrain_noise();
index 402ca60082f94cc69c7436b82b7e8600a590f896..f6d629ddd36f618044f27a1c24b3c6d079e0c84b 100644 (file)
@@ -84,7 +84,7 @@ static void render_world_override( world_instance *world,
                                    world_instance *lighting_source,
                                    m4x3f mmdl,
                                    camera *cam,
-                                   ent_spawn *dest_spawn, f32 iso_amt );
+                                   ent_spawn *dest_spawn, v4f map_info );
 
 #define WORLD_BIND_LIGHT_BUFFERS_UB0_TEX234( WORLD, SHADER )            \
    world_link_lighting_ub( WORLD, _shader_##SHADER.id );                \