• Advertisement
Sign in to follow this  

transparency and alpha blending in HLSL

This topic is 4493 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

HI how can i implement transparency and alpha blending in HLSL??? I searched the web and i didnt find anything useful. it would be appreciated if you post some code about this or if you have any tutorials please send me the link. THX in advance

Share this post


Link to post
Share on other sites
Advertisement
alpha blending is enabled in the engine via the following:

[source lang=c#]
this.device.RenderState.SourceBlend = Blend.SourceAlpha; //set the source to be the source's alpha
this.device.RenderState.DestinationBlend = Blend.InvSourceAlpha; //set the destination to be the inverse of the source's alpha
this.device.RenderState.AlphaBlendEnable = true; //enable this.texture = TextureLoader.FromFile(device, "tex.bmp");



I'm still somewhat new but I beleive this is correct, colors in HLSL are are comprised of four float values. those four values correspond to alpha, red, green and blue.

Ensure that your render target and textures are a format that has valid alpha information, ie A8R8G8B8 or such.

-Devin

Share this post


Link to post
Share on other sites
I'm not sure, but I think, you need this(i hope [smile] ):


technique RenderScene
{
pass p0
{
AlphaBlendEnable=true;
SrcBlend=srcalpha;
DestBlend=invsrcColor;
VertexShader = compile vs_1_1 vertexs();
PixelShader = compile ps_1_1 pixels();
}
}

Share this post


Link to post
Share on other sites
HI
where should I set render states. in my engine's code or in a FX file.
I'm using FX file for my effects. and i want to render a transparent window. which way should i use.

[Edited by - ehsan_the_tiamat on January 4, 2006 12:58:30 AM]

Share this post


Link to post
Share on other sites
Generally, they should not be set within the FX file. This allows you to batch render states and minimize changes.

FX files, IIRC, use state blocks and unless you tell them otherwise, will restore any state changes you set within a technique. This doesn't lend itself well if you need to render two things in a row using the same render states.

While you can tell them not to restore changed states... no

keep them out of the FX file if you can :)

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement