Pushing Unity To The Limit - Hyperbolica Devlog #6

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
welcome to the sixth hyperbolica devlog i've been really busy making a lot of progress and i'm actually still on schedule for december release which is why it's been so hard to find time to make these videos so don't expect too many new ones in the next few months anyway let's talk about a few of the unity hacks i had to do to get hyperbolico working you might think accurate reflections would be really hard in hyperbolic space and of course they are but there's always tricks you can do the trick i'm using here is really simple i'm just drawing another copy of the tile underneath the level and then i added a wavy effect and color change it's actually a pretty common trick in euclidean games too but it's nice to know that mathematically it also works in other geometries i've mentioned that hyperbolic coordinates are used to render the object's positions but that's not really the full story you see unity has a euclidean coordinate system and while they could theoretically be combined somehow with great difficulty it's actually really useful to use a dual coordinate system basically the hyperbolic coordinate is kind of like the object's origin and then unity's transformations are offsets from that origin using the beltrami klein projection exactly the same as the vertices this means i can move objects around on a tile in the regular unity editor without any modification and the objects will correctly appear there that makes it way easier to do things like animations colliders and precise placement as long as they don't stray too far from the origin otherwise you'll start to notice distortion but if they are too far away the origin can just be reset to a different hyper coordinate one thing unity likes to do is something called frustum culling it basically means that any object that's not in the camera frustum doesn't attempt to render this makes sense since you don't want to slow down your game rendering things behind the camera but since i'm using a vertex shader it means that where the vertices project to has nothing to do with the object's unity coordinates so things end up randomly disappearing because unity thinks they're behind the camera and for some reason there's no way to turn this off so i have to do a hack where i set every object's bounding box to be ridiculously large so unity always thinks it's in the camera's view then i just manually do the culling myself by selectively disabling the renderers colliders and physics are something that unity just doesn't support well for warping geometries and that was something i had to scrap entirely and write from scratch so i disabled all of unity physics and built my own lightweight physics engine based on marble marcher since that was specifically designed to work with geometry that warps every frame the trickiest part was actually writing a bunch of unity editor code so that i could preview and drag around my custom colliders in unity otherwise it would have taken forever to add so many colliders to every object in the game my engine supports spheres cylinders capsules and things made out of triangles like planes cubes and meshes i also have other basic optimizations like bounding volumes and caching the warped collider so that multiple collisions on the same frame are significantly faster let's talk about the shader now because it's probably one of the hardest parts of working with non-euclidean geometries and why i saved it for the end since i need to apply special vertex transforms i can't use any of the existing unity shaders so everything needs to be custom built and due to the rendering differences i've talked about in previous videos i actually need different shaders for hyperbolic geometry spherical geometry and the map and editor need their own 2d projections of hyperbolic and spherical geometry in order to make things simple and manageable in the game i'm using something called replacement shaders in unity it means i can just use one material and have it automatically choose the correct shader depending on the level geometry and each camera can use a different replacement shader so the same object can render two different ways depending on if it's the main camera or the map camera another thing to note is that all these different shaders share a majority of their code with only slight differences and plus i'll need even more shaders for different special effects such as transparency shadows waves and other things like that so to reduce code redundancy i'm using another technique called an uber shader essentially i have one gigantic shader which i call hypercore and then i use unity's preprocessor and multi-compile options to enable and disable the different geometries and effects it makes it a little messier but it's way easier to maintain and it's very performant one last thing to mention is batching normally when the same object is drawn multiple times like say these background tiles unity batches them together so the geometry data only needs to be sent to the gpu once which makes it much faster but since i'm using unity's property blocks to update the hyper coordinates every frame it's unable to match these draw calls which makes it kind of slow the solution is to use gpu instancing instead as i understand it this internally creates some kind of lookup table in the gpu that each mesh can index into so the data doesn't have to be sent multiple times it was a little tricky to set up but i had to do it anyway because it was a requirement for single pass stereo rendering since each mesh also draws to both eyes in the same draw call combining all of these shader methods together in addition to just the regular complexity of non-euclidean geometry makes for quite a complicated shader and it's still evolving as i continue to optimize it if you're interested in following hyperbolic's release don't forget to wishlist the game on steam and join my discord and a huge thanks again to all my supporters on patreon and coffee see you all next time [Music]
Info
Channel: CodeParade
Views: 87,331
Rating: 4.9875774 out of 5
Keywords:
Id: rBr-0bHQfxc
Channel Id: undefined
Length: 6min 41sec (401 seconds)
Published: Sat Sep 11 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.