I have been looking around and attempting to get my objects to reflect the scene around it properly. As it stands, I have some metal balls rolling around a surface and I need them to reflect the surrounding scene and each other, however I cannot seem to get the right setup.
I currently try to spawn a ASphereReflection for each of my metal balls and am trying to make it so each ball will only use that reflection capture, rather than all of the captures being blended into 1, as it becomes a mess on my object.
So is there any way to have a specific object/material only use the capture of one scene capture or do I have to go for another approach?
EDIT: I have my current setup now with a sphere reflector in each of the balls themselves with a small radius, so each ball takes its sphere reflection of the world and applies it to their material. However, I cannot seem to get the ASphereReflections to move by setting their location based on that of the balls. Is there any way to make the sphere reflections moveable in code so I can have them at the same position as dynamic objects?
Reflections update in realtime during
editing to aid in placement but are
static at runtime.
(More info here)
The Sphere Reflection Capture cannot be used as a dynamic object. You can however, use a Box Reflection Capture to cover your play area where the spheres would be moving and it would reflect the area within that reflection box.
This will cover what you’re looking to accomplish by having your spheres reflect the area around them. You can also adjust the material to have a metallic value between 0-1 (1 being more metallic and shiny) and a roughness value between 0-1. (0 being no roughness vs 1 being rough).
If you need more help with this feel free to post here and I’ll help you out!
Hi Tim, thanks for the response.
I made an attempt at using a box reflection capture over my area, however it didn’t seem to give me the desired result. It does give a nice reflection, however only from a specific point of the box. I require each sphere to have a reflection done from their required location, which I understand can be expensive and therefore I could use reflection probe which only renders specific objects.
However, I have gone down a route at the moment and added a USceneCaptureComponentCube to each of my spheres. I then loop through the components of my sphere, find the SceneCaptureComponentCube and then get its TextureTarget. I then use the texture target and try and set the texture parameter of the cubemap within the spheres material. This has given me a result close to what I require, although I can’t seem to get each sphere to use the correct cubemap I am creating.
USceneCaptureComponentCube* thisComp = Cast<USceneCaptureComponentCube>(comps);
SphereCubemap = thisComp->TextureTarget;
UMaterialInstanceDynamic* MatInst = Cast<UMaterialInstanceDynamic>(StaticMeshComponent->GetMaterial(0));
Is this a reasonable approach or should I look at some other methods
Got it working as intended by adding a USceneCaptureComponentCube to the sphere and then a UTextureRenderTargetCube* SphereCubemap in the header file of the class. I then set the capture components texture target (CaptureComp->TextureTarget = SphereCubemap) on start-up. The engine then renders the scene (currently only when the object moves) into the TextureTarget (SphereCubemap now) and I then use that value to set the cubemap in the material on the sphere.
However, when many spheres are moving and updating, it currently kills my PC performance. which I am expecting as with 10 spheres, 6 faces rendered for each sphere, when all are moving, it becomes 60 extra renders of the whole scene. Preferably, I want to only render certain aspects of the scene, such as the other spheres and then use a static reflection cubemap of the rest of my scene due to only the spheres being the dynamic objects.
So, is it possible to have a USceneCaptureComponentCube only capture specific objects/actors in it’s rendering of the cubemap?
To my knowledge and from looking through our docs this is not possible with everything as it stands. It may be possible to adjust some things in code telling it to render out only specific components but C++ is certainly out of my range of expertise to provide you with a concise answer.
These reflection captures are meant to be used statically not dynamically. So as you mentioned you will see the performance hit by using the code you have to manipulate it.
You may want to check the Forums under C++ GamePlay Programming to see if anyone there may have suggestions for how to go about getting this kind of result, if it’s possible.
Thanks, I’ll probably drop a thread in there. However, I noticed that the SceneCaptureComponent has a tick box to only capture when moving? Are you sure these where not built with some form of dynamic reflection in mind? Either way, thanks for the help.