Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def shader():
- vertex_shader = """
- #version 450 core
- layout (location = 0) in vec3 position;
- layout (location = 1) in vec3 color;
- layout (location = 2) in vec2 texCoord;
- layout (location = 3) in vec3 normal;
- uniform mat4 transform;
- out vec4 pos;
- out vec3 ourColor;
- out vec2 TexCoord;
- out vec3 norm;
- void main()
- {
- gl_Position = transform * vec4(position.x, position.y, position.z, 1.0f);
- pos = gl_Position;
- ourColor = color;
- TexCoord = vec2(texCoord.x, texCoord.y);
- norm = (transform * vec4(normal, 0.0)).xyz;
- }
- """
- fragment_shader = """
- #version 450 core
- in vec4 pos;
- in vec3 ourColor;
- in vec2 TexCoord;
- in vec3 norm;
- out vec4 color;
- uniform sampler2D texture1;
- uniform bool flag;
- uniform vec4 l_pos;
- uniform vec4 l_amb;
- uniform vec4 l_diff;
- uniform vec4 l_spec;
- uniform float l_shine;
- void main()
- {
- vec3 L = normalize(l_pos.xyz - pos.xyz);
- vec3 E = normalize(vec3(0, 0, -1)-pos.xyz);
- vec3 R = normalize(-reflect(L, norm));
- vec4 Iamb = l_amb;
- vec4 Idiff = l_diff * max(dot(norm, L), 0.0);
- Idiff = clamp(Idiff, 0.0, 1.0);
- vec4 Ispec = l_spec * pow(max(dot(R, E), 0.0), l_shine);
- Ispec = clamp(Ispec, 0.0, 1.0);
- if (flag){
- color = vec4(ourColor, 1.0f);
- }
- else {
- color = texture(texture1, TexCoord);
- }
- color = color * (Iamb + Idiff + Ispec);
- }
- """
- global shader
- shader = OpenGL.GL.shaders.compileProgram(OpenGL.GL.shaders.compileShader(vertex_shader, GL_VERTEX_SHADER),
- OpenGL.GL.shaders.compileShader(fragment_shader, GL_FRAGMENT_SHADER))
- buildVAO()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement