Updated bloom shaders (better lighting with specular)

This commit is contained in:
saschawillems 2016-02-24 23:14:47 +01:00
parent 997898032c
commit 4807931164
12 changed files with 22 additions and 21 deletions

View file

@ -80,7 +80,7 @@ public:
int32_t texWidth = TEX_DIM; int32_t texWidth = TEX_DIM;
int32_t texHeight = TEX_DIM; int32_t texHeight = TEX_DIM;
float blurScale = 1.0f; float blurScale = 1.0f;
float blurStrength = 1.0f; float blurStrength = 1.5f;
uint32_t horizontal; uint32_t horizontal;
}; };

View file

@ -8,28 +8,26 @@ layout (binding = 1) uniform sampler2D colorMap;
layout (location = 0) in vec3 inNormal; layout (location = 0) in vec3 inNormal;
layout (location = 1) in vec2 inUV; layout (location = 1) in vec2 inUV;
layout (location = 2) in vec3 inColor; layout (location = 2) in vec3 inColor;
layout (location = 3) in vec3 inEyePos; layout (location = 3) in vec3 inViewVec;
layout (location = 4) in vec3 inLightVec; layout (location = 4) in vec3 inLightVec;
layout (location = 0) out vec4 outFragColor; layout (location = 0) out vec4 outFragColor;
void main() void main()
{ {
// No light calculations for glow color vec3 ambient = vec3(0.0f);
// Use max. color channel value
// to detect bright glow emitters // Adjust light calculations for glow color
if ((inColor.r >= 0.9) || (inColor.g >= 0.9) || (inColor.b >= 0.9)) if ((inColor.r >= 0.9) || (inColor.g >= 0.9) || (inColor.b >= 0.9))
{ {
outFragColor.rgb = inColor; ambient = inColor * 0.25;
} }
else
{
vec3 Eye = normalize(-inEyePos);
vec3 Reflected = normalize(reflect(-inLightVec, inNormal));
vec4 IDiffuse = vec4(inColor, 1.0) * max(dot(inNormal, inLightVec), 0.0); vec3 N = normalize(inNormal);
float specular = 0.25; vec3 L = normalize(inLightVec);
vec4 ISpecular = vec4(0.5, 0.5, 0.5, 1.0) * pow(max(dot(Reflected, Eye), 0.0), 16.0) * specular; vec3 V = normalize(inViewVec);
outFragColor = IDiffuse + ISpecular; vec3 R = reflect(-L, N);
} vec3 diffuse = max(dot(N, L), 0.0) * inColor;
vec3 specular = pow(max(dot(R, V), 0.0), 8.0) * vec3(0.75);
outFragColor = vec4(ambient + diffuse + specular, 1.0);
} }

View file

@ -11,13 +11,13 @@ layout (location = 3) in vec3 inNormal;
layout (binding = 0) uniform UBO layout (binding = 0) uniform UBO
{ {
mat4 projection; mat4 projection;
mat4 model; mat4 modelview;
} ubo; } ubo;
layout (location = 0) out vec3 outNormal; layout (location = 0) out vec3 outNormal;
layout (location = 1) out vec2 outUV; layout (location = 1) out vec2 outUV;
layout (location = 2) out vec3 outColor; layout (location = 2) out vec3 outColor;
layout (location = 3) out vec3 outEyePos; layout (location = 3) out vec3 outViewVec;
layout (location = 4) out vec3 outLightVec; layout (location = 4) out vec3 outLightVec;
void main() void main()
@ -25,8 +25,11 @@ void main()
outNormal = inNormal; outNormal = inNormal;
outColor = inColor; outColor = inColor;
outUV = inUV; outUV = inUV;
gl_Position = ubo.projection * ubo.model * inPos; gl_Position = ubo.projection * ubo.modelview * inPos;
outEyePos = vec3(ubo.model * inPos);
vec4 lightPos = vec4(-5.0, -5.0, 0.0, 1.0); vec3 lightPos = vec3(-5.0, -5.0, 0.0);
outLightVec = normalize(lightPos.xyz - inPos.xyz); vec4 pos = ubo.modelview * inPos;
outNormal = mat3(ubo.modelview) * inNormal;
outLightVec = lightPos - pos.xyz;
outViewVec = -pos.xyz;
} }

Binary file not shown.

Binary file not shown.

Binary file not shown.

Before

Width:  |  Height:  |  Size: 483 KiB

After

Width:  |  Height:  |  Size: 476 KiB

Before After
Before After