Jump to content

  • Log In with Google      Sign In   
  • Create Account

Awesome job so far everyone! Please give us your feedback on how our article efforts are going. We still need more finished articles for our May contest theme: Remake the Classics

#ActualTunisia hawker

Posted 12 July 2012 - 08:16 PM

I was trying to save some texture from 3D rendering scene,and then get them to reuse.
The big problem is that rgb value can not match its alpha value.I need some picture without black edge,so I must use rgb colors to divide its alpha value(Image manipulation software such as Photoshop can just deal with picture which alpha channel is nonpremultiplied.)
Unfortunally,the color is too light that some result value are cut off to 1.
So I turned to a technique called premultiplied alpha.(See more). Instead of using shaders,I just use separate alpha calculation.
For example:
RenderState.SourceBlend = Blend.SourceAlpha;
RenderState.DestinationBlend = Blend.InverseSourceAlpha;
Now I add some renderstate.
RenderState.SourceBlendAlpha = Blend.One;
RenderState.DestinationBlendAlpha = Blend.InverseSourceAlpha;
It works well.But when I try to handle following things:
RenderState.SourceBlend = Blend.SourceAlpha;
RenderState.DestinationBlend = Blend.One;
RenderState.SourceBlendAlpha = Blend.One;
RenderState.DestinationBlendAlpha = Blend.One;
The result is totally wrong.
Because when I use nonpremultiplied blend state,which is SourceAlpha and inverseSourceAlpha.The rgba value is definitely controlled within 0~1.But when I switch to additive state,which is SourceAlpha and 1,the rgb values might be over one,thus cause the incorrect value.
Now my problem is how to control the alpha value,to make sure it keep all details and do not overflow at the same time?

//Modified
PS:If you don't understand what I am trying to do,there is a commercial software called "Particle Illusion".You can create various particles and then save the scene to texture,where you can choose to remove background of particles.
[attachment=9970:particleIllusionDemostrate.png]

#2Tunisia hawker

Posted 05 July 2012 - 09:42 PM

I was trying to save some texture from 3D rendering scene,and then get them to reuse.
The big problem is that rgb value can not match its alpha value.I need some picture without black edge,so I must use rgb colors to divide its alpha value(Image manipulation software such as Photoshop can just deal with picture which alpha channel is nonpremultiplied.)
Unfortunally,the color is too light that some result value are cut off to 1.
So I turned to a technique called premultiplied alpha.(See more). Instead of using shaders,I just use separate alpha calculation.
For example:
RenderState.SourceBlend = Blend.SourceAlpha;
RenderState.DestinationBlend = Blend.InverseSourceAlpha;
Now I add some renderstate.
RenderState.SourceBlendAlpha = Blend.One;
RenderState.DestinationBlendAlpha = Blend.InverseSourceAlpha;
It works well.But when I try to handle following things:
RenderState.SourceBlend = Blend.SourceAlpha;
RenderState.DestinationBlend = Blend.One;
RenderState.SourceBlendAlpha = Blend.One;
RenderState.DestinationBlendAlpha = Blend.One;
The result is totally wrong.
Because when I use nonpremultiplied blend state,which is SourceAlpha and inverseSourceAlpha.The rgba value is definitely controlled within 0~1.But when I switch to additive state,which is SourceAlpha and 1,the rgb values might be over one,thus cause the incorrect value.
Now my problem is how to control the alpha value,to make sure it keep all details and do not overflow at the same time?

#1Tunisia hawker

Posted 05 July 2012 - 09:41 PM

I was trying to save some texture from 3D rendering scene,and then get them to reuse.
The big problem is that rgb value can not match its alpha value.I need some picture without black edge,so I must use rgb colors to divide its alpha value(Image manipulation software such as Photoshop can just deal with picture which alpha channel is nonpremultiplied.)
Unfortunally,the color is too light that some result value are cut off to 1.
So I turned to a technique called premultiplied alpha.(See more). Instead of using shaders,I just use separate alpha calculation.
For example:
RenderState.SourceBlend = Blend.SourceAlpha;
RenderState.DestinationBlend = Blend.InverseSourceAlpha;
Now I add some renderstate.
RenderState.SourceBlendAlpha = Blend.One;
RenderState.DestinationBlendAlpha = Blend.InverseSourceAlpha;
It works well.But when I try to handle following things:
RenderState.SourceBlend = Blend.SourceAlpha;
RenderState.DestinationBlend = Blend.One;
RenderState.SourceBlendAlpha = Blend.One;
RenderState.DestinationBlendAlpha = Blend.One;
The result is totally wrong.
Because when I use nonpremultiplied blend state,which is SourceAlpha and inverseSourceAlpha.The rgba value is definitely controlled within 0~1.But when I switch to additive state,which is SourceAlpha and 1,the rgb values might be over one,thus cause the incorrect value.
Now my problem is how to control the alpha value,to make sure it keep all details and do not overflow at the same time?

PARTNERS