RiazorMC


RiazorMC

🌌 MK8 PORTALS EXPLAINED 🌌

Since many people are interested in how the portal shader works, here is a short explanation:

The effect is based on a fragment shader that discards fragments by checking if the camera-to-fragment world vector intersects with a portal. The portal shape is defined by a 3D plane and, inside the plane local space, a 2D circle with a radius that is distorted by a seamless noise texture. Given the position of the camera, the shader calculates the index of the track in which it is located by checking if it is inside multiple bounding boxes (this is done in the vertex shader for performance reasons). If the camera-to-fragment vector intersects with the portal, the track index is incremented (or decremented in case it is a portal to the previus track). Finally, if the resulting track index is not equal to the track index of the material to be rendered, the fragment is discarded.

This means that the portal is not a model itself, but rather the track model is procedurally cut into the shape of the portal. The portal contour is drawn by changing the emissive color of the fragments which have a camera-to-fragment vector that intersects with portal countour. And the popup effect is a linear step that modulates the portal radius, depending on the distance from camera.

This method is quite inefficient compared to the classic stencil buffer approach, but the point is to implement the effect only with shaders so that there is no need to modify the game's code (obviously, it would be faster to calculate the track index of the camera in CPU once per frame, instead of doing it thousands of times in the GPU). All data from bounding boxes (inverse matrix, track index) and portals (position, normal, scale, popup distance) is hardcoded in the shader.

The main problem I have encountered when implementing this technique is object clipping. Regular objects like coins and item boxes can be clipped easily with MK8 clipping areas, but those can't be used for items (bananas, shells) or players. One solution to this problem is to change every single shader used by those objects, which is technically possible but takes a lot of time and effort. A more reasonable option is to manipulate the fragment depth (gl_FragDepth) of the course model so that it is drawn on top of those objects.

Just to finish, a fun fact: the shaders used for the Fractal Rainbow Road track are much more complex than this and that track already uses a similar portal effect (for the starting line banner).

Thanks for watching!

4 days ago (edited) | [YT] | 355

RiazorMC

Legendary video Tomorrow 🌍🚨

4 months ago | [YT] | 465

RiazorMC

🎮❗

6 months ago | [YT] | 17

RiazorMC

Release this weekend 🎮❗

6 months ago | [YT] | 194

RiazorMC

Tomorrow ❗

7 months ago | [YT] | 509

RiazorMC

Thanks for watching my videos and Happy New Year 2024! 🎉🎇🎊

1 year ago | [YT] | 298

RiazorMC

Tomorrow 😲

1 year ago | [YT] | 908

RiazorMC

Check out the original video in my secondary channel: https://www.youtube.com/watch?v=g-hUD...

2 years ago (edited) | [YT] | 65

RiazorMC

Thanks for watching my videos and Happy New Year 2023! 🎉🎇🎊

2 years ago | [YT] | 256

RiazorMC

Thanks for watching my videos and Happy New Year! 🎉🎇🎊

3 years ago | [YT] | 267