Delivering physically correct lighting computations (it is real!)

Talk about anything related to Unvanquished.
Post Reply
User avatar
illwieckz
Project Head
Posts: 761
Joined: Sat Aug 11, 2012 7:22 pm UTC
Location: France
Contact:

Delivering physically correct lighting computations (it is real!)

Post by illwieckz »

For 10 years I did research and spent time and effort to improve our lighting. We are close to finally achieve something I was pursuing since a long time…

We are close to get linear lighting being working.

This is something that required changes in two places:

  • In the map compiler, those changes were already implemented by Xonotic guys in q3map2.
  • In the game engine, this is what we are now close to merge in Dæmon.

I think we may follow this roadmap:

  1. We test, review and merge Dæmon#1687.
  2. Once Dæmon#1687 is merged, we publish a point release to distribute the feature to users as soon as possible, it would only ship the feature in the engine, the stock maps would not be re-released (to make it simple to do).
  3. I re-release NetRadiant and include an updated build menu enabling correct light computations, so mappers can start distribute maps using the new correct lighting computations, having people hosting those maps, knowing players have a compatible engine to display them.
  4. We prepare the 0.56.0 release and release it, including all stock maps being rebuilt with the correct lighting computations and maybe some other asset change (like including atcshd map and texture set as stock map, with new heightmaps, etc.).

I'm currently working on making a new NetRadiant release very soon, but it would be stupid to release a new NetRadiant right before releasing the feature in the Dæmon engine, that would require me to re-publish a new NetRadiant release right after the engine release…

So I'm OK to put the NetRadiant release on hold, waiting for the 0.55.5 point-release, but for that we need to merge that Dæmon#1687 pull request soon.

This comment is licensed under cc ​​by 4 and antecedent. The Crunch tool is awesome!

User avatar
killing time
Programmer
Posts: 177
Joined: Wed Jul 04, 2012 7:55 am UTC

Re: Delivering physically correct lighting computations (it is real!)

Post by killing time »

There is the issue that letting the map determine the color space for the entire rendering pipeline can mess up rendering of our game assets (i.e. players, buildables, weapons, and their effects). I don't think it's nice for a model to look totally different depending on which map is loaded. Last time we discussed sRGB, I found the example of the rifle smoke puff appearing much brighter than it should when in sRGB mode. Any multi-stage shaders, as well as dynamic lights would likely be affected. In any case it would be nice to merge some code soon so that we can more easily tested, but IMO it's not production ready if the game assets don't look consistent and good.

I still think it would be interesting to try the following algorithm to partially support mixing content designed for different color spaces:

  1. Render all opaque sRGB-unaware surfaces without doing sRGB-to-linear conversion on image textures. Dynamic lights would need to be adjusted to make sure the result is the same as if the surface were sRGB-aware.
  2. Run a screen-space shader to convert the color buffer from sRGB to linear space.
  3. Render all opaque sRGB-aware surfaces, with sRGB-to-linear conversion of image textures enabled.
  4. Render all translucent surfaces with sRGB-to-linear conversion of image textures enabled.
  5. cameraEffects shader converts color buffer to sRGB in preparation for 2d rendering.

Note that this means translucent sRGB-unaware surfaces would not be rendered correctly. In our goal state where all our game assets are sRGB-aware, this would mean that just the translucent surfaces in legacy maps have incorrect blending. But hey, transparent surfaces are FUBAR anyway, between being rendered in the wrong order and using wacked-out blending modes which don't play nicely with the floating point framebuffer. I think accepting potentially wrong blending for those would be superior to the alternatives of having to eternally maintain our game assets such that they look good in both color space pipelines, or accepting that they are blended way differently depending on the map. To be specific, multi-stage shaders and all dynamic lights would work differently depending on the map, if we let the map's color space determine how blending works for the entire pipeline.

We could implement a q3shader parameter to mark a shader as being sRGB-ready or not. But that would probably not be useful since it would only affect opaque shaders with multiple stages. Such shaders are common in legacy maps (e.g. lightmap stages which we don't manage to auto-collapse, or light styles), but probably don't occur hardly at all in our game assets. Probably we would just assume either that all game assets are ready or that all are unready.

For "turning on/off" sRGB-to-linear conversion for image texture reads, we would need to be able to register more than one instance of an image, since the conversion is effected by setting the GL image format. But this ability already exists with SHADER_2D / SHADER_3D_DYNAMIC / SHADER_3D_STATIC. In fact I believe that will need to be used even for a straight sRGB pipeline since we want linearization to occur for 3D rendering, but not 2D.

If we're too lazy to migrate the game assets at first, we could also consider the obverse of the algorithm described above:

  1. Render all opaque sRGB-aware surfaces, with sRGB-to-linear conversion of images enabled. Dynamic lights would need to be adjusted to make sure the result is the same as if the surface were sRGB-unaware.
  2. Run a screen-space shader to convert the color buffer from linear to sRGB space.
  3. Render all opaque sRGB-unaware surfaces, with sRGB-to-linear conversion of images disabled.
  4. Render all translucent surfaces, with sRGB-to-linear conversion of images disabled.
    In that case the translucent surfaces of new sRGB maps are what would have blending that does not work as it should.
Post Reply