Skip to content

Commit

Permalink
Model Renderer|GL: Ambient light in the model shader
Browse files Browse the repository at this point in the history
  • Loading branch information
skyjake committed Aug 13, 2014
1 parent 92affc1 commit 3b745b6
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 2 deletions.
2 changes: 2 additions & 0 deletions doomsday/client/include/render/modelrenderer.h
Expand Up @@ -84,6 +84,8 @@ class ModelRenderer
de::Matrix4f const &modelToLocal,
de::Matrix4f const &localToView);

void setAmbientLight(de::Vector3f const &ambientIntensity);

void clearLights();

void addLight(de::Vector3f const &direction, de::Vector3f const &intensity);
Expand Down
Expand Up @@ -59,6 +59,7 @@ group model {
}"
fragment = "
uniform sampler2D uTex;
uniform highp vec4 uAmbientLight;
uniform highp vec4 uLightIntensities[4];

varying highp vec2 vUV;
Expand Down Expand Up @@ -92,7 +93,8 @@ group model {
highp vec4 diffuse = texture2D(uTex, vUV);

gl_FragColor = diffuse *
(diffuseLight(0, normal) +
(uAmbientLight +
diffuseLight(0, normal) +
diffuseLight(1, normal) +
diffuseLight(2, normal) +
diffuseLight(3, normal));
Expand Down
7 changes: 7 additions & 0 deletions doomsday/client/src/render/modelrenderer.cpp
Expand Up @@ -47,6 +47,7 @@ DENG2_PIMPL(ModelRenderer)
GLUniform uMvpMatrix { "uMvpMatrix", GLUniform::Mat4 };
GLUniform uTex { "uTex", GLUniform::Sampler2D };
GLUniform uEyeDir { "uEyeDir", GLUniform::Vec3 };
GLUniform uAmbientLight { "uAmbientLight", GLUniform::Vec4 };
GLUniform uLightDirs { "uLightDirs", GLUniform::Vec3Array, MAX_LIGHTS };
GLUniform uLightIntensities { "uLightIntensities", GLUniform::Vec4Array, MAX_LIGHTS };
Matrix4f inverseLocal;
Expand All @@ -65,6 +66,7 @@ DENG2_PIMPL(ModelRenderer)
<< uMvpMatrix
<< uTex
<< uEyeDir
<< uAmbientLight
<< uLightDirs
<< uLightIntensities;

Expand Down Expand Up @@ -247,6 +249,11 @@ void ModelRenderer::setTransformation(Vector3f const &eyeDir, Matrix4f const &mo
d->uEyeDir = (d->inverseLocal * eyeDir).normalize();
}

void ModelRenderer::setAmbientLight(Vector3f const &ambientIntensity)
{
d->uAmbientLight = Vector4f(ambientIntensity, 1.f);
}

void ModelRenderer::clearLights()
{
d->lightCount = 0;
Expand Down
3 changes: 2 additions & 1 deletion doomsday/client/src/render/rend_model.cpp
Expand Up @@ -1164,7 +1164,8 @@ void Rend_DrawModel2(vissprite_t const &spr)
// Set up a suitable matrix for the pose.
rend.setTransformation(vOrigin - spr.pose.mid().xzy(), localMat, viewMat);

// Lighting vectors and ambient color.
// Ambient color and lighting vectors.
rend.setAmbientLight(spr.light.ambientColor * .8f);
rend.clearLights();
VL_ListIterator(spr.light.vLightListIdx, [&rend] (VectorLight const *light, void *) -> int {
// Use this when drawing the model.
Expand Down

0 comments on commit 3b745b6

Please sign in to comment.