Sign in to follow this  
serumas

Render to screen buffer vs. to texture problem

Recommended Posts

Hi,

what would be so wonderfull if you guys help me to solve this problem.

I cant get why rendering to screen buffers and to texture so differs.

 

Bouth screen and texture formats are identical A8R8G8B8, blending mode and params are exect

SetRenderState( D3DRS_SRCBLEND,  D3DBLEND_SRCALPHA );
SetRenderState( D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA );
but result so differs. Rendering to texture starting to become grey. I could imagine that it for sure could be gray(darker) if

destination would be black. But its not. In bouth cases its filled with bold color with alpha == 1.0

I have tried lots of different params and states, so now iam desperate...

 

dif.jpg

Share this post


Link to post
Share on other sites

Yeah, this is two cases, than i render the same orange texture to screen and to texture , becouse it has alhpa chanel == 1.0 it apears in both cases the same exact color .
There is no problem. Problem is colors with chanle alpha != 1.0; They becomes darker and grey independent on background.

Share this post


Link to post
Share on other sites

Nahh,

 

bouth cases has blending mode enabled

 

1 case:

 

a) Clear screen with solid color  = ARGB(1, 1, 1, 1) (any solid color)

b) Draw sprite with sprite color  = ARGB(0.3, 1 , 1 , 1)  (D3DRS_SRCBLEND, D3DRS_DESTBLEND as written in topic) (simple shader return textureColor * color;)

 

2 case:

a) Clear screen with solid color  = ARGB(1, 1, 1, 1) (any solid color)

b) Clear render target texture with solid color  = ARGB(1, 1, 1, 1) (all pixels alpha == 1)

c) Render sprite to target texture color  = ARGB(0.3, 1 , 1 , 1)  (D3DRS_SRCBLEND, D3DRS_DESTBLEND as written in topic) (simple shader return textureColor * color;)

d) Render target texture color = ARGB(1, 1, 1, 1) (than i render this texture it has all pixels alpha == 1)

 

problem apears on c). Render target texture has solid color for example yallow, rendering sprite with alpha == 0.3

the new pixel color should be finalColor = targetTexColor * (1 - 0.3) + spriteColor * 0.3 

after that target texture renders to screen srcreeTexColor * 0.0 + renderTargetColor * 1.0

 

So...

 

1 case: screen color = yallow

screen * (1 - 0.3) + sprite * 0.3

 

2 case: target color = yallow , screen color = any

screen * 0 + (target * (1 - 0.3) + sprite * 0.3) * 1.0

 

Should be the same color , but but no....

Share this post


Link to post
Share on other sites

No, hodgman is correct.

d.)Render target texture color = ARGB(1, 1, 1, 1) (than i render this texture it has all pixels alpha == 1)

 

This is wrong. Your target has an alpha channel, and therefore will write to the alpha component. Which in this case will be .3.

If you want to do that properly, createa a render texture as RGB, not ARGB.

Share this post


Link to post
Share on other sites

I just told you. Your target has an alpha component which means alpha writes are enabled. It will write the incoming fragments alpha, which is .3

 

Make your target texture RGB. It still blends properly. Still gives you the same color. Destination alpha will always be 1.0 when you don't have an alpha channel.

Share this post


Link to post
Share on other sites

Yes you are right it becomes 0.3. I need a transparent texture, so ARGB must be. I just want to merge sprites as in photoshop layers :)

 

so is it possible that alpha chanel  for target texture not overwrites but adds  newAlphaChanel = 1 + 0.3

Edited by serumas

Share this post


Link to post
Share on other sites

You don't need a transparent texture. And no you can't just add them.

 

You can take any number of non-transparent textures, and blend them like photoshop does. Just call glColor4f(1,1,1, layerAlpha), before you draw it to the screen. This is what gives your layer/texture alpha instead of an actual alpha component in the texture.

Edited by dpadam450

Share this post


Link to post
Share on other sites

If you actually have an image that when layered together like photoshop has alpha, then you need to be a bit tricker.

 

If you really want to overwrite the alpha channel, you can use glColor4f(1,1,1, alpha), and glColorMask(false, false, false, true)  which makes you write only alpha components to the screen. In this case you can just draw a black quad and set any alpha you want.

Share this post


Link to post
Share on other sites

so is it posible on dx to merge several sprites to texture and get texture like merged layer on photoshop - change alpha chanel calculation

Edited by serumas

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this