Last active
June 27, 2021 13:16
-
-
Save mkvenkit/a29421ca4fbcd470799bd814646c5abf to your computer and use it in GitHub Desktop.
Vertex shader for Phong shading
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#version 450 core | |
layout(location = 0) in vec3 aVert; | |
layout(location = 1) in vec3 aNorm; | |
uniform mat4 vMat; | |
uniform mat4 pMat; | |
uniform mat4 mMat; | |
out VS_OUT { | |
out vec3 N; | |
out vec3 L; | |
out vec3 V; | |
} vs_out; | |
void main() | |
{ | |
// vertex in world coords | |
vec3 wcVert = (vMat * mMat * vec4(aVert, 1.0)).xyz; | |
// normal in world coords | |
mat4 nMat = transpose(inverse(vMat * mMat)); | |
vs_out.N = (nMat* vec4(aNorm, 1.0)).xyz; | |
// diffuse | |
vec3 lightPos = vec3(0.0, 0.0, 10.0); | |
vs_out.L = lightPos - wcVert; | |
// specular | |
vs_out.V = -wcVert; | |
gl_Position = pMat * vMat * mMat * vec4(aVert, 1.0); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment