Could someone explain Gouraud shading to me? I can go ahead and Google "gouraud shading", but it doesn't make much sense to me. I have 3 vertices with an (x, y) position and an int[r,g,b] color. I want to linearly interpolate (not sure what this means) the colors of the vertices to shade in the triangle. What is the logic for doing so?
Asked
Active
Viewed 718 times
0
-
If you want the authentic experience of learning about Gouraud shading, you could read the "3D shading" section of the [PC-GPE](http://bespin.org/~qz/pc-gpe/)! – Blorgbeard Feb 25 '14 at 01:10
-
1This is a kind of broad question. The format of Stack Overflow doesn't lend itself to explaining large concepts in detail. You should look up [linear interpolation](http://en.wikipedia.org/wiki/Linear_interpolation) and try implementing it between 2 colors. If you have trouble doing that, ask specific questions (in a new question) about what you're having trouble with and post some code that you think should be working but isn't. – user1118321 Feb 25 '14 at 02:17
1 Answers
0
You will perform a bi-linear interpolation.
Scan the triangle from top to bottom, following the rows of pixels. Every row will intersect the triangle twice, along two distinct edges.
You will first perform two linear interpolations along these edges, computing a mixture of the RGB components at the vertices, weighted with the distances to these (weight Db/(Da+Db)
for color a
and Da/(Da+Db)
for color b
).
Then you will scan the pixels between the intersections, performing another linear interpolation between the two colors you just computed.
This way you will fill the triangle with a smooth gradient, in a way that will make it continuous with neighboring triangles, if any.