dongju.jeong Posted February 25, 2020 Posted February 25, 2020 Can't I create and use a render texture in editor? Like Unity. Should I make the code myself like an example of mirror programming?
silent Posted February 25, 2020 Posted February 25, 2020 dongju.jeong What do you mean by create a render texture inside Editor? Do you have any example use-case? What kind of task you are trying to do? Thanks! 1 How to submit a good bug report --- FTP server for test scenes and user uploads: ftp://files.unigine.com user: upload password: 6xYkd6vLYWjpW6SN
thomalex Posted February 25, 2020 Posted February 25, 2020 Hello @dongju.jeong, If I got this right, you want to render a camera view to a texture right in the Editor (just like Render Textures in Unity). There is no special texture types in UNIGINE for that, it is available via API. UnigineScript is the only coding workflow that runs logic inside the Editor at the moment. Below I've described the simplest way to render to a texture using engine.render.renderImage2D: All you need is to create a player and a target mesh (e.g. a plane primitive having an arbitrary material inherited from mesh_base) and make them children of a WorldExpression node. Then use the following expression to update the plane's albedo texture: { #include <core/unigine.h> // in order to use node_cast int size = 1024; // image width float aspect_ratio = 2.0f; // aspect ratio to fit the target plane (which is 2×1 units here) Object plane = node_cast(getChild(0)); // get the target plane being the first child Material mat = plane.getMaterial(0); Player dummy = node_cast(getChild(1)); // get the camera being the second child in this example Camera cam = dummy.getCamera(); Image image = new Image(); engine.render.renderImage2D(cam, image, size, size / aspect_ratio, 0, 0); mat.setTextureImage(mat.findTexture("albedo"),image); image.clear(); } And we can see the desired result: It's not the best approach as all necessary objects are retrieved each frame (due to limitation of WorldExpression), I would suggest using the same code in the world script, where you can split the logic to the init and update stages. If you seek the best performance and fine tuning, take a look at the Samples > C++ API > Render > RenderTarget sample (it's in C++ but turning it into UnigineScript is a quite trivial task). You may also find these samples and articles helpful: Creating Mirrors Using Viewports Samples > UnigineScript > Render > viewport_00-viewport_03 (rendering the camera's view to a WidgetSpriteViewport widget). Thank you! 2
dongju.jeong Posted February 26, 2020 Author Posted February 26, 2020 (edited) Samples > C++ API > Render >RenderTarget RenderTarget sample does not exist... Edited February 26, 2020 by dongju.jeong
silent Posted February 26, 2020 Posted February 26, 2020 dongju.jeong For some reason this sample is not displayed in SDK Browser in 2.9 SDK release. You can navigate to it manually by opening the <SDK_DIR>/source/samples/Api/Render/RenderTarget. In 2.8 and earlier this sample named as TextureRender. Thanks! 1 How to submit a good bug report --- FTP server for test scenes and user uploads: ftp://files.unigine.com user: upload password: 6xYkd6vLYWjpW6SN
werner.poetzelberger Posted February 26, 2020 Posted February 26, 2020 (edited) woot. where have you been hiding??? oO (... render texture I mean) Edited February 26, 2020 by werner.poetzelberger
dongju.jeong Posted February 27, 2020 Author Posted February 27, 2020 (edited) What is the difference between using Image of Render class and texture of viewport class? the way of using a Render class is much heavier. Edited February 27, 2020 by dongju.jeong
gr7.76 Posted January 21, 2021 Posted January 21, 2021 On 2/27/2020 at 7:53 AM, dongju.jeong said: What is the difference between using Image of Render class and texture of viewport class? I could be wrong but I think the difference is: Unigine::ViewPort::renderTexture2D -> you render your world, from the given camera Unigine::RenderTarget -> You render the geometry you want. Not necessarily the world
rohit.gonsalves Posted January 22, 2021 Posted January 22, 2021 On 2/27/2020 at 12:23 PM, dongju.jeong said: What is the difference between using Image of Render class and texture of viewport class? the way of using a Render class is much heavier. The only thing that matters here. Textures reside on GPU video memory. Image reside on System Memory (RAM). Rohit
Recommended Posts