From 108976bdffff8acbd5126b30cb9c835876d2a729 Mon Sep 17 00:00:00 2001 From: Roz K Date: Mon, 26 Dec 2022 14:14:33 +0100 Subject: [PATCH] Bump engine submodule and switch to mat3 orientations. --- engine | 2 +- game/game.py | 28 +++++++++++++++------------- game/shaders/terrain_opengles.vert | 3 +-- game/shaders/tests_opengles.vert | 9 +++------ 4 files changed, 20 insertions(+), 22 deletions(-) diff --git a/engine b/engine index cdfce62..6b33f82 160000 --- a/engine +++ b/engine @@ -1 +1 @@ -Subproject commit cdfce62c909cfeb50a7dec261c47331a5573e44e +Subproject commit 6b33f8285cd37f9aca381c3800d21a26435b7cfb diff --git a/game/game.py b/game/game.py index a51ff2a..ebd4823 100644 --- a/game/game.py +++ b/game/game.py @@ -115,7 +115,7 @@ def main(): model.spawn(terrain_batch, vec3(float(((mx - 128) * 8) + 4), float(((127 - my) * 8) + 4), 0.0)) class TestsParams(Structure): - _fields_ = ('translation', vec3), ('orientation', vec3) + _fields_ = ('translation', vec3), ('orientation', mat3) tests_texture = archive.get_texture('tests') tests_sampler = resolve_input(tests_shader, b'u_texture_sampler') @@ -124,13 +124,15 @@ def main(): cube_model = archive.get_model('cube') clouds_model = archive.get_model('clouds') tests_batch = Batch(tests_vertices, 3, - params_format(PARAM_FORMAT_VEC3_FLOAT, PARAM_FORMAT_VEC3_INT10 | PARAM_FORMAT_NORMALIZE), TestsParams) + params_format(PARAM_FORMAT_VEC3_FLOAT, PARAM_FORMAT_MAT3_INT10 | PARAM_FORMAT_NORMALIZE), TestsParams) blob_spawn_translation = vec3(-100.0, -500.0, 0.0) cube_spawn_translation = vec3(100.0, -500.0, 0.0) + blob_forward = math.vec3_normalize((sun_direction[0], sun_direction[1], 0.0)) + blob_right = math.vec3_cross(blob_forward, math.vec3_up) blob_id = blob_model.spawn(tests_batch, - TestsParams(blob_spawn_translation, vec3(*math.vec3_normalize((sun_direction[0], sun_direction[1], 0.0))))) - cube_id = cube_model.spawn(tests_batch, TestsParams(cube_spawn_translation, vec3_forward)) - clouds_id = clouds_model.spawn(tests_batch, TestsParams(vec3(0.0, 0.0, 32.0), vec3_forward)) + TestsParams(blob_spawn_translation, mat3(vec3(*blob_right), vec3(*blob_forward), vec3_up))) + cube_id = cube_model.spawn(tests_batch, TestsParams(cube_spawn_translation, mat3_identity)) + clouds_id = clouds_model.spawn(tests_batch, TestsParams(vec3(0.0, 0.0, 32.0), mat3_identity)) sea_phase = resolve_input(sky_shader, b'u_sea_phase') sea_polar_textures = sea.load_polar_textures(('data/sea_bump1.png', 'data/sea_bump2.png')) @@ -177,8 +179,8 @@ def main(): mat3_rotation(rotation, vec3_up, (current_time * 0.21) % tau) mat3_mul_vec3(blob_translation, rotation, blob_spawn_translation) mat3_mul_vec3(cube_translation, rotation, cube_spawn_translation) - vec3_rotate(cube_orientation, vec3_forward, vec3_up, (current_time * 0.43) % tau) - vec3_rotate(clouds_orientation, vec3_forward, vec3_up, (current_time * -0.037) % tau) + mat3_rotation(cube_orientation, vec3_up, (current_time * 0.43) % tau) + mat3_rotation(clouds_orientation, vec3_up, (current_time * -0.037) % tau) camera.set_view(camera_origin, camera_lookat, vec3_up, (current_time * 0.05) % tau) environment.from_sun(camera.view, sun_direction, sun_power) @@ -277,13 +279,13 @@ def main(): # for x in range(10000) # current_time = 0 - # Draw * 9999 : min = 0.2 , max = 2.31 , avg = 0.27 ms - # Draw * 9999 : min = 0.2 , max = 2.41 , avg = 0.27 ms - # Draw * 9999 : min = 0.2 , max = 2.73 , avg = 0.27 ms + # Draw * 9999 : min = 0.21 , max = 1.8 , avg = 0.27 ms + # Draw * 9999 : min = 0.2 , max = 2.03 , avg = 0.27 ms + # Draw * 9999 : min = 0.2 , max = 1.75 , avg = 0.27 ms - # Frame * 9999 : min = 0.26 , max = 2.44 , avg = 0.38 ms - # Frame * 9999 : min = 0.26 , max = 2.54 , avg = 0.37 ms - # Frame * 9999 : min = 0.26 , max = 2.90 , avg = 0.38 ms + # Frame * 9999 : min = 0.26 , max = 1.94 , avg = 0.37 ms + # Frame * 9999 : min = 0.26 , max = 2.21 , avg = 0.36 ms + # Frame * 9999 : min = 0.26 , max = 1.89 , avg = 0.37 ms print("Quitting...") del tests_batch diff --git a/game/shaders/terrain_opengles.vert b/game/shaders/terrain_opengles.vert index 6d0469d..12cb544 100644 --- a/game/shaders/terrain_opengles.vert +++ b/game/shaders/terrain_opengles.vert @@ -35,7 +35,6 @@ const vec2 c_terrain_scale = vec2(1.0 / 2048.0, -1.0 / 2048.0); const vec2 c_terrain_shift = vec2(0.5, 0.5); const float c_weight_scale = 1.0 / 64.f; const vec3 c_world_forward = vec3(0.0, 1.0, 0.0); -const vec3 c_world_up = vec3(0.0, 0.0, 1.0); out vec4 v_position; // view space out vec4 v_normal; // view space @@ -48,7 +47,7 @@ void main(void) { world_position.z += texture(u_height_sampler, terrain_coords).r; vec4 view_position = u_view * world_position; vec3 terrain_normal = normalize(c_normal_shift + texture(u_normal_sampler, terrain_coords).rgb * c_normal_scale); - vec3 world_normal = mat3(cross(c_world_forward, terrain_normal), c_world_forward, terrain_normal) * normalize(a_normal); + vec3 world_normal = mat3(cross(c_world_forward, terrain_normal), c_world_forward, terrain_normal) * a_normal; v_position = view_position; v_normal = u_view * vec4(world_normal, 0.0); v_terrain_normal = vec4((u_view * vec4(terrain_normal, 0.0)).xyz, 1.0); diff --git a/game/shaders/tests_opengles.vert b/game/shaders/tests_opengles.vert index ca37b81..2bb1924 100644 --- a/game/shaders/tests_opengles.vert +++ b/game/shaders/tests_opengles.vert @@ -21,7 +21,7 @@ layout(location = 1) in vec3 a_normal; // model space layout(location = 2) in vec3 a_texcoord; // texture space layout(location = 3) in vec3 i_translation; // per mesh, model space -> world space -layout(location = 4) in vec3 i_orientation; // per mesh, model space -> world space +layout(location = 4) in mat3 i_orientation; // per mesh, model space -> world space uniform mat4 u_view; // world space -> view space uniform mat4 u_projection; // view space -> screen space @@ -36,7 +36,6 @@ const vec2 c_terrain_scale = vec2(1.0 / 2048.0, -1.0 / 2048.0); const vec2 c_terrain_shift = vec2(0.5, 0.5); const float c_weight_scale = 1.0 / 64.f; const vec3 c_world_forward = vec3(0.0, 1.0, 0.0); -const vec3 c_world_up = vec3(0.0, 0.0, 1.0); out vec4 v_position; // view space out vec4 v_normal; // view space @@ -44,11 +43,9 @@ out vec4 v_terrain_normal; // view space (x, y, z, weigth) out vec4 v_texcoord; // texture space (s, t, pixel_level, material_level) void main(void) { - vec3 orientation = normalize(i_orientation); - mat3 rotation = mat3(cross(orientation, c_world_up), orientation, c_world_up); - vec4 world_position = vec4(i_translation + rotation * a_position, 1.0); + vec4 world_position = vec4(i_translation + i_orientation * a_position, 1.0); float weight = max(0.0, 1.0 - world_position.z * c_weight_scale); - vec3 world_normal = rotation * normalize(a_normal); + vec3 world_normal = i_orientation * a_normal; vec2 terrain_coords = c_terrain_shift + world_position.xy * c_terrain_scale; world_position.z += texture(u_height_sampler, terrain_coords).r; vec4 view_position = u_view * world_position;