From 2efdcdca647e94fef687fea29bedeff12cf90da9 Mon Sep 17 00:00:00 2001 From: Roz K Date: Sat, 31 Dec 2022 13:42:22 +0100 Subject: [PATCH] Bump engine submodule and move samplers bindings to shaders. --- engine | 2 +- game/game.py | 25 ++++++++----------------- game/shaders/common_opengles.frag | 2 +- game/shaders/sky_opengles.frag | 4 ++-- game/shaders/terrain_opengles.vert | 4 ++-- game/shaders/tests_opengles.vert | 4 ++-- 6 files changed, 16 insertions(+), 25 deletions(-) diff --git a/engine b/engine index 2095e33..ae3333e 160000 --- a/engine +++ b/engine @@ -1 +1 @@ -Subproject commit 2095e335ead1967fde413b0d61d35e2f3b90461a +Subproject commit ae3333e22e36667a0c02817fafb16ab7b8d1341b diff --git a/game/game.py b/game/game.py index 810c3e2..f80eb4f 100644 --- a/game/game.py +++ b/game/game.py @@ -60,21 +60,15 @@ def main(): heightmap = create_texture( TEXTURE_FORMAT_FLOAT_32, 256, 256, 0, TEXTURE_FLAG_MIN_LINEAR | TEXTURE_FLAG_MAG_LINEAR, generated.packed_heights) - terrain_heightmap_sampler = resolve_input(terrain_shader, b'u_height_sampler') - tests_heightmap_sampler = resolve_input(tests_shader, b'u_height_sampler') - normalmap = create_texture( TEXTURE_FORMAT_RGB10_A2, 256, 256, 0, TEXTURE_FLAG_MIN_LINEAR | TEXTURE_FLAG_MAG_LINEAR, generated.packed_normals) - terrain_normalmap_sampler = resolve_input(terrain_shader, b'u_normal_sampler') - tests_normalmap_sampler = resolve_input(tests_shader, b'u_normal_sampler') print("Loading resources...") archive = RuntimeArchive.load('data/rk_island.rkar') print("Building tiles...") tiles_texture = archive.get_texture('tiles') - tiles_sampler = resolve_input(terrain_shader, b'u_texture_sampler') tiles_vertices = archive.get_vertices('tiles') water_model = archive.get_model('water') sand_model = archive.get_model('sand') @@ -117,7 +111,6 @@ def main(): model.spawn(terrain_batch, vec3(float(((mx - 128) * 8) + 4), float(((127 - my) * 8) + 4), 0.0)) tests_texture = archive.get_texture('tests') - tests_sampler = resolve_input(tests_shader, b'u_texture_sampler') tests_vertices = archive.get_vertices('tests') blob_model = archive.get_model('blob') cube_model = archive.get_model('cube') @@ -136,9 +129,7 @@ def main(): 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')) - sea_polar_sampler = resolve_input(sky_shader, b'u_sea_polar_sampler') sea_detail_texture = sea.load_detail_texture('data/sea_bump.png') - sea_detail_sampler = resolve_input(sky_shader, b'u_sea_detail_sampler') sky_triangles = create_triangles(triangles.sky_triangles(64, proj_far_z - 0.1, proj_ratio)) camera = Camera() @@ -188,9 +179,9 @@ def main(): select_shader(terrain_shader) camera.update_inputs(terrain_camera_inputs) environment.update_inputs(terrain_environment_inputs) - select_texture(0, tiles_texture, tiles_sampler) - select_texture(1, heightmap, terrain_heightmap_sampler) - select_texture(2, normalmap, terrain_normalmap_sampler) + select_texture(0, tiles_texture) + select_texture(1, heightmap) + select_texture(2, normalmap) draw_begin = time.thread_time() terrain_batch.draw() draw_end = time.thread_time() @@ -209,9 +200,9 @@ def main(): select_shader(tests_shader) camera.update_inputs(tests_camera_inputs) environment.update_inputs(tests_environment_inputs) - select_texture(0, tests_texture, tests_sampler) - select_texture(1, heightmap, tests_heightmap_sampler) - select_texture(2, normalmap, tests_normalmap_sampler) + select_texture(0, tests_texture) + select_texture(1, heightmap) + select_texture(2, normalmap) tests_batch.draw() unselect_texture(0, tests_texture) unselect_texture(1, heightmap) @@ -224,8 +215,8 @@ def main(): camera.update_inputs(sky_camera_inputs) environment.update_inputs(sky_environment_inputs) set_input_float(sea_phase, (current_time * 0.023) % 1.0) - select_texture(0, sea_polar_textures, sea_polar_sampler) - select_texture(1, sea_detail_texture, sea_detail_sampler) + select_texture(0, sea_polar_textures) + select_texture(1, sea_detail_texture) draw_triangles(sky_triangles) unselect_texture(0, sea_polar_textures) unselect_texture(1, sea_detail_texture) diff --git a/game/shaders/common_opengles.frag b/game/shaders/common_opengles.frag index a8ba8cb..6036b1d 100644 --- a/game/shaders/common_opengles.frag +++ b/game/shaders/common_opengles.frag @@ -26,7 +26,7 @@ in vec4 v_texcoord; // texture space (s, t, pixel_level, material_level) uniform vec3 u_light_direction; // view space (-direction_x, -direction_y, -direction_z) uniform vec3 u_light_color; // (color.r * power, color.g * power, color.b * power) -uniform highp sampler2DArray u_texture_sampler; +layout(binding=0) uniform highp sampler2DArray u_texture_sampler; layout(location = 0) out vec4 o_color; diff --git a/game/shaders/sky_opengles.frag b/game/shaders/sky_opengles.frag index 7dc3b1f..8648e21 100644 --- a/game/shaders/sky_opengles.frag +++ b/game/shaders/sky_opengles.frag @@ -31,8 +31,8 @@ uniform float u_sea_phase; #define u_up u_view[2].xyz #define u_origin u_view[3].xyz -uniform highp sampler2DArray u_sea_polar_sampler; -uniform highp sampler2D u_sea_detail_sampler; +layout(binding=0) uniform highp sampler2DArray u_sea_polar_sampler; +layout(binding=1) uniform highp sampler2D u_sea_detail_sampler; const float c_sea_radius = 637.1; const float c_sea_radius_sq = c_sea_radius * c_sea_radius; diff --git a/game/shaders/terrain_opengles.vert b/game/shaders/terrain_opengles.vert index 12cb544..6d0b17b 100644 --- a/game/shaders/terrain_opengles.vert +++ b/game/shaders/terrain_opengles.vert @@ -25,8 +25,8 @@ layout(location = 3) in vec3 i_translation; // per mesh, model space -> world sp uniform mat4 u_view; // world space -> view space uniform mat4 u_projection; // view space -> screen space -uniform highp sampler2D u_height_sampler; -uniform highp sampler2D u_normal_sampler; +layout(binding=1) uniform highp sampler2D u_height_sampler; +layout(binding=2) uniform highp sampler2D u_normal_sampler; const vec3 c_normal_scale = vec3(2.0, 2.0, 1.0); const vec3 c_normal_shift = vec3(-1.0, -1.0, 0.0); diff --git a/game/shaders/tests_opengles.vert b/game/shaders/tests_opengles.vert index 2bb1924..998e2a5 100644 --- a/game/shaders/tests_opengles.vert +++ b/game/shaders/tests_opengles.vert @@ -26,8 +26,8 @@ layout(location = 4) in mat3 i_orientation; // per mesh, model space -> world sp uniform mat4 u_view; // world space -> view space uniform mat4 u_projection; // view space -> screen space -uniform highp sampler2D u_height_sampler; -uniform highp sampler2D u_normal_sampler; +layout(binding=1) uniform highp sampler2D u_height_sampler; +layout(binding=2) uniform highp sampler2D u_normal_sampler; const vec3 c_normal_scale = vec3(2.0, 2.0, 1.0); const vec3 c_normal_shift = vec3(-1.0, -1.0, 0.0);