Light: Sunlight uses the new shaders.
This commit is contained in:
parent
4438db3bbf
commit
4cbbf91e4e
@ -1,23 +1,21 @@
|
|||||||
#version 130
|
#version 130
|
||||||
uniform sampler2D ntex;
|
uniform sampler2D ntex;
|
||||||
uniform sampler2D cloudtex;
|
//uniform sampler2D cloudtex;
|
||||||
|
|
||||||
uniform vec3 center;
|
uniform vec3 direction;
|
||||||
uniform vec3 col;
|
uniform vec3 col;
|
||||||
uniform vec2 screen;
|
|
||||||
uniform mat4 invproj;
|
uniform mat4 invproj;
|
||||||
uniform int hasclouds;
|
//uniform int hasclouds;
|
||||||
uniform vec2 wind;
|
//uniform vec2 wind;
|
||||||
|
|
||||||
|
in vec2 uv;
|
||||||
out vec4 Diff;
|
out vec4 Diff;
|
||||||
out vec4 Spec;
|
out vec4 Spec;
|
||||||
out vec4 SpecularMap;
|
out vec4 SpecularMap;
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
|
float z = texture(ntex, uv).a;
|
||||||
vec2 texc = gl_FragCoord.xy / screen;
|
vec4 xpos = 2.0 * vec4(uv, z, 1.0) - 1.0;
|
||||||
float z = texture(ntex, texc).a;
|
|
||||||
vec4 xpos = 2.0 * vec4(texc, z, 1.0) - 1.0;
|
|
||||||
xpos = invproj * xpos;
|
xpos = invproj * xpos;
|
||||||
xpos.xyz /= xpos.w;
|
xpos.xyz /= xpos.w;
|
||||||
|
|
||||||
@ -29,11 +27,11 @@ void main() {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
vec3 norm = texture(ntex, texc).xyz;
|
vec3 norm = texture(ntex, uv).xyz;
|
||||||
norm = (norm - 0.5) * 2.0;
|
norm = (norm - 0.5) * 2.0;
|
||||||
|
|
||||||
// Normalized on the cpu
|
// Normalized on the cpu
|
||||||
vec3 L = center;
|
vec3 L = direction;
|
||||||
|
|
||||||
float NdotL = max(0.0, dot(norm, L));
|
float NdotL = max(0.0, dot(norm, L));
|
||||||
vec3 R = reflect(L, norm);
|
vec3 R = reflect(L, norm);
|
||||||
@ -42,14 +40,14 @@ void main() {
|
|||||||
|
|
||||||
vec3 outcol = NdotL * col;
|
vec3 outcol = NdotL * col;
|
||||||
|
|
||||||
if (hasclouds == 1)
|
/* if (hasclouds == 1)
|
||||||
{
|
{
|
||||||
vec2 cloudcoord = (xpos.xz * 0.00833333) + wind;
|
vec2 cloudcoord = (xpos.xz * 0.00833333) + wind;
|
||||||
float cloud = texture(cloudtex, cloudcoord).x;
|
float cloud = texture(cloudtex, cloudcoord).x;
|
||||||
//float cloud = step(0.5, cloudcoord.x) * step(0.5, cloudcoord.y);
|
//float cloud = step(0.5, cloudcoord.x) * step(0.5, cloudcoord.y);
|
||||||
|
|
||||||
outcol *= cloud;
|
outcol *= cloud;
|
||||||
}
|
}*/
|
||||||
|
|
||||||
Diff = vec4(NdotL * col, 1.);
|
Diff = vec4(NdotL * col, 1.);
|
||||||
Spec = vec4(Specular * col, 1.);
|
Spec = vec4(Specular * col, 1.);
|
||||||
|
@ -368,6 +368,21 @@ public:
|
|||||||
m_color[1] = g;
|
m_color[1] = g;
|
||||||
m_color[2] = b;
|
m_color[2] = b;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
float getRed() const
|
||||||
|
{
|
||||||
|
return m_color[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
float getGreen() const
|
||||||
|
{
|
||||||
|
return m_color[1];
|
||||||
|
}
|
||||||
|
|
||||||
|
float getBlue() const
|
||||||
|
{
|
||||||
|
return m_color[2];
|
||||||
|
}
|
||||||
|
|
||||||
void setPosition(float x, float y, float z)
|
void setPosition(float x, float y, float z)
|
||||||
{
|
{
|
||||||
@ -383,6 +398,11 @@ public:
|
|||||||
m_pos[1] = pos.Y;
|
m_pos[1] = pos.Y;
|
||||||
m_pos[2] = pos.Z;
|
m_pos[2] = pos.Z;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
core::vector3df getPosition() const
|
||||||
|
{
|
||||||
|
return core::vector3df(m_pos[0], m_pos[1], m_pos[2]);
|
||||||
|
}
|
||||||
|
|
||||||
void setShadowMatrix(const core::matrix4 &mat)
|
void setShadowMatrix(const core::matrix4 &mat)
|
||||||
{
|
{
|
||||||
|
@ -333,6 +333,24 @@ void PostProcessing::renderPointlight(ITexture *in, const std::vector<float> &po
|
|||||||
glDisable(GL_BLEND);
|
glDisable(GL_BLEND);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void PostProcessing::renderSunlight()
|
||||||
|
{
|
||||||
|
SunLightProvider * const cb = (SunLightProvider *) irr_driver->getCallback(ES_SUNLIGHT);
|
||||||
|
|
||||||
|
glEnable(GL_BLEND);
|
||||||
|
glDisable(GL_DEPTH_TEST);
|
||||||
|
glBlendFunc(GL_ONE, GL_ONE);
|
||||||
|
glBlendEquation(GL_FUNC_ADD);
|
||||||
|
|
||||||
|
glUseProgram(FullScreenShader::SunLightShader::Program);
|
||||||
|
glBindVertexArray(FullScreenShader::SunLightShader::vao);
|
||||||
|
GLuint ntex_id = static_cast<irr::video::COpenGLTexture*>(irr_driver->getRTT(RTT_NORMAL_AND_DEPTH))->getOpenGLTextureName();
|
||||||
|
setTexture(0, ntex_id, GL_NEAREST, GL_NEAREST);
|
||||||
|
FullScreenShader::SunLightShader::setUniforms(cb->getPosition(), irr_driver->getInvProjMatrix(), cb->getRed(), cb->getGreen(), cb->getBlue(), 0);
|
||||||
|
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
|
||||||
|
glBindVertexArray(0);
|
||||||
|
}
|
||||||
|
|
||||||
void PostProcessing::renderLightbBlend(ITexture *diffuse, ITexture *specular, ITexture *ao, ITexture *specmap, bool debug)
|
void PostProcessing::renderLightbBlend(ITexture *diffuse, ITexture *specular, ITexture *ao, ITexture *specmap, bool debug)
|
||||||
{
|
{
|
||||||
const SColorf s = irr_driver->getSceneManager()->getAmbientLight();
|
const SColorf s = irr_driver->getSceneManager()->getAmbientLight();
|
||||||
|
@ -74,7 +74,7 @@ public:
|
|||||||
|
|
||||||
/** Generate diffuse and specular map */
|
/** Generate diffuse and specular map */
|
||||||
void renderPointlight(video::ITexture *in, const std::vector<float> &positions, const std::vector<float> &colors, const std::vector<float> &energy);
|
void renderPointlight(video::ITexture *in, const std::vector<float> &positions, const std::vector<float> &colors, const std::vector<float> &energy);
|
||||||
|
void renderSunlight();
|
||||||
/** Blend all light related map */
|
/** Blend all light related map */
|
||||||
void renderLightbBlend(video::ITexture *diffuse, video::ITexture *specular, video::ITexture *ao, video::ITexture *specmap, bool debug);
|
void renderLightbBlend(video::ITexture *diffuse, video::ITexture *specular, video::ITexture *ao, video::ITexture *specmap, bool debug);
|
||||||
|
|
||||||
|
@ -740,6 +740,7 @@ void IrrDriver::renderLights(const core::aabbox3df& cambox,
|
|||||||
if (!m_lights[i]->isPointLight())
|
if (!m_lights[i]->isPointLight())
|
||||||
{
|
{
|
||||||
m_lights[i]->render();
|
m_lights[i]->render();
|
||||||
|
m_post_processing->renderSunlight();
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
const core::vector3df &lightpos = (m_lights[i]->getAbsolutePosition() - campos);
|
const core::vector3df &lightpos = (m_lights[i]->getAbsolutePosition() - campos);
|
||||||
|
@ -236,6 +236,7 @@ void Shaders::loadShaders()
|
|||||||
FullScreenShader::PointLightShader::init();
|
FullScreenShader::PointLightShader::init();
|
||||||
FullScreenShader::PPDisplaceShader::init();
|
FullScreenShader::PPDisplaceShader::init();
|
||||||
FullScreenShader::SSAOShader::init();
|
FullScreenShader::SSAOShader::init();
|
||||||
|
FullScreenShader::SunLightShader::init();
|
||||||
MeshShader::ColorizeShader::init();
|
MeshShader::ColorizeShader::init();
|
||||||
MeshShader::NormalMapShader::init();
|
MeshShader::NormalMapShader::init();
|
||||||
MeshShader::ObjectPass1Shader::init();
|
MeshShader::ObjectPass1Shader::init();
|
||||||
@ -949,6 +950,31 @@ namespace FullScreenShader
|
|||||||
vao = createVAO(Program);
|
vao = createVAO(Program);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
GLuint SunLightShader::Program;
|
||||||
|
GLuint SunLightShader::uniform_ntex;
|
||||||
|
GLuint SunLightShader::uniform_direction;
|
||||||
|
GLuint SunLightShader::uniform_col;
|
||||||
|
GLuint SunLightShader::uniform_invproj;
|
||||||
|
GLuint SunLightShader::vao;
|
||||||
|
|
||||||
|
void SunLightShader::init()
|
||||||
|
{
|
||||||
|
Program = LoadProgram(file_manager->getAsset("shaders/screenquad.vert").c_str(), file_manager->getAsset("shaders/sunlight.frag").c_str());
|
||||||
|
uniform_ntex = glGetUniformLocation(Program, "ntex");
|
||||||
|
uniform_direction = glGetUniformLocation(Program, "direction");
|
||||||
|
uniform_col = glGetUniformLocation(Program, "col");
|
||||||
|
uniform_invproj = glGetUniformLocation(Program, "invproj");
|
||||||
|
vao = createVAO(Program);
|
||||||
|
}
|
||||||
|
|
||||||
|
void SunLightShader::setUniforms(const core::vector3df &direction, const core::matrix4 &InvProjMatrix, float r, float g, float b, unsigned TU_ntex)
|
||||||
|
{
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
GLuint LightBlendShader::Program;
|
GLuint LightBlendShader::Program;
|
||||||
GLuint LightBlendShader::uniform_diffuse;
|
GLuint LightBlendShader::uniform_diffuse;
|
||||||
GLuint LightBlendShader::uniform_specular;
|
GLuint LightBlendShader::uniform_specular;
|
||||||
|
@ -274,6 +274,17 @@ public:
|
|||||||
static void init();
|
static void init();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class SunLightShader
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
static GLuint Program;
|
||||||
|
static GLuint uniform_ntex, uniform_direction, uniform_col, uniform_invproj;
|
||||||
|
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);
|
||||||
|
};
|
||||||
|
|
||||||
class LightBlendShader
|
class LightBlendShader
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
@ -87,12 +87,7 @@ void SunNode::render()
|
|||||||
|
|
||||||
vector3df pos = getPosition();
|
vector3df pos = getPosition();
|
||||||
cb->setPosition(pos.X, pos.Y, pos.Z);
|
cb->setPosition(pos.X, pos.Y, pos.Z);
|
||||||
|
return;
|
||||||
if (!UserConfigParams::m_shadows || !World::getWorld()->getTrack()->hasShadows())
|
|
||||||
{
|
|
||||||
sq->render(false);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
array<IRenderTarget> mrt;
|
array<IRenderTarget> mrt;
|
||||||
mrt.reallocate(2);
|
mrt.reallocate(2);
|
||||||
|
Loading…
Reference in New Issue
Block a user