Add an attenuation based on depth
This commit is contained in:
parent
ee76d9b579
commit
7393fa0603
@ -1,6 +1,8 @@
|
||||
uniform sampler2D tex;
|
||||
uniform sampler2D dtex;
|
||||
uniform vec3 inlevel;
|
||||
uniform vec2 outlevel;
|
||||
uniform mat4 invprojm;
|
||||
|
||||
#if __VERSION__ >= 130
|
||||
in vec2 uv;
|
||||
@ -16,6 +18,12 @@ void main()
|
||||
{
|
||||
vec4 col = texture(tex, uv);
|
||||
|
||||
float curdepth = texture(dtex, uv).x;
|
||||
vec4 FragPos = invprojm * (2.0 * vec4(uv, curdepth, 1.0f) - 1.0f);
|
||||
FragPos /= FragPos.w;
|
||||
float depth = clamp(FragPos.z / 180, 0, 1);
|
||||
depth = (1 - depth);
|
||||
|
||||
// Compute the vignette
|
||||
vec2 inside = uv - 0.5;
|
||||
float vignette = 1 - dot(inside, inside);
|
||||
@ -29,8 +37,11 @@ void main()
|
||||
float outBlack = outlevel.x;
|
||||
float outWhite = outlevel.y;
|
||||
|
||||
col.rgb = (pow(((col.rgb * 255.0) - inBlack) / (inWhite - inBlack),
|
||||
vec3 colSat = (pow(((col.rgb * 255.0) - inBlack) / (inWhite - inBlack),
|
||||
vec3(1.0 / inGamma)) * (outWhite - outBlack) + outBlack) / 255.0;
|
||||
|
||||
vec3 colFinal = colSat * depth + col.rgb * (1 - depth);
|
||||
|
||||
FragColor = vec4(col.rgb * vignette, 1.0);
|
||||
FragColor = vec4(colFinal * vignette, 1.0);
|
||||
//FragColor = vec4(vec3(depth), 1.0);
|
||||
}
|
||||
|
@ -296,9 +296,13 @@ void renderColorLevel(ITexture *in)
|
||||
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
glBindTexture(GL_TEXTURE_2D, getTextureGLuint(in));
|
||||
glActiveTexture(GL_TEXTURE1);
|
||||
glBindTexture(GL_TEXTURE_2D, getDepthTexture(irr_driver->getRTT(RTT_NORMAL_AND_DEPTH)));
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
||||
glUniform1i(FullScreenShader::ColorLevelShader::uniform_tex, 0);
|
||||
glUniform1i(FullScreenShader::ColorLevelShader::uniform_dtex, 1);
|
||||
glUniformMatrix4fv(FullScreenShader::ColorLevelShader::uniform_invprojm, 1, GL_FALSE, irr_driver->getInvProjMatrix().pointer());
|
||||
|
||||
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
|
||||
glBindVertexArray(0);
|
||||
|
@ -1264,12 +1264,16 @@ namespace FullScreenShader
|
||||
GLuint ColorLevelShader::uniform_inlevel;
|
||||
GLuint ColorLevelShader::uniform_outlevel;
|
||||
GLuint ColorLevelShader::vao;
|
||||
GLuint ColorLevelShader::uniform_invprojm;
|
||||
GLuint ColorLevelShader::uniform_dtex;
|
||||
void ColorLevelShader::init()
|
||||
{
|
||||
Program = LoadProgram(file_manager->getAsset("shaders/screenquad.vert").c_str(), file_manager->getAsset("shaders/color_levels.frag").c_str());
|
||||
uniform_tex = glGetUniformLocation(Program, "tex");
|
||||
uniform_dtex = glGetUniformLocation(Program, "dtex");
|
||||
uniform_inlevel = glGetUniformLocation(Program, "inlevel");
|
||||
uniform_outlevel = glGetUniformLocation(Program, "outlevel");
|
||||
uniform_invprojm = glGetUniformLocation(Program, "invprojm");
|
||||
vao = createVAO(Program);
|
||||
}
|
||||
|
||||
|
@ -368,7 +368,7 @@ class ColorLevelShader
|
||||
{
|
||||
public:
|
||||
static GLuint Program;
|
||||
static GLuint uniform_tex, uniform_inlevel, uniform_outlevel;
|
||||
static GLuint uniform_tex, uniform_invprojm, uniform_dtex, uniform_inlevel, uniform_outlevel;
|
||||
static GLuint vao;
|
||||
|
||||
static void init();
|
||||
|
Loading…
Reference in New Issue
Block a user