basic lighting
This commit is contained in:
@@ -1,11 +1,34 @@
|
||||
#version 330 core
|
||||
|
||||
out vec4 FragColor;
|
||||
in vec3 Color; // Input color from the vertex shader
|
||||
in vec2 TexCoord; // Input texture coordinate from the vertex shader
|
||||
in vec3 FragPos;
|
||||
in vec3 Normal;
|
||||
in vec2 TexCoord;
|
||||
|
||||
uniform vec3 objectColor;
|
||||
uniform vec3 lightColor;
|
||||
uniform vec3 lightPos;
|
||||
uniform vec3 viewPos;
|
||||
uniform sampler2D Texture1;
|
||||
|
||||
void main() {
|
||||
FragColor = texture(Texture1, TexCoord);
|
||||
void main()
|
||||
{
|
||||
// ambient
|
||||
float ambientStrength = 0.1;
|
||||
vec3 ambient = ambientStrength * lightColor;
|
||||
|
||||
// diffuse
|
||||
vec3 norm = normalize(Normal);
|
||||
vec3 lightDir = normalize(lightPos - FragPos);
|
||||
float diff = max(dot(norm, lightDir), 0.0);
|
||||
vec3 diffuse = diff * lightColor;
|
||||
|
||||
// specular
|
||||
float specularStrength = 0.5;
|
||||
vec3 viewDir = normalize(viewPos - FragPos);
|
||||
vec3 reflectDir = normalize(reflect(-lightDir, norm));
|
||||
float spec = pow(max(dot(viewDir, reflectDir), 0.0), 32.0);
|
||||
vec3 specular = specularStrength * spec * lightColor;
|
||||
|
||||
vec3 result = (ambient + diffuse + specular) * texture(Texture1, TexCoord).rgb;
|
||||
FragColor = vec4(result, 1.0);
|
||||
}
|
||||
@@ -3,8 +3,9 @@
|
||||
layout(location = 0) in vec3 position; // Vertex position
|
||||
layout(location = 1) in vec3 normal; // Vertex normal
|
||||
layout(location = 2) in vec2 texCoord; // Vertex texture coordinate
|
||||
out vec3 Color; // Output color to the fragment shader
|
||||
out vec2 TexCoord; // Output texture coordinate to the fragment shader
|
||||
out vec3 Normal;
|
||||
out vec3 FragPos;
|
||||
out vec2 TexCoord;
|
||||
|
||||
uniform mat4 model;
|
||||
uniform mat4 view;
|
||||
@@ -12,6 +13,7 @@ uniform mat4 projection;
|
||||
|
||||
void main() {
|
||||
gl_Position = projection * view * model * vec4(position, 1.0); // Apply transformation matrices
|
||||
Color = normal * 0.5 + 0.5; // Simple coloring based on normal
|
||||
TexCoord = texCoord; // Pass through the texture coordinate
|
||||
FragPos = vec3(model * vec4(position, 1.0));
|
||||
Normal = mat3(transpose(inverse(model))) * normal;
|
||||
TexCoord = texCoord;
|
||||
}
|
||||
7
shaders/triangle_light_source.frag
Normal file
7
shaders/triangle_light_source.frag
Normal file
@@ -0,0 +1,7 @@
|
||||
#version 330 core
|
||||
out vec4 FragColor;
|
||||
|
||||
void main()
|
||||
{
|
||||
FragColor = vec4(1.0); // set all 4 vector values to 1.0
|
||||
}
|
||||
Reference in New Issue
Block a user