Shading now respects colours.
This commit is contained in:
parent
129866d0d7
commit
afbf41ea0d
@ -8,17 +8,18 @@ out vec4 oColor;
|
|||||||
uniform sampler2D uTexture;
|
uniform sampler2D uTexture;
|
||||||
uniform int lightCount;
|
uniform int lightCount;
|
||||||
uniform vec3 lightSources[128];
|
uniform vec3 lightSources[128];
|
||||||
uniform vec3 ambientIntensity;
|
uniform vec3 ambientColor;
|
||||||
uniform float ambientFactor;
|
uniform float ambientFactor;
|
||||||
uniform vec3 diffuseIntensity;
|
uniform vec3 lightColors[128];
|
||||||
uniform float diffuseFactor;
|
uniform float diffuseFactor;
|
||||||
|
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
vec3 ambientColor = ambientFactor * ambientIntensity;
|
vec3 ambientColor = ambientFactor * ambientColor;
|
||||||
vec3 diffuseColor = vec3(0.0, 0.0, 0.0);
|
vec3 diffuseColor = vec3(0.0, 0.0, 0.0);
|
||||||
for(int i = 0; i<lightCount; i++) {
|
for(int i = 0; i<lightCount; i++) {
|
||||||
diffuseColor += dot(normalize(vNormal), normalize(lightSources[i]))*diffuseFactor*diffuseIntensity;
|
diffuseColor += dot(normalize(vNormal), normalize(lightSources[i]))
|
||||||
|
*diffuseFactor*lightColors[i];
|
||||||
}
|
}
|
||||||
vec3 finalColor = diffuseColor + ambientColor;
|
vec3 finalColor = diffuseColor + ambientColor;
|
||||||
|
|
||||||
|
19
graphics.cc
19
graphics.cc
@ -49,20 +49,27 @@ void draw( float runTime )
|
|||||||
shader.getReference()->setUniform( "uProjectionMatrix", buildFrustum(75.0, 0.1, 100.0, (float)g_windowSize.x/(float)g_windowSize.y) );
|
shader.getReference()->setUniform( "uProjectionMatrix", buildFrustum(75.0, 0.1, 100.0, (float)g_windowSize.x/(float)g_windowSize.y) );
|
||||||
|
|
||||||
//set lighting parameters
|
//set lighting parameters
|
||||||
shader.getReference()->setUniform("ambientIntensity", level.getAmbientLight());
|
shader.getReference()->setUniform("ambientColor", level.getAmbientLight());
|
||||||
shader.getReference()->setUniform("ambientFactor", 1.0f);
|
shader.getReference()->setUniform("ambientFactor", 1.0f);
|
||||||
if (level.getLights().size() > 0) {
|
if (level.getLights().size() > 0) {
|
||||||
shader.getReference()->setUniform("diffuseIntensity", glm::vec3(1.0f, 1.0f, 1.0f));
|
shader.getReference()->setUniform("diffuseFactor", 0.7f);
|
||||||
shader.getReference()->setUniform("diffuseFactor", 1.0f);
|
|
||||||
shader.getReference()->setUniform("lightCount", (int) level.getLights().size());
|
shader.getReference()->setUniform("lightCount", (int) level.getLights().size());
|
||||||
|
|
||||||
// TODO look into doing this less often
|
// TODO look into doing this less often
|
||||||
// Build light position array
|
// Build light position array
|
||||||
glm::vec3 lights[level.getLights().size()];
|
glm::vec3 lightSources[level.getLights().size()];
|
||||||
for(int i = 0; i<level.getLights().size(); i++) {
|
for(int i = 0; i<level.getLights().size(); i++) {
|
||||||
lights[i] = level.getLights()[i].getPosition();
|
lightSources[i] = level.getLights()[i].getPosition();
|
||||||
}
|
}
|
||||||
glUniform3fv(shader.getReference()->getUniformLocation("lightSources"), sizeof(lights), (GLfloat*) lights);
|
glUniform3fv(shader.getReference()->getUniformLocation("lightSources"),
|
||||||
|
sizeof(lightSources), (GLfloat*) lightSources);
|
||||||
|
// Build light colour array
|
||||||
|
glm::vec3 lightColours[level.getLights().size()];
|
||||||
|
for(int i = 0; i<level.getLights().size(); i++) {
|
||||||
|
lightColours[i] = level.getLights()[i].getColour();
|
||||||
|
}
|
||||||
|
glUniform3fv(shader.getReference()->getUniformLocation("lightColors"),
|
||||||
|
sizeof(lightColours), (GLfloat*) lightColours);
|
||||||
}
|
}
|
||||||
|
|
||||||
// render the level(currently only a bunny):
|
// render the level(currently only a bunny):
|
||||||
|
Loading…
Reference in New Issue
Block a user