This commit is contained in:
milek7
2018-07-11 12:36:49 +02:00
parent e53b4fba26
commit 59cea820b0
4 changed files with 107 additions and 0 deletions

26
shaders/postfx.vert Normal file
View File

@@ -0,0 +1,26 @@
#version 330 core
const vec2 vert[4] = vec2[]
(
vec2(-1.0, 1.0),
vec2(-1.0, -1.0),
vec2( 1.0, 1.0),
vec2( 1.0, -1.0)
);
const vec2 uv[4] = vec2[]
(
vec2(0.0, 1.0),
vec2(0.0, 0.0),
vec2(1.0, 1.0),
vec2(1.0, 0.0)
);
out vec2 TexCoords;
void main()
{
gl_Position = vec4(vert[gl_VertexID], 0.0, 1.0);
TexCoords = uv[gl_VertexID];
}

57
shaders/postfx_copy.frag Normal file
View File

@@ -0,0 +1,57 @@
#version 330 core
out vec4 FragColor;
in vec2 TexCoords;
uniform sampler2D tex1;
vec3 reinhard(vec3 x)
{
return x / (x + vec3(1.0));
}
// https://knarkowicz.wordpress.com/2016/01/06/aces-filmic-tone-mapping-curve/
vec3 ACESFilm(vec3 x)
{
float a = 2.51f;
float b = 0.03f;
float c = 2.43f;
float d = 0.59f;
float e = 0.14f;
return (x*(a*x+b))/(x*(c*x+d)+e);
}
// https://www.slideshare.net/ozlael/hable-john-uncharted2-hdr-lighting
vec3 filmicF(vec3 x)
{
float A = 0.22f;
float B = 0.30f;
float C = 0.10f;
float D = 0.20f;
float E = 0.01f;
float F = 0.30f;
return ((x*(A*x+C*B)+D*E)/(x*(A*x+B)+D*F)) - E/F;
}
vec3 filmic(vec3 x)
{
return filmicF(x) / filmicF(vec3(11.2f));
}
void main()
{
vec2 texcoord = TexCoords;
// float x = texcoord.x;
// texcoord.x += sin(texcoord.y * 4*2*3.14159 + 0) / 100;
// texcoord.y += sin(x * 4*2*3.14159 + 0) / 100;
vec3 hdr_color = texture(tex1, texcoord).xyz;
vec3 mapped;
if (texcoord.x < 0.33f)
mapped = reinhard(hdr_color);
else if (texcoord.x < 0.66f)
mapped = filmic(hdr_color);
else
mapped = ACESFilm(hdr_color);
gl_FragColor = vec4(mapped, 1.0);
}

10
shaders/shadowmap.frag Normal file
View File

@@ -0,0 +1,10 @@
#version 330
in vec2 f_coord;
uniform sampler2D tex;
void main()
{
gl_FragDepth = gl_FragCoord.z + (1.0 - texture(tex, f_coord).w);
}

14
shaders/shadowmap.vert Normal file
View File

@@ -0,0 +1,14 @@
#version 330
layout (location = 0) in vec3 v_vert;
layout (location = 2) in vec2 v_coord;
out vec2 f_coord;
#include <common>
void main()
{
gl_Position = (projection * modelview) * vec4(v_vert, 1.0f);
f_coord = v_coord;
}