From 4ff17823eb9047010ae98a65cb1c024fb0b0de11 Mon Sep 17 00:00:00 2001 From: Riyyi Date: Mon, 4 Jan 2021 15:45:27 +0100 Subject: [PATCH] Add model matrix, camera matrix to color and texture shader --- assets/glsl/{simple.frag => color.frag} | 0 assets/glsl/color.vert | 16 ++++++++++++++++ assets/glsl/simple.vert | 12 ------------ assets/glsl/texture.frag | 3 ++- assets/glsl/texture.vert | 11 +++++++++-- 5 files changed, 27 insertions(+), 15 deletions(-) rename assets/glsl/{simple.frag => color.frag} (100%) create mode 100644 assets/glsl/color.vert delete mode 100644 assets/glsl/simple.vert diff --git a/assets/glsl/simple.frag b/assets/glsl/color.frag similarity index 100% rename from assets/glsl/simple.frag rename to assets/glsl/color.frag diff --git a/assets/glsl/color.vert b/assets/glsl/color.vert new file mode 100644 index 0000000..6cc61c7 --- /dev/null +++ b/assets/glsl/color.vert @@ -0,0 +1,16 @@ +#version 450 core + +layout(location = 0) in vec3 a_position; +layout(location = 1) in vec4 a_color; + +out vec4 v_color; + +uniform mat4 u_projectionView; +uniform mat4 u_model; + +void main() +{ + v_color = a_color; + // Vclip = Camera projection * Camera view * Model transform * Vlocal + gl_Position = u_projectionView * u_model * vec4(a_position, 1.0f); +} diff --git a/assets/glsl/simple.vert b/assets/glsl/simple.vert deleted file mode 100644 index 99148ce..0000000 --- a/assets/glsl/simple.vert +++ /dev/null @@ -1,12 +0,0 @@ -#version 450 core - -layout(location = 0) in vec3 a_position; -layout(location = 1) in vec4 a_color; - -out vec4 v_color; - -void main() -{ - v_color = a_color; - gl_Position = vec4(a_position, 1.0f); -} diff --git a/assets/glsl/texture.frag b/assets/glsl/texture.frag index 056ef4a..493503a 100644 --- a/assets/glsl/texture.frag +++ b/assets/glsl/texture.frag @@ -2,11 +2,12 @@ layout(location = 0) out vec4 color; +in vec4 v_color; in vec2 v_texCoord; uniform sampler2D u_texture; void main() { - color = texture(u_texture, v_texCoord); + color = v_color * texture(u_texture, v_texCoord); } diff --git a/assets/glsl/texture.vert b/assets/glsl/texture.vert index ee0da5a..a661497 100644 --- a/assets/glsl/texture.vert +++ b/assets/glsl/texture.vert @@ -1,12 +1,19 @@ #version 450 core layout(location = 0) in vec3 a_position; -layout(location = 1) in vec2 a_texCoord; +layout(location = 1) in vec4 a_color; +layout(location = 2) in vec2 a_texCoord; +out vec4 v_color; out vec2 v_texCoord; +uniform mat4 u_projectionView; +uniform mat4 u_model; + void main() { + v_color = a_color; v_texCoord = a_texCoord; - gl_Position = vec4(a_position, 1.0f); + // Vclip = Camera projection * Camera view * Model transform * Vlocal + gl_Position = u_projectionView * u_model * vec4(a_position, 1.0f); }