Added lens dirt, posterization and pixelization postfx
This commit is contained in:
@@ -23,6 +23,9 @@ uniform float u_Exposure;
|
||||
uniform float u_Gamma;
|
||||
uniform sampler2D u_Source2;
|
||||
uniform vec2 u_Source2Size;
|
||||
uniform int u_HasLensDirt;
|
||||
uniform sampler2D u_LensDirt;
|
||||
uniform float u_LensDirtIntensity;
|
||||
|
||||
uniform float u_Threshold;
|
||||
uniform float u_BlurAmount;
|
||||
@@ -127,6 +130,13 @@ void main()
|
||||
}
|
||||
else if (u_Stage == 5) // Final combine
|
||||
{
|
||||
vec4 lensDirt = vec4(0.0f);
|
||||
if(u_HasLensDirt == 1)
|
||||
{
|
||||
lensDirt = max(texture(u_LensDirt, UV) * u_LensDirtIntensity, 1.0 - u_LensDirtIntensity);
|
||||
}
|
||||
|
||||
outputColor *= lensDirt;
|
||||
outputColor += texture(u_Source2, UV);
|
||||
|
||||
vec3 color = outputColor.rgb;
|
||||
|
||||
40
Resources/Shaders/pixelization.shader
Normal file
40
Resources/Shaders/pixelization.shader
Normal file
@@ -0,0 +1,40 @@
|
||||
#shader vertex
|
||||
#version 440 core
|
||||
|
||||
layout(location = 0) in vec3 VertexPosition;
|
||||
layout(location = 1) in vec2 UVPosition;
|
||||
|
||||
out flat vec2 UV;
|
||||
|
||||
void main()
|
||||
{
|
||||
UV = UVPosition;
|
||||
gl_Position = vec4(VertexPosition, 1.0f);
|
||||
}
|
||||
|
||||
#shader fragment
|
||||
#version 440 core
|
||||
|
||||
uniform int u_PixelSize = 4;
|
||||
|
||||
uniform sampler2D u_Source;
|
||||
uniform vec2 u_SourceSize;
|
||||
|
||||
in vec2 UV;
|
||||
|
||||
out vec4 FragColor;
|
||||
|
||||
// Implementation from: https://lettier.github.io/3d-game-shaders-for-beginners/pixelization.html
|
||||
void main()
|
||||
{
|
||||
vec2 pixelCoord = UV * u_SourceSize;
|
||||
float x = int(pixelCoord.x) % u_PixelSize;
|
||||
float y = int(pixelCoord.y) % u_PixelSize;
|
||||
|
||||
x = floor(u_PixelSize / 2.0) - x;
|
||||
y = floor(u_PixelSize / 2.0) - y;
|
||||
|
||||
x = pixelCoord.x + x;
|
||||
y = pixelCoord.y + y;
|
||||
FragColor = texture(u_Source, vec2(x, y) / u_SourceSize);
|
||||
}
|
||||
36
Resources/Shaders/posterization.shader
Normal file
36
Resources/Shaders/posterization.shader
Normal file
@@ -0,0 +1,36 @@
|
||||
#shader vertex
|
||||
#version 440 core
|
||||
|
||||
layout(location = 0) in vec3 VertexPosition;
|
||||
layout(location = 1) in vec2 UVPosition;
|
||||
|
||||
out flat vec2 UV;
|
||||
|
||||
void main()
|
||||
{
|
||||
UV = UVPosition;
|
||||
gl_Position = vec4(VertexPosition, 1.0f);
|
||||
}
|
||||
|
||||
#shader fragment
|
||||
#version 440 core
|
||||
|
||||
uniform sampler2D u_Source;
|
||||
uniform int u_Levels = 10;
|
||||
in vec2 UV;
|
||||
|
||||
out vec4 FragColor;
|
||||
|
||||
// Implementation from: https://lettier.github.io/3d-game-shaders-for-beginners/posterization.html
|
||||
void main()
|
||||
{
|
||||
vec4 frameColor = texture(u_Source, UV);
|
||||
float greyscale = max(frameColor.r, max(frameColor.g, frameColor.b));
|
||||
float lower = floor(greyscale * u_Levels) / u_Levels;
|
||||
float lowerDiff = abs(greyscale - lower);
|
||||
float upper = ceil(greyscale * u_Levels) / u_Levels;
|
||||
float upperDiff = abs(upper - greyscale);
|
||||
float level = lowerDiff <= upperDiff ? lower : upper;
|
||||
float adjustment = level / greyscale;
|
||||
FragColor = frameColor * adjustment;
|
||||
}
|
||||
Reference in New Issue
Block a user