From f3a34665978729ef65010ac2a4a9408e27d5bf3e Mon Sep 17 00:00:00 2001 From: ccolin Date: Mon, 28 Dec 2020 17:36:45 +0100 Subject: skybox --- shaders/main.frag | 20 ++++++++++++++++++++ shaders/main.vert | 20 ++++++++++++++++++++ shaders/skybox.frag | 23 +++++++++++++++++++++++ shaders/skybox.vert | 28 ++++++++++++++++++++++++++++ 4 files changed, 91 insertions(+) create mode 100644 shaders/main.frag create mode 100644 shaders/main.vert create mode 100644 shaders/skybox.frag create mode 100644 shaders/skybox.vert (limited to 'shaders') diff --git a/shaders/main.frag b/shaders/main.frag new file mode 100644 index 0000000..8eb47ec --- /dev/null +++ b/shaders/main.frag @@ -0,0 +1,20 @@ +#version 330 core + +in vec3 norm; +in vec2 uv; +in vec3 frag_pos; + +out vec4 final_col; + +uniform sampler2D tex; + +void main() { + vec3 light_col = vec3(1, .964, .783); + vec3 ambient = light_col * .2; + + vec3 light_dir = normalize(vec3(5, 10, -8)); + float diff = max(dot(normalize(norm), light_dir), 0.0); + vec3 diffuse = diff * light_col; + + final_col = texture(tex, uv) * vec4(ambient + diffuse, 1); +} diff --git a/shaders/main.vert b/shaders/main.vert new file mode 100644 index 0000000..33e6849 --- /dev/null +++ b/shaders/main.vert @@ -0,0 +1,20 @@ +#version 330 core + +layout(location = 0) in vec3 in_pos; +layout(location = 1) in vec3 in_norm; +layout(location = 2) in vec2 in_uv; + +out vec3 norm; +out vec2 uv; +out vec3 frag_pos; + +uniform mat4 proj; +uniform mat4 view; +uniform mat4 model; + +void main() { + gl_Position = proj * view * model * vec4(in_pos, 1.0); + norm = in_norm; + uv = in_uv; + frag_pos = vec3(model * vec4(in_pos, 1.0)); +} diff --git a/shaders/skybox.frag b/shaders/skybox.frag new file mode 100644 index 0000000..f5f8edb --- /dev/null +++ b/shaders/skybox.frag @@ -0,0 +1,23 @@ +#version 330 core + +// in vec3 tex_coord; + +// out vec4 final_col; + +// uniform samplerCube skybox; + +// void main() { +// // final_col = texture(skybox, tex_coord); +// final_col = vec4(0, 0, 0, 1); +// } + +in vec3 tex_coords; + +out vec4 final_col; + +uniform samplerCube tex; + +void main() { + final_col = texture(tex, tex_coords); + // final_col = vec4(1, 0, 1, 1); +} diff --git a/shaders/skybox.vert b/shaders/skybox.vert new file mode 100644 index 0000000..ac4ac5e --- /dev/null +++ b/shaders/skybox.vert @@ -0,0 +1,28 @@ +#version 330 core + +// layout(location = 0) in vec3 in_pos; + +// out vec3 tex_coords; + +// uniform mat4 proj; +// uniform mat4 view; + +// void main() { +// // vec4 pos = proj * view * vec4(in_pos, 1.0); +// // gl_Position = pos.xyww; +// gl_Position = proj * vec4(in_pos, 1.0); +// tex_coords = in_pos; +// } + +layout(location = 0) in vec3 in_pos; + +out vec3 tex_coords; + +uniform mat4 proj; +uniform mat4 view; + +void main() { + tex_coords = in_pos; + vec4 pos = proj * mat4(mat3(view)) * vec4(in_pos, 1.0); + gl_Position = pos.xyww; +} -- cgit v1.2.3-70-g09d2