Farel13

07-31-2013, 12:45 PM

Allright, I've got a problem. From what I can gather all the xml object that I use have a "normal" parameter. This is used whenever an object is scaled, this way the lightning on the object is appropriate and not. It was done properly in this tutorial:

http://arcsynthesis.org/gltut/Illumination/Tut09%20Normal%20Transformation.html

Here's how I render in my .cpp:

//Back Wall_4

{

glutil::PushStack push(modelMatrix);

glUseProgram(UniformColorTint.theProgram);

modelMatrix.Scale(glm::vec3(10.0f, 1.0f, g_fParthenonBaseHeight));

modelMatrix.Translate(glm::vec3(-1.2925f, 14.5f, -12.15f ));

glUniformMatrix4fv(UniformColorTint.modelToWorldMa trixUnif, 1, GL_FALSE, glm::value_ptr(modelMatrix.Top()));

glm::mat3 normMatrix(modelMatrix.Top());

normMatrix = glm::transpose(glm::inverse(normMatrix));

glUniformMatrix4fv(UniformColorTint.modelToWorldMa trixUnif, 1, GL_FALSE, glm::value_ptr(modelMatrix.Top()));

glUniform4f(UniformColorTint.baseColorUnif, 0.5f, 0.9f, 0.9f, 0.9f);

glm::mat4 invTransform = glm::inverse(modelMatrix.Top());

glm::vec4 lightPosModelSpace = invTransform * worldLightPos;

glUniform3fv(UniformColorTint.modelSpaceLightPosUn if, 1, glm::value_ptr(lightPosModelSpace));

g_pCubeMesh->Render();

glUseProgram(0);

}

And here's my vertex shader:

#version 330

layout(location = 0) in vec4 position;

layout(location = 1) in vec4 color;

layout(location = 2) in vec3 normal;

smooth out vec4 interpColor;

out vec3 vertexNormal;

out vec3 modelSpacePosition;

uniform mat4 worldToCameraMatrix;

uniform mat4 modelToWorldMatrix;

uniform mat3 normalModelToCameraMatrix;

uniform vec3 dirToLight;

uniform vec4 lightIntensity;

uniform vec4 ambientIntensity;

uniform vec4 baseColor;

uniform mat4 cameraToClipMatrix;

void main()

{

vertexNormal = normal;

vec3 normCamSpace = normalize(normalModelToCameraMatrix * vertexNormal);

//vec3 dirToLight = normalize(dirToLight);

float cosAngIncidence = dot(normCamSpace, dirToLight);

cosAngIncidence = clamp(cosAngIncidence, 0, 1);

modelSpacePosition.x = position.x;

modelSpacePosition.y = position.y;

modelSpacePosition.z = position.z;

vec4 temp = modelToWorldMatrix * position;

temp = worldToCameraMatrix * temp;

gl_Position = cameraToClipMatrix * temp;

interpColor = ((lightIntensity * cosAngIncidence) + (ambientIntensity)) * baseColor;

}

My version doesn't work at all, I tried some minor edits, but nothing fixes it. The normals don't seem to exist. What's the problem?

http://arcsynthesis.org/gltut/Illumination/Tut09%20Normal%20Transformation.html

Here's how I render in my .cpp:

//Back Wall_4

{

glutil::PushStack push(modelMatrix);

glUseProgram(UniformColorTint.theProgram);

modelMatrix.Scale(glm::vec3(10.0f, 1.0f, g_fParthenonBaseHeight));

modelMatrix.Translate(glm::vec3(-1.2925f, 14.5f, -12.15f ));

glUniformMatrix4fv(UniformColorTint.modelToWorldMa trixUnif, 1, GL_FALSE, glm::value_ptr(modelMatrix.Top()));

glm::mat3 normMatrix(modelMatrix.Top());

normMatrix = glm::transpose(glm::inverse(normMatrix));

glUniformMatrix4fv(UniformColorTint.modelToWorldMa trixUnif, 1, GL_FALSE, glm::value_ptr(modelMatrix.Top()));

glUniform4f(UniformColorTint.baseColorUnif, 0.5f, 0.9f, 0.9f, 0.9f);

glm::mat4 invTransform = glm::inverse(modelMatrix.Top());

glm::vec4 lightPosModelSpace = invTransform * worldLightPos;

glUniform3fv(UniformColorTint.modelSpaceLightPosUn if, 1, glm::value_ptr(lightPosModelSpace));

g_pCubeMesh->Render();

glUseProgram(0);

}

And here's my vertex shader:

#version 330

layout(location = 0) in vec4 position;

layout(location = 1) in vec4 color;

layout(location = 2) in vec3 normal;

smooth out vec4 interpColor;

out vec3 vertexNormal;

out vec3 modelSpacePosition;

uniform mat4 worldToCameraMatrix;

uniform mat4 modelToWorldMatrix;

uniform mat3 normalModelToCameraMatrix;

uniform vec3 dirToLight;

uniform vec4 lightIntensity;

uniform vec4 ambientIntensity;

uniform vec4 baseColor;

uniform mat4 cameraToClipMatrix;

void main()

{

vertexNormal = normal;

vec3 normCamSpace = normalize(normalModelToCameraMatrix * vertexNormal);

//vec3 dirToLight = normalize(dirToLight);

float cosAngIncidence = dot(normCamSpace, dirToLight);

cosAngIncidence = clamp(cosAngIncidence, 0, 1);

modelSpacePosition.x = position.x;

modelSpacePosition.y = position.y;

modelSpacePosition.z = position.z;

vec4 temp = modelToWorldMatrix * position;

temp = worldToCameraMatrix * temp;

gl_Position = cameraToClipMatrix * temp;

interpColor = ((lightIntensity * cosAngIncidence) + (ambientIntensity)) * baseColor;

}

My version doesn't work at all, I tried some minor edits, but nothing fixes it. The normals don't seem to exist. What's the problem?