Use a more efficient screen to view conversion

Also use the opportunity to use UBO where possible.
This commit is contained in:
vlj 2014-05-02 18:11:34 +02:00
parent 2f1578ba32
commit 2a1623d8ca
13 changed files with 161 additions and 83 deletions

View File

@ -6,27 +6,33 @@ uniform float endH;
uniform float start;
uniform float end;
uniform vec3 col;
uniform mat4 ipvmat;
#if __VERSION__ >= 130
in vec2 uv;
out vec4 FragColor;
#ifdef UBO_DISABLED
uniform mat4 ViewMatrix;
uniform mat4 ProjectionMatrix;
uniform mat4 InverseViewMatrix;
uniform mat4 InverseProjectionMatrix;
#else
varying vec2 uv;
#define FragColor gl_FragColor
layout (std140) uniform MatrixesData
{
mat4 ViewMatrix;
mat4 ProjectionMatrix;
mat4 InverseViewMatrix;
mat4 InverseProjectionMatrix;
mat4 ShadowViewProjMatrixes[4];
};
#endif
in vec2 uv;
out vec4 FragColor;
vec4 getPosFromUVDepth(vec3 uvDepth, mat4 InverseProjectionMatrix);
void main()
{
float z = texture(tex, uv).x;
vec3 tmp = vec3(uv, z);
tmp = tmp * 2.0 - 1.0;
vec4 xpos = vec4(tmp, 1.0);
xpos = ipvmat * xpos;
xpos.xyz /= xpos.w;
vec4 xpos = getPosFromUVDepth(vec3(uv, z), InverseProjectionMatrix);
float dist = length(xpos.xyz);
float fog = smoothstep(start, end, dist);

View File

@ -1,10 +1,24 @@
uniform sampler2D ntex;
uniform sampler2D dtex;
uniform float spec;
uniform mat4 invproj;
uniform mat4 ViewMatrix;
uniform vec2 screen;
#ifdef UBO_DISABLED
uniform mat4 ViewMatrix;
uniform mat4 ProjectionMatrix;
uniform mat4 InverseViewMatrix;
uniform mat4 InverseProjectionMatrix;
#else
layout (std140) uniform MatrixesData
{
mat4 ViewMatrix;
mat4 ProjectionMatrix;
mat4 InverseViewMatrix;
mat4 InverseProjectionMatrix;
mat4 ShadowViewProjMatrixes[4];
};
#endif
flat in vec3 center;
flat in float energy;
flat in vec3 col;
@ -14,6 +28,7 @@ out vec4 Specular;
vec3 DecodeNormal(vec2 n);
vec3 getSpecular(vec3 normal, vec3 eyedir, vec3 lightdir, vec3 color, float roughness);
vec4 getPosFromUVDepth(vec3 uvDepth, mat4 InverseProjectionMatrix);
void main()
{
@ -22,9 +37,7 @@ void main()
vec3 norm = normalize(DecodeNormal(2. * texture(ntex, texc).xy - 1.));
float roughness = texture(ntex, texc).z;
vec4 xpos = 2.0 * vec4(texc, z, 1.0) - 1.0f;
xpos = invproj * xpos;
xpos /= xpos.w;
vec4 xpos = getPosFromUVDepth(vec3(texc, z), InverseProjectionMatrix);
vec3 eyedir = -normalize(xpos.xyz);
vec4 pseudocenter = ViewMatrix * vec4(center.xyz, 1.0);

View File

@ -1,5 +1,18 @@
#ifdef UBO_DISABLED
uniform mat4 ViewMatrix;
uniform mat4 ProjectionMatrix;
uniform mat4 InverseViewMatrix;
uniform mat4 InverseProjectionMatrix;
#else
layout (std140) uniform MatrixesData
{
mat4 ViewMatrix;
mat4 ProjectionMatrix;
mat4 InverseViewMatrix;
mat4 InverseProjectionMatrix;
mat4 ShadowViewProjMatrixes[4];
};
#endif
in vec3 Position;
in float Energy;

View File

@ -1,17 +1,26 @@
uniform sampler2D ntex;
uniform sampler2D dtex;
uniform sampler2D noise_texture;
uniform mat4 invprojm;
uniform mat4 projm;
uniform vec4 samplePoints[16];
#if __VERSION__ >= 130
#ifdef UBO_DISABLED
uniform mat4 ViewMatrix;
uniform mat4 ProjectionMatrix;
uniform mat4 InverseViewMatrix;
uniform mat4 InverseProjectionMatrix;
#else
layout (std140) uniform MatrixesData
{
mat4 ViewMatrix;
mat4 ProjectionMatrix;
mat4 InverseViewMatrix;
mat4 InverseProjectionMatrix;
mat4 ShadowViewProjMatrixes[4];
};
#endif
in vec2 uv;
out float AO;
#else
varying vec2 uv;
#define AO gl_FragColor.x
#endif
const float strengh = 5.;
const float radius = 1.f;
@ -28,13 +37,13 @@ vec3 rand(vec2 co)
}
vec3 DecodeNormal(vec2 n);
vec4 getPosFromUVDepth(vec3 uvDepth, mat4 InverseProjectionMatrix);
void main(void)
{
vec4 cur = texture(ntex, uv);
float curdepth = texture(dtex, uv).x;
vec4 FragPos = invprojm * (2.0f * vec4(uv, curdepth, 1.0f) - 1.0f);
FragPos /= FragPos.w;
vec4 FragPos = getPosFromUVDepth(vec3(uv, curdepth), InverseProjectionMatrix);
// get the normal of current fragment
vec3 norm = normalize(DecodeNormal(2. * texture(ntex, uv).xy - 1.));
@ -52,15 +61,14 @@ void main(void)
vec3 sampleDir = samplePoints[i].x * tangent + samplePoints[i].y * bitangent + samplePoints[i].z * norm;
sampleDir *= samplePoints[i].w;
vec4 samplePos = FragPos + radius * vec4(sampleDir, 0.0);
vec4 sampleProj = projm * samplePos;
vec4 sampleProj = ProjectionMatrix * samplePos;
sampleProj /= sampleProj.w;
bool isInsideTexture = (sampleProj.x > -1.) && (sampleProj.x < 1.) && (sampleProj.y > -1.) && (sampleProj.y < 1.);
// get the depth of the occluder fragment
float occluderFragmentDepth = texture(dtex, (sampleProj.xy * 0.5) + 0.5).x;
// Position of the occluder fragment in worldSpace
vec4 occluderPos = invprojm * vec4(sampleProj.xy, 2.0 * occluderFragmentDepth - 1.0, 1.0f);
occluderPos /= occluderPos.w;
vec4 occluderPos = getPosFromUVDepth(vec3((sampleProj.xy * 0.5) + 0.5, occluderFragmentDepth), InverseProjectionMatrix);
bool isOccluded = isInsideTexture && (sampleProj.z > (2. * occluderFragmentDepth - 1.0)) && (distance(FragPos, occluderPos) < radius);
bl += isOccluded ? samplePoints[i].z * smoothstep(5 * radius, 0, distance(samplePos, FragPos)) : 0.;

View File

@ -8,6 +8,22 @@ uniform mat4 invproj;
//uniform int hasclouds;
//uniform vec2 wind;
#ifdef UBO_DISABLED
uniform mat4 ViewMatrix;
uniform mat4 ProjectionMatrix;
uniform mat4 InverseViewMatrix;
uniform mat4 InverseProjectionMatrix;
#else
layout (std140) uniform MatrixesData
{
mat4 ViewMatrix;
mat4 ProjectionMatrix;
mat4 InverseViewMatrix;
mat4 InverseProjectionMatrix;
mat4 ShadowViewProjMatrixes[4];
};
#endif
#if __VERSION__ >= 130
in vec2 uv;
out vec4 Diff;
@ -21,12 +37,11 @@ varying vec2 uv;
vec3 DecodeNormal(vec2 n);
vec3 getSpecular(vec3 normal, vec3 eyedir, vec3 lightdir, vec3 color, float roughness);
vec4 getPosFromUVDepth(vec3 uvDepth, mat4 InverseProjectionMatrix);
void main() {
float z = texture(dtex, uv).x;
vec4 xpos = 2.0 * vec4(uv, z, 1.0) - 1.0;
xpos = invproj * xpos;
xpos.xyz /= xpos.w;
vec4 xpos = getPosFromUVDepth(vec3(uv, z), InverseProjectionMatrix);
if (z < 0.03)
{

View File

@ -10,6 +10,12 @@ uniform vec3 col;
//uniform vec2 wind;
//uniform float shadowoffset;
#ifdef UBO_DISABLED
uniform mat4 ViewMatrix;
uniform mat4 ProjectionMatrix;
uniform mat4 InverseViewMatrix;
uniform mat4 InverseProjectionMatrix;
#else
layout (std140) uniform MatrixesData
{
mat4 ViewMatrix;
@ -18,6 +24,7 @@ layout (std140) uniform MatrixesData
mat4 InverseProjectionMatrix;
mat4 ShadowViewProjMatrixes[4];
};
#endif
in vec2 uv;
out vec4 Diff;
@ -25,6 +32,7 @@ out vec4 Spec;
vec3 DecodeNormal(vec2 n);
vec3 getSpecular(vec3 normal, vec3 eyedir, vec3 lightdir, vec3 color, float roughness);
vec4 getPosFromUVDepth(vec3 uvDepth, mat4 InverseProjectionMatrix);
float getShadowFactor(vec3 pos, float bias, int index)
{
@ -60,9 +68,7 @@ float getShadowFactor(vec3 pos, float bias, int index)
void main() {
float z = texture(dtex, uv).x;
vec4 xpos = 2.0 * vec4(uv, z, 1.0) - 1.0;
xpos = InverseProjectionMatrix * xpos;
xpos.xyz /= xpos.w;
vec4 xpos = getPosFromUVDepth(vec3(uv, z), InverseProjectionMatrix);
vec3 norm = normalize(DecodeNormal(2. * texture(ntex, uv).xy - 1.));
float roughness =texture(ntex, uv).z;

View File

@ -5,6 +5,12 @@ uniform sampler2DArrayShadow shadowtex;
uniform vec3 direction;
uniform vec3 col;
#ifdef UBO_DISABLED
uniform mat4 ViewMatrix;
uniform mat4 ProjectionMatrix;
uniform mat4 InverseViewMatrix;
uniform mat4 InverseProjectionMatrix;
#else
layout (std140) uniform MatrixesData
{
mat4 ViewMatrix;
@ -13,6 +19,7 @@ layout (std140) uniform MatrixesData
mat4 InverseProjectionMatrix;
mat4 ShadowViewProjMatrixes[4];
};
#endif
in vec2 uv;

View File

@ -0,0 +1,8 @@
vec4 getPosFromUVDepth(vec3 uvDepth, mat4 InverseProjectionMatrix)
{
vec4 pos = 2.0 * vec4(uvDepth, 1.0) - 1.0f;
pos.xy *= vec2(InverseProjectionMatrix[0][0], InverseProjectionMatrix[1][1]);
pos.zw = vec2(pos.z * InverseProjectionMatrix[2][2] + pos.w, pos.z * InverseProjectionMatrix[2][3] + pos.w);
pos /= pos.w;
return pos;
}

View File

@ -274,7 +274,7 @@ void PostProcessing::renderSunlight()
glBindVertexArray(FullScreenShader::SunLightShader::vao);
setTexture(0, irr_driver->getRenderTargetTexture(RTT_NORMAL_AND_DEPTH), GL_NEAREST, GL_NEAREST);
setTexture(1, irr_driver->getDepthStencilTexture(), GL_NEAREST, GL_NEAREST);
FullScreenShader::SunLightShader::setUniforms(cb->getPosition(), irr_driver->getInvProjMatrix(), cb->getRed(), cb->getGreen(), cb->getBlue(), 0, 1);
FullScreenShader::SunLightShader::setUniforms(cb->getPosition(), cb->getRed(), cb->getGreen(), cb->getBlue(), 0, 1);
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
glBindVertexArray(0);
}
@ -412,7 +412,7 @@ void PostProcessing::renderGlow(unsigned tex)
ITexture *noise_tex = 0;
void PostProcessing::renderSSAO(const core::matrix4 &invprojm, const core::matrix4 &projm)
void PostProcessing::renderSSAO()
{
glDisable(GL_DEPTH_TEST);
glDisable(GL_BLEND);
@ -427,12 +427,12 @@ void PostProcessing::renderSSAO(const core::matrix4 &invprojm, const core::matri
setTexture(1, irr_driver->getDepthStencilTexture(), GL_LINEAR, GL_LINEAR);
setTexture(2, getTextureGLuint(noise_tex), GL_LINEAR, GL_LINEAR);
FullScreenShader::SSAOShader::setUniforms(projm, invprojm, 0, 1, 2);
FullScreenShader::SSAOShader::setUniforms(0, 1, 2);
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
}
void PostProcessing::renderFog(const core::matrix4 &ipvmat)
void PostProcessing::renderFog()
{
const Track * const track = World::getWorld()->getTrack();
@ -457,7 +457,7 @@ void PostProcessing::renderFog(const core::matrix4 &ipvmat)
glBindVertexArray(FullScreenShader::FogShader::vao);
setTexture(0, irr_driver->getDepthStencilTexture(), GL_NEAREST, GL_NEAREST);
FullScreenShader::FogShader::setUniforms(ipvmat, fogmax, startH, endH, start, end, col, 0);
FullScreenShader::FogShader::setUniforms(fogmax, startH, endH, start, end, col, 0);
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
glBindVertexArray(0);

View File

@ -76,8 +76,8 @@ public:
void renderSunlight();
void renderShadowedSunlight(const std::vector<core::matrix4> &sun_ortho_matrix, unsigned depthtex);
void renderFog(const core::matrix4 &ipvmat);
void renderSSAO(const core::matrix4 &invprojm, const core::matrix4 &projm);
void renderFog();
void renderSSAO();
void renderDiffuseEnvMap(const float *bSHCoeff, const float *gSHCoeff, const float *rSHCoeff);
/** Blur the in texture */

View File

@ -215,7 +215,7 @@ void IrrDriver::renderGLSL(float dt)
if (UserConfigParams::m_dynamic_lights && World::getWorld()->getTrack()->isFogEnabled())
{
PROFILER_PUSH_CPU_MARKER("- Fog", 0xFF, 0x00, 0x00);
m_post_processing->renderFog(irr_driver->getInvProjMatrix());
m_post_processing->renderFog();
PROFILER_POP_CPU_MARKER();
}
@ -858,11 +858,9 @@ static void renderPointLights(unsigned count)
setTexture(0, irr_driver->getRenderTargetTexture(RTT_NORMAL_AND_DEPTH), GL_NEAREST, GL_NEAREST);
setTexture(1, irr_driver->getDepthStencilTexture(), GL_NEAREST, GL_NEAREST);
LightShader::PointLightShader
::setUniforms(irr_driver->getViewMatrix(), irr_driver->getProjMatrix(),
irr_driver->getInvProjMatrix(),
core::vector2df(float(UserConfigParams::m_width),
float(UserConfigParams::m_height) ),
200, 0, 1);
::setUniforms(core::vector2df(float(UserConfigParams::m_width),
float(UserConfigParams::m_height) ),
200, 0, 1);
glDrawArraysInstanced(GL_TRIANGLE_STRIP, 0, 4, count);
}
@ -968,7 +966,7 @@ void IrrDriver::renderLights(const core::aabbox3df& cambox,
glClearColor(1., 1., 1., 1.);
glClear(GL_COLOR_BUFFER_BIT);
glViewport(0, 0, UserConfigParams::m_width / 2, UserConfigParams::m_height / 2);
m_post_processing->renderSSAO(irr_driver->getInvProjMatrix(), irr_driver->getProjMatrix());
m_post_processing->renderSSAO();
// Blur it to reduce noise.
m_post_processing->renderGaussian6Blur(irr_driver->getFBO(FBO_SSAO), irr_driver->getRenderTargetTexture(RTT_SSAO),
irr_driver->getFBO(FBO_HALF1), irr_driver->getRenderTargetTexture(RTT_HALF1), UserConfigParams::m_width / 2, UserConfigParams::m_height / 2);

View File

@ -1636,6 +1636,8 @@ namespace MeshShader
uniform_tex = glGetUniformLocation(Program, "tex");
attrib_color = glGetAttribLocation(Program, "Color");
uniform_windDir = glGetUniformLocation(Program, "windDir");
GLuint uniform_ViewProjectionMatrixesUBO = glGetUniformBlockIndex(Program, "MatrixesData");
glUniformBlockBinding(Program, uniform_ViewProjectionMatrixesUBO, 0);
}
void GrassShadowShader::setUniforms(const core::matrix4 &ModelViewProjectionMatrix, const core::vector3df &windDirection, unsigned TU_tex)
@ -1756,9 +1758,6 @@ namespace LightShader
GLuint PointLightShader::uniform_dtex;
GLuint PointLightShader::uniform_spec;
GLuint PointLightShader::uniform_screen;
GLuint PointLightShader::uniform_invproj;
GLuint PointLightShader::uniform_VM;
GLuint PointLightShader::uniform_PM;
GLuint PointLightShader::vbo;
GLuint PointLightShader::vao;
@ -1768,6 +1767,7 @@ namespace LightShader
GL_VERTEX_SHADER, file_manager->getAsset("shaders/pointlight.vert").c_str(),
GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/utils/decodeNormal.frag").c_str(),
GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/utils/getSpecular.frag").c_str(),
GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/utils/getPosFromUVDepth.frag").c_str(),
GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/pointlight.frag").c_str());
attrib_Position = glGetAttribLocation(Program, "Position");
attrib_Color = glGetAttribLocation(Program, "Color");
@ -1776,10 +1776,7 @@ namespace LightShader
uniform_ntex = glGetUniformLocation(Program, "ntex");
uniform_dtex = glGetUniformLocation(Program, "dtex");
uniform_spec = glGetUniformLocation(Program, "spec");
uniform_invproj = glGetUniformLocation(Program, "invproj");
uniform_screen = glGetUniformLocation(Program, "screen");
uniform_VM = glGetUniformLocation(Program, "ViewMatrix");
uniform_PM = glGetUniformLocation(Program, "ProjectionMatrix");
glGenVertexArrays(1, &vao);
glBindVertexArray(vao);
@ -1804,13 +1801,12 @@ namespace LightShader
glVertexAttribDivisor(attrib_Color, 1);
}
void PointLightShader::setUniforms(const core::matrix4 &ViewMatrix, const core::matrix4 &ProjMatrix, const core::matrix4 &InvProjMatrix, const core::vector2df &screen, unsigned spec, unsigned TU_ntex, unsigned TU_dtex)
void PointLightShader::setUniforms(const core::vector2df &screen, unsigned spec, unsigned TU_ntex, unsigned TU_dtex)
{
if (UserConfigParams::m_ubo_disabled)
bypassUBO(Program);
glUniform1f(uniform_spec, 200);
glUniform2f(uniform_screen, screen.X, screen.Y);
glUniformMatrix4fv(uniform_invproj, 1, GL_FALSE, InvProjMatrix.pointer());
glUniformMatrix4fv(uniform_VM, 1, GL_FALSE, ViewMatrix.pointer());
glUniformMatrix4fv(uniform_PM, 1, GL_FALSE, ProjMatrix.pointer());
glUniform1i(uniform_ntex, TU_ntex);
glUniform1i(uniform_dtex, TU_dtex);
@ -2149,7 +2145,6 @@ namespace FullScreenShader
GLuint SunLightShader::uniform_dtex;
GLuint SunLightShader::uniform_direction;
GLuint SunLightShader::uniform_col;
GLuint SunLightShader::uniform_invproj;
GLuint SunLightShader::vao;
void SunLightShader::init()
@ -2158,18 +2153,21 @@ namespace FullScreenShader
GL_VERTEX_SHADER, file_manager->getAsset("shaders/screenquad.vert").c_str(),
GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/utils/decodeNormal.frag").c_str(),
GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/utils/getSpecular.frag").c_str(),
GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/utils/getPosFromUVDepth.frag").c_str(),
GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/sunlight.frag").c_str());
uniform_ntex = glGetUniformLocation(Program, "ntex");
uniform_dtex = glGetUniformLocation(Program, "dtex");
uniform_direction = glGetUniformLocation(Program, "direction");
uniform_col = glGetUniformLocation(Program, "col");
uniform_invproj = glGetUniformLocation(Program, "invproj");
vao = createVAO(Program);
GLuint uniform_ViewProjectionMatrixesUBO = glGetUniformBlockIndex(Program, "MatrixesData");
glUniformBlockBinding(Program, uniform_ViewProjectionMatrixesUBO, 0);
}
void SunLightShader::setUniforms(const core::vector3df &direction, const core::matrix4 &InvProjMatrix, float r, float g, float b, unsigned TU_ntex, unsigned TU_dtex)
void SunLightShader::setUniforms(const core::vector3df &direction, float r, float g, float b, unsigned TU_ntex, unsigned TU_dtex)
{
glUniformMatrix4fv(uniform_invproj, 1, GL_FALSE, InvProjMatrix.pointer());
if (UserConfigParams::m_ubo_disabled)
bypassUBO(Program);
glUniform3f(uniform_direction, direction.X, direction.Y, direction.Z);
glUniform3f(uniform_col, r, g, b);
glUniform1i(uniform_ntex, TU_ntex);
@ -2221,6 +2219,7 @@ namespace FullScreenShader
GL_VERTEX_SHADER, file_manager->getAsset("shaders/screenquad.vert").c_str(),
GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/utils/decodeNormal.frag").c_str(),
GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/utils/getSpecular.frag").c_str(),
GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/utils/getPosFromUVDepth.frag").c_str(),
GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/sunlightshadow.frag").c_str());
uniform_ntex = glGetUniformLocation(Program, "ntex");
uniform_dtex = glGetUniformLocation(Program, "dtex");
@ -2234,6 +2233,8 @@ namespace FullScreenShader
void ShadowedSunLightShader::setUniforms(const core::vector3df &direction, float r, float g, float b, unsigned TU_ntex, unsigned TU_dtex, unsigned TU_shadowtex)
{
if (UserConfigParams::m_ubo_disabled)
bypassUBO(Program);
glUniform3f(uniform_direction, direction.X, direction.Y, direction.Z);
glUniform3f(uniform_col, r, g, b);
glUniform1i(uniform_ntex, TU_ntex);
@ -2268,6 +2269,8 @@ namespace FullScreenShader
void ShadowedSunLightDebugShader::setUniforms(const core::vector3df &direction, float r, float g, float b, unsigned TU_ntex, unsigned TU_dtex, unsigned TU_shadowtex)
{
if (UserConfigParams::m_ubo_disabled)
bypassUBO(Program);
glUniform3f(uniform_direction, direction.X, direction.Y, direction.Z);
glUniform3f(uniform_col, r, g, b);
glUniform1i(uniform_ntex, TU_ntex);
@ -2422,8 +2425,6 @@ namespace FullScreenShader
GLuint SSAOShader::uniform_ntex;
GLuint SSAOShader::uniform_dtex;
GLuint SSAOShader::uniform_noise_texture;
GLuint SSAOShader::uniform_invprojm;
GLuint SSAOShader::uniform_projm;
GLuint SSAOShader::uniform_samplePoints;
GLuint SSAOShader::vao;
float SSAOShader::SSAOSamples[64];
@ -2433,14 +2434,15 @@ namespace FullScreenShader
Program = LoadProgram(
GL_VERTEX_SHADER, file_manager->getAsset("shaders/screenquad.vert").c_str(),
GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/utils/decodeNormal.frag").c_str(),
GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/utils/getPosFromUVDepth.frag").c_str(),
GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/ssao.frag").c_str());
uniform_ntex = glGetUniformLocation(Program, "ntex");
uniform_dtex = glGetUniformLocation(Program, "dtex");
uniform_noise_texture = glGetUniformLocation(Program, "noise_texture");
uniform_invprojm = glGetUniformLocation(Program, "invprojm");
uniform_projm = glGetUniformLocation(Program, "projm");
uniform_samplePoints = glGetUniformLocation(Program, "samplePoints[0]");
vao = createVAO(Program);
GLuint uniform_ViewProjectionMatrixesUBO = glGetUniformBlockIndex(Program, "MatrixesData");
glUniformBlockBinding(Program, uniform_ViewProjectionMatrixesUBO, 0);
// SSAOSamples[4 * i] and SSAOSamples[4 * i + 1] can be negative
@ -2556,10 +2558,10 @@ namespace FullScreenShader
}*/
}
void SSAOShader::setUniforms(const core::matrix4& projm, const core::matrix4 &invprojm, unsigned TU_ntex, unsigned TU_dtex, unsigned TU_noise)
void SSAOShader::setUniforms(unsigned TU_ntex, unsigned TU_dtex, unsigned TU_noise)
{
glUniformMatrix4fv(FullScreenShader::SSAOShader::uniform_invprojm, 1, GL_FALSE, invprojm.pointer());
glUniformMatrix4fv(FullScreenShader::SSAOShader::uniform_projm, 1, GL_FALSE, projm.pointer());
if (UserConfigParams::m_ubo_disabled)
bypassUBO(Program);
glUniform4fv(FullScreenShader::SSAOShader::uniform_samplePoints, 16, FullScreenShader::SSAOShader::SSAOSamples);
glUniform1i(FullScreenShader::SSAOShader::uniform_ntex, TU_ntex);
@ -2575,13 +2577,13 @@ namespace FullScreenShader
GLuint FogShader::uniform_start;
GLuint FogShader::uniform_end;
GLuint FogShader::uniform_col;
GLuint FogShader::uniform_ipvmat;
GLuint FogShader::vao;
void FogShader::init()
{
Program = LoadProgram(
GL_VERTEX_SHADER, file_manager->getAsset("shaders/screenquad.vert").c_str(),
GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/utils/getPosFromUVDepth.frag").c_str(),
GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/fog.frag").c_str());
uniform_tex = glGetUniformLocation(Program, "tex");
uniform_fogmax = glGetUniformLocation(Program, "fogmax");
@ -2590,19 +2592,21 @@ namespace FullScreenShader
uniform_start = glGetUniformLocation(Program, "start");
uniform_end = glGetUniformLocation(Program, "end");
uniform_col = glGetUniformLocation(Program, "col");
uniform_ipvmat = glGetUniformLocation(Program, "ipvmat");
vao = createVAO(Program);
GLuint uniform_ViewProjectionMatrixesUBO = glGetUniformBlockIndex(Program, "MatrixesData");
glUniformBlockBinding(Program, uniform_ViewProjectionMatrixesUBO, 0);
}
void FogShader::setUniforms(const core::matrix4 &ipvmat, float fogmax, float startH, float endH, float start, float end, const core::vector3df &col, unsigned TU_ntex)
void FogShader::setUniforms(float fogmax, float startH, float endH, float start, float end, const core::vector3df &col, unsigned TU_ntex)
{
if (UserConfigParams::m_ubo_disabled)
bypassUBO(Program);
glUniform1f(uniform_fogmax, fogmax);
glUniform1f(uniform_startH, startH);
glUniform1f(uniform_endH, endH);
glUniform1f(uniform_start, start);
glUniform1f(uniform_end, end);
glUniform3f(uniform_col, col.X, col.Y, col.Z);
glUniformMatrix4fv(uniform_ipvmat, 1, GL_FALSE, ipvmat.pointer());
glUniform1i(uniform_tex, TU_ntex);
}

View File

@ -435,12 +435,12 @@ namespace LightShader
static GLuint Program;
static GLuint attrib_Position, attrib_Energy, attrib_Color;
static GLuint attrib_Corner;
static GLuint uniform_ntex, uniform_dtex, uniform_spec, uniform_screen, uniform_invproj, uniform_VM, uniform_PM;
static GLuint uniform_ntex, uniform_dtex, uniform_spec, uniform_screen;
static GLuint vbo;
static GLuint vao;
static void init();
static void setUniforms(const core::matrix4 &ViewMatrix, const core::matrix4 &ProjMatrix, const core::matrix4 &InvProjMatrix, const core::vector2df &screen, unsigned spec, unsigned TU_ntex, unsigned TU_dtex);
static void setUniforms(const core::vector2df &screen, unsigned spec, unsigned TU_ntex, unsigned TU_dtex);
};
}
@ -556,11 +556,11 @@ class SunLightShader
{
public:
static GLuint Program;
static GLuint uniform_ntex, uniform_dtex, uniform_direction, uniform_col, uniform_invproj;
static GLuint uniform_ntex, uniform_dtex, uniform_direction, uniform_col;
static GLuint vao;
static void init();
static void setUniforms(const core::vector3df &direction, const core::matrix4 &InvProjMatrix, float r, float g, float b, unsigned TU_ntex, unsigned TU_dtex);
static void setUniforms(const core::vector3df &direction, float r, float g, float b, unsigned TU_ntex, unsigned TU_dtex);
};
class DiffuseEnvMapShader
@ -693,23 +693,23 @@ class SSAOShader
{
public:
static GLuint Program;
static GLuint uniform_ntex, uniform_dtex, uniform_noise_texture, uniform_invprojm, uniform_projm, uniform_samplePoints;
static GLuint uniform_ntex, uniform_dtex, uniform_noise_texture, uniform_samplePoints;
static GLuint vao;
static float SSAOSamples[64];
static void init();
static void setUniforms(const core::matrix4& projm, const core::matrix4 &invprojm, unsigned TU_ntex, unsigned TU_dtex, unsigned TU_noise);
static void setUniforms(unsigned TU_ntex, unsigned TU_dtex, unsigned TU_noise);
};
class FogShader
{
public:
static GLuint Program;
static GLuint uniform_tex, uniform_fogmax, uniform_startH, uniform_endH, uniform_start, uniform_end, uniform_col, uniform_ipvmat;
static GLuint uniform_tex, uniform_fogmax, uniform_startH, uniform_endH, uniform_start, uniform_end, uniform_col;
static GLuint vao;
static void init();
static void setUniforms(const core::matrix4 &ipvmat, float fogmax, float startH, float endH, float start, float end, const core::vector3df &col, unsigned TU_ntex);
static void setUniforms(float fogmax, float startH, float endH, float start, float end, const core::vector3df &col, unsigned TU_ntex);
};
class MotionBlurShader