add: added point light shader and light object shader
This commit is contained in:
parent
d1b444bcef
commit
0337c70e26
3 changed files with 68 additions and 16 deletions
9
resources/shaders/light_object.glsl
Normal file
9
resources/shaders/light_object.glsl
Normal file
|
@ -0,0 +1,9 @@
|
|||
#version 330 core
|
||||
out vec4 FragColor;
|
||||
|
||||
uniform vec3 lightColor;
|
||||
|
||||
void main()
|
||||
{
|
||||
FragColor = vec4(lightColor, 1.0f);
|
||||
}
|
|
@ -11,6 +11,7 @@ struct Light {
|
|||
vec3 ambient;
|
||||
vec3 diffuse;
|
||||
vec3 specular;
|
||||
vec3 color;
|
||||
|
||||
float constant;
|
||||
float linear;
|
||||
|
@ -22,14 +23,17 @@ uniform vec3 viewPos;
|
|||
uniform Light light;
|
||||
|
||||
void main()
|
||||
{
|
||||
{
|
||||
float distance = length(light.position - FragPos);
|
||||
float attenuation = 1.0 / (light.constant + light.linear * distance + light.quadratic * (distance * distance));
|
||||
|
||||
// ambient// ambient
|
||||
float ambientStrength = 0.1;
|
||||
vec3 ambient = ambientStrength * light.color;
|
||||
|
||||
// diffuse
|
||||
vec3 norm = normalize(Normal);
|
||||
vec3 lightDir = normalize(-light.direction);
|
||||
vec3 lightDir = normalize(light.position - FragPos);
|
||||
float diff = max(dot(norm, lightDir), 0.0);
|
||||
vec3 diffuse = diff * light.color;
|
||||
|
||||
|
@ -39,6 +43,10 @@ void main()
|
|||
vec3 reflectDir = reflect(-lightDir, norm);
|
||||
float spec = pow(max(dot(viewDir, reflectDir), 0.0), 32);
|
||||
vec3 specular = specularStrength * spec * light.color;
|
||||
|
||||
ambient *= attenuation;
|
||||
diffuse *= attenuation;
|
||||
specular *= attenuation;
|
||||
|
||||
vec3 result = ambient + diffuse + specular;
|
||||
vec4 light = vec4(result, 1.0);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue