Factorise sun color/position
This commit is contained in:
parent
2995051f7c
commit
7aa7e2d148
@ -6,9 +6,13 @@ uniform mat4 InverseProjectionMatrix;
|
|||||||
uniform mat4 ProjectionViewMatrix;
|
uniform mat4 ProjectionViewMatrix;
|
||||||
uniform vec2 screen;
|
uniform vec2 screen;
|
||||||
|
|
||||||
|
uniform vec3 sun_direction;
|
||||||
|
uniform vec3 sun_col;
|
||||||
|
uniform float sun_angle;
|
||||||
uniform float blueLmn[9];
|
uniform float blueLmn[9];
|
||||||
uniform float greenLmn[9];
|
uniform float greenLmn[9];
|
||||||
uniform float redLmn[9];
|
uniform float redLmn[9];
|
||||||
|
|
||||||
#else
|
#else
|
||||||
layout (std140) uniform MatrixesData
|
layout (std140) uniform MatrixesData
|
||||||
{
|
{
|
||||||
@ -24,6 +28,9 @@ layout (std140) uniform MatrixesData
|
|||||||
// Expand because of catalyst (14.12) not correctly associating array in UBO
|
// Expand because of catalyst (14.12) not correctly associating array in UBO
|
||||||
layout (std140) uniform LightingData
|
layout (std140) uniform LightingData
|
||||||
{
|
{
|
||||||
|
vec3 sun_direction;
|
||||||
|
vec3 sun_col;
|
||||||
|
float sun_angle;
|
||||||
float bL00;
|
float bL00;
|
||||||
float bL1m1;
|
float bL1m1;
|
||||||
float bL10;
|
float bL10;
|
||||||
|
@ -1,10 +1,6 @@
|
|||||||
uniform sampler2D ntex;
|
uniform sampler2D ntex;
|
||||||
uniform sampler2D dtex;
|
uniform sampler2D dtex;
|
||||||
|
|
||||||
uniform vec3 direction;
|
|
||||||
uniform vec3 col;
|
|
||||||
uniform float sunangle = .54;
|
|
||||||
|
|
||||||
out vec4 Diff;
|
out vec4 Diff;
|
||||||
out vec4 Spec;
|
out vec4 Spec;
|
||||||
|
|
||||||
@ -32,19 +28,18 @@ void main() {
|
|||||||
float roughness = texture(ntex, uv).z;
|
float roughness = texture(ntex, uv).z;
|
||||||
vec3 eyedir = -normalize(xpos.xyz);
|
vec3 eyedir = -normalize(xpos.xyz);
|
||||||
|
|
||||||
// Normalized on the cpu
|
vec3 L = normalize((transpose(InverseViewMatrix) * vec4(sun_direction, 0.)).xyz);
|
||||||
vec3 L = direction;
|
|
||||||
float NdotL = clamp(dot(norm, L), 0., 1.);
|
float NdotL = clamp(dot(norm, L), 0., 1.);
|
||||||
|
|
||||||
float angle = 3.14 * sunangle / 180.;
|
float angle = 3.14 * sun_angle / 180.;
|
||||||
vec3 R = reflect(-eyedir, norm);
|
vec3 R = reflect(-eyedir, norm);
|
||||||
vec3 Lightdir = getMostRepresentativePoint(direction, R, angle);
|
vec3 Lightdir = getMostRepresentativePoint(L, R, angle);
|
||||||
|
|
||||||
vec3 Specular = SpecularBRDF(norm, eyedir, Lightdir, vec3(1.), roughness);
|
vec3 Specular = SpecularBRDF(norm, eyedir, Lightdir, vec3(1.), roughness);
|
||||||
vec3 Diffuse = DiffuseBRDF(norm, eyedir, Lightdir, vec3(1.), roughness);
|
vec3 Diffuse = DiffuseBRDF(norm, eyedir, Lightdir, vec3(1.), roughness);
|
||||||
|
|
||||||
Diff = vec4(NdotL * Diffuse * col, 1.);
|
Diff = vec4(NdotL * Diffuse * sun_col, 1.);
|
||||||
Spec = vec4(NdotL * Specular * col, 1.);
|
Spec = vec4(NdotL * Specular * sun_col, 1.);
|
||||||
|
|
||||||
/* if (hasclouds == 1)
|
/* if (hasclouds == 1)
|
||||||
{
|
{
|
||||||
|
@ -7,10 +7,6 @@ uniform float split1;
|
|||||||
uniform float split2;
|
uniform float split2;
|
||||||
uniform float splitmax;
|
uniform float splitmax;
|
||||||
|
|
||||||
uniform vec3 direction;
|
|
||||||
uniform vec3 col;
|
|
||||||
uniform float sunangle = .54;
|
|
||||||
|
|
||||||
in vec2 uv;
|
in vec2 uv;
|
||||||
out vec4 Diff;
|
out vec4 Diff;
|
||||||
out vec4 Spec;
|
out vec4 Spec;
|
||||||
@ -50,13 +46,12 @@ void main() {
|
|||||||
float roughness =texture(ntex, uv).z;
|
float roughness =texture(ntex, uv).z;
|
||||||
vec3 eyedir = -normalize(xpos.xyz);
|
vec3 eyedir = -normalize(xpos.xyz);
|
||||||
|
|
||||||
// Normalized on the cpu
|
vec3 L = normalize((transpose(InverseViewMatrix) * vec4(sun_direction, 0.)).xyz);
|
||||||
vec3 L = direction;
|
|
||||||
float NdotL = clamp(dot(norm, L), 0., 1.);
|
float NdotL = clamp(dot(norm, L), 0., 1.);
|
||||||
|
|
||||||
float angle = 3.14 * sunangle / 180.;
|
float angle = 3.14 * sun_angle / 180.;
|
||||||
vec3 R = reflect(-eyedir, norm);
|
vec3 R = reflect(-eyedir, norm);
|
||||||
vec3 Lightdir = getMostRepresentativePoint(direction, R, angle);
|
vec3 Lightdir = getMostRepresentativePoint(L, R, angle);
|
||||||
|
|
||||||
vec3 Specular = SpecularBRDF(norm, eyedir, Lightdir, vec3(1.), roughness);
|
vec3 Specular = SpecularBRDF(norm, eyedir, Lightdir, vec3(1.), roughness);
|
||||||
vec3 Diffuse = DiffuseBRDF(norm, eyedir, Lightdir, vec3(1.), roughness);
|
vec3 Diffuse = DiffuseBRDF(norm, eyedir, Lightdir, vec3(1.), roughness);
|
||||||
@ -74,6 +69,6 @@ void main() {
|
|||||||
else
|
else
|
||||||
factor = 1.;
|
factor = 1.;
|
||||||
|
|
||||||
Diff = vec4(factor * NdotL * Diffuse * col, 1.);
|
Diff = vec4(factor * NdotL * Diffuse * sun_col, 1.);
|
||||||
Spec = vec4(factor * NdotL * Specular * col, 1.);
|
Spec = vec4(factor * NdotL * Specular * sun_col, 1.);
|
||||||
}
|
}
|
||||||
|
@ -663,12 +663,7 @@ public:
|
|||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
void setSunDirection(const core::vector3df &SunPos)
|
void setSunDirection(const core::vector3df &SunPos)
|
||||||
{
|
{
|
||||||
core::matrix4 m_view = getViewMatrix();
|
|
||||||
m_view.makeInverse();
|
|
||||||
m_view = m_view.getTransposed();
|
|
||||||
m_sundirection = SunPos;
|
m_sundirection = SunPos;
|
||||||
m_view.transformVect(m_sundirection);
|
|
||||||
m_sundirection.normalize();
|
|
||||||
}
|
}
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
video::SColorf getSunColor() const { return m_suncolor; }
|
video::SColorf getSunColor() const { return m_suncolor; }
|
||||||
|
@ -963,13 +963,21 @@ void IrrDriver::computeCameraMatrix(scene::ICameraSceneNode * const camnode, siz
|
|||||||
glBindBuffer(GL_UNIFORM_BUFFER, SharedObject::ViewProjectionMatrixesUBO);
|
glBindBuffer(GL_UNIFORM_BUFFER, SharedObject::ViewProjectionMatrixesUBO);
|
||||||
glBufferSubData(GL_UNIFORM_BUFFER, 0, (16 * 9 + 2) * sizeof(float), tmp);
|
glBufferSubData(GL_UNIFORM_BUFFER, 0, (16 * 9 + 2) * sizeof(float), tmp);
|
||||||
|
|
||||||
float Lighting[27];
|
float Lighting[36];
|
||||||
memcpy(Lighting, blueSHCoeff, 9 * sizeof(float));
|
Lighting[0] = m_sundirection.X;
|
||||||
memcpy(&Lighting[9], greenSHCoeff, 9 * sizeof(float));
|
Lighting[1] = m_sundirection.Y;
|
||||||
memcpy(&Lighting[18], redSHCoeff, 9 * sizeof(float));
|
Lighting[2] = m_sundirection.Z;
|
||||||
|
Lighting[4] = m_suncolor.getRed();
|
||||||
|
Lighting[5] = m_suncolor.getGreen();
|
||||||
|
Lighting[6] = m_suncolor.getBlue();
|
||||||
|
Lighting[7] = 0.54f;
|
||||||
|
|
||||||
|
memcpy(&Lighting[8], blueSHCoeff, 9 * sizeof(float));
|
||||||
|
memcpy(&Lighting[17], greenSHCoeff, 9 * sizeof(float));
|
||||||
|
memcpy(&Lighting[26], redSHCoeff, 9 * sizeof(float));
|
||||||
|
|
||||||
glBindBuffer(GL_UNIFORM_BUFFER, SharedObject::LightingDataUBO);
|
glBindBuffer(GL_UNIFORM_BUFFER, SharedObject::LightingDataUBO);
|
||||||
glBufferSubData(GL_UNIFORM_BUFFER, 0, 27 * sizeof(float), Lighting);
|
glBufferSubData(GL_UNIFORM_BUFFER, 0, 36 * sizeof(float), Lighting);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -433,7 +433,7 @@ static void initLightingDataUBO()
|
|||||||
{
|
{
|
||||||
glGenBuffers(1, &SharedObject::LightingDataUBO);
|
glGenBuffers(1, &SharedObject::LightingDataUBO);
|
||||||
glBindBuffer(GL_UNIFORM_BUFFER, SharedObject::LightingDataUBO);
|
glBindBuffer(GL_UNIFORM_BUFFER, SharedObject::LightingDataUBO);
|
||||||
glBufferData(GL_UNIFORM_BUFFER, 27 * sizeof(float), 0, GL_STREAM_DRAW);
|
glBufferData(GL_UNIFORM_BUFFER, 36 * sizeof(float), 0, GL_STREAM_DRAW);
|
||||||
glBindBuffer(GL_UNIFORM_BUFFER, 0);
|
glBindBuffer(GL_UNIFORM_BUFFER, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -591,6 +591,12 @@ void bypassUBO(GLuint Program)
|
|||||||
glUniform1fv(gLmn, 9, irr_driver->greenSHCoeff);
|
glUniform1fv(gLmn, 9, irr_driver->greenSHCoeff);
|
||||||
GLint rLmn = glGetUniformLocation(Program, "redLmn[0]");
|
GLint rLmn = glGetUniformLocation(Program, "redLmn[0]");
|
||||||
glUniform1fv(rLmn, 9, irr_driver->redSHCoeff);
|
glUniform1fv(rLmn, 9, irr_driver->redSHCoeff);
|
||||||
|
GLint sundir = glGetUniformLocation(Program, "sun_direction");
|
||||||
|
glUniform3f(sundir, irr_driver->getSunDirection().X, irr_driver->getSunDirection().Y, irr_driver->getSunDirection().Z);
|
||||||
|
GLint suncol = glGetUniformLocation(Program, "sun_col");
|
||||||
|
glUniform3f(suncol, irr_driver->getSunColor().getRed(), irr_driver->getSunColor().getGreen(), irr_driver->getSunColor().getBlue());
|
||||||
|
GLint sunangle = glGetUniformLocation(Program, "sun_angle");
|
||||||
|
glUniform1f(sunangle, 0.54f);
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace UtilShader
|
namespace UtilShader
|
||||||
|
Loading…
x
Reference in New Issue
Block a user