How to create a custom G-Buffer ?

Hello,

In an other game engine I was able to work with a great feature that allowed me to render something in a specific render “layer”. This allowed me to draw some meshes only in a specific render to texture and use this texture for some special cases in my shaders.

I would like to create a similar possibility in UE4 by creating a custom Render Buffer. Unfortunately I have no idea how or even where to look. Digging in the source code is a bit hard when you don’t know what you are looking for.

So how do you create a custom Render Buffer ? :slight_smile:

Start your search looking for the SceneCaptureComponent2D component and TextureRenderTarget2D.

If you look at the Blueprints example in the marketplace, there are security cameras that have SceneCaptureComponent2Ds attached that capture the scene/process it to a TextureRenderTarget2D, and then you are able to use that TextureRenderTarget2D as a texture in other shaders/post processes/etc.

Some documentation on the security camera setup is here: Engine Feature Examples for Unreal Engine | Unreal Engine 5.1 Documentation , although it’s probably best to dive in and play with it in the editor.

This isn’t exactly a ‘custom G-Buffer’, but a custom render target for only drawing certain items to sounds more the direction you’re headed?

Hey thanks for your comment ! :slight_smile:

Unfortunately a classic RTT will not work in my case as it would requires to have the meshes displayed on the screen (on the user side I mean) to be able to draw them in the texture.

What I’m looking for is a way to draw some meshes in the texture without having to draw them on the screen. (Well technically I will have to draw them, but I don’t want the player to see them.)

I’m hoping to be able to do exactly that as well; rendering certain objects from a scene sepparately on a texture by a camera that is not the active one (active one=being shown full screen).

Could you guys clarify if you mean “meshes not on screen” or “meshes not in the scene”? The method I mentioned and in the example works for anything that is in the level. You can put a camera pointing at anything in the level, even if the camera is “off screen” and far away, and it’ll render to the texture.

If you’re meaning that you want to render an object that isn’t placed in the scene, sort of like the thumbnails in the Editor, then that’s a separate issue and my answer would not cover that.

Well my goal is to get/set an additional stencil buffer. A camera far away in the scene is a viable solution indeed and will work in my case. I’m not sure however it will work for everything.

You mentioned the thumbnails and I didn’t thought about them, I will dig into that. Thanks. :slight_smile:

In my case I need to be able to render only two objects from a complex scene in a TextureRenderTarget2D with one camera, while having another camera rendering the entire scene except the two previously mentioned objects.

Can look at this [Odessey] Creating my own G-Buffer in UE4 - C++ Programming - Unreal Engine Forums