Sign in to follow this  
john13to

Backside of transparent textures aren´t visible at certain view directions

Recommended Posts

john13to    151
[size="2"]I have a glass prism that is built up by transparent textures and I have
a problem of making the backside of them to be visible from any arbitrary
viewing direction. I use HLSL modify the alpha channel to make
the textures transparent and to view them.

I write the following code in XNA to activate the transparent shader
and to draw the textures on every triangle of the glass prism:

transparencyFx.CurrentTechnique = transparencyFx.Techniques[

[/size][size="2"][color="#a31515"][color="#a31515"]"Transparency"[/color][/color]];[/size]

[size="2"]

transparencyFx.Begin();



graphics.GraphicsDevice.RenderState.AlphaBlendEnable =

[/size][size="2"][color="#0000ff"][color="#0000ff"]true[/color][/color];[/size]

[size="2"]

graphics.GraphicsDevice.RenderState.SourceBlend =

[/size][size="2"][color="#2b91af"][color="#2b91af"]Blend[/color][/color].One;[/size]

[size="2"]

graphics.GraphicsDevice.RenderState.DestinationBlend =

[/size][size="2"][color="#2b91af"][color="#2b91af"]Blend[/color][/color].InverseSourceAlpha;[/size]

[size="2"][color="#0000ff"][color="#0000ff"]foreach[/color][/color] ([color="#2b91af"][color="#2b91af"]EffectPass[/color][/color] pass [color="#0000ff"][color="#0000ff"]in[/color][/color] transparencyFx.CurrentTechnique.Passes)[/size]

[size="2"]

{



pass.Begin();



transparencyFx.Parameters[

[/size][size="2"][color="#a31515"][color="#a31515"]"ModelTexture"[/color][/color]].SetValue(prismTexture);[/size]

[size="2"]

transparencyFx.Parameters[

[/size][size="2"][color="#a31515"][color="#a31515"]"World"[/color][/color]].SetValue(cam.GetWorld());[/size]

[size="2"]

transparencyFx.Parameters[

[/size][size="2"][color="#a31515"][color="#a31515"]"View"[/color][/color]].SetValue(cam.GetView());[/size]

[size="2"]

transparencyFx.Parameters[

[/size][size="2"][color="#a31515"][color="#a31515"]"Projection"[/color][/color]].SetValue(cam.GetProjection());[/size]

[size="2"]





graphics.GraphicsDevice.RenderState.CullMode =

[/size][size="2"][color="#2b91af"][color="#2b91af"]CullMode[/color][/color].None;[/size]

[size="2"]

graphics.GraphicsDevice.VertexDeclaration = vDTexture;



graphics.GraphicsDevice.DrawUserPrimitives<

[/size][size="2"][color="#2b91af"][color="#2b91af"]VertexPositionTexture[/color][/color]>[/size]

[size="2"]

(

[/size][size="2"][color="#2b91af"][color="#2b91af"]PrimitiveType[/color][/color].TriangleList, texTriP.GetTexTriPrism(), 0, texTriP.GetLength() / 3);[/size]

[size="2"]

pass.End();



}



transparencyFx.End();



graphics.GraphicsDevice.RenderState.AlphaBlendEnable =

[/size][size="2"][color="#0000ff"][color="#0000ff"]false[/color][/color];

I then get the following result when I run the application and it
works as properly in these viewing directions for instance:

[attachment=2459:transprism1.png]

[attachment=2460:transprism2.png]

But when it comes these viewing directions you can see that
two of the backside of the transparent textures in each image
aren´t visible any longer:

[attachment=2461:transprism3.png]

[attachment=2462:transprism4.png]

Why is that? How come one of the backsides is always visible while
the two others aren´t? I have deactivated Culling completely when I
am drawing the glass prism. How do you make every backside visible?
[/size]

Share this post


Link to post
Share on other sites
ayrton2388    100
Thing is, every time you want to render some transparent/semitransparent (using alpha-blend) models, you have to sort them 1st. You have to sort them by the distance from the camera, and then draw them backwards.

So.... you draw all your opaque models. Sort the transparent models/meshes/MeshParts/polygons , whatever they are . You turn on alpha blending, draw them backwards, and then turn off alpha blending.

Have a look at this.
http://forums.create.msdn.com/forums/p/82491/497908.aspx#497908

Or you can can do as i did.
Using a two pass rendering technique. You need a bit of knowledge about shaders.

* Pass 1: draw the solid part: alpha blending disabled, alpha test set to only accept the 100% opaque areas, and depth buffer enabled
* Pass 2: draw the fringes: alpha blending enabled, alpha test set to only accept pixels with alpha < 1, depth buffer enabled, depth writes disabled

Share this post


Link to post
Share on other sites
john13to    151
Yepp, it did work when I tried with the first solution by deactivating the
DepthBufferWriteEnable when drawing the transparent glass prism! =)

Thanks a million! =D

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