Shadows: Clean shaders.
This commit is contained in:
parent
dd3e15b298
commit
a457b9f423
@ -6,22 +6,22 @@ uniform sampler2DArrayShadow shadowtex;
|
||||
|
||||
uniform vec3 direction;
|
||||
uniform vec3 col;
|
||||
uniform mat4 invproj;
|
||||
uniform mat4 shadowmat[4];
|
||||
//uniform int hasclouds;
|
||||
//uniform vec2 wind;
|
||||
//uniform float shadowoffset;
|
||||
|
||||
#if __VERSION__ >= 130
|
||||
layout (std140) uniform MatrixesData
|
||||
{
|
||||
mat4 ViewMatrix;
|
||||
mat4 ProjectionMatrix;
|
||||
mat4 InverseViewMatrix;
|
||||
mat4 InverseProjectionMatrix;
|
||||
mat4 ShadowViewProjMatrixes[4];
|
||||
};
|
||||
|
||||
in vec2 uv;
|
||||
out vec4 Diff;
|
||||
out vec4 Spec;
|
||||
#else
|
||||
varying vec2 uv;
|
||||
#define Diff gl_FragData[0]
|
||||
#define Spec gl_FragData[1]
|
||||
#endif
|
||||
|
||||
|
||||
vec3 DecodeNormal(vec2 n);
|
||||
vec3 getSpecular(vec3 normal, vec3 eyedir, vec3 lightdir, vec3 color, float roughness);
|
||||
@ -37,7 +37,7 @@ float getShadowFactor(vec3 pos, float bias, int index)
|
||||
vec2(1., 1.)
|
||||
);
|
||||
|
||||
vec4 shadowcoord = (shadowmat[index] * vec4(pos, 1.0));
|
||||
vec4 shadowcoord = (ShadowViewProjMatrixes[index] * InverseViewMatrix * vec4(pos, 1.0));
|
||||
shadowcoord /= shadowcoord.w;
|
||||
vec2 shadowtexcoord = shadowcoord.xy * 0.5 + 0.5;
|
||||
// shadowcoord = (shadowcoord * 0.5) + vec3(0.5);
|
||||
@ -61,7 +61,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 = invproj * xpos;
|
||||
xpos = InverseProjectionMatrix * xpos;
|
||||
xpos.xyz /= xpos.w;
|
||||
|
||||
vec3 norm = normalize(DecodeNormal(2. * texture(ntex, uv).xy - 1.));
|
||||
|
@ -304,14 +304,14 @@ void PostProcessing::renderShadowedSunlight(const std::vector<core::matrix4> &su
|
||||
{
|
||||
glUseProgram(FullScreenShader::ShadowedSunLightDebugShader::Program);
|
||||
glBindVertexArray(FullScreenShader::ShadowedSunLightDebugShader::vao);
|
||||
FullScreenShader::ShadowedSunLightDebugShader::setUniforms(cb->getPosition(), irr_driver->getInvProjMatrix(), cb->getRed(), cb->getGreen(), cb->getBlue(), 0, 1, 2);
|
||||
FullScreenShader::ShadowedSunLightDebugShader::setUniforms(cb->getPosition(), cb->getRed(), cb->getGreen(), cb->getBlue(), 0, 1, 2);
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
glUseProgram(FullScreenShader::ShadowedSunLightShader::Program);
|
||||
glBindVertexArray(FullScreenShader::ShadowedSunLightShader::vao);
|
||||
FullScreenShader::ShadowedSunLightShader::setUniforms(sun_ortho_matrix, cb->getPosition(), irr_driver->getInvProjMatrix(), cb->getRed(), cb->getGreen(), cb->getBlue(), 0, 1, 2);
|
||||
FullScreenShader::ShadowedSunLightShader::setUniforms(cb->getPosition(), cb->getRed(), cb->getGreen(), cb->getBlue(), 0, 1, 2);
|
||||
}
|
||||
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
|
||||
glBindVertexArray(0);
|
||||
|
@ -2150,10 +2150,8 @@ namespace FullScreenShader
|
||||
GLuint ShadowedSunLightShader::uniform_ntex;
|
||||
GLuint ShadowedSunLightShader::uniform_dtex;
|
||||
GLuint ShadowedSunLightShader::uniform_shadowtex;
|
||||
GLuint ShadowedSunLightShader::uniform_shadowmat;
|
||||
GLuint ShadowedSunLightShader::uniform_direction;
|
||||
GLuint ShadowedSunLightShader::uniform_col;
|
||||
GLuint ShadowedSunLightShader::uniform_invproj;
|
||||
GLuint ShadowedSunLightShader::vao;
|
||||
|
||||
void ShadowedSunLightShader::init()
|
||||
@ -2166,29 +2164,20 @@ namespace FullScreenShader
|
||||
uniform_ntex = glGetUniformLocation(Program, "ntex");
|
||||
uniform_dtex = glGetUniformLocation(Program, "dtex");
|
||||
uniform_shadowtex = glGetUniformLocation(Program, "shadowtex");
|
||||
uniform_shadowmat = glGetUniformLocation(Program, "shadowmat[0]");
|
||||
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 ShadowedSunLightShader::setUniforms(const std::vector<core::matrix4> &shadowmat, const core::vector3df &direction, const core::matrix4 &InvProjMatrix, float r, float g, float b, unsigned TU_ntex, unsigned TU_dtex, unsigned TU_shadowtex)
|
||||
void ShadowedSunLightShader::setUniforms(const core::vector3df &direction, float r, float g, float b, unsigned TU_ntex, unsigned TU_dtex, unsigned TU_shadowtex)
|
||||
{
|
||||
size_t size = shadowmat.size();
|
||||
float *tmp = new float[16 * size];
|
||||
for (unsigned i = 0; i < size; i++) {
|
||||
memcpy(&tmp[16 * i], shadowmat[i].pointer(), 16 * sizeof(float));
|
||||
}
|
||||
|
||||
glUniformMatrix4fv(uniform_shadowmat, size, GL_FALSE, tmp);
|
||||
glUniformMatrix4fv(uniform_invproj, 1, GL_FALSE, InvProjMatrix.pointer());
|
||||
glUniform3f(uniform_direction, direction.X, direction.Y, direction.Z);
|
||||
glUniform3f(uniform_col, r, g, b);
|
||||
glUniform1i(uniform_ntex, TU_ntex);
|
||||
glUniform1i(uniform_dtex, TU_dtex);
|
||||
glUniform1i(uniform_shadowtex, TU_shadowtex);
|
||||
delete[] tmp;
|
||||
}
|
||||
|
||||
GLuint ShadowedSunLightDebugShader::Program;
|
||||
@ -2197,7 +2186,6 @@ namespace FullScreenShader
|
||||
GLuint ShadowedSunLightDebugShader::uniform_shadowtex;
|
||||
GLuint ShadowedSunLightDebugShader::uniform_direction;
|
||||
GLuint ShadowedSunLightDebugShader::uniform_col;
|
||||
GLuint ShadowedSunLightDebugShader::uniform_invproj;
|
||||
GLuint ShadowedSunLightDebugShader::vao;
|
||||
|
||||
void ShadowedSunLightDebugShader::init()
|
||||
@ -2212,13 +2200,13 @@ namespace FullScreenShader
|
||||
uniform_shadowtex = glGetUniformLocation(Program, "shadowtex");
|
||||
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 ShadowedSunLightDebugShader::setUniforms(const core::vector3df &direction, const core::matrix4 &InvProjMatrix, float r, float g, float b, unsigned TU_ntex, unsigned TU_dtex, unsigned TU_shadowtex)
|
||||
void ShadowedSunLightDebugShader::setUniforms(const core::vector3df &direction, float r, float g, float b, unsigned TU_ntex, unsigned TU_dtex, unsigned TU_shadowtex)
|
||||
{
|
||||
glUniformMatrix4fv(uniform_invproj, 1, GL_FALSE, InvProjMatrix.pointer());
|
||||
glUniform3f(uniform_direction, direction.X, direction.Y, direction.Z);
|
||||
glUniform3f(uniform_col, r, g, b);
|
||||
glUniform1i(uniform_ntex, TU_ntex);
|
||||
|
@ -556,22 +556,22 @@ class ShadowedSunLightShader
|
||||
{
|
||||
public:
|
||||
static GLuint Program;
|
||||
static GLuint uniform_ntex, uniform_dtex, uniform_shadowtex, uniform_shadowmat, uniform_direction, uniform_col, uniform_invproj;
|
||||
static GLuint uniform_ntex, uniform_dtex, uniform_shadowtex, uniform_direction, uniform_col;
|
||||
static GLuint vao;
|
||||
|
||||
static void init();
|
||||
static void setUniforms(const std::vector<core::matrix4> &shadowmat, const core::vector3df &direction, const core::matrix4 &InvProjMatrix, float r, float g, float b, unsigned TU_ntex, unsigned TU_dtex, unsigned TU_shadowtex);
|
||||
static void setUniforms(const core::vector3df &direction, float r, float g, float b, unsigned TU_ntex, unsigned TU_dtex, unsigned TU_shadowtex);
|
||||
};
|
||||
|
||||
class ShadowedSunLightDebugShader
|
||||
{
|
||||
public:
|
||||
static GLuint Program;
|
||||
static GLuint uniform_ntex, uniform_dtex, uniform_shadowtex, uniform_direction, uniform_col, uniform_invproj;
|
||||
static GLuint uniform_ntex, uniform_dtex, uniform_shadowtex, 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, unsigned TU_shadowtex);
|
||||
static void setUniforms(const core::vector3df &direction, float r, float g, float b, unsigned TU_ntex, unsigned TU_dtex, unsigned TU_shadowtex);
|
||||
};
|
||||
|
||||
class Gaussian6HBlurShader
|
||||
|
Loading…
x
Reference in New Issue
Block a user