47 lines
1.1 KiB
GLSL
47 lines
1.1 KiB
GLSL
#version 430 core
|
|
|
|
float AMBIENT = 0.1;
|
|
|
|
uniform vec3 color;
|
|
uniform vec3 lightPos;
|
|
uniform vec3 lightColor;
|
|
|
|
in vec3 vecNormal;
|
|
in vec3 worldPos;
|
|
in vec2 vtc;
|
|
vec4 textureColor;
|
|
layout (location = 0) out vec4 outColor;
|
|
layout (location = 1) out vec4 bloomColor;
|
|
|
|
vec3 outputColor;
|
|
uniform sampler2D colorTexture;
|
|
|
|
vec3 toneMapping(vec3 color)
|
|
{
|
|
float exposure = 0.06;
|
|
vec3 mapped = 1 - exp(-color * exposure);
|
|
return mapped;
|
|
}
|
|
|
|
void main()
|
|
{
|
|
vec3 lightDir = normalize(lightPos - worldPos);
|
|
vec3 normal = normalize(vecNormal);
|
|
float diffuse = max(0, dot(normal, lightDir));
|
|
textureColor = texture2D(colorTexture, vtc);
|
|
|
|
vec3 distance = lightColor / pow(length(lightPos - worldPos), 2.0) * 200;
|
|
outputColor = vec3(textureColor) * min(1, AMBIENT + diffuse) * distance;
|
|
|
|
//gamma correction
|
|
//outputColor = pow(outputColor, vec3(1.0/2.2));
|
|
|
|
outputColor = toneMapping(outputColor);
|
|
outColor = vec4(outputColor , 1.0);
|
|
|
|
float brightness = dot(outColor.rgb, vec3(0.2126f, 0.7152f, 0.0722f));
|
|
if(brightness > 0.15f)
|
|
bloomColor = vec4(outColor.rgb, 1.0f);
|
|
else
|
|
bloomColor = vec4(0.0f, 0.0f, 0.0f, 1.0f);
|
|
} |