Skip to content

Commit

Permalink
shader fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
oxydia committed Jan 14, 2012
1 parent 8173777 commit 9b06bbf
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 21 deletions.
18 changes: 9 additions & 9 deletions shaders/lightingShader.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@
in vec4 vertexColor;

// Varyings : data to transmit to fragments
varying out vec3 position;
varying out vec3 normal;
varying out vec2 uvs;
varying out vec4 localColor;
out vec4 position;
out vec4 normal;
out vec2 uvs;
out vec4 localColor;

void main()
{
Expand All @@ -24,7 +24,7 @@ void main()
if (filledData[2]) uvs = vertexUvs;
if (filledData[3]) localColor = vertexColor;

gl_Position = projection * view * model * vec4(vertexPosition,1);
gl_Position = projection * view * model * vec4(vertexPosition);
}

#endif
Expand Down Expand Up @@ -54,8 +54,8 @@ void main()

// If texture
if (filledData[2]) {
diffuseColor = vec4(texture2d(textureUnitDiffuse, uvs).rgb, 1.);
specularColorMix = vec4(texture2d(textureUnitSpecular, uvs).rgb, 1.);
diffuseColorMix = vec4(texture2D(textureUnitDiffuse, uvs).rgb, 1.);
specularColorMix = vec4(texture2D(textureUnitSpecular, uvs).rgb, 1.);
}

// If no normal
Expand All @@ -72,8 +72,8 @@ void main()
float diffuseValue=light.power * max( dot(L, N), 0.0);
float specularValue=light.power * pow( max(dot(R, V), 0.0), material.shininess);
vec4 ambientContribution=vec4(ambientValue*material.ka*material.ambient.rgb, material.ambient.a);
vec4 diffuseContribution=vec4(diffuseValue*material.kd*diffuseColorMix.rgb, diffuseColorMix.a);
vec4 specularContribution=vec4(specularValue*material.ks*specularColorMix.rgb, material.specular.a);
vec4 diffuseContribution=vec4(diffuseValue*material.kd*material.diffuse.rgb, diffuseColorMix.a);
vec4 specularContribution=vec4(specularValue*material.ks*material.specular.rgb, material.specular.a);

fragColor = ambientContribution + diffuseContribution + specularContribution;
}
Expand Down
2 changes: 0 additions & 2 deletions shaders/shaderTools.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,3 @@ uniform bvec4 filledData; // filledData[0] : true if position,
uniform sampler2D textureUnitDiffuse; // 0
uniform sampler2D textureUnitSpecular; // 1
uniform sampler2D textureUnitNormal; // 2


25 changes: 15 additions & 10 deletions src/Game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,18 +84,23 @@ void Game::start() { // init level configuration
m_player.setPosition(Vector3f(37,.5,10));

// Shader
GLuint shaderId = loadProgram("../shaders/lightingShader.glsl");
//m_pScene->setDefaultShaderID();
// loadTexture("../res/textures/image1.ppm");
// glUniform1i(glGetUniformLocation(shaderId, "textureUnit0"), 0);

vector<string> files;
files.push_back("../shaders/shaderTools.glsl");
files.push_back("../shaders/lightingShader.glsl");
GLuint shaderId = loadProgram(files);
files.pop_back();
//m_pScene->setDefaultShaderID(shaderId);
glUseProgram(shaderId);
GLfloat ambient[] = {1., 1., 1., 1.,};
GLfloat diffuse[] = {1., 1., 1., 1.,};
GLfloat specular[] = {1., 1., 1., 1.,};
GLfloat ka=0.01, kd=1.0, ks=2.0, shininess=5.0;
setMaterialInShader(shaderId, ambient, diffuse, specular, ka, kd, ks, shininess);

// prepare level using xml.
// build objects from xml
// add 'em to the scene
// ... like that

// prepare level using xml for building objects
loadLevel();

// add 'em to the scene
for(list<Obj*>::iterator i = m_lObjects.begin(); i != m_lObjects.end(); ++i) {
buildObjectGeometryFromOBJ((*i)->object, (*i)->path.c_str(), false, false, (*i)->builder);
m_pScene->addObjectToDraw((*i)->object.id);
Expand Down

0 comments on commit 9b06bbf

Please sign in to comment.