### Author Topic: EDAF80 - Computer Graphics 2018 HT1  (Read 20725 times)

#### Pierre Moreau

• Full Member
•   • Posts: 217 ##### Re: EDAF80 - Computer Graphics 2018 HT1
« Reply #120 on: 2018-10-29 20:08:50 »
In the lecture slides they are presented as " k_d represent the fraction of incoming diffuse light L_d that is reflected". Here it seems like k_d is a scalar, but later in the slides, k_d is presented as a color vector.
The amount of light reflected will not be uniform across all colour channels in most cases, which is why you usually have it as a colour vector.

And if L_i_d is the intensity for light i, why are there different intensities, i.e. L_i_a, L_i_d and L_i_s for ambient, diffuse and specular. Does this have any physical interpretation? Are they scalar or vectors?
Unless your light emits uniformly across all channels, you will need to have your light intensities as vectors as well; for example, you could have a red light lighting your scene and your green object should appear black: if it looks green to you with a white light, that means only the green wavelengths are reflected and all the other ones are absorbed, so if you only have a red wavelength incoming from the light, nothing will get reflected. To handle that situation, you really need a vector to have different intensities for each colour channel.

As for having different intensities for the different terms, I think it is only there for more artistic control than anything else: in the rendering equation, you only have one (spectral) intensity value that multiplies the whole BRDF.

#### tfy14esa

• Newbie
• • Posts: 11 ##### Re: EDAF80 - Computer Graphics 2018 HT1
« Reply #121 on: 2018-10-29 23:31:55 »
So I have a question about the edge equations for the rasterizer. Consider the picture attached.

If I understand things correctly, all edge equations are done in clip space (or NDC, but this doesn't really matter for the purposes of the discussion). This means that all triangles are viewed from the camera projected on a 2D plane with a fixed distance along the z-axis. This is confirmed by the picture where the triangle vertices both have the same z-value of 1.

Now, in the picture attached, assume that the point not named is called p_2 = (1,0,1). Taking the cross product p_1 x p_2 = (1, 1, -1) which has a direction pointing along the z-direction, which I find odd. Aren't we purely looking for the normals to the triangle sides in the clip space? Furthermore, it seems like you will get the correct sign of the normal (pointing outwards from the triangle) if you take each cross product in a counter clockwise fashion i.e. p_0 x p_1, p_1 x p_2 and p_2 x p_0. This has not been clarified in detail, but it is important. Maybe you can elaborate more on this ordering?

Thanks!
Erik

#### Pierre Moreau

• Full Member
•   • Posts: 217 ##### Re: EDAF80 - Computer Graphics 2018 HT1
« Reply #122 on: 2018-10-30 13:13:45 »
If I understand things correctly, all edge equations are done in clip space (or NDC, but this doesn't really matter for the purposes of the discussion). This means that all triangles are viewed from the camera projected on a 2D plane with a fixed distance along the z-axis. This is confirmed by the picture where the triangle vertices both have the same z-value of 1.
If all triangles are projected on a 2D plane, you can't be in clip space or NDC since those still define a volume, but in screen-space instead. And edge equations are indeed computed in screen-space as you want to process flat triangles.

Now, in the picture attached, assume that the point not named is called p_2 = (1,0,1). Taking the cross product p_1 x p_2 = (1, 1, -1) which has a direction pointing along the z-direction, which I find odd. Aren't we purely looking for the normals to the triangle sides in the clip space?
If you look at e(x,y) = dot(n, (x,y,1)), you could re-write it as e(x,y) = dot(n.xy, (x,y)) + n.z. The direction of the normal is really only the first two components, x and y, with z being used as an offset.
If you look at the point c_0 = (0.5,0.5,1) located right on the segment p1p2, e(0.5,0.5) = dot((1,1), (0.5,0.5)) + -1 = 1 + -1 = 0, as expected.

Furthermore, it seems like you will get the correct sign of the normal (pointing outwards from the triangle) if you take each cross product in a counter clockwise fashion i.e. p_0 x p_1, p_1 x p_2 and p_2 x p_0. This has not been clarified in detail, but it is important. Maybe you can elaborate more on this ordering?
You are taking the points in clockwise order there, not counter-clockwise.
I would recommend you read section 2.1 (subsections 2.1.1 and later not included) of those notes that are used in the EDAN35 course: it explains in more details how it works; note that it defines the points in counter-clockwise order, and as such a point is inside if the edge equation is positive.
When they define e_0(x, y) = −(p^2_y − p^1_y)(x − p^1_x) + (p^2_x − p^1_x)(y − p^1_y) it actually comes from e_0(x, y) = dot(n.xy, (x, y) - p^1) where n = (p^1_x, p^1_y, 1) x (p^2_x, p^2_y, 1)

#### tfy14esa

• Newbie
• • Posts: 11 ##### Re: EDAF80 - Computer Graphics 2018 HT1
« Reply #123 on: 2018-10-30 17:22:50 »
Thanks, I think it makes sense now.

Another question for the vertex shader. We always have to specify the vertex position in clip space via the gl_position variable. We also know from one of the exam solutions that backface culling is done in the rasterizer. I wonder why we do not have to specify these attributes i.e. viewing direction and normal to be forwarded to the gpu like in the case with the transformed vertices. It is true that we don't need to transform the viewing vector and normal since they are in world space so are they just forwarded automatically to the gpu (rasterizer)?

#### Pierre Moreau

• Full Member
•   • Posts: 217 ##### Re: EDAF80 - Computer Graphics 2018 HT1
« Reply #124 on: 2018-10-30 17:43:23 »
Another question for the vertex shader. We always have to specify the vertex position in clip space via the gl_position variable. We also know from one of the exam solutions that backface culling is done in the rasterizer. I wonder why we do not have to specify these attributes i.e. viewing direction and normal to be forwarded to the gpu like in the case with the transformed vertices. It is true that we don't need to transform the viewing vector and normal since they are in world space so are they just forwarded automatically to the gpu (rasterizer)?
The rasteriser computes the geometrical normal for each triangle by doing (p1 - p0) x (p2 - p0) where p0 through p2 are the vertices in clip-space that you emitted in your vertex shader. This is where it is important to use the proper winding when generating your triangles: if it is counter-clockwise, then n.z > 0 would mean a front-facing triangle, whereas if it is clockwise, then it is n.z < 0 which means a front-facing triangle.

#### tfy14esa

• Newbie
• • Posts: 11 ##### Re: EDAF80 - Computer Graphics 2018 HT1
« Reply #125 on: 2018-10-31 00:24:32 »
Thanks! Normally though, I guess (correct me if I'm wrong) one of the object's attribute are the normals and they are stored in the application code (c++) and could be forwarded to the rasterizer without calculating the normals using the cross-product you mention? Just a thought of mine.

#### Pierre Moreau

• Full Member
•   • Posts: 217 ##### Re: EDAF80 - Computer Graphics 2018 HT1
« Reply #126 on: 2018-10-31 09:40:46 »
Thanks! Normally though, I guess (correct me if I'm wrong) one of the object's attribute are the normals and they are stored in the application code (c++) and could be forwarded to the rasterizer without calculating the normals using the cross-product you mention? Just a thought of mine.
The normal is indeed one of the attributes you usually send, along with the vertices and other attributes, to the vertex shader. The issue with those attributes, is that they are per-vertex whereas the rasteriser will want something for the whole triangle. You could (arbitrarily) decide to interpolate between all three normals (this will have to be done by the hardware, as you only have access to one normal in your vertex shader) to compute the normal at the centre of the triangle. This will work if the resulting normal is perpendicular to the triangle, but what if (due to normal mapping, or to the curvature of the object) this is not the case: you might end up with the triangle disappearing too early, or too late in which case you will see its back-face (see the attached figure).

#### Pierre Moreau

• Full Member
•   • Posts: 217 ##### Re: EDAF80 - Computer Graphics 2018 HT1
« Reply #127 on: 2018-11-20 09:54:20 »
Good morning everyone,

All the exams have been marked and the grades can now be seen on the department's board on the 2nd floor of the E-building by the staircase near the E:B lecture hall. You can probably see them in LADOK as well.
You will be able to come and look at your exams on Thursday the 22nd between 16:00 and 17:00 in my office (same staircase as above, but on the 4th floor; office: E:4126). Mike will also be there (online) to answer your questions.

Have a nice day!
Pierre

#### MikeD

• Full Member
•   • Posts: 213 ##### Re: EDAF80 - Computer Graphics 2018 HT1
« Reply #128 on: 2018-11-30 17:21:55 »

Re-exam is 2019-04-27, Saturday, 08-13, in MA10H.