I’m a beginner and I want to make certain objects in the scene visible in the left eye but not in the right eye, or show different states. Does anyone know how to do this in VR mode?
You can do this in the material editor by adding a Custom node with the output set to float1
and the following code:
return ResolvedView.StereoPassIndex;
It will output 0 for the left eye and 1 for the right eye, so you can switch off it to drive any effects per-eye.
To make an object visible in one eye only, set the material blend mode to Masked, and connect the custom node to the Opacity output. To switch which eye it is, put a OneMinus node in between.
Would you happen to know why the return ResolvedView.StereoPassIndex;
custom code material node doesn’t seem to work when using it in a User Interface Material Doman material? I’m applying it to an Image brush material and don’t get the results I would expect when looking at the Widget with the Image on it in VR. I know this same code segment works on a Surface material, just not a User Interface material apparently. I’ve also tried setting the Blend Mode to every available option with no results.
It’s probably because the UI widget gets rendered to a texture in a separate pass before the main rendering passes. Not sure if it’s possible do anything about it, apart from having separate widgets for each eye.
Ah okay, that would make sense. I did manage to get what I wanted out of two separate widgets at least after copying the default widget material and replacing some of the calculations with the custom node.
How did you managed to split it into 2 widgets? How to show the corresponding widgets in only one eye?
I ended up figuring out how to use a single Material to do what I wanted. This Material adjusts the spacing per eye using the ResolvedView.StereoPassIndex
that Rectus mentioned in a Custom node.
The Material settings:
The Material Blueprint (Take note that the Texture Sampler is 2D. I try to name it SlateUI usually in case Unreal has that hard coded but you might be able to name it whatever you want) :
The Custom node code:
if (ResolvedView.StereoPassIndex == 0)
{
return dist;
}
else
{
return dist * -1.0;
}
I just applied that Material to a Widget component and placed it as a child of my Pawn’s camera and put it a distance away so it looked okay. Ended up using that EyeDistance scalar parameter to adjust the focal distance when looking at near or far objects with a bit of tweaking for the value.
If you want to still use 2 separate Widgets then you can just separate the Custom node code out into 2 different Materials with one checking for a StereoPassIndex of 0 and another for 1. For example you could check for 0 and return 0 if true and use that value to control the Opacity to hide the Widget in one eye like Rectus mentioned.
Just wanted to let ya’ll know that I added M_LeftEyeGreen_RightEyeRed
to the VR Template for 5.4. This material demonstrates how to display different colors in each view.
Does it work in stereo as widget material?
I am using UE4.23.1, any suggestion for that?
You can use the same solution that’s been described in the previous posts in older versions of UE as well.