Perhaps the pseudocode helps.
Code: Select all
for each object that should be transparent with only one surface
disable its color writes
draw it
enable its color writes
draw it
done
Code: Select all
for each object that should be transparent with only one surface
disable its color writes
draw it
enable its color writes
draw it
done
Code: Select all
/*
Simple shader with Alpha.
keywords: Alpha
date: 20130109
*/
// GLSL Vertex shader
float4x4 mWorld;
float4x4 mWorldViewProj: WorldViewProjection;
float4x4 mView : WorldView;
float4x4 mWorldInverseTranspose;
float fAlpha;
float3 LightPosition; // (0.0, 10.0, 4.0)
float3 lightVec;
texture _texture;
sampler Texture =
sampler_state
{
Texture= <_texture>;
};
struct VS_INPUT
{
float4 position:POSITION;
float3 normal:NORMAL;
float2 TexCoord:TEXCOORD0;
float3 tangent:TANGENT;
};
struct VS_OUTPUT
{
float4 position:POSITION;
float2 TexCoord:TEXCOORD0;
};
struct PS_OUTPUT
{
float4 color:COLOR;
};
VS_OUTPUT mainVS(VS_INPUT In)
{
VS_OUTPUT Out;
Out.position = mul(In.position, mWorldViewProj);
Out.TexCoord = In.TexCoord;
return Out;
}
PS_OUTPUT mainPS(VS_OUTPUT In)
{
PS_OUTPUT Out;
if ( fAlpha != 0.0 )
{
float4 col = tex2D(Texture, In.TexCoord);
Out.color = float4(col.xyz, fAlpha);
}
else
Out.color = float4(0.0, 0.0, 0.0, 0.0);
return Out;
}
technique Gooch {
pass p0 {
CullMode = None;
VertexShader = compile vs_2_0 mainVS();
PixelShader = compile ps_2_0 mainPS();
}
}
technique GoochforEight {
pass p0 {
CullMode = None;
PixelShader = compile ps_2_0 mainPS();
SrcBlend=Srcalpha;
destblend=invsrcalpha;
}
}
Everything will be in correct order even with overlaps. The Z buffer is taking care of that.robmar wrote:okay but what happens if a non-transparent object partially overlaps a transparent object? Will the transparent object get drawn over the non-transparent, even though the non-transparent is in front of it?
If you enable Z-writing for a transparent part, you will always get artifacts. I get tired of repeating thisWhy should a torus mesh cause these artifacts (not just a torus mesh, but also the coke can mesh I tried)?
More than one surface. It's not a flat cardboard made to look like it's 3d, it's a real 3d "glass" object with more surfaces than one.And its not my shader, as why should the simplest of shaders have problems with these artifacts, just simply passing the textels through the shader and only changing the alpha value?
This is really what I would like to understand, why is this happening?
LOL, you're right. I meant no disrespect in it. For all I know you could be a professional 3d modeler. But I really meant it for the poster more than for you.hendu wrote:How nice of you to imply I bet I have more experience than you. (I too can do ad-hom!)
Absolutely I could be wrong. Let's wait for the model to be posted.