Skip to main content
GameDev.net gamedev.net
🔒 Locked

Render to screen buffer vs. to texture problem

Started by serumas Apr 10, 2016 at 3:42 PM 15 replies 7.4k views
Original Post
serumas
serumas

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

dpadam450
dpadam450

If you don't render the image into the texture, is your texture actually showing up as orange?

NBA2K, Madden, Maneater, Killing Floor, Sims 
serumas
serumas

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.

Merlin Roger Avery
Merlin Roger Avery

Rendering to them doesn't differ, other than the fact you may be actually writing the alpha out to the texture as well. Which can also change what you draw when you draw a texture.

Matt_Aufderheide
Matt_Aufderheide

Can you post the pixel shader you are using? and the code where you clear the render target?

Hodgman
Hodgman

Looks like you're blending it twice...

"To screen" is: blend( background1, texture )

"To texture" is: blend( background1, blend( background2, texture ) )

Turn off one of those blends and they will look the same.

serumas
serumas

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....

dpadam450
dpadam450

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.

NBA2K, Madden, Maneater, Killing Floor, Sims 
serumas
serumas

i can understand what 3 means. 3 of what?

ok target texture has alpha chanel 1 sprite has 0.3 , i render this sprite to texture , what alpha and colors i will get?

dpadam450
dpadam450

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.

NBA2K, Madden, Maneater, Killing Floor, Sims 
serumas
serumas

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

dpadam450
dpadam450

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.

NBA2K, Madden, Maneater, Killing Floor, Sims 
dpadam450
dpadam450

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.

NBA2K, Madden, Maneater, Killing Floor, Sims 
serumas
serumas

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

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.