Render to Texture, transparent Background? (3 posts)

  • Profile picture of Empire Phoenix Empire Phoenix156p said 5 months, 2 weeks ago:

    Well I try to render a overlay for my screen into a texture. Now I want this texture to have a transparent background. However
    offView.setBackgroundColor(new ColorRGBA(0,0,0,0));
    still renders the background as black.

    Is there a way to force the background of the rendered texture to be transparent, so only the scene is visible on the texture?

    offCamera = new Camera(screenresx, screenresy);
    
    		offView = ClientApplication.getInstance().getRenderManager().createPreView("Offscreen View", offCamera);
    		offView.setClearFlags(true, true,true);
    		// create offscreen framebuffer
    		offBuffer = new FrameBuffer(screenresx, screenresy, 1);
    
    		// setup framebuffer's cam
    		offCamera.setFrustumPerspective(45f, 1f, 1f, 1000f);
    		offCamera.setLocation(new Vector3f(0f, 0f, 50f));
    		offCamera.lookAt(new Vector3f(0f, 0f, 0f), Vector3f.UNIT_Y);
    
    		// setup framebuffer's texture
    		Texture2D offTex = new Texture2D(screenresx, screenresy, Format.ABGR8);
    		offTex.setMinFilter(Texture.MinFilter.NearestNoMipMaps);
    		offTex.setMagFilter(Texture.MagFilter.Nearest);
    
    		// setup framebuffer to use texture
    		offBuffer.setDepthBuffer(Format.Depth);
    		offBuffer.setColorTexture(offTex);
    
    		// set viewport to render to offscreen framebuffer
    		offView.setOutputFrameBuffer(offBuffer);
    		offView.setBackgroundColor(new ColorRGBA(0,0,0,1));
    		offView.attachScene(sceneNode);
    
    		guiNode.setLocalTranslation(0, 0, 20);
    		guiNode.setQueueBucket(Bucket.Gui);
    		sceneNode.attachChild(guiNode);
    
    		Quad mesh = new Quad(screenresx,screenresy);
    		guiBridge = new Geometry("guibridge",mesh);
    		guiBridge.setLocalTranslation(0, 0, 20);
    		guiBridge.setCullHint(CullHint.Never);
    		guiBridge.setShadowMode(ShadowMode.Off);
    		guiBridge.setQueueBucket(Bucket.Gui);
    
    		Material mat = new Material(ClientApplication.getInstance().getAssetManager(), "matdef/GuiBridge.j3md");
    		mat.setTexture("ColorMap", offTex);
    		guiBridge.setMaterial(mat);
    
    		ClientApplication.getInstance().addUpdateSceneGraphListener(this);
    
  • Profile picture of nehon nehon590p said 5 months, 2 weeks ago:

    I think the problem is not when you render the texture but more when you display it afterward. ColorRGBA(0,0,0,0) should be ok for transparency.
    You have to account for the alpha value when you use it as an overlay. (I guess in your GUIBridge material) try to set the blend mode to Alpha

  • Profile picture of Empire Phoenix Empire Phoenix156p said 5 months, 2 weeks ago:

    Hm, your right, its transparent now.