Bump engine submodule and move texture slots.
This commit is contained in:
parent
8db60a0c01
commit
9dd97baee8
2
engine
2
engine
@ -1 +1 @@
|
||||
Subproject commit 028ba40148ec570f9f979c70d36fe268cfad1a2e
|
||||
Subproject commit ddb9b0598f182ad84ef3f5501ac3934eb7959578
|
46
game/game.py
46
game/game.py
@ -33,11 +33,12 @@ proj_ratio = 16.0 / 9.0
|
||||
proj_near_z = 8.0
|
||||
proj_far_z = 3000.0
|
||||
|
||||
sun_direction = math.vec3_normalize((1.0, 0.0, 1.0))
|
||||
sun_power = 1.0
|
||||
camera_origin = (0.0, -1200.0, 500.0)
|
||||
camera_lookat = (0.0, 500.0, -500.0)
|
||||
|
||||
sun_direction = math.vec3_normalize((1.0, 0.0, 1.0))
|
||||
sun_power = 1.0
|
||||
|
||||
def main():
|
||||
print("Generating terrain...")
|
||||
gen_begin = time.process_time()
|
||||
@ -52,19 +53,21 @@ def main():
|
||||
sky_shader = shader.load('sky')
|
||||
|
||||
heightmap = create_texture(
|
||||
1, TEXTURE_FORMAT_32F, 256, 256, 0, TEXTURE_FLAG_MIN_LINEAR | TEXTURE_FLAG_MAG_LINEAR,
|
||||
TEXTURE_FORMAT_32F, 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(
|
||||
2, TEXTURE_FORMAT_RGB10_A2, 256, 256, 0, TEXTURE_FLAG_MIN_LINEAR | TEXTURE_FLAG_MAG_LINEAR,
|
||||
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 = resources.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')
|
||||
@ -75,10 +78,9 @@ def main():
|
||||
rock = archive.get_model('rock')
|
||||
mud = archive.get_model('mud')
|
||||
lava = archive.get_model('lava')
|
||||
terrain_batch = batch.Batch(tiles_vertices, generated.size ** 2, params_format(PARAM_FORMAT_VEC3_SHORT))
|
||||
|
||||
#TODO: generator & for real
|
||||
print("Building tiles...")
|
||||
terrain_batch = batch.Batch(tiles_vertices, generated.size ** 2, params_format(PARAM_FORMAT_VEC3_SHORT))
|
||||
vc = generated.volcano_c
|
||||
vr = generated.volcano_r
|
||||
for my, mx in generated.map_coords:
|
||||
@ -191,31 +193,31 @@ def main():
|
||||
select_shader(terrain_shader)
|
||||
camera.update_inputs(terrain_camera_inputs)
|
||||
environment.update_inputs(terrain_environment_inputs)
|
||||
select_texture(tiles_texture, tiles_sampler)
|
||||
select_texture(heightmap, terrain_heightmap_sampler)
|
||||
select_texture(normalmap, terrain_normalmap_sampler)
|
||||
select_texture(0, tiles_texture, tiles_sampler)
|
||||
select_texture(1, heightmap, terrain_heightmap_sampler)
|
||||
select_texture(2, normalmap, terrain_normalmap_sampler)
|
||||
select_vertices(tiles_vertices)
|
||||
draw_begin = time.thread_time()
|
||||
terrain_batch.draw()
|
||||
draw_end = time.thread_time()
|
||||
unselect_vertices(tiles_vertices)
|
||||
unselect_texture(tiles_texture)
|
||||
unselect_texture(normalmap)
|
||||
unselect_texture(heightmap)
|
||||
unselect_texture(0, tiles_texture)
|
||||
unselect_texture(1, heightmap)
|
||||
unselect_texture(2, normalmap)
|
||||
unselect_shader(terrain_shader)
|
||||
|
||||
select_shader(tests_shader)
|
||||
camera.update_inputs(tests_camera_inputs)
|
||||
environment.update_inputs(tests_environment_inputs)
|
||||
select_texture(tests_texture, tests_sampler)
|
||||
select_texture(heightmap, tests_heightmap_sampler)
|
||||
select_texture(normalmap, tests_normalmap_sampler)
|
||||
select_texture(0, tests_texture, tests_sampler)
|
||||
select_texture(1, heightmap, tests_heightmap_sampler)
|
||||
select_texture(2, normalmap, tests_normalmap_sampler)
|
||||
select_vertices(tests_vertices)
|
||||
tests_batch.draw()
|
||||
unselect_vertices(tests_vertices)
|
||||
unselect_texture(tests_texture)
|
||||
unselect_texture(normalmap)
|
||||
unselect_texture(heightmap)
|
||||
unselect_texture(0, tests_texture)
|
||||
unselect_texture(1, heightmap)
|
||||
unselect_texture(2, normalmap)
|
||||
unselect_shader(tests_shader)
|
||||
|
||||
camera.set_view(vec3(math.vec3_scale(_origin, 0.001)), vec3(math.vec3_scale(_lookat, 0.001)))
|
||||
@ -224,11 +226,11 @@ 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(sea_polar_textures, sea_polar_sampler)
|
||||
select_texture(sea_detail_texture, sea_detail_sampler)
|
||||
select_texture(0, sea_polar_textures, sea_polar_sampler)
|
||||
select_texture(1, sea_detail_texture, sea_detail_sampler)
|
||||
draw_triangles(sky_triangles)
|
||||
unselect_texture(sea_detail_texture)
|
||||
unselect_texture(sea_polar_textures)
|
||||
unselect_texture(0, sea_polar_textures)
|
||||
unselect_texture(1, sea_detail_texture)
|
||||
unselect_shader(sky_shader)
|
||||
|
||||
frame_end = time.thread_time()
|
||||
|
@ -132,9 +132,8 @@ class TextureData:
|
||||
_write_struct(file, 'IIIII', (self.format, self.width, self.height, self.nlevels, self.flags))
|
||||
_write_blob(file, self.pixels)
|
||||
|
||||
def create_texture(slot, data):
|
||||
return engine.create_texture(
|
||||
slot, data.format, data.width, data.height, data.nlevels, data.flags, data.pixels)
|
||||
def create_texture(data):
|
||||
return engine.create_texture(data.format, data.width, data.height, data.nlevels, data.flags, data.pixels)
|
||||
|
||||
class VerticesData:
|
||||
__slots__ = 'name', 'vertices', 'indices'
|
||||
@ -279,7 +278,7 @@ class Archive:
|
||||
class RuntimeArchive(Archive):
|
||||
@classmethod
|
||||
def _new_texture(cls, data):
|
||||
return create_texture(0, data)
|
||||
return create_texture(data)
|
||||
|
||||
@classmethod
|
||||
def _new_vertices(cls, data):
|
||||
|
@ -51,7 +51,7 @@ def load_polar_textures(paths, waves_height = 0.008):
|
||||
_width, _height, normals = load_texture(path)
|
||||
assert _width == width and _height == height
|
||||
data.extend(list(map(_conv, normals)))
|
||||
return create_texture(0, _format, width, height, len(paths), _flags, data)
|
||||
return create_texture(_format, width, height, len(paths), _flags, data)
|
||||
|
||||
def load_detail_texture(path, scale = 0.5, waves_height = 0.002):
|
||||
width, height, data = load_png(path)
|
||||
@ -68,4 +68,4 @@ def load_detail_texture(path, scale = 0.5, waves_height = 0.002):
|
||||
return vec3_scale(n, copysign(1.0, n[2]))
|
||||
normals = list(map(normal, product(range(height), range(width)), data))
|
||||
data = array(_typecode, list(map(_conv, normals)))
|
||||
return create_texture(1, _format, width, height, 0, _flags, data)
|
||||
return create_texture(_format, width, height, 0, _flags, data)
|
||||
|
Loading…
Reference in New Issue
Block a user