more lighting
This commit is contained in:
parent
16b674efc1
commit
79fa59c3aa
5 changed files with 89 additions and 27 deletions
|
|
@ -1,16 +1,56 @@
|
|||
#version 330 core
|
||||
out vec4 FragColor;
|
||||
|
||||
in vec3 FragPos;
|
||||
in vec3 Normal;
|
||||
in vec2 TexCoord;
|
||||
|
||||
uniform sampler2D ourTexture;
|
||||
uniform sampler2D decal;
|
||||
|
||||
void main()
|
||||
{
|
||||
uniform vec3 lightPos;
|
||||
uniform vec3 lightColor;
|
||||
uniform vec3 viewPos;
|
||||
|
||||
vec4 calcTextures(){
|
||||
vec4 tex1 = texture(ourTexture, TexCoord);
|
||||
vec4 tex2 = texture(decal, TexCoord);
|
||||
vec4 textures = mix(tex1, tex2, 0.2f);
|
||||
|
||||
FragColor = textures;
|
||||
return textures;
|
||||
}
|
||||
|
||||
vec4 calcDirectLight(norm, viewDir){
|
||||
// Ambient Lighting
|
||||
float ambientStrength = 0.1;
|
||||
vec3 ambient = ambientStrength * lightColor;
|
||||
|
||||
// Diffuse Lighting
|
||||
vec3 lightDir = normalize(lightPos - FragPos);
|
||||
|
||||
float diff = max(dot(norm, lightDir), 0.0);
|
||||
vec3 diffuse = diff * lightColor;
|
||||
|
||||
// Specular Lighting
|
||||
float specularStrength = 0.5;
|
||||
|
||||
vec3 reflectDir = reflect(-lightDir, norm);
|
||||
|
||||
float spec = pow(max(dot(viewDir, reflectDir), 0.0), 32);
|
||||
vec3 specular = specularStrength * spec * lightColor;
|
||||
|
||||
vec4 result = vec4(ambient.rgb + diffuse.rgb + specular.rgb, 1.0f);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
void main()
|
||||
{
|
||||
vec3 norm = normalize(Normal);
|
||||
vec3 viewDir = normalize(viewPos - FragPos);
|
||||
|
||||
vec4 result = calcTextures();
|
||||
result += calcDirectLight(norm, viewDir);
|
||||
|
||||
FragColor = result;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue