0

can someone please direct me to a link where I would be able to then solve such a question, seeing as this is an exam question I would like to attempt it first before asking for a solution.

Consider a triangular face of three vertices A(0,2,-1), B(1,0,1) and the origin O, and the normal vectors at the vertices are nA=(0,1,0), nB=(1,0,0) and nO=(0,0,1), respectively. The incident light is white and directional in direction of L=(1,2,2) and the intensity is 1, the background ambient light intensity is 0.1, and the diffuse reflection coefficients for (red, green, blue) are (0.6,0.7,0.8). No specular light contribution needs to be considered..

a) Find the (red, green, blue) intensity values in the face using flat shading at the centre of the face.

Thanks

  • 1
    Find the interpolated normal at the centre, compute the lambert (cosine) for the diffuse colour, add the ambient to get the result. – BeyelerStudios Jun 03 '16 at 23:19
  • Could you please provide me a link to how I would go about this – user6227505 Jun 03 '16 at 23:36
  • @user6227505 do not ask for a link (off site resources request is off topic here) You stated it is for exam and you do not want solution but instead a tutorial on how to approach this ... that is completely fine here for such easy task that can fit into single answer. You should remove/reformulate the link request to prevent close votes ... – Spektre Jun 04 '16 at 10:16

1 Answers1

1

BeyelerStudios comment tells everything you need to know. But I feel you are complete rookie in the field so here some more info:

  1. definitions

    Lets have triangle face defined by its 3 vertexes (v0,v1,v2) and normals (n0,n1,n2). Let the light source be directional with to light vector light. The light has ambient and directional parts with (r,g,b) colors: col_dir=(1.0,1.0,1.0) and col_amb=(0.1,0.1,0.1). The reflectance of the surface is col_face=(0.6,0.7,0.8). You want to get the pixel color for center point of triangle.

  2. compute normal at the the point of interest

    To map arbitrary point of interest you can use barycentric coordinates (as you are computing this on paper it is better in such case).

    triangle face

    But in your case the point is center so the normal is just average of the 3 normals:

    n=(n0+n1+n2)/3.0
    

    If I remember correctly In case of arbitrary point given in barycentric coordinates (u,v,w=1-u-v) it would be like this:

    n=u*n0 + v*n1 + w*n2 
    
  3. compute cos(angle) between normal and to light vector

    That is easy use dot product for this (while both vectors are unit in size ... normalized):

    cos(angle) = (n.x*light.x)+(n.y*light.y)+(n.z*light.z)
    

    If your vectors are not normalized you need to divide the result by their size.

    cos(angle) = ( (n.x*light.x)+(n.y*light.y)+(n.z*light.z) ) / (|n|*|light|)
    
  4. compute the color

    That is also easy:

    color = col_face * ( col_dir*cos(ang) + col_amb )
    

    Do not forget to handle negative cos(ang). The behavior depends on your implementation. sometimes is used max(0.0,cos(ang)) other times |cos(ang)|.

[Notes]

If you are interested how rendering engines handle the interpolations see

Community
  • 1
  • 1
Spektre
  • 49,595
  • 11
  • 110
  • 380
  • Actually, the _real_ rendering engines - the ones using hardware - do in fact use barycentric coordinates for interpolation. – Quinchilion Jun 04 '16 at 11:48
  • 1
    @Quinchilion I do not think so because each low level rasterizer implementation I saw along the years use circumference 2 buffer interpolation (separation of axises). Barycentric coordinate system limits rasterizers to triangle primitives and adding overhead. But if you know of any real HW implementation actually using it I would like to know about it ... – Spektre Jun 04 '16 at 13:35
  • I'm talking about GPUs here. The reasons behind it are explained [here](https://fgiesen.wordpress.com/2011/07/06/a-trip-through-the-graphics-pipeline-2011-part-6/) better than I ever could. – Quinchilion Jun 04 '16 at 13:44
  • Too late to edit... I realized that part only talks about rasterization, though that alone hints that barycentric coordinates are used. He talks more about interpolation in [the next part](https://fgiesen.wordpress.com/2011/07/08/a-trip-through-the-graphics-pipeline-2011-part-7/). – Quinchilion Jun 04 '16 at 13:53
  • In summary, the rasterizers in GPUs are already limited to triangles only and using barycentric coordinates is faster if you need perspective correct interpolation of more than a few values. – Quinchilion Jun 04 '16 at 14:06
  • @Spektre How did you get the values for u and v? – TheRapture87 Jun 05 '16 at 21:07
  • @Aceboy1993 the image was fast painted in MSPaint and I made a mistake which I spotted after posting it. Anyway for this case the coordinate system is not important so I did not repair it and added the statement that is not barycentric instead. To avoid confusion I repaired the image now (into barycentric)... – Spektre Jun 06 '16 at 06:57
  • @Spektre Thanks. Also out of curiosity, how would this differ from Phong shading once you have found it for flat shading? – TheRapture87 Jun 07 '16 at 13:44
  • @Aceboy1993 **Flat shading** computes one color per whole face. **Gourard shading** computes one color per vertex and interpolate the surface between them and **Phong shading** compute the color on per pixel basis. Flat is fastest Phong is nicest – Spektre Jun 07 '16 at 15:08
  • @Spektre Ok, so if we were to do Gourard shading would we compute the intensity at each point (based on the calculations you provided in your answer) then interpolate the surface? – TheRapture87 Jun 07 '16 at 15:28