Gouraud?

BlitzPlus Forums/BlitzPlus Programming/Gouraud?

Fjodor(Posted 2004) [#1]
I'm having trouble figuring out how to code a descent
gouraud filler for my 3D engine, as I'm quite new to
programming. So I was hoping that maby someone here had
some tip or maby some code they could share?

If anyone can help it would be very apreciated :-)


soja(Posted 2004) [#2]
If you're implementing gouraud shading yourself, know that it's going to be quite slow, as it will be run in software (not accelerated by hardware).

I don't have any code, but basically you have to get the normals of each corner of your polygon (I'll assume triangle) and then interpolate the normal values of the pixels between them.

For example, let's say the normals of a certain triangle (corners) are 10 (point A), 100 (point B), 60 (point C), and the distance between A,B and also A,C are 4 pixels, and between B,C, 10 pixels. So for A,B you interpolate between 10 and 100 in 4 steps (step value = (100-10)/4) and so the resulting pixel normals would be 10, 32.5, 55, 77.5, 100. You do something simliar for the other sides, and then you have to do the same thing for every pixel inside the triangle. It's the same deal except you use the sides instead of the corners. Then once you have the interpolated normal value of each, you can use your shading routine. Of course, using Gouraud shading, you'll miss any specular highlights and stuff.

But the question that stands out to me is that if you're new to programming, why are you coding a 3D engine?