How to use reflections with an Arcball camera?

im following chapter 22 on reflections and changing the camera PlayerCamera() to ArcballCamera(), the reflections stop working.

how can I fix it? should I use .target instead of position? hmmm

thank you

Hi @masaldana2

The view matrix is calculated differently for the arcball than the player camera. You’d probably want to create a camera to suit your own requirements, rather than use PlayerCamera and ArcballCamera.

I was able to get reflections working by changing the code in WaterRenderPass:

var reflectionCamera = PlayerCamera()
reflectionCamera.rotation =
reflectionCamera.position =
let refractionViewMatrix = reflectionCamera.viewMatrix
reflectionCamera.rotation.x *= -1
let position = ( - water.position.y) * 2
reflectionCamera.position.y -= position

var uniforms = uniforms
uniforms.viewMatrix = reflectionCamera.viewMatrix

This just creates a new PlayerCamera using the ArcballCamera’s position and rotation, simply so that it uses the view matrix expected by the code. I’m sure this can be better optimized :smiley:

1 Like

that’s great!! thank you so much

I have a noob question :slight_smile:
why we use Euler instead of using quaternions?
some tutorials have quaternions some dont :slight_smile:

I’m trying to use quaternion for the player PlayerCamera

this was my try at using quaternions by converting quaternion to Euler and using your solution

Well done :clap: - I think it actually makes more sense to use quaternions where you can.

In the book, we’re teaching conventional 3d graphics, which uses Euler for rotations, and we only introduce quaternions really late in the book. It’s my belief that Euler rotation is initially easier to understand because you can look at a matrix and see the vectors. A quaternion is made up of apparently weird numbers.

Euler rotations have historically been preferred because GPUs natively support matrices. You can use quaternions on the CPU and convert to Euler when moving to the GPU, but that introduces extra overhead and complexity.

Math isn’t my strong point, but I think geometric algebra is becoming more common, being espoused by people like Eric Lengyel. Geometric Algebra uses Rotors to represent rotations.

You might enjoy this article and video :slight_smile: :
Let's remove Quaternions from every 3D Engine (An Interactive Introduction to Rotors from Geometric Algebra) - Marc ten Bosch

1 Like

Thank you so much for you guidance!
Metal is a journey :slight_smile:

1 Like