简体   繁体   中英

Unreal Engine / C++: How to draw a texture mask based on where 2D UI Widgets are on-screen

It seems like the Unreal Engine (4.8.1) lacks a built-in "buffer" or similar that masks out where 2D UI Widgets are laid out on screen while they are being rendered; while it's very simple to extract various Depth Buffers for the 3D world (including 3D UI elements that are part of that domain, unlike the 2D UI that is being rendered on top of everything).

However, I figure that there has to be a way to use C++ and draw some black rectangles on a white base texture; based on the positions and sizes of the UI widgets that are part of a UMG UI HUD. Perhaps, even to extract the absolute screen bounds of each "rectangle" per Widget (in order to avoid having to deal with the various "anchor" points or do conversions from some local UMG space to screen space).

What I'm after, is to create a "render target" texture that looks something like this attachment - that is being updated each frame, or whenever the UI updates (as Widgets may be moved or resized, like when a Minimap or Inventory is re-arranged by the player). A texture asset that in turn can be used in a normal Unreal Material, for example, to mask a Post Process layer:

在此处输入图片说明

Any help would be greatly appreciated as I'm completely stuck on my own.

You may want to look into setting up a sort of green screen on your UMG. You can do this by using the SceneCapture2D object and a green-screen. Then get a render target out of it and create a render material.

Blueprint for green-screen: 在此处输入图片说明

在此处输入图片说明

You can then add an image to your UMG widget and apply the green-screen material as the brush.

在此处输入图片说明

Hope this helped.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM