Grafika2023/PlanetCreator/cw 6/shaders/shader_pbr.frag
2024-01-31 16:09:43 +01:00

52 lines
1.1 KiB
GLSL

#version 430 core
float AMBIENT = 0.1;
uniform vec3 color;
uniform vec3 lightPos;
uniform sampler2D colorTexture;
in vec3 fragNormal;
in vec3 fragPosition;
in vec2 texCoords;
out vec4 outColor;
uniform float shininess;
uniform vec3 ambientColor;
uniform vec3 specularColor;
uniform vec3 emissiveColor;
uniform float opticalDensity;
uniform float dissolve;
uniform int illuminationModel;
void main()
{
vec3 lightDir = normalize(lightPos - fragPosition);
vec3 normal = normalize(fragNormal);
float diffuse = max(0.0, dot(normal, lightDir));
vec3 lambertian = texture(colorTexture, texCoords).rgb * diffuse;
vec3 viewDir = normalize(-fragPosition);
vec3 halfwayDir = normalize(lightDir + viewDir);
float specular = pow(max(0.0, dot(normal, halfwayDir)), shininess);
vec3 blinnPhong = specularColor * specular;
vec3 emissive = emissiveColor;
vec3 ambient = ambientColor * AMBIENT;
vec3 finalColor = lambertian + blinnPhong + emissive + ambient;
finalColor *= (1.0 - dissolve);
outColor = vec4(finalColor, 1.0);
}