glium_types/shaders.rs
1//! Shader examples to help get you started
2
3
4/// simple vertex shader. uniform requires `model: Mat4`,
5/// `perspective: Mat4` (use `Mat4::view_matrix_3d()` for 3d or `Mat4::view_matrix_2d()` for
6/// 2d/orthographic) and `camera: Mat4` (inverse camera matrix. use `Mat4::from_inverse_transform()`
7/// or call `.inverse()` before feeding the matrix into to the shader)
8///
9/// If you are new to shaders or how things render I highly recomend you check out the glium tutorial
10/// book (https://github.com/glium/glium/tree/master/book) it is where this shader is from after
11/// all
12///
13/// WARNING! if ALL vertex bindings aren't bound in the draw call your program will PANIC on most
14/// computers, HOWEVER, some don't panic, which may lead you to FALSELY believe you program will run
15/// else where
16pub const VERTEX: &str =
17"#version 140
18in vec3 position;
19in vec2 texture_coords;
20in vec3 normal;
21in vec4 colour;
22
23out vec3 v_position;
24out vec2 uv;
25out vec3 v_normal;
26out vec4 v_colour;
27
28uniform mat4 model;
29uniform mat4 perspective;
30uniform mat4 camera;
31void main() {
32 v_colour = colour;
33 uv = texture_coords;
34 mat3 norm_mat = transpose(inverse(mat3(camera * model)));
35 v_normal = normalize(norm_mat * normal);
36 gl_Position = perspective * camera * model * vec4(position, 1.0);
37 v_position = gl_Position.xyz / gl_Position.w;
38}";