Download

Render specific objects in a capture component

Current overview of what I have:

Some spheres which each have their own ‘USceneCaptureComponentCube’ component. This is used to take a cubemap of the scene from the position of the spheres, and with this cubemap I apply it to a material which I use on the sphere to give the effect that the object is reflecting the world correctly. While this approach works, it is very process heavy as you’d imagine, as the USceneCaptureComponentCube is capturing all of the other actors and data within the scene.

What I was hoping for, is to know if there was a way for a ‘USceneCaptureComponentCube’ camera, to select specific objects (the dynamic ones) to render into the cubemap, as to reduce the amount of data each ball would need to update each frame. In Unity, there was a way to give layers/tags to specific objects and then for certain cameras, they would only render those specific objects within a layer mask. I would then blend this reduced render of my dynamic scene objects with a pre-made static cubemap to give the illusion of a correct, real-time reflection of the world.

My AnswerHub question which directed me here.

You could iterate through the actors and discriminate by class, presumably derived from one common class. E.g. AMyParentClassToRender, and objects derived from that (or with an interface).



for (TActorIterator<AMyParentClassToRender> it(GetWorld()); it; ++it) {
      AMyParentClassToRender* object = it;
     (...do something with it...)
}


Warning, code not checked :slight_smile:

I understand it’s possible to loop through certain objects and possibly turn off/on the objects to render, however I am not aware of when the cubemap’s capture takes place and I also am not sure how to force a specific camera (the capture component) to render these chosen objects without taking into account the rest of the scene?

Still having some problems trying to get the visual effect I need and I may start looking into the ‘USceneCaptureComponentCube’ in the source code to try and solve it. The current setup I have does give me the correct visuals I need, but at a considerable run-time price as each object has a capture component running, which is multiplying my rendering amount by 6 * number of objects. What I was hoping for, was a way to only render a specific capture component when I needed to:

if (IHaveANeedForUpdate)
CaptureComponent->RenderYourCubemapNow();

or if possible, rather than only render the cubemap when the object is moving, render each face of the cubemap once each frame (as done in Unity) or allow me to choose which face to render.

if (IHaveANeedForUpdate)
CaptureComponent->RenderFaceX();

This way, I will be able to create a sufficient dynamic reflections of the scene (SSR doesn’t fit my needs fully) at a much lower performance cost. Also, if anyone has any other methods of creating dynamic reflections or more efficient ways to capture cubemaps at run-time, please let me know :slight_smile:

So i have gone into the engine source and added a blueprint tickbox on scene capture components to allow 1 face to be rendered each frame and it seems to be running better for now. However, I’m still having issues with finding out when the USceneCapture actually performs its capture when running the game. I need to know this so I can loop through my objects in the scene, hide the ones I don’t need to be rendering into my cubemap and then switch them back on.

I can do the basics with a naive approach and it seems to work, however it’s really obvious that the objects are being hidden/unhidden each frame (almost caused an epileptic fit), so I need to work out where in the code to hide given objects, allow the render of my cubemap and then unhide them.

The effect I’m trying to achieve can be seen here:
https://www.youtube.com/watch?v=NptcTI1jKi8