I want my camera to render only objects that are within a radius of a specific point, this point would be independent of the camera’s location so I should be able to fly around this subsection of my world. That centre point will change as part of the game play.
I also want the edges to alpha-blend out rather than immediately ending (it will be an agumented reality game).
I there an existing technique for doing this? Perhaps a shader or something?
Just add trigger sphere to “object”, if it intersect trigger sphere of the “point” in space - enable renderer.
Regarding alpha-blending. When “object” enabled, then pass world space coordinates of nearest “point” to the shader. In shader Lerp alpha channel of color in fragment shader based on distance to the point. Please notice that all objects should be in transparent queue and this will create some overdraws, so there will be performance hit.
That’s kind of what I want, but in the cases where the object is only partially inside the sphere I would like to only render the parts of the object that are inside the sphere and not the parts that are not.
You’ll need a specific shader in either case, but the big question is what you want to do with the holes that remain.
Just skipping pixels that fall outside of a sphere can be done with a fairly simple clip instruction. Say you have a float4 that contains the center of the sphere in xyz and the radius in w:
But this will allow you to look through the objects where they get clipped by the sphere. To fill this up you’ll need to use the stencil buffer and an actual geometrical sphere. Then you can essentially do geometrical boolean operations on a per pixel base using the stencil buffer.