GameEngineJava/TestGame/res/dev/euph/game/shader/default.fs.glsl

29 lines
849 B
Text
Raw Normal View History

2023-11-13 21:31:36 +00:00
#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;
}
}