source: opengl-game/shaders/ship.vert@ 60578ce

feature/imgui-sdl points-test
Last change on this file since 60578ce was 60578ce, checked in by Dmitry Portnoy <dmp1488@…>, 5 years ago

In VulkanGame, make lighting work correctly in the ship shader with the model, view, and projection matrices all being applied

  • Property mode set to 100644
File size: 1.5 KB
Line 
1#version 450
2#extension GL_ARB_separate_shader_objects : enable
3
4struct Object {
5 mat4 model;
6};
7
8layout (binding = 0) uniform UniformBufferObject {
9 mat4 view;
10 mat4 proj;
11} ubo;
12
13layout(binding = 1) readonly buffer StorageBufferObject {
14 Object objects[];
15} sbo;
16
17layout(location = 0) in vec3 vertex_position;
18layout(location = 1) in vec3 vertex_color;
19layout(location = 2) in vec3 vertex_normal;
20layout(location = 3) in uint obj_index;
21
22layout(location = 0) out vec3 position_eye;
23layout(location = 1) out vec3 color;
24layout(location = 2) out vec3 normal_eye;
25layout(location = 3) out vec3 light_position_eye;
26layout(location = 4) out vec3 light2_position_eye;
27
28// fixed point light positions
29//vec3 light_position_world = vec3(0.0, 0.0, 2.0);
30//vec3 light2_position_world = vec3(0.0, 1.5, -0.1);
31vec3 light_position_world = vec3(7.0, -7.0, -10.0);
32vec3 light2_position_world = vec3(4.0, -3.0, -10.0);
33
34// TODO: This does not account for scaling in the model matrix
35// Check Anton's book to see how to fix this
36void main() {
37 position_eye = vec3(ubo.view * sbo.objects[obj_index].model * vec4(vertex_position, 1.0));
38
39 // Using 0.0 instead of 1.0 means translations won't effect the normal
40 normal_eye = normalize(vec3(ubo.view * sbo.objects[obj_index].model * vec4(vertex_normal, 0.0)));
41
42 color = vertex_color;
43
44 light_position_eye = vec3(ubo.view * vec4(light_position_world, 1.0));
45 light2_position_eye = vec3(ubo.view * vec4(light2_position_world, 1.0));
46
47 gl_Position = ubo.proj * vec4(position_eye, 1.0);
48}
Note: See TracBrowser for help on using the repository browser.