diff options
-rw-r--r-- | engine/fragment.glsl | 13 | ||||
-rw-r--r-- | engine/vertex.glsl | 13 |
2 files changed, 9 insertions, 17 deletions
diff --git a/engine/fragment.glsl b/engine/fragment.glsl index afeef25..cc46f36 100644 --- a/engine/fragment.glsl +++ b/engine/fragment.glsl @@ -7,10 +7,7 @@ out vec4 FragColor; -in vec2 in_texture_coords; - -in vec3 in_frag_pos; -in vec3 in_normal; +in VertexData vertex_data; uniform vec3 view_pos; uniform sampler2D input_texture; @@ -20,13 +17,7 @@ uniform int point_light_cnt; void main() { - VertexData vertex_data; - - vertex_data.texture_coords = in_texture_coords; - vertex_data.world_space_pos = in_frag_pos; - vertex_data.world_space_normal = in_normal; - - vec3 ambient_light = calc_ambient_light(material, in_texture_coords); + vec3 ambient_light = calc_ambient_light(material, vertex_data.texture_coords); vec3 point_light_sum = vec3(0.0, 0.0, 0.0); diff --git a/engine/vertex.glsl b/engine/vertex.glsl index f282864..b57caa6 100644 --- a/engine/vertex.glsl +++ b/engine/vertex.glsl @@ -1,11 +1,12 @@ #version 330 core + +#preinclude "vertex_data.glsl" + layout (location = 0) in vec3 pos; layout (location = 1) in vec2 texture_coords; layout (location = 2) in vec3 normal; -out vec3 in_frag_pos; -out vec2 in_texture_coords; -out vec3 in_normal; +out VertexData vertex_data; uniform mat4 model; uniform mat4 view; @@ -15,9 +16,9 @@ void main() { gl_Position = projection * view * model * vec4(pos, 1.0); - in_frag_pos = vec3(model * vec4(pos, 1.0)); - in_texture_coords = texture_coords; + vertex_data.world_space_pos = vec3(model * vec4(pos, 1.0)); + vertex_data.texture_coords = texture_coords; // TODO: Do this using CPU for performance increase - in_normal = mat3(transpose(inverse(model))) * normal; + vertex_data.world_space_normal = mat3(transpose(inverse(model))) * normal; } |