summaryrefslogtreecommitdiffstats
path: root/engine/shaders/forward.vert
blob: bb38cc740c66d88f18848b542a70bae25b0f5139 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
// Forward rendering vertex shader.
//
// Copyright 2020 Sergiusz 'q3k' Bazanski <q3k@q3k.org>
//
// This file is part of Abrasion.
//
// Abrasion is free software: you can redistribute it and/or modify it under
// the terms of the GNU General Public License as published by the Free
// Software Foundation, version 3.
//
// Abrasion is distributed in the hope that it will be useful, but WITHOUT ANY
// WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
// FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
// details.
//
// You should have received a copy of the GNU General Public License along with
// Abrasion.  If not, see <https://www.gnu.org/licenses/>.
//
// vim: set ft=glsl:

#version 450

layout(push_constant) uniform PushConstantObject {
    mat4 view;
} pco;

layout(location = 0) in vec3 pos;
layout(location = 1) in vec3 normal;
layout(location = 2) in mat4 model;
layout(location = 6) in vec2 tex;

layout(location = 0) out vec2 fragTexCoord;
layout(location = 1) out vec3 fragWorldPos;
layout(location = 2) out vec3 fragNormal;

out gl_PerVertex {
    vec4 gl_Position;
};

void main() {
    vec4 world = model * vec4(pos, 1.0);
    vec4 normal4 = model * vec4(normal, 1.0);

    fragTexCoord = tex;
    fragNormal = normal4.xyz / normal4.w;
    fragWorldPos = world.xyz / world.w;

    gl_Position = pco.view * world;
    // Vulkanize (see comment about counter-clockwise triangles in //engine/src/render/vulkan/pipeline_forward.rs).
    gl_Position.y = -gl_Position.y;
}