Author Topic: RenderToTexture and alpha blending problem  (Read 275 times)

Offline MichaelJPCT

  • long
  • ***
  • Posts: 200
    • View Profile
RenderToTexture and alpha blending problem
« on: March 28, 2020, 02:37:44 pm »
hi Egon,
i encounter a strange problem.
i want to render some clouds into textures and put them into rectangle meshes then put them back to the scene. the replaced method is putting the clouds directly into the scene.
there is a far scene where nothing but clouds are in, and the far scene is rendered without depth test/depth write.
i believe the environment for rtt is the same as the non rtt one - same shader, same depth test setting.
but the rtt texture doesnt look the same.
without rtt, the overlapping particles blend, the result looks thick. but with rtt it seems only one layer remains, which indicates a replace method rather than blending.
and even if the rtt texture has opaque background, the particles make the texture look-through. the below screenshots are comparison of 2 methods .
 the large white area is because i clear the rtt fb with color 0xffffffff, which is not necessary, but it indicates the opaque background was lost because of the particles. i also tried to use an opaque mesh as background, same result.
turning depth test on, doesnt change the result either.
the texture for rtt is created with Texture(x,y) method.
more strangely, the main scene is also rendered into a texture(npot) then blit into the true fb, but the clouds directly in main scene doesnt change the npot texture to transparent.

why would the rtt result be different from directly rendering into the main scene?


Offline MichaelJPCT

  • long
  • ***
  • Posts: 200
    • View Profile
Re: RenderToTexture and alpha blending problem
« Reply #1 on: March 28, 2020, 02:55:35 pm »
i tested on 2 different gpu , same result.
the rectangle holding the rtt texture uses a shader which just copies texture color to gl_fragcolor.

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12060
    • View Profile
    • http://www.jpct.net
Re: RenderToTexture and alpha blending problem
« Reply #2 on: March 28, 2020, 09:52:05 pm »
Have you tried to use the http://www.jpct.net/jpct-ae/doc/com/threed/jpct/Texture.html#Texture(int,%20int,%20int) constructor instead to force the texture to have an alpha channel? Maybe that helps...

Offline MichaelJPCT

  • long
  • ***
  • Posts: 200
    • View Profile
Re: RenderToTexture and alpha blending problem
« Reply #3 on: March 29, 2020, 09:56:25 am »
i just tried, it doesnt change. i think the first time the texture is used, alpha channel is automatically created.
if i remove the channel after the first time, i get a total black texture after render.
but to the npot texture of screen size, i cant call removeAlpha, or the app crashes.
i tried creating npot texture (but with pot size) for this case, but the result doesnt differ from Texture(x,y).

Offline MichaelJPCT

  • long
  • ***
  • Posts: 200
    • View Profile
Re: RenderToTexture and alpha blending problem
« Reply #4 on: March 30, 2020, 12:04:28 pm »
hi Egon,
don't worry about this, i just figured out this method can't get me the same visual effect at all, it's wrong method.
setAlphaWrites(false) can let me get a texture of the same look, just that it can't be transparent so it can't be put back to the main scene.
the blending is always correct, i didn't understand it, now i understand.