textures: add support for emission textures

This commit is contained in:
2023-11-02 22:02:00 +02:00
parent eba6894a07
commit 8decddbf14
4 changed files with 22 additions and 5 deletions
+12
View File
@@ -9,6 +9,7 @@ struct Material {
sampler2D texture_diffuse;
sampler2D texture_specular;
sampler2D texture_ambient;
sampler2D texture_emission;
vec3 ambient;
vec3 diffuse;
@@ -61,6 +62,7 @@ uniform DirLight dirLight;
uniform PointLight pointLights[NR_POINT_LIGHTS];
uniform SpotLight spotLight;
uniform bool useTextures;
uniform bool hasEmissionTexture;
vec3 CalculateDirLight(DirLight light, vec3 normal, vec3 viewDir) {
vec3 lightDir = normalize(-light.direction);
@@ -181,6 +183,12 @@ vec3 CalculateSpotLight(SpotLight light, vec3 normal, vec3 fragPos, vec3 viewDir
void main()
{
// discard completely transparent fragments, such as the ones used in
// leaves or grass textures
if (texture(material.texture_diffuse, texCoords).a == 0.0) {
discard;
}
vec3 norm = normalize(fragNormals);
vec3 viewDir = normalize(viewPos - fragPos);
@@ -194,6 +202,10 @@ void main()
result += CalculateSpotLight(spotLight, norm, fragPos, viewDir);
if (useTextures && hasEmissionTexture) {
result += texture(material.texture_emission, texCoords).rgb;
}
FragColor = vec4(result, material.opacity);
}