Is it possible to draw primitives (lines, triangles…) into a texture? I’m currently playing with Paper2D. To achieve a certain effect I need to create a “mask” texture by drawing shapes into it. This texture has to be updated every frame and multiplied into the rest of the rendered scene. The result is comparable to the example below. Basically it modifies the rendered scene’s brightness, sort of like a post processing effect.
I’ve done this in Cocos2D previously and now I’m thinking about porting it over to UE4 for better portability and because of the convenient editors. How would I go about this in UE4 and Paper2D?
Hey Bajee -
There are two possible ways to achieve this effect. One way would be to take a post process material which increases the brightness of objects found behind the mesh and assign it to a basic mesh shape like the flashlight’s triangle and adjust the 3D scale of that mesh to simulate shape change. There are some limitations to this method as you would have to do some complicated variable alignment to check for blocking objects and then either fun a gradient fade to cut the brightness effect or change the Relative Scale 3D.
The other method would require a significant investment into some Programming and is explored quite nicely on this website here, 2d Visibility
Hopefully this will point you in the right direction, if you have further questions about this method please feel free to comment below -
Hi Eric. Thanks for the reply. The second method is exactly what I mean. I implemented a very similar lighting in the Cocos2d engine a while back (using [this article] from gamedev.net). My problem is not about calculating the shadow geometry, but porting this solution to UE4. Mainly because it’s a huge code base and I don’t even know where to look first.
The way I did it in Cocos2d was to first let the engine render the unlit scene, like this ugly example:
Then I added a final step, where I rendered all the lights (and shadows) into a render texture. This texture was then multiplied into the framebuffer (with the already rendered scene) to get the final result:
Since I posted this question I learned about the [UTextureRenderTarget2D] class. I didn’t have much time to look into it yet and I found very little information on how to use it. Can I use this class to render some 2D shapes into a texture which I then multiply into the scene as a post processing effect?
In my Cocos2d implementation I simply used some OpenGL draw calls to render the lights and shadows into the render texture. I think we are not supposed to do that in UE4 for portability reasons (right?). What would I use instead? What is a low level drawing API that would allow me to efficiently draw some colored and/or textured triangles?
Hey Bajee -
Yes I think you are on the right track and know that I think I have a better handle on exactly what you are asking, we actually have a tool that will probably immensely help you out. In the Art tools section of the Engine content you can find a render to texture workflow including imposter sprites which I believe would give you what you want, information can be found here, https://docs.unrealengine.com/latest/INT/Engine/Content/Tools/RenderToTextureTools/3/index.html