First attempt at Phong shading. Build broken.
This commit is contained in:
parent
911c8ebfcc
commit
c505553439
@ -6,11 +6,18 @@ in vec2 vTexCoord;
|
||||
out vec4 oColor;
|
||||
|
||||
uniform sampler2D uTexture;
|
||||
uniform vec3 lightSources[128];
|
||||
uniform vec3 ambientIntensity;
|
||||
uniform float ambientFactor;
|
||||
uniform vec3 diffuseIntensity;
|
||||
uniform float diffuseFactor;
|
||||
|
||||
void main()
|
||||
{
|
||||
vec3 color = texture(uTexture, vTexCoord).rgb;
|
||||
color *= dot(normalize(vNormal),vec3(0,0,1));
|
||||
{
|
||||
vec3 ambientColor = ambientFactor * ambientIntensity;
|
||||
vec3 diffuseColor = dot(normalize(vNormal),vec3(0,0,1))*diffuseFactor*diffuseIntensity;
|
||||
vec3 finalColor = diffuseColor + ambientColor;
|
||||
|
||||
oColor = vec4( color, 1.0 );
|
||||
vec3 texture = texture(uTexture, vTexCoord).rgb;
|
||||
oColor = vec4(finalColor*texture, 1.0 );
|
||||
}
|
||||
|
19
graphics.cc
19
graphics.cc
@ -48,7 +48,24 @@ void draw( float runTime )
|
||||
shader.getReference()->setUniform( "uViewMatrix", viewMatrix );
|
||||
shader.getReference()->setUniform( "uProjectionMatrix", buildFrustum(75.0, 0.1, 100.0, (float)g_windowSize.x/(float)g_windowSize.y) );
|
||||
|
||||
// render the bunny:
|
||||
//set lighting parameters
|
||||
shader.getReference()->setUniform("ambientIntensity", level.getAmbientLight());
|
||||
shader.getReference()->setUniform("ambientFactor", 1.0f);
|
||||
shader.getReference()->setUniform("diffuseIntensity", glm::vec3(1.0f, 1.0f, 1.0f));
|
||||
shader.getReference()->setUniform("diffuseFactor", 1.0f);
|
||||
|
||||
|
||||
// TODO look into doing this less often
|
||||
// Build light position array
|
||||
glm::vec3 lights[level.getLights().size()];
|
||||
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);
|
||||
|
||||
// render the level(currently only a bunny):
|
||||
level.render();
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user