-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathshader_program.py
45 lines (31 loc) · 1.14 KB
/
shader_program.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
from settings import *
class ShaderProgram:
def __init__(self, app):
self.app = app
self.ctx = app.ctx
self.player = app.player
# -----=== shaders ===-----
self.chunk = self.get_program(shader_name="chunk")
self.voxel_marker = self.get_program(shader_name="voxel_marker")
# -----===---------===-----
self.set_uniforms_on_init()
def set_uniforms_on_init(self):
# chunk
self.chunk["m_proj"].write(self.player.m_proj)
self.chunk["m_model"].write(glm.mat4())
self.chunk["u_texture_array_0"] = 1
self.chunk["bg_color"].write(BG_COLOR)
# voxel marker
self.voxel_marker["m_proj"].write(self.player.m_proj)
self.voxel_marker["m_model"].write(glm.mat4())
self.voxel_marker["u_texture_0"] = 0
def update(self):
self.chunk["m_view"].write(self.player.m_view)
self.voxel_marker["m_view"].write(self.player.m_view)
def get_program(self, shader_name):
with open(f"shaders/{shader_name}.vert") as file:
vertex_shader = file.read()
with open(f"shaders/{shader_name}.frag") as file:
fragment_shader = file.read()
program = self.ctx.program(vertex_shader=vertex_shader, fragment_shader=fragment_shader)
return program