Group Group Group Group Group Group Group Group Group

Chapter 5, cone direction

Hello! Thank you for this amazing book, really enjoying it so far!
I’ve got a question though about this line of fragment shader in Chapter 5:

float3 coneDirection = normalize(-light.coneDirection);

Why cone direction should be negated here? Aren’t both light and cone direction vectors originate from the same point? I guess it’s a silly question but I just can’t get my head around it.
Thanks!

It is confusing. Especially when we’re using position to calculate the direction.

Take a look at this picture, which I hope helps.

The light position (pink) is a positive direction. The cone direction is negative. To get them to point in the same direction, we have to negate one of them. Here I chose to negate the cone direction, but I could have negated the lightDirection instead, which probably would have been more “true”.

In that case, I’d have to negate the normal direction too, when calculating the diffuse intensity, which is also confusing! Consider the dot product result you want to achieve. Full intensity is where the dot product is 1.0. That’s when the two vectors point in the same direction. Intuitively, and in the chapter diagram, the direction vectors of the normal and the light direction point in different directions, which gives you a dot product of -1.0. However, to get full intensity of 1.0, you want the normal vector and the light direction vector pointing in the same direction.

I would suggest taking a look at the results in the shader debugger and drawing quick diagrams like the one I just did, to see what the directions actually are.

Once you can visualise the direction vectors, you can use whichever vector directions and dot products make most sense to you.

1 Like

Wow, thanks for this elaborated answer, it certainly helped a lot! Now I get it! Many thanks!

1 Like