<blockquote>
  <p>(Is gouraud shading even supposed to be perspective correct?)</p>
</blockquote>

<p>Originally, it wouldn't have been perspective correct, but on (hardware) systems these days it will be. FWIW Dreamcast had perspective correct Gouraud shading because, once you are doing perspective correct texturing, it is relatively little additional cost to do Gouraud "correctly".</p>

<blockquote>
  <p>I have flat shading working and I have perspective correct texture mapping working. Is the way your raster Gouraud shading much different from the perspective correct texture mapping?</p>
</blockquote>

<p>I'm assuming that you've started with homogeneous 'world space' vertices, i.e. something like, </p>

<p>$[x,y,z, 1, u,v, R,G,B]$,</p>

<p>applied a projection matrix to get</p>

<p>$[X_p, Y_p, Z_p, 1, u, v, R, G, B, w]$,</p>

<p>and then, after clipping, divided through by w to obtain screen coordinates</p>

<p>$[X_p/w, Y_p/w, Z_p/w, 1/w, u/w, v/w, R/w,... ]$.  </p>

<p>For convenience, let's rename $u/w$ and $v/w$ as $u'$ &amp; $v'$, $1/w$ as $w'$, $R/w$ as $R'$ etc.</p>

<p>To do perspective correct texturing I <em>assume</em> you are linearly interpolating, per pixel, the $u'$, $v'$, and $w'$ values, computing the reciprocal of the interpolated  $w'$ and multiplying that by $u'$ and $v'$ to obtain the per-pixel U &amp; V coordinates.</p>

<p>To do perspective correct Gouraud, simply use the same approach with the interpolated $R'$ , $G'$ and $B'$ values. The most expensive part is typically the division (i.e. reciprocal) but that can be shared with the texturing.</p>

CC BY-SA 3.0
2017-09-06T13:21:14.370Z
2017-09-12T07:38:11.637Z
2017-09-12T07:38:11.637Z
Simon F
<p>What's the algorithm for doing so?</p>

<p>I have flat shading working and I have perspective correct texture mapping working.  Is the way your raster Gouraud shading much different from the perspective correct texture mapping?  (Is gouraud shading even supposed to be perspective correct?)</p>

<p>It is my understanding that you interpolate the lighting color/value down the edges, then interpolate across each scanline.  However,  I think I'm stuck on how to properly divide by Z for each pixel to get the correct light/color value for each pixel.</p>

<p>Any algorithm/article/tutorial would be of great help as I've searched everywhere but can only find high level, abstract descriptions of it.</p>

<p>Thanks in advance!</p>

<lighting><normal-mapping>
How do you implement perspective correct Gouraud shading across a triangle?
MarkInTheDark
# How do you implement perspective correct Gouraud shading across a triangle?

(Asked by: username_0 on 2017-09-06)

What's the algorithm for doing so?

I have flat shading working and I have perspective correct texture mapping working. Is the way your raster Gouraud shading much different from the perspective correct texture mapping? (Is gouraud shading even supposed to be perspective correct?)

It is my understanding that you interpolate the lighting color/value down the edges, then interpolate across each scanline. However, I think I'm stuck on how to properly divide by Z for each pixel to get the correct light/color value for each pixel.

Any algorithm/article/tutorial would be of great help as I've searched everywhere but can only find high level, abstract descriptions of it.

Thanks in advance!

**Tags:** lighting, normal-mapping


---

## 1 answers

### Answer by username_1 on 2017-09-06. Score: 1 | Accepted answer

> (Is gouraud shading even supposed to be perspective correct?)

Originally, it wouldn't have been perspective correct, but on (hardware) systems these days it will be. FWIW Dreamcast had perspective correct Gouraud shading because, once you are doing perspective correct texturing, it is relatively little additional cost to do Gouraud "correctly".

> I have flat shading working and I have perspective correct texture mapping working. Is the way your raster Gouraud shading much different from the perspective correct texture mapping?

I'm assuming that you've started with homogeneous 'world space' vertices, i.e. something like,

$[x,y,z, 1, u,v, R,G,B]$,

applied a projection matrix to get

$[X\_p, Y\_p, Z\_p, 1, u, v, R, G, B, w]$,

and then, after clipping, divided through by w to obtain screen coordinates

$[X\_p/w, Y\_p/w, Z\_p/w, 1/w, u/w, v/w, R/w,... ]$.

For convenience, let's rename $u/w$ and $v/w$ as $u'$ & $v'$, $1/w$ as $w'$, $R/w$ as $R'$ etc.

To do perspective correct texturing I *assume* you are linearly interpolating, per pixel, the $u'$, $v'$, and $w'$ values, computing the reciprocal of the interpolated $w'$ and multiplying that by $u'$ and $v'$ to obtain the per-pixel U & V coordinates.

To do perspective correct Gouraud, simply use the same approach with the interpolated $R'$ , $G'$ and $B'$ values. The most expensive part is typically the division (i.e. reciprocal) but that can be shared with the texturing.


---

