Terrain not lighting correctly

Started by
14 comments, last by StoneMask 11 years, 6 months ago
Thanks for the advice I will do that.
Advertisement
Going to take a wild guess as I cannot see much or download the zip on my phone lol. Anyway, its a solid colour, shouldn't it be blended with the terrain colour? Sampling the terrain texture and multiply with the final colour? Also not sure if its just weird naming but intensity is a constant value that's applied to the diffuse light n dot l calculation :S
Thanks for your input Daniel. I am not attempting to apply any textures at this point, just passing in white as the diffuse color and lighting the terrain based on a light direction. And I just followed the tutorial on Rastertek.com, he used the word intensity so I did as well, that's all I know about the word choice.
Well I have made some discoveries using the PIX tool. The value of every normal is (0, 0, -1) going into and out of the vertex shader. As a sanity check I ran PIX with the executable from the tutorial and the normals going into the vertex shader are all different (e.g (-0.050, 0.999, 0.0) ). I definitely have something wrong with normals before they even get passed into the graphics card.
Okay I solved it, it was just a simple typo.

Just for the record, when I was calculating the normals I had this line:

normals[index].x = (vector1[1] * vector2[2]) - (vector1[2] * vector2[1]);
normals[index].y = (vector1[2] * vector2[0]) - (vector1[0] * vector2[2]);
normals[index].y = (vector1[0] * vector2[1]) - (vector1[1] * vector2[0]);


It should be:

normals[index].x = (vector1[1] * vector2[2]) - (vector1[2] * vector2[1]);
normals[index].y = (vector1[2] * vector2[0]) - (vector1[0] * vector2[2]);
normals[index].z = (vector1[0] * vector2[1]) - (vector1[1] * vector2[0]);


It's funny how small typos can make you lose days of coding time. I guess that's the joys of programming!
Thanks to those who tried to help me anyway :)
They look identical to me? What was the error?

Oh, .y, right. I gotcha'.

This topic is closed to new replies.

Advertisement