Filling the GBuffer from two different view locations, with a stencil mask?

Hi,
While investigating this problem my first guess was also to try stencil. It’s exactly what stencil is made for after all.
But as usual the graphics pipeline is quite limiting in unreal. After my tests it seems that stencil in unreal cannot be used as an actual stencil (I mean like this: Learn OpenGL, extensive tutorial resource for learning Modern OpenGL ) but only as a sort of area buffer (which is quite strange IMO…)
The best I could get is object silhouette through a transparent objects.
So to get the effect I will need to go to the unreal’s geometry pass code and add a way to cut the image.
I can go to 2 strategy:

  1. write an actual stencil cut feature
  2. adding an “if () { discard; }” somewhere in a shader code
    I tend to prefer the second approach… (less code, more contained, easier to test, less unreal stuff to understand etc…)

Today I dived into unreal code to make unreal to not render a part of the screen that was pretty easy:
I opened “BasePassPixelShader.usf” and spend some time to understand what epic did and endup adding this line:


if ((MaterialParameters.ScreenPosition.xy).x > 0.5f) { discard; }

line 579
and as expected half of the screen is not rendering meshes anymore.
I was a bit worried about how well the keyword “discard” will pass though the cross compiler but I tried on linux and the cross compiler usf->glsl worked without any problem warning or anything.
I was also worried that the lacks of information would broke a lot of things but it appear that the epic guys made the rendering hierarchy in a smart way (or I’m just lucky).
The next step will be to call “discard” according an user input (simple float, keycode, texture etc…) and this look like a bit harder than expected because it look like this shader wasn’t really designed to get parameters from anywhere…
PS: I don’t really understand everything (yet) about how the C++ brings parameters to shaders in unreal… I hope the OpenGL RHI call “glUniform*” functions that would be a great place to start.