View direction for specular calculation

Hi, I just read through chapters 10 and 11 and in the PBR.metal shader the view direction is calculated as
float3 viewDirection = normalize(params.cameraPosition);

Seems to me like this will only be correct if the pixel’s worldPosition is at the origin, which given that most examples are just rendering models at the origin, is a working approximation, but if the model was moved wouldn’t this be incorrect?

Looking at later sample code it looks like IBL.metal calculates it as
float3 viewDirection = - params.cameraPosition;

Which is what I would assume is correct (but inverted?)

Shouldn’t PBR.metal also be calculating the viewDirection in a similar way, i.e. as the vector from the worldPosition to the cameraPosition, not just the origin to the cameraPosition, or have I missed something?

Also I just want to say I love the book. :smiley:

Hi @jonmhob - what a great first contribution - thank you! Yes, I think you are right.

float3 viewDirection = normalize(params.cameraPosition -;

I’m glad you’re enjoying the book :smiley: .

(I’m sorry about the delay in answering - I’ve been :tent: without internet for a week :sweat_smile:)