SSAO: Use a noise texture rather than a function
This commit is contained in:
parent
ab3cb86359
commit
d6d8301f17
@ -1,5 +1,6 @@
|
||||
#version 130
|
||||
uniform sampler2D normals_and_depth;
|
||||
uniform sampler2D noise_texture;
|
||||
uniform mat4 invprojm;
|
||||
uniform mat4 projm;
|
||||
uniform vec4 samplePoints[16];
|
||||
@ -13,10 +14,9 @@ const float radius = .4f;
|
||||
|
||||
const float invSamples = strengh / SAMPLES;
|
||||
|
||||
// Found here : http://byteblacksmith.com/improvements-to-the-canonical-one-liner-glsl-rand-for-opengl-es-2-0/
|
||||
float rand(vec2 co)
|
||||
{
|
||||
return fract(sin(dot(co.xy,vec2(12.9898,78.233))) * 43758.5453);
|
||||
return texture(noise_texture, co).x;
|
||||
}
|
||||
|
||||
void main(void)
|
||||
|
@ -502,6 +502,7 @@ void PostProcessing::renderGlow(ITexture *tex)
|
||||
glDisable(GL_BLEND);
|
||||
}
|
||||
|
||||
ITexture *noise_tex = 0;
|
||||
|
||||
void PostProcessing::renderSSAO(const core::matrix4 &invprojm, const core::matrix4 &projm)
|
||||
{
|
||||
@ -522,6 +523,16 @@ void PostProcessing::renderSSAO(const core::matrix4 &invprojm, const core::matri
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
|
||||
glUniform1i(FullScreenShader::SSAOShader::uniform_normals_and_depth, 0);
|
||||
|
||||
if (!noise_tex)
|
||||
noise_tex = irr_driver->getTexture(file_manager->getAsset("textures/tarmac.jpg").c_str());
|
||||
glActiveTexture(GL_TEXTURE1);
|
||||
glBindTexture(GL_TEXTURE_2D, static_cast<irr::video::COpenGLTexture*>(noise_tex)->getOpenGLTextureName());
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
|
||||
glUniform1i(FullScreenShader::SSAOShader::uniform_noise_texture, 1);
|
||||
|
||||
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
|
||||
glBindVertexArray(0);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
||||
|
@ -710,6 +710,7 @@ namespace FullScreenShader
|
||||
|
||||
GLuint SSAOShader::Program;
|
||||
GLuint SSAOShader::uniform_normals_and_depth;
|
||||
GLuint SSAOShader::uniform_noise_texture;
|
||||
GLuint SSAOShader::uniform_invprojm;
|
||||
GLuint SSAOShader::uniform_projm;
|
||||
GLuint SSAOShader::uniform_samplePoints;
|
||||
@ -719,6 +720,7 @@ namespace FullScreenShader
|
||||
{
|
||||
Program = LoadProgram(file_manager->getAsset("shaders/screenquad.vert").c_str(), file_manager->getAsset("shaders/ssao.frag").c_str());
|
||||
uniform_normals_and_depth = glGetUniformLocation(Program, "normals_and_depth");
|
||||
uniform_noise_texture = glGetUniformLocation(Program, "noise_texture");
|
||||
uniform_invprojm = glGetUniformLocation(Program, "invprojm");
|
||||
uniform_projm = glGetUniformLocation(Program, "projm");
|
||||
uniform_samplePoints = glGetUniformLocation(Program, "samplePoints[0]");
|
||||
|
@ -243,7 +243,7 @@ class SSAOShader
|
||||
{
|
||||
public:
|
||||
static GLuint Program;
|
||||
static GLuint uniform_normals_and_depth, uniform_invprojm, uniform_projm, uniform_samplePoints;
|
||||
static GLuint uniform_normals_and_depth, uniform_noise_texture, uniform_invprojm, uniform_projm, uniform_samplePoints;
|
||||
static GLuint vao;
|
||||
static float SSAOSamples[64];
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user