mirror of
https://github.com/cyberarm/i-mic-fps.git
synced 2025-12-15 15:42:35 +00:00
Initital shader lighting support
This commit is contained in:
@@ -5,6 +5,8 @@ in vec3 outColor;
|
||||
in vec4 outNormal;
|
||||
in vec3 outUV;
|
||||
in float outTextureID;
|
||||
in vec3 outLightPos;
|
||||
in vec3 outFragPos;
|
||||
|
||||
// optimizing compilers are annoying at this stage of my understanding of GLSL
|
||||
vec4 lokiVar;
|
||||
@@ -12,5 +14,13 @@ vec4 lokiVar;
|
||||
void main() {
|
||||
lokiVar = vec4(outColor, 1.0) + outNormal + vec4(outUV, 1.0) + vec4(outTextureID, 1.0, 1.0, 1.0);
|
||||
lokiVar = normalize(lokiVar);
|
||||
gl_FragColor = vec4(outColor, 1.0);
|
||||
|
||||
vec3 lightDir = normalize(outLightPos - outFragPos);
|
||||
vec3 ambient = vec3(0.5, 0.5, 0.35);
|
||||
float diffuse = max(dot(vec3(outNormal), lightDir), -0.2);
|
||||
vec3 specular = vec3(0, 0, 0);
|
||||
|
||||
vec3 result =(ambient + diffuse + specular) * outColor;
|
||||
|
||||
gl_FragColor = vec4(result, 1.0);
|
||||
}
|
||||
@@ -12,11 +12,15 @@ out vec4 outNormal;
|
||||
out vec3 outUV;
|
||||
out float outTextureID;
|
||||
out float outHasTexture;
|
||||
out vec3 outLightPos;
|
||||
out vec3 outFragPos;
|
||||
|
||||
uniform mat4 projection;
|
||||
uniform mat4 view;
|
||||
uniform mat4 model;
|
||||
uniform int hasTexture;
|
||||
uniform vec3 lightPos;
|
||||
|
||||
|
||||
void main() {
|
||||
// projection * view * model * position
|
||||
@@ -26,6 +30,9 @@ void main() {
|
||||
outUV = inUV;
|
||||
outTextureID = inTextureID;
|
||||
outHasTexture = hasTexture;
|
||||
outLightPos = lightPos;
|
||||
|
||||
outFragPos = vec3(model * vec4(inPosition, 1.0));
|
||||
|
||||
gl_Position = projection * view * model * vec4(inPosition, 1.0);
|
||||
}
|
||||
Reference in New Issue
Block a user