Continued with lighting
This commit is contained in:
parent
597a14743b
commit
e88d972ecc
12 changed files with 95 additions and 6 deletions
|
|
@ -1,13 +1,47 @@
|
|||
#version 330
|
||||
#define PI 3.14159265359
|
||||
|
||||
struct Light {
|
||||
int Type;
|
||||
vec2 Position;
|
||||
vec4 Color;
|
||||
};
|
||||
|
||||
in vec2 vTexture;
|
||||
|
||||
vec4 GetRenderColor();
|
||||
in vec2 FragPos;
|
||||
|
||||
uniform vec4 Ambient = vec4(1);
|
||||
uniform Light[24] Lights;
|
||||
uniform int LightCount;
|
||||
|
||||
layout(location = 0) out vec4 color;
|
||||
|
||||
vec4 GetRenderColor();
|
||||
|
||||
vec3 calcPointLight(Light light) {
|
||||
float dis = distance(FragPos, light.Position);
|
||||
float intensity = 4 / 4 * PI * pow(dis, 2);
|
||||
|
||||
return vec3(light.Color * intensity);
|
||||
}
|
||||
|
||||
vec3 calcLight() {
|
||||
vec3 addedLight = vec3(0);
|
||||
|
||||
for(int i = 0; i < LightCount; i++) {
|
||||
Light light = Lights[i];
|
||||
|
||||
switch(light.Type) {
|
||||
case 0:
|
||||
addedLight += calcPointLight(light);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return addedLight;
|
||||
}
|
||||
|
||||
void main() {
|
||||
color = GetRenderColor() * Ambient;
|
||||
color += vec4(calcLight(), 1);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue