Hooked up the directional light colour and directional light intensity parameters from the scene graph
--HG-- extra : convert_revision : svn%3A7752d6cf-9f14-4ad2-affc-04f1e67b81a5/trunk%4053
This commit is contained in:
@@ -51,13 +51,13 @@ KRCamera::KRCamera() {
|
||||
bEnableDeferredLighting = true;
|
||||
|
||||
|
||||
dAmbientR = 0.25f;
|
||||
dAmbientG = 0.25f;
|
||||
dAmbientB = 0.35f;
|
||||
dAmbientR = 0.0f;
|
||||
dAmbientG = 0.0f;
|
||||
dAmbientB = 0.0f;
|
||||
|
||||
dSunR = 1.0f;
|
||||
dSunG = 1.0f;
|
||||
dSunB = 0.70f;
|
||||
dSunB = 1.0f;
|
||||
|
||||
perspective_fov = PI / 8.0;
|
||||
perspective_nearz = 0.25f;
|
||||
|
||||
@@ -58,7 +58,12 @@ void KRDirectionalLight::render(KRCamera *pCamera, KRContext *pContext, KRBoundi
|
||||
|
||||
KRShader *pShader = pContext->getShaderManager()->getShader("light_directional", pCamera, false, false, false, 0, false, false, false, false, false, false, false, gBufferPass);
|
||||
pShader->bind(pCamera, matModelToView, mvpmatrix, cameraPosition, light_direction, pShadowMatrices, shadowDepthTextures, 0, gBufferPass);
|
||||
|
||||
glUniform3f(
|
||||
pShader->m_uniforms[KRShader::KRENGINE_UNIFORM_LIGHT_COLOR],
|
||||
m_color.x * m_intensity / 100.0f,
|
||||
m_color.y * m_intensity / 100.0f,
|
||||
m_color.z * m_intensity / 100.0f
|
||||
);
|
||||
|
||||
// Render a full screen quad
|
||||
static const GLfloat squareVertices[] = {
|
||||
|
||||
@@ -65,6 +65,7 @@ typedef enum KREngineParameterType {KRENGINE_PARAMETER_INT, KRENGINE_PARAMETER_F
|
||||
KRENGINE_UNIFORM_MATERIAL_AMBIENT,
|
||||
KRENGINE_UNIFORM_MATERIAL_DIFFUSE,
|
||||
KRENGINE_UNIFORM_MATERIAL_SPECULAR,
|
||||
KRENGINE_UNIFORM_LIGHT_COLOR,
|
||||
KRENGINE_UNIFORM_MVP,
|
||||
KRENGINE_UNIFORM_M2V,
|
||||
KRENGINE_UNIFORM_SHADOWMVP1,
|
||||
|
||||
@@ -232,21 +232,41 @@ void KRMaterial::bind(KRMaterial **prevBoundMaterial, char *szPrevShaderKey, KRC
|
||||
}
|
||||
|
||||
if(!bSameDiffuse) {
|
||||
glUniform3f(
|
||||
pShader->m_uniforms[KRShader::KRENGINE_UNIFORM_MATERIAL_DIFFUSE],
|
||||
m_kd_r * pCamera->dSunR,
|
||||
m_kd_g * pCamera->dSunG,
|
||||
m_kd_b * pCamera->dSunB
|
||||
);
|
||||
if(gBufferPass == 0) {
|
||||
// We pre-multiply the light color with the material color in the forward renderer
|
||||
glUniform3f(
|
||||
pShader->m_uniforms[KRShader::KRENGINE_UNIFORM_MATERIAL_DIFFUSE],
|
||||
m_kd_r * pCamera->dSunR,
|
||||
m_kd_g * pCamera->dSunG,
|
||||
m_kd_b * pCamera->dSunB
|
||||
);
|
||||
} else {
|
||||
glUniform3f(
|
||||
pShader->m_uniforms[KRShader::KRENGINE_UNIFORM_MATERIAL_DIFFUSE],
|
||||
m_kd_r,
|
||||
m_kd_g,
|
||||
m_kd_b
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if(!bSameSpecular) {
|
||||
glUniform3f(
|
||||
pShader->m_uniforms[KRShader::KRENGINE_UNIFORM_MATERIAL_SPECULAR],
|
||||
m_ks_r * pCamera->dSunR,
|
||||
m_ks_g * pCamera->dSunG,
|
||||
m_ks_b * pCamera->dSunB
|
||||
);
|
||||
if(gBufferPass == 0) {
|
||||
// We pre-multiply the light color with the material color in the forward renderer
|
||||
glUniform3f(
|
||||
pShader->m_uniforms[KRShader::KRENGINE_UNIFORM_MATERIAL_SPECULAR],
|
||||
m_ks_r * pCamera->dSunR,
|
||||
m_ks_g * pCamera->dSunG,
|
||||
m_ks_b * pCamera->dSunB
|
||||
);
|
||||
} else {
|
||||
glUniform3f(
|
||||
pShader->m_uniforms[KRShader::KRENGINE_UNIFORM_MATERIAL_SPECULAR],
|
||||
m_ks_r,
|
||||
m_ks_g,
|
||||
m_ks_b
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if(bDiffuseMap && !bSameDiffuseScale && m_diffuseMapScale != default_scale) {
|
||||
|
||||
@@ -83,6 +83,10 @@ void KRScene::render(KRCamera *pCamera, KRContext *pContext, KRBoundingVolume &f
|
||||
KRDirectionalLight *directional_light = getFirstDirectionalLight();
|
||||
if(directional_light) {
|
||||
forward_render_light_direction = directional_light->getLightDirection();
|
||||
KRVector3 sun_color = directional_light->getColor() * (directional_light->getIntensity() / 100.0f);
|
||||
pCamera->dSunR = sun_color.x;
|
||||
pCamera->dSunG = sun_color.y;
|
||||
pCamera->dSunB = sun_color.z;
|
||||
}
|
||||
|
||||
m_pRootNode->render(pCamera, pContext, frustrumVolume, bRenderShadowMap, viewMatrix, cameraPosition, forward_render_light_direction, pShadowMatrices, shadowDepthTextures, cShadowBuffers, gBufferPass);
|
||||
|
||||
@@ -104,6 +104,8 @@ KRShader::KRShader(char *szKey, std::string options, std::string vertShaderSourc
|
||||
m_uniforms[KRENGINE_UNIFORM_MATERIAL_AMBIENT] = glGetUniformLocation(m_iProgram, "material_ambient");
|
||||
m_uniforms[KRENGINE_UNIFORM_MATERIAL_DIFFUSE] = glGetUniformLocation(m_iProgram, "material_diffuse");
|
||||
m_uniforms[KRENGINE_UNIFORM_MATERIAL_SPECULAR] = glGetUniformLocation(m_iProgram, "material_specular");
|
||||
m_uniforms[KRENGINE_UNIFORM_LIGHT_COLOR] = glGetUniformLocation(m_iProgram, "light_color");
|
||||
|
||||
m_uniforms[KRENGINE_UNIFORM_MATERIAL_ALPHA] = glGetUniformLocation(m_iProgram, "material_alpha");
|
||||
m_uniforms[KRENGINE_UNIFORM_MATERIAL_SHININESS] = glGetUniformLocation(m_iProgram, "material_shininess");
|
||||
|
||||
|
||||
@@ -70,6 +70,7 @@ public:
|
||||
KRENGINE_UNIFORM_MATERIAL_AMBIENT,
|
||||
KRENGINE_UNIFORM_MATERIAL_DIFFUSE,
|
||||
KRENGINE_UNIFORM_MATERIAL_SPECULAR,
|
||||
KRENGINE_UNIFORM_LIGHT_COLOR,
|
||||
KRENGINE_UNIFORM_MATERIAL_ALPHA,
|
||||
KRENGINE_UNIFORM_MATERIAL_SHININESS,
|
||||
KRENGINE_UNIFORM_MVP,
|
||||
|
||||
@@ -124,12 +124,6 @@ void main()
|
||||
mediump vec2 gbuffer_uv = vec2(gl_FragCoord.xy / viewport.zw);
|
||||
#endif
|
||||
|
||||
#if GBUFFER_PASS == 2
|
||||
lowp vec4 gbuffer_sample = texture2D(gbuffer_frame, gbuffer_uv);
|
||||
mediump vec3 gbuffer_normal = normalize(2.0 * gbuffer_sample.rgb - 1.0);
|
||||
mediump float gbuffer_specular_exponent = gbuffer_sample.a;
|
||||
#endif
|
||||
|
||||
#if GBUFFER_PASS == 3
|
||||
lowp vec4 gbuffer_sample = texture2D(gbuffer_frame, gbuffer_uv);
|
||||
lowp vec3 gbuffer_lamber_factor = gbuffer_sample.rgb;
|
||||
@@ -159,7 +153,7 @@ void main()
|
||||
#endif
|
||||
|
||||
#if GBUFFER_PASS == 3
|
||||
mediump float lamberFactor = gbuffer_lamber_factor.r;
|
||||
mediump vec3 lamberFactor = gbuffer_lamber_factor;
|
||||
#else
|
||||
mediump float lamberFactor = max(0.0,dot(lightVec, normal));
|
||||
#endif
|
||||
@@ -221,7 +215,11 @@ void main()
|
||||
|
||||
#if SHADOW_QUALITY >= 1
|
||||
if(vertexShadowDepth >= shadowMapDepth && shadowMapDepth < 1.0) {
|
||||
lamberFactor = 0.0;
|
||||
#if GBUFFER_PASS == 3
|
||||
lamberFactor = vec3(0.0);
|
||||
#else
|
||||
lamberFactor = 0.0;
|
||||
#endif
|
||||
specularFactor = 0.0;
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -29,7 +29,8 @@
|
||||
uniform sampler2D gbuffer_frame;
|
||||
uniform sampler2D gbuffer_depth;
|
||||
|
||||
uniform highp vec3 lightDirection; // Must be normalized and converted to view space before entering shader
|
||||
uniform mediump vec3 lightDirection; // Must be normalized and converted to view space before entering shader
|
||||
uniform lowp vec3 light_color;
|
||||
uniform mediump vec4 viewport;
|
||||
|
||||
void main()
|
||||
@@ -55,5 +56,5 @@ void main()
|
||||
specularFactor = clamp(pow(dot(halfVec,normalize(gbuffer_normal)), gbuffer_specular_exponent), 0.0, 1.0);
|
||||
}
|
||||
|
||||
gl_FragColor = vec4(vec3(lamberFactor), specularFactor);
|
||||
gl_FragColor = vec4(light_color * lamberFactor, specularFactor);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user