forked from gameprogcpp/code
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPhong.vert
More file actions
44 lines (37 loc) · 1.25 KB
/
Phong.vert
File metadata and controls
44 lines (37 loc) · 1.25 KB
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
// ----------------------------------------------------------------
// From Game Programming in C++ by Sanjay Madhav
// Copyright (C) 2017 Sanjay Madhav. All rights reserved.
//
// Released under the BSD License
// See LICENSE in root directory for full details.
// ----------------------------------------------------------------
// Request GLSL 3.3
#version 330
// Uniforms for world transform and view-proj
uniform mat4 uWorldTransform;
uniform mat4 uViewProj;
// Attribute 0 is position, 1 is normal, 2 is tex coords.
layout(location = 0) in vec3 inPosition;
layout(location = 1) in vec3 inNormal;
layout(location = 2) in vec2 inTexCoord;
// Any vertex outputs (other than position)
out vec2 fragTexCoord;
// Normal (in world space)
out vec3 fragNormal;
// Position (in world space)
out vec3 fragWorldPos;
void main()
{
// Convert position to homogeneous coordinates
vec4 pos = vec4(inPosition, 1.0);
// Transform position to world space
pos = pos * uWorldTransform;
// Save world position
fragWorldPos = pos.xyz;
// Transform to clip space
gl_Position = pos * uViewProj;
// Transform normal into world space (w = 0)
fragNormal = (vec4(inNormal, 0.0f) * uWorldTransform).xyz;
// Pass along the texture coordinate to frag shader
fragTexCoord = inTexCoord;
}