Immersive Portals

Immersive Portals

5M Downloads

Probing the Compatibility with Sodium

qouteall opened this issue ยท 4 comments

commented

https://github.com/qouteall/ImmersivePortalsMod/wiki/Implementation-Details

https://github.com/jellysquid3/sodium-fabric

How to solve the Mixin Conflicts

Immersive Portals will have a soft dependency of Sodium and make the conflict injections optional. Lithium should provide events for IP to subscribe.
If Sodium plans to port to Forge then Fabric's event cannot be used. It can be replaced by a simple static function object field which is fast.

Client Chunk Manager

IP and Sodium both replace the client chunk manager and do mostly the same thing: turn the array into a map.
But Sodium's client chunk manager rejects the chunk data of faraway chunk data. So IP's chunk manager should remain. And IP call listener.onChunkAdded() etc.

Sodium's ChunkRenderManager

It assumes that only one world is loaded on the client. This needs to be changed.
Sodium also uses a map to store built chunk meshes so IP's MyBuiltChunkStorage is obsolete.

Manage Render States

  • Set ChunkRenderManager.dirty when rendering portal
  • Disable rough chunk culling when rendering portal because rough chunk culling is incorrect between camera and portal plane.
  • Disable translucent sort when rendering portal
  • Switch ChunkRenderManager#renderLists when rendering portal

Front Culling

glClipPlane does not work with OptiFine shaders so it probably won't work with Sodium which uses shaders.
Sodium should provide hooks for IP to supply a geometry shader to do front culling and load uniforms about the culling plane.

Schedule Chunk Rebuild when Rendering Portal

Rebuild fewer or no remote sections when rendering portal to avoid lag spike

commented

IP has recursive portal rendering so it's necessary to isolate the informations that's only used in one rendering and reseted after the world rendering has done. It includes:

ChunkRenderManager.iterationQueue
ChunkRenderManager.chunkRenderLists
ChunkRenderManager.tickableChunks
ChunkRenderManager.visibleBlockEntities

These probably doesn't need to be switched

SodiumWorldRenderer.lastCameraX lastCameraY...
SodiumWorldRenderer.frustum

IP renders the portal after solid mesh rendering and before translucent block rendering. When rendering a portal, it will firstly store these per-render information and then reset them, do recursive rendering, and then restore them.
Making them into one object will make the switch easier. @jellysquid3 what's your opinion

commented

About the front culling, one very severe issue manifests. Sodium builds the chunk mesh in quads. However opengl does not allow geometry shader to accept quad input. Which means that the culling cannot be done in geometry shader unless sodium change the chunk mesh building code. The culling can still be done in fragment shader but it will affect performance.
The possible solution is to create two sets of shaders, one without culling and one with culling. Use the one with culling when rendering portal.
About
https://www.khronos.org/registry/OpenGL/extensions/EXT/EXT_geometry_shader4.txt

  1. Geometry shaders don't provide a QUADS or generic POLYGON input
    primitive type. In this extension, what happens if an application
    provides QUADS, QUAD_STRIP, or POLYGON primitives?

    RESOLVED: Not all vendors supporting this extension were able to accept
    quads and polygon primitives as input, so such functionality was not
    provided in this extension. This extension requires that primitives
    provided to the GL must match the input primitive type of the active
    geometry shader (if any). QUADS, QUAD_STRIP, and POLYGON primitives are
    considered not to match any input primitive type, so an
    INVALID_OPERATION error will result.

    The NV_geometry_shader4 extension (built on top of this one) allows
    applications to provide quads or general polygon primitives to a
    geometry shader with an input primitive type of TRIANGLES. Such
    primitives are decomposed into triangles, and a geometry shader is run
    on each triangle independently.

commented

The Event Hooks that Sodium Needs

  • Frustum culling
  • Binding geometry shaders for block rendering
  • Should sort transparency
  • Should disable rough chunk culling
commented

Found out that vertex shader can also use gl_ClipDistance. So maintaining another set of shaders is not needed.