From 1142fd5c27cf6d5bef073969b55e20b160646164 Mon Sep 17 00:00:00 2001 From: hgn Date: Fri, 2 Dec 2022 20:52:52 +0000 Subject: [PATCH] fix motion vectors going through gate --- models_src/rs_gate.mdl | Bin 1584 -> 2224 bytes player_physics.h | 9 +++++++++ render.h | 28 ++++++++++++++-------------- shaders/alphatest.h | 6 ++++-- shaders/gpos.h | 4 +++- shaders/menu.h | 4 +++- shaders/motion_vectors_common.glsl | 2 +- shaders/motion_vectors_vs.glsl | 2 ++ shaders/route.h | 6 ++++-- shaders/scoretext.h | 6 ++++-- shaders/sky.h | 6 ++++-- shaders/standard.h | 6 ++++-- shaders/terrain.h | 6 ++++-- shaders/vblend.h | 6 ++++-- shaders/viewchar.h | 6 ++++-- shaders/water.h | 6 ++++-- shaders/water_fast.h | 6 ++++-- world_gate.h | 12 +++++++++--- world_gen.h | 8 +++++++- 19 files changed, 88 insertions(+), 41 deletions(-) diff --git a/models_src/rs_gate.mdl b/models_src/rs_gate.mdl index c554abe87fb8f593c51155a682f58ea680b371f8..f3221b9c00c7e9016cba506a975d4d755849ad1a 100644 GIT binary patch delta 302 zcmdnMvq6xHf#K|GMg|6k4IC4>+{6@stOr1@0f=U2U=RS(3pgelGOA4Ms*(VSf`9@L z|NmdVAH=RwN!mYIhB1PXd2%D8^JE7`p3O%X?=VkZz{J5KaMfu4i_@x{UA1<#<6{qWf&tE*(WzLI!|_Btransport, phys->m, phys->m ); m3x3_mulv( gate->transport, phys->bob, phys->bob ); + /* Pre-emptively edit the camera matrices so that the motion vectors + * are correct */ + m4x3f transport_i; + m4x4f transport_4; + m4x3_invert_affine( gate->transport, transport_i ); + m4x3_expand( transport_i, transport_4 ); + m4x4_mul( main_camera.mtx.pv, transport_4, main_camera.mtx.pv ); + m4x4_mul( main_camera.mtx.v, transport_4, main_camera.mtx.v ); + v4f transport_rotation; m3x3_q( gate->transport, transport_rotation ); q_mul( transport_rotation, phys->rb.q, phys->rb.q ); diff --git a/render.h b/render.h index 0bb4c33..e3c7ee7 100644 --- a/render.h +++ b/render.h @@ -139,13 +139,13 @@ framebuffers[] = /* * The primary draw target */ - "Main", + "main", .link = &gpipeline.fb_main, .resolution_div = 1, .attachments = { { - "Colour", k_framebuffer_attachment_type_colour, + "colour", k_framebuffer_attachment_type_colour, .internalformat = GL_RGB, .format = GL_RGB, @@ -153,7 +153,7 @@ framebuffers[] = .attachment = GL_COLOR_ATTACHMENT0 }, { - "Motion Vectors", k_framebuffer_attachment_type_colour, + "motion", k_framebuffer_attachment_type_colour, .quality = k_framebuffer_quality_high_only, .internalformat = GL_RG16F, @@ -162,7 +162,7 @@ framebuffers[] = .attachment = GL_COLOR_ATTACHMENT1 }, { - "Depth/Stencil", k_framebuffer_attachment_type_renderbuffer, + "depth_stencil", k_framebuffer_attachment_type_renderbuffer, .internalformat = GL_DEPTH24_STENCIL8, .attachment = GL_DEPTH_STENCIL_ATTACHMENT @@ -175,7 +175,7 @@ framebuffers[] = * Note: it does not have a render buffer attachement because it's * intended to be drawn to in a MAX blending mode */ - "Heightmap", + "heightmap", .link = &gpipeline.fb_heightmap, .fixed_w = 1024, .fixed_h = 1024, @@ -183,7 +183,7 @@ framebuffers[] = .attachments = { { - "Depth", k_framebuffer_attachment_type_colour, + "depth", k_framebuffer_attachment_type_colour, .internalformat = GL_R32F, .format = GL_RED, @@ -196,20 +196,20 @@ framebuffers[] = /* * Second rendered view from the perspective of the water reflection */ - "Water reflection", + "water_reflection", .link = &gpipeline.fb_water_reflection, .resolution_div = 3, .attachments = { { - "Colour", k_framebuffer_attachment_type_colour, + "colour", k_framebuffer_attachment_type_colour, .internalformat = GL_RGB, .format = GL_RGB, .type = GL_UNSIGNED_BYTE, .attachment = GL_COLOR_ATTACHMENT0 }, { - "Depth/Stencil", k_framebuffer_attachment_type_renderbuffer, + "depth_stencil", k_framebuffer_attachment_type_renderbuffer, .internalformat = GL_DEPTH24_STENCIL8, .attachment = GL_DEPTH_STENCIL_ATTACHMENT @@ -221,20 +221,20 @@ framebuffers[] = * Thid rendered view from the perspective of the camera, but just * captures stuff thats under the water */ - "Water Beneath", + "water_beneath", .link = &gpipeline.fb_water_beneath, .resolution_div = 4, .attachments = { { - "Colour", k_framebuffer_attachment_type_colour, + "colour", k_framebuffer_attachment_type_colour, .internalformat = GL_RGBA, .format = GL_RGBA, .type = GL_UNSIGNED_BYTE, .attachment = GL_COLOR_ATTACHMENT0 }, { - "Depth/Stencil", k_framebuffer_attachment_type_renderbuffer, + "depth_stencil", k_framebuffer_attachment_type_renderbuffer, .internalformat = GL_DEPTH24_STENCIL8, .attachment = GL_DEPTH_STENCIL_ATTACHMENT @@ -596,7 +596,7 @@ VG_STATIC void render_init_fs_quad(void) 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, 1.0f, 0.2f, 0.0f, 0.8f, 1.0f, 0.2f, 1.0f, - 0.2f, 0.0f, 0.8f, 0.0f, 0.8f, 1.0f}; + 0.2f, 0.0f, 0.8f, 0.0f, 0.8f, 1.0f }; glGenVertexArrays( 1, &gpipeline.fsquad.vao ); glGenBuffers( 1, &gpipeline.fsquad.vbo ); @@ -605,7 +605,7 @@ VG_STATIC void render_init_fs_quad(void) glBufferData( GL_ARRAY_BUFFER, sizeof(quad), quad, GL_STATIC_DRAW ); glBindVertexArray( gpipeline.fsquad.vao ); glVertexAttribPointer( 0, 2, GL_FLOAT, GL_FALSE, - sizeof(float)*2, (void*)0 ); + sizeof(float)*2, (void*)0 ); glEnableVertexAttribArray( 0 ); VG_CHECK_GL_ERR(); diff --git a/shaders/alphatest.h b/shaders/alphatest.h index 8b06893..25e5879 100644 --- a/shaders/alphatest.h +++ b/shaders/alphatest.h @@ -17,7 +17,7 @@ static struct vg_shader _shader_alphatest = { "\n" "#line 2 0 \n" "#line 1 2 \n" -"const float k_motion_lerp_amount = 0.05;\n" +"const float k_motion_lerp_amount = 0.01;\n" "\n" "#line 2 0 \n" "\n" @@ -26,6 +26,8 @@ static struct vg_shader _shader_alphatest = { "\n" "void vs_motion_out( vec4 vproj0, vec4 vproj1 )\n" "{\n" +" // This magically solves some artifacting errors!\n" +" //\n" " vproj1 = vproj0*(1.0-k_motion_lerp_amount) + vproj1*k_motion_lerp_amount;\n" "\n" " aMotionVec0 = vec3( vproj0.xy, vproj0.w );\n" @@ -182,7 +184,7 @@ static struct vg_shader _shader_alphatest = { "\n" "#line 13 0 \n" "#line 1 2 \n" -"const float k_motion_lerp_amount = 0.05;\n" +"const float k_motion_lerp_amount = 0.01;\n" "\n" "#line 2 0 \n" "\n" diff --git a/shaders/gpos.h b/shaders/gpos.h index a41a7f7..2f4440d 100644 --- a/shaders/gpos.h +++ b/shaders/gpos.h @@ -17,7 +17,7 @@ static struct vg_shader _shader_gpos = { "\n" "#line 2 0 \n" "#line 1 2 \n" -"const float k_motion_lerp_amount = 0.05;\n" +"const float k_motion_lerp_amount = 0.01;\n" "\n" "#line 2 0 \n" "\n" @@ -26,6 +26,8 @@ static struct vg_shader _shader_gpos = { "\n" "void vs_motion_out( vec4 vproj0, vec4 vproj1 )\n" "{\n" +" // This magically solves some artifacting errors!\n" +" //\n" " vproj1 = vproj0*(1.0-k_motion_lerp_amount) + vproj1*k_motion_lerp_amount;\n" "\n" " aMotionVec0 = vec3( vproj0.xy, vproj0.w );\n" diff --git a/shaders/menu.h b/shaders/menu.h index a0baa70..3bf0d1f 100644 --- a/shaders/menu.h +++ b/shaders/menu.h @@ -17,7 +17,7 @@ static struct vg_shader _shader_menu = { "\n" "#line 2 0 \n" "#line 1 2 \n" -"const float k_motion_lerp_amount = 0.05;\n" +"const float k_motion_lerp_amount = 0.01;\n" "\n" "#line 2 0 \n" "\n" @@ -26,6 +26,8 @@ static struct vg_shader _shader_menu = { "\n" "void vs_motion_out( vec4 vproj0, vec4 vproj1 )\n" "{\n" +" // This magically solves some artifacting errors!\n" +" //\n" " vproj1 = vproj0*(1.0-k_motion_lerp_amount) + vproj1*k_motion_lerp_amount;\n" "\n" " aMotionVec0 = vec3( vproj0.xy, vproj0.w );\n" diff --git a/shaders/motion_vectors_common.glsl b/shaders/motion_vectors_common.glsl index 1d6ed97..7e6c114 100644 --- a/shaders/motion_vectors_common.glsl +++ b/shaders/motion_vectors_common.glsl @@ -1 +1 @@ -const float k_motion_lerp_amount = 0.05; +const float k_motion_lerp_amount = 0.01; diff --git a/shaders/motion_vectors_vs.glsl b/shaders/motion_vectors_vs.glsl index 63a17db..492f7a4 100644 --- a/shaders/motion_vectors_vs.glsl +++ b/shaders/motion_vectors_vs.glsl @@ -5,6 +5,8 @@ out vec3 aMotionVec1; void vs_motion_out( vec4 vproj0, vec4 vproj1 ) { + // This magically solves some artifacting errors! + // vproj1 = vproj0*(1.0-k_motion_lerp_amount) + vproj1*k_motion_lerp_amount; aMotionVec0 = vec3( vproj0.xy, vproj0.w ); diff --git a/shaders/route.h b/shaders/route.h index b003858..60b5c5c 100644 --- a/shaders/route.h +++ b/shaders/route.h @@ -17,7 +17,7 @@ static struct vg_shader _shader_route = { "\n" "#line 2 0 \n" "#line 1 2 \n" -"const float k_motion_lerp_amount = 0.05;\n" +"const float k_motion_lerp_amount = 0.01;\n" "\n" "#line 2 0 \n" "\n" @@ -26,6 +26,8 @@ static struct vg_shader _shader_route = { "\n" "void vs_motion_out( vec4 vproj0, vec4 vproj1 )\n" "{\n" +" // This magically solves some artifacting errors!\n" +" //\n" " vproj1 = vproj0*(1.0-k_motion_lerp_amount) + vproj1*k_motion_lerp_amount;\n" "\n" " aMotionVec0 = vec3( vproj0.xy, vproj0.w );\n" @@ -182,7 +184,7 @@ static struct vg_shader _shader_route = { "\n" "#line 13 0 \n" "#line 1 2 \n" -"const float k_motion_lerp_amount = 0.05;\n" +"const float k_motion_lerp_amount = 0.01;\n" "\n" "#line 2 0 \n" "\n" diff --git a/shaders/scoretext.h b/shaders/scoretext.h index 06fa719..fea61cc 100644 --- a/shaders/scoretext.h +++ b/shaders/scoretext.h @@ -17,7 +17,7 @@ static struct vg_shader _shader_scoretext = { "\n" "#line 2 0 \n" "#line 1 2 \n" -"const float k_motion_lerp_amount = 0.05;\n" +"const float k_motion_lerp_amount = 0.01;\n" "\n" "#line 2 0 \n" "\n" @@ -26,6 +26,8 @@ static struct vg_shader _shader_scoretext = { "\n" "void vs_motion_out( vec4 vproj0, vec4 vproj1 )\n" "{\n" +" // This magically solves some artifacting errors!\n" +" //\n" " vproj1 = vproj0*(1.0-k_motion_lerp_amount) + vproj1*k_motion_lerp_amount;\n" "\n" " aMotionVec0 = vec3( vproj0.xy, vproj0.w );\n" @@ -203,7 +205,7 @@ static struct vg_shader _shader_scoretext = { "\n" "#line 12 0 \n" "#line 1 2 \n" -"const float k_motion_lerp_amount = 0.05;\n" +"const float k_motion_lerp_amount = 0.01;\n" "\n" "#line 2 0 \n" "\n" diff --git a/shaders/sky.h b/shaders/sky.h index 931dec1..b7b26ef 100644 --- a/shaders/sky.h +++ b/shaders/sky.h @@ -17,7 +17,7 @@ static struct vg_shader _shader_sky = { "\n" "#line 2 0 \n" "#line 1 2 \n" -"const float k_motion_lerp_amount = 0.05;\n" +"const float k_motion_lerp_amount = 0.01;\n" "\n" "#line 2 0 \n" "\n" @@ -26,6 +26,8 @@ static struct vg_shader _shader_sky = { "\n" "void vs_motion_out( vec4 vproj0, vec4 vproj1 )\n" "{\n" +" // This magically solves some artifacting errors!\n" +" //\n" " vproj1 = vproj0*(1.0-k_motion_lerp_amount) + vproj1*k_motion_lerp_amount;\n" "\n" " aMotionVec0 = vec3( vproj0.xy, vproj0.w );\n" @@ -75,7 +77,7 @@ static struct vg_shader _shader_sky = { "in vec3 aCo;\n" "\n" "#line 1 1 \n" -"const float k_motion_lerp_amount = 0.05;\n" +"const float k_motion_lerp_amount = 0.01;\n" "\n" "#line 2 0 \n" "\n" diff --git a/shaders/standard.h b/shaders/standard.h index 319e6be..cf61d03 100644 --- a/shaders/standard.h +++ b/shaders/standard.h @@ -17,7 +17,7 @@ static struct vg_shader _shader_standard = { "\n" "#line 2 0 \n" "#line 1 2 \n" -"const float k_motion_lerp_amount = 0.05;\n" +"const float k_motion_lerp_amount = 0.01;\n" "\n" "#line 2 0 \n" "\n" @@ -26,6 +26,8 @@ static struct vg_shader _shader_standard = { "\n" "void vs_motion_out( vec4 vproj0, vec4 vproj1 )\n" "{\n" +" // This magically solves some artifacting errors!\n" +" //\n" " vproj1 = vproj0*(1.0-k_motion_lerp_amount) + vproj1*k_motion_lerp_amount;\n" "\n" " aMotionVec0 = vec3( vproj0.xy, vproj0.w );\n" @@ -182,7 +184,7 @@ static struct vg_shader _shader_standard = { "\n" "#line 13 0 \n" "#line 1 2 \n" -"const float k_motion_lerp_amount = 0.05;\n" +"const float k_motion_lerp_amount = 0.01;\n" "\n" "#line 2 0 \n" "\n" diff --git a/shaders/terrain.h b/shaders/terrain.h index cf32d5e..b2730fb 100644 --- a/shaders/terrain.h +++ b/shaders/terrain.h @@ -17,7 +17,7 @@ static struct vg_shader _shader_terrain = { "\n" "#line 2 0 \n" "#line 1 2 \n" -"const float k_motion_lerp_amount = 0.05;\n" +"const float k_motion_lerp_amount = 0.01;\n" "\n" "#line 2 0 \n" "\n" @@ -26,6 +26,8 @@ static struct vg_shader _shader_terrain = { "\n" "void vs_motion_out( vec4 vproj0, vec4 vproj1 )\n" "{\n" +" // This magically solves some artifacting errors!\n" +" //\n" " vproj1 = vproj0*(1.0-k_motion_lerp_amount) + vproj1*k_motion_lerp_amount;\n" "\n" " aMotionVec0 = vec3( vproj0.xy, vproj0.w );\n" @@ -183,7 +185,7 @@ static struct vg_shader _shader_terrain = { "\n" "#line 14 0 \n" "#line 1 2 \n" -"const float k_motion_lerp_amount = 0.05;\n" +"const float k_motion_lerp_amount = 0.01;\n" "\n" "#line 2 0 \n" "\n" diff --git a/shaders/vblend.h b/shaders/vblend.h index ad3f82b..fd558ef 100644 --- a/shaders/vblend.h +++ b/shaders/vblend.h @@ -17,7 +17,7 @@ static struct vg_shader _shader_vblend = { "\n" "#line 2 0 \n" "#line 1 2 \n" -"const float k_motion_lerp_amount = 0.05;\n" +"const float k_motion_lerp_amount = 0.01;\n" "\n" "#line 2 0 \n" "\n" @@ -26,6 +26,8 @@ static struct vg_shader _shader_vblend = { "\n" "void vs_motion_out( vec4 vproj0, vec4 vproj1 )\n" "{\n" +" // This magically solves some artifacting errors!\n" +" //\n" " vproj1 = vproj0*(1.0-k_motion_lerp_amount) + vproj1*k_motion_lerp_amount;\n" "\n" " aMotionVec0 = vec3( vproj0.xy, vproj0.w );\n" @@ -181,7 +183,7 @@ static struct vg_shader _shader_vblend = { "\n" "#line 12 0 \n" "#line 1 2 \n" -"const float k_motion_lerp_amount = 0.05;\n" +"const float k_motion_lerp_amount = 0.01;\n" "\n" "#line 2 0 \n" "\n" diff --git a/shaders/viewchar.h b/shaders/viewchar.h index e8d6fe7..604cae2 100644 --- a/shaders/viewchar.h +++ b/shaders/viewchar.h @@ -17,7 +17,7 @@ static struct vg_shader _shader_viewchar = { "\n" "#line 2 0 \n" "#line 1 2 \n" -"const float k_motion_lerp_amount = 0.05;\n" +"const float k_motion_lerp_amount = 0.01;\n" "\n" "#line 2 0 \n" "\n" @@ -26,6 +26,8 @@ static struct vg_shader _shader_viewchar = { "\n" "void vs_motion_out( vec4 vproj0, vec4 vproj1 )\n" "{\n" +" // This magically solves some artifacting errors!\n" +" //\n" " vproj1 = vproj0*(1.0-k_motion_lerp_amount) + vproj1*k_motion_lerp_amount;\n" "\n" " aMotionVec0 = vec3( vproj0.xy, vproj0.w );\n" @@ -191,7 +193,7 @@ static struct vg_shader _shader_viewchar = { "\n" "#line 11 0 \n" "#line 1 2 \n" -"const float k_motion_lerp_amount = 0.05;\n" +"const float k_motion_lerp_amount = 0.01;\n" "\n" "#line 2 0 \n" "\n" diff --git a/shaders/water.h b/shaders/water.h index 710d5c1..93dcba8 100644 --- a/shaders/water.h +++ b/shaders/water.h @@ -17,7 +17,7 @@ static struct vg_shader _shader_water = { "\n" "#line 2 0 \n" "#line 1 2 \n" -"const float k_motion_lerp_amount = 0.05;\n" +"const float k_motion_lerp_amount = 0.01;\n" "\n" "#line 2 0 \n" "\n" @@ -26,6 +26,8 @@ static struct vg_shader _shader_water = { "\n" "void vs_motion_out( vec4 vproj0, vec4 vproj1 )\n" "{\n" +" // This magically solves some artifacting errors!\n" +" //\n" " vproj1 = vproj0*(1.0-k_motion_lerp_amount) + vproj1*k_motion_lerp_amount;\n" "\n" " aMotionVec0 = vec3( vproj0.xy, vproj0.w );\n" @@ -189,7 +191,7 @@ static struct vg_shader _shader_water = { "\n" "#line 20 0 \n" "#line 1 2 \n" -"const float k_motion_lerp_amount = 0.05;\n" +"const float k_motion_lerp_amount = 0.01;\n" "\n" "#line 2 0 \n" "\n" diff --git a/shaders/water_fast.h b/shaders/water_fast.h index 756f308..196c71e 100644 --- a/shaders/water_fast.h +++ b/shaders/water_fast.h @@ -17,7 +17,7 @@ static struct vg_shader _shader_water_fast = { "\n" "#line 2 0 \n" "#line 1 2 \n" -"const float k_motion_lerp_amount = 0.05;\n" +"const float k_motion_lerp_amount = 0.01;\n" "\n" "#line 2 0 \n" "\n" @@ -26,6 +26,8 @@ static struct vg_shader _shader_water_fast = { "\n" "void vs_motion_out( vec4 vproj0, vec4 vproj1 )\n" "{\n" +" // This magically solves some artifacting errors!\n" +" //\n" " vproj1 = vproj0*(1.0-k_motion_lerp_amount) + vproj1*k_motion_lerp_amount;\n" "\n" " aMotionVec0 = vec3( vproj0.xy, vproj0.w );\n" @@ -186,7 +188,7 @@ static struct vg_shader _shader_water_fast = { "\n" "#line 17 0 \n" "#line 1 2 \n" -"const float k_motion_lerp_amount = 0.05;\n" +"const float k_motion_lerp_amount = 0.01;\n" "\n" "#line 2 0 \n" "\n" diff --git a/world_gate.h b/world_gate.h index 3e35081..9d12877 100644 --- a/world_gate.h +++ b/world_gate.h @@ -52,7 +52,11 @@ VG_STATIC int render_gate( teleport_gate *gate, camera *cam ) v3f v0; v3_sub( cam->pos, gate->co[0], v0 ); - if( v3_dot(v0, gatedir) >= 0.0f ) + + float dist = v3_dot(v0, gatedir); + + /* Hard cutoff */ + if( dist > 3.0f ) return 0; if( v3_dist( cam->pos, gate->co[0] ) > 100.0f ) @@ -80,7 +84,7 @@ VG_STATIC int render_gate( teleport_gate *gate, camera *cam ) static camera gate_view; gate_view.fov = cam->fov; gate_view.nearz = 0.1f; - gate_view.farz = 900.0f; + gate_view.farz = 2000.0f; m4x3_mul( gate->transport, cam->transform, gate_view.transform ); camera_update_view( &gate_view ); @@ -93,7 +97,9 @@ VG_STATIC int render_gate( teleport_gate *gate, camera *cam ) m4x3_mulp( gate_view.transform_inverse, surface, surface ); surface[3] = -fabsf(surface[3]); - m4x4_clip_projection( gate_view.mtx.p, surface ); + + if( dist < -0.5f ) + m4x4_clip_projection( gate_view.mtx.p, surface ); /* Ready to draw with new camrea */ camera_finalize( &gate_view ); diff --git a/world_gen.h b/world_gen.h index 1648bdf..47ed5ee 100644 --- a/world_gen.h +++ b/world_gen.h @@ -54,6 +54,8 @@ VG_STATIC void world_apply_procedural_foliage( struct world_material *mat ) mdl_node *mblob = mdl_node_from_name( mfoliage, "blob" ); mdl_submesh *sm_blob = mdl_node_submesh( mfoliage, mblob, 0 ); + int count = 0; + for( int i=0;i<100000;i++ ) { v3f pos; @@ -64,7 +66,7 @@ VG_STATIC void world_apply_procedural_foliage( struct world_material *mat ) ray_hit hit; hit.dist = INFINITY; - if( ray_world( pos, (v3f){0.0f,-1.0f,0.0f}, &hit )) + if( ray_world( pos, (v3f){0.0001f,-1.0f,0.0001f}, &hit )) { struct world_material *m1 = ray_hit_material( &hit ); if((hit.normal[1] > 0.8f) && (m1 == mat) && (hit.pos[1] > 0.0f+10.0f)) @@ -83,9 +85,13 @@ VG_STATIC void world_apply_procedural_foliage( struct world_material *mat ) v3_copy( hit.pos, transform[3] ); scene_add_submesh( world.scene_no_collide, mfoliage, sm_blob, transform); + + count ++; } } } + + vg_info( "%d foliage models added\n", count ); } VG_STATIC void world_ents_allocate(void) -- 2.25.1