Added basic shading and support for up to 100 lights of any color; By default now, states with no lights are dark
This commit is contained in:
1 parent
dff0d86558
commit
5c10fdc1a4
35 files changed
+4037
-2664
No files matched your search
@@ -1,11 +1,65 @@
|
||||
#version 330 core
|
||||
|
||||
in vec2 texCoord;
|
||||
in vec3 normals;
|
||||
in vec3 fragPos;
|
||||
|
||||
uniform sampler2D tex;
|
||||
struct Camera {
|
||||
vec3 pos;
|
||||
};
|
||||
|
||||
out vec4 color;
|
||||
struct Material {
|
||||
float shininess;
|
||||
//Do I want a specular color here?
|
||||
};
|
||||
|
||||
struct Light {
|
||||
//Directional = 1, Point = 2, Spotlight = 3
|
||||
int type;
|
||||
vec3 pos;
|
||||
vec3 direction;
|
||||
vec3 color;
|
||||
|
||||
float falloffConstant;
|
||||
float falloffLinear;
|
||||
float falloffQuad;
|
||||
|
||||
float cutoff;
|
||||
};
|
||||
|
||||
uniform sampler2D modelTexture;
|
||||
uniform Camera camera;
|
||||
uniform Material material;
|
||||
uniform Light light[100];
|
||||
uniform int numberOfLights;
|
||||
|
||||
out vec4 outColor;
|
||||
|
||||
void main() {
|
||||
color = texture(tex, texCoord);
|
||||
vec4 texColor = texture(modelTexture, texCoord);
|
||||
|
||||
vec3 color = vec3(0.0);
|
||||
|
||||
for (int i = 0; i < numberOfLights; i++) {
|
||||
float ambientStrength = 0.2f;
|
||||
vec3 ambient = ambientStrength * texColor.rgb;
|
||||
if (i == numberOfLights - 1 && numberOfLights == 1) {
|
||||
color += ambient;
|
||||
break;
|
||||
}
|
||||
|
||||
vec3 norm = normalize(normals);
|
||||
vec3 lightDir = normalize(light[i].pos - fragPos);
|
||||
float diff = max(dot(norm, lightDir), 0.0);
|
||||
vec3 diffuse = light[i].color * (diff * texColor.rgb);
|
||||
|
||||
vec3 viewDir = normalize(camera.pos - fragPos);
|
||||
vec3 reflectDir = reflect(-lightDir, norm);
|
||||
float spec = pow(max(dot(viewDir, reflectDir), 0.0), material.shininess * 32.0f);
|
||||
vec3 specular = light[i].color * spec;
|
||||
|
||||
color += (ambient + diffuse + specular);
|
||||
}
|
||||
|
||||
outColor = vec4(color, texColor.a);
|
||||
}
|
||||
@@ -2,14 +2,20 @@
|
||||
|
||||
layout(location = 0) in vec3 pos;
|
||||
layout(location = 1) in vec2 texCoords;
|
||||
layout(location = 2) in vec3 normal;
|
||||
|
||||
uniform mat4 model;
|
||||
uniform mat4 view;
|
||||
uniform mat4 proj;
|
||||
|
||||
out vec2 texCoord;
|
||||
out vec3 normals;
|
||||
out vec3 fragPos;
|
||||
|
||||
void main() {
|
||||
gl_Position = proj * view * model * vec4(pos, 1.0);
|
||||
texCoord = texCoords;
|
||||
normals = mat3(transpose(inverse(model))) * normal;
|
||||
fragPos = vec3(model * vec4(pos, 1.0));
|
||||
|
||||
gl_Position = proj * view * model * vec4(pos, 1.0);
|
||||
}
|
||||
Reference in new issue
Block a user