Rename sea shader.

This commit is contained in:
Roz K 2022-12-31 19:27:23 +01:00
parent f4bfb7fee0
commit 9e77e6680b
Signed by: roz
GPG Key ID: 51FBF4E483E1C822
5 changed files with 45 additions and 48 deletions

View File

@ -31,7 +31,6 @@ from game.environment import Environment
from game.inputs import InputFloat
from game.batch import Batch
from game.scene import SceneNode, TextureNode, ShaderNode, InputNode, DrawNode, FuncNode
from game.triangles import SkyTriangles
from game import sea
proj_hfov = pi * 0.25
@ -71,12 +70,12 @@ def main():
tiles_shader = Shader('tiles', 'common')
tests_shader = Shader('tests', 'common')
sky_shader = Shader('sky')
sea_shader = Shader('sea')
camera = Camera()
camera.set_projection(proj_hfov, proj_ratio, proj_near_z, proj_far_z)
environment = Environment()
sea_phase = InputFloat(sky_shader.u_sea_phase, 0.0)
sea_phase = InputFloat(sea_shader.u_sea_phase, 0.0)
print("Generating terrain...")
generated = Generator(256)
@ -158,7 +157,7 @@ def main():
sea_polar_textures = sea.load_polar_textures(('data/sea_bump1.png', 'data/sea_bump2.png'))
sea_detail_texture = sea.load_detail_texture('data/sea_bump.png')
sky_triangles = SkyTriangles(64, proj_far_z - 0.1, proj_ratio)
sea_triangles = sea.SeaTriangles(64, proj_far_z - 0.1, proj_ratio)
scene = SceneNode(
FuncNode(update_camera, (mouse, camera, environment)),
@ -179,11 +178,11 @@ def main():
),
FuncNode(update_sea, (camera, sea_phase)),
TextureNode((sea_polar_textures, sea_detail_texture),
ShaderNode(sky_shader,
InputNode(sky_shader, camera),
InputNode(sky_shader, environment),
InputNode(sky_shader, sea_phase),
DrawNode(sky_triangles)
ShaderNode(sea_shader,
InputNode(sea_shader, camera),
InputNode(sea_shader, environment),
InputNode(sea_shader, sea_phase),
DrawNode(sea_triangles)
)
)
)
@ -204,7 +203,7 @@ def main():
print("Quitting...")
del tests_batch
del tiles_batch
del sky_triangles
del sea_triangles
del sea_polar_textures
del sea_detail_texture
del heightmap
@ -212,7 +211,7 @@ def main():
archive.destroy()
del tiles_shader
del tests_shader
del sky_shader
del sea_shader
render_terminate()
del events
destroy_display(display)

View File

@ -13,7 +13,7 @@
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from itertools import product
from itertools import chain, product
from math import tau, cos, sin, copysign
from array import array
@ -21,6 +21,7 @@ from engine import TEXTURE_FORMAT_RGB10_A2, TEXTURE_FORMAT_TYPECODE, TEXTURE_FLA
from game.math import vec3_scale, vec3_direction, vec3_cross, vec3_normal_rgb10a2
from game.texture import Texture
from game.triangles import Triangles
from game.resources import load_png
_format = TEXTURE_FORMAT_RGB10_A2
@ -69,3 +70,36 @@ def load_detail_texture(path, scale = 0.5, waves_height = 0.002):
normals = list(map(normal, product(range(height), range(width)), data))
data = array(_typecode, list(map(_conv, normals)))
return Texture(_format, width, height, 0, _flags, data)
class SeaTriangles(Triangles):
# TODO: with FOV
def __init__(self, vsubdivs, distance, projection_ratio):
assert vsubdivs > 0
vertices = []
hsubdivs = round(vsubdivs * projection_ratio)
z = -distance
width = distance * projection_ratio
height = distance
startx = width * -0.5
starty = height * -0.5
stepx = width / hsubdivs
stepy = height / vsubdivs
y1 = starty
y2 = y1 + stepy
for sy in range(vsubdivs):
x1 = startx
x2 = x1 + stepx
for sx in range(hsubdivs):
a = (x1, y2, z)
b = (x2, y1, z)
vertices.append((x1, y1, z))
vertices.append(b)
vertices.append(a)
vertices.append((x2, y2, z))
vertices.append(a)
vertices.append(b)
x1 = x2
x2 += stepx
y1 = y2
y2 += stepy
super().__init__(array('f', chain.from_iterable(vertices)))

View File

@ -13,9 +13,6 @@
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from itertools import chain
from array import array
from math import cos, sin
from engine import create_triangles, draw_triangles, destroy_triangles
class Triangles:
@ -29,36 +26,3 @@ class Triangles:
def draw(self):
draw_triangles(self._triangles)
class SkyTriangles(Triangles):
# TODO: with FOV
def __init__(self, vsubdivs, distance, projection_ratio):
assert vsubdivs > 0
vertices = []
hsubdivs = round(vsubdivs * projection_ratio)
z = -distance
width = distance * projection_ratio
height = distance
startx = width * -0.5
starty = height * -0.5
stepx = width / hsubdivs
stepy = height / vsubdivs
y1 = starty
y2 = y1 + stepy
for sy in range(vsubdivs):
x1 = startx
x2 = x1 + stepx
for sx in range(hsubdivs):
a = (x1, y2, z)
b = (x2, y1, z)
vertices.append((x1, y1, z))
vertices.append(b)
vertices.append(a)
vertices.append((x2, y2, z))
vertices.append(a)
vertices.append(b)
x1 = x2
x2 += stepx
y1 = y2
y2 += stepy
super().__init__(array('f', chain.from_iterable(vertices)))