GameEngineJava/TestGame/res/dev/euph/game/shader/default.fs.glsl
2024-08-28 21:39:49 +02:00

29 lines
No EOL
849 B
GLSL

#version 330 core
in vec2 passTextureCoords;
in vec3 passNormals;
uniform vec4 color;
uniform sampler2D albedoTexture;
uniform bool useAlbedoTexture;
out vec4 fragmentColor;
void main() {
if (useAlbedoTexture) {
vec4 textureColor = texture(albedoTexture, passTextureCoords);
vec3 lightDirection = normalize(vec3(0.5, 0.5, 1.0)); // Direction of the light source
// Calculate diffuse lighting
float diffuseFactor = max(dot(normalize(passNormals), lightDirection), 0.0);
vec3 diffuseLight = vec3(1.0) * diffuseFactor;
// Combine diffuse lighting and texture color
vec3 finalColor = (diffuseLight + color.xyz) * textureColor.rgb;
fragmentColor = vec4(finalColor, textureColor.a);
} else {
// If no texture, use the solid color
fragmentColor = color;
}
}