Jump to content

rendering an image to a gui


photo

Recommended Posts

 

Hello,
I am rendering an image to a gui as follows:

init()

map_gui = object_gui->getGui();

viewportCam = Viewport::create();

m_textureCamera = Texture::create();

m_textureCamera->create2D(1080, int(1080 * 9.f / 16), Texture::FORMAT_RGBA8, Texture::USAGE_RENDER);

m_spriteCamera = WidgetSprite::create(map_gui, "Camera");

m_spriteCamera->setRender(m_textureCamera);

m_spriteCamera->setBlendFunc(Gui::BLEND_NONE, Gui::BLEND_NONE);

map_gui->addChild(m_spriteCamera, Gui::ALIGN_LEFT);

 

update()

viewportCam->renderTexture2D(cam->getCamera(), m_textureCamera);

 

The sky is not rendered properly. Is there any way to render the image properly without  Cubemap?

with kind regards  

Leon

 

image.thumb.png.b41204c358f9505f65e96efca1d2873f.png

Link to comment

This is probably caused by the fact, that Sky has 0 alpha. Hence GPU blends textures in places where the sky should be. 
You'd need to write UUSL shader and material. You can make simple Scriptable Material.
1. Create Template of Scriptable Material from the Editor.
2. Open it with some code editor and change this line from:

OUT_COLOR = color * var_my_color;

To:

OUT_COLOR = float4(color.rgb, 1.0f);

This will ensure that composed screen texture will have 1 alpha everywhere.
3. Just assign this Scriptable Material to either Viewport it self, or to the camera that renders in specified viewport (depending on your needs*).


* If you assign SM to the camera, each time this camera is used to render something assigned SMs to this camera will be executed too.
If you assign SM to the viewport, it will affect only this viewport.

A side note, you can use this button to paste formatted code into messages:
image.png

 

 

 

AlphaTo1.basemat

  • Thanks 1
Link to comment
  • 2 months later...

Hello all 
yesterday I have upgraded to Unigine 2.15. Now I have the problem that the scriptable material "AlphaTO1.basemat" does not work anymore can someone tell me why?
With best regards

Leon

Link to comment

Hi leon,

We changed a lot in how materials and shaders written, most of the changes are minor.
1) Remove name from base material, as it is no longer needed
2) Change argument for screen_texture from "type" to "source"
3) Change path for shader include from "core/shaders/common/fragment.h" to "core/materials/shaders/render/common.h"
4) Add render target definition. It will define "FRAGMENT_OUT" inside of it automatically.

STRUCT_FRAG_BEGIN
	INIT_COLOR(float4)
STRUCT_FRAG_END

5) Change "MAIN_BEGIN(FRAGMENT_OUT, FRAGMENT_IN)" to "MAIN_FRAG_BEGIN(FRAGMENT_IN)". Now FRAGMENT_OUT is passed automatically
6) Rename "MAIN_END" to "MAIN_FRAG_END"

Hope it helps
 

  • Like 2
Link to comment
×
×
  • Create New...