Which coordinate space to do lighting in?

Started by
9 comments, last by alexpanter 2 years ago

Hi,

Which coordinate space would be a good way to do lighting calculations in?

Different graphics techniques have different requirements, like SSAO which is practical with view space calculations. Other algorithms such as normal mapping is great in tangent space.

For me personally, world space seems the most intuitive and logical.

My goal is to create a deferred renderer (normal, albedo, roughness, metalness, AO, emissive).

A secondary goal is to avoid performing basis change transformations for every pixel all through the pipeline, if possible.

I can accept that there might be no “correct” answer, so a discussion on benefits/drawbacks would also be really great.

Thanks!

Advertisement

World space is fine, I would start with that. If you ever start to work with very large coordinates you can run into precision issues, but there are ways to fix those by offsetting world coordinates so that they're relative to the camera.

Not sure about real time rendering, but I've found tangent space to be quite comfortable in raytracing.

MJP said:

World space is fine, I would start with that. If you ever start to work with very large coordinates you can run into precision issues, but there are ways to fix those by offsetting world coordinates so that they're relative to the camera.

Thank you - that's good news for me. Do you any particular situations where you would prefer view space instead?

cignox1 said:

Not sure about real time rendering, but I've found tangent space to be quite comfortable in raytracing.

Not sure they are mutually exclusive, as many modern graphics techniques involve ray tracing or ray casting in real-time as well (screen-space reflections (SSR), water caustics, etc.). Especially as GPUs get better I think we will see much more of that stuff. But would you perhaps like to clarify why you would prefer tangent space, and perhaps any reasons why other coordinate spaces would be uncomfortable for your workflow?

I've been using view space mainly because I never go to world space on the GPU since I'm using very large coordinates and world space would cause everything to fail. Most examples from my books do use world space however so it's probably fine for most stuff.

Gnollrunner said:

I've been using view space mainly because I never go to world space on the GPU since I'm using very large coordinates and world space would cause everything to fail. Most examples from my books do use world space however so it's probably fine for most stuff.

Sounds cool! What are your books called? ? And for reference, what do you define as very large coordinates"? Is it open-world stuff, something smaller, or are we talking about simulating a solar system?

I've found it easier to work (understand/debug/etc) by having normals and rays all in tangent space. I don't know of any objective reason to prefer that, it's just what I've found easier to work with.

alexpanter said:

Sounds cool! What are your books called? ? And for reference, what do you define as very large coordinates"? Is it open-world stuff, something smaller, or are we talking about simulating a solar system?

I think perhaps I should have worded this better. I meant books that I own, not written. Frank Luna's DirectX books and also I have a lot of the old ShaderX books. As for my stuff you can check my very slow moving blog. The target application is a game with walkable full sized planets all the way up to solar systems and even larger. It's mostly procedural.

All the Kool Kids used to do it in clip space, because that ends up being the fewest overall transform math operations, which mattered when your transform pipeline was a 200 MHz MIPS CPU on an SGI in the 90's or something.

Personally, I really like world space. All your cube maps and other environmental factors Just Work. All the lights are in the same space, so no special handling needed. With modern shaders, this is totally fine, and not particularly more work for the GPU than most other spaces.

enum Bool { True, False, FileNotFound };

Thank you, everyone! I think I have my answer.

This topic is closed to new replies.

Advertisement