Got phong shading working.
This commit is contained in:
parent
c505553439
commit
769514af88
@ -6,6 +6,7 @@ in vec2 vTexCoord;
|
||||
out vec4 oColor;
|
||||
|
||||
uniform sampler2D uTexture;
|
||||
uniform int lightCount;
|
||||
uniform vec3 lightSources[128];
|
||||
uniform vec3 ambientIntensity;
|
||||
uniform float ambientFactor;
|
||||
@ -15,7 +16,10 @@ uniform float diffuseFactor;
|
||||
void main()
|
||||
{
|
||||
vec3 ambientColor = ambientFactor * ambientIntensity;
|
||||
vec3 diffuseColor = dot(normalize(vNormal),vec3(0,0,1))*diffuseFactor*diffuseIntensity;
|
||||
vec3 diffuseColor = vec3(0.0, 0.0, 0.0);
|
||||
for(int i = 0; i<lightCount; i++) {
|
||||
diffuseColor += dot(normalize(vNormal), normalize(lightSources[i]))*diffuseFactor*diffuseIntensity;
|
||||
}
|
||||
vec3 finalColor = diffuseColor + ambientColor;
|
||||
|
||||
vec3 texture = texture(uTexture, vTexCoord).rgb;
|
||||
|
@ -51,9 +51,10 @@ void draw( float runTime )
|
||||
//set lighting parameters
|
||||
shader.getReference()->setUniform("ambientIntensity", level.getAmbientLight());
|
||||
shader.getReference()->setUniform("ambientFactor", 1.0f);
|
||||
if (level.getLights().size() > 0) {
|
||||
shader.getReference()->setUniform("diffuseIntensity", glm::vec3(1.0f, 1.0f, 1.0f));
|
||||
shader.getReference()->setUniform("diffuseFactor", 1.0f);
|
||||
|
||||
shader.getReference()->setUniform("lightCount", (int) level.getLights().size());
|
||||
|
||||
// TODO look into doing this less often
|
||||
// Build light position array
|
||||
@ -61,9 +62,8 @@ void draw( float runTime )
|
||||
for(int i = 0; i<level.getLights().size(); i++) {
|
||||
lights[i] = level.getLights()[i].getPosition();
|
||||
}
|
||||
|
||||
shader.getReference()->setUniform("lightSources", lights);
|
||||
//glUniform1fv(glGetUniformLocation(shader.getReference(), "lightSources", 128, lights);
|
||||
glUniform3fv(shader.getReference()->getUniformLocation("lightSources"), sizeof(lights), (GLfloat*) lights);
|
||||
}
|
||||
|
||||
// render the level(currently only a bunny):
|
||||
level.render();
|
||||
|
4
level.cc
4
level.cc
@ -23,6 +23,10 @@ void Level::load(Shader shader) {
|
||||
objects.push_back(object);
|
||||
//set lighting parameters
|
||||
ambientLight = glm::vec3(0.1f, 0.1f, 0.1f);
|
||||
Light light = Light(glm::vec3(1.0f, 0.0f, 0.0f), glm::vec3(0.0f, 0.0f, 0.0f), glm::vec3(0.0f, 0.0f, 1.0f), 1.0f);
|
||||
lights.push_back(light);
|
||||
Light light2 = Light(glm::vec3(0.0f, 0.0f, 1.0f), glm::vec3(0.0f, 0.0f, 0.0f), glm::vec3(1.0f, 0.0f, 0.0f), 1.0f);
|
||||
lights.push_back(light2);
|
||||
}
|
||||
|
||||
void Level::render() {
|
||||
|
Loading…
Reference in New Issue
Block a user