-
Notifications
You must be signed in to change notification settings - Fork 2
/
shader.py
38 lines (30 loc) · 852 Bytes
/
shader.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
from pyglet.graphics.shader import Shader, ShaderProgram
# create vertex and fragment shader sources
vertex_source_default = """
#version 330
layout(location =0) in vec3 vertices;
layout(location =1) in vec4 colors;
out vec4 newColor;
// add a view-projection uniform and multiply it by the vertices
uniform mat4 view_proj;
uniform mat4 model;
void main()
{
gl_Position = view_proj * model * vec4(vertices, 1.0f); // local->world->vp
newColor = colors;
}
"""
fragment_source_default = """
#version 330
in vec4 newColor;
out vec4 outColor;
void main()
{
outColor = newColor;
}
"""
def create_program(vs_source, fs_source):
# compile the vertex and fragment sources to a shader program
vert_shader = Shader(vs_source, 'vertex')
frag_shader = Shader(fs_source, 'fragment')
return ShaderProgram(vert_shader, frag_shader)