Hacker Newsnew | past | comments | ask | show | jobs | submitlogin
Rendering a Sphere on a Quad (bgolus.medium.com)
78 points by juliendorra on Jan 10, 2021 | hide | past | favorite | 10 comments


This is a great tutorial leading one to learn about GPU imposters.

If you liked this, I suggest you look at Fortnite: https://www.shaderbits.com/blog/octahedral-impostors

However, let me point out a very big gotcha with this technology: Usually, outputting a custom z-depth will disable any sort of early z-culling in the GPU. That means the performance hit of drawing this might be huge, and even more costly than drawing the high-res models if screen coverage is large enough. That's why game engines will usually run a skybox pre-pass to get a stencil mask on where imposters might be needed and then only render there.


SV_Depth disables early z culling for that draw. But doesn't disable early z culling for subsequent draws. It does disable some z buffer compression that some older / mobile GPUs implement, but that's less of an issue for modern GPUs.

As for disabling early Z culling when drawing the impostor, the section titled "Fragmented Depth" covers this problem, and the solution. https://bgolus.medium.com/rendering-a-sphere-on-a-quad-13c92...


Yes, there is a SM5 extension to reduce the impact when you're on a high-end Windows PC. But for most games, relying on that is not really practical, or else you lose Linux, Mac, most consoles and mobile.

I agree that impostors are great for far-distance background. But I would never use them for anything too close to the camera. So in a sense, impostors are the new skybox.


Vulkan & Metal both have equivalents, at least for Linux & MacOS. As do most modern consoles.

Mobile is an issue, yes. Though curiously sphere impostors were first proposed for use with and implemented using GLES 2.0 for a significant performance and quality improvement in drawing thousands of spheres for molecular rendering. It all depends on what your use case is.

Also hardware with Shader Model 5.0 support came out >10 years ago now. There aren't a lot of desktop computers still using hardware that don't support it.


Does a depth prepass not avoid this?


Yes and no. The pixel shader still has to be run for every pixel covered by the impostor, because you don't know in advance if the custom depth will be in front of or behind the z-prepass.

So you likely pay the full rendering price for an impostor, even if it completely invisible.


This is great, thanks for sharing!

Even as a game dev myself, I'm still constantly amazed by the witchcraft that the rendering experts do.


Nice. I need to understand shaders over the next few months.


This is a very good place to start - https://thebookofshaders.com/


Yeah, on modern 3D APIs 90% of the work is done via shaders, have a look at mesh shaders as well, the future of shading languages, as GPUs are now general purpose computing devices.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: