Alpha blending

A place for users of OGRE to discuss ideas and experiences of utilitising OGRE in their games / demos / applications.
Post Reply
kubatp
Gnome
Posts: 354
Joined: Tue Jan 06, 2009 1:12 pm
x 7

Alpha blending

Post by kubatp » Sun Sep 07, 2014 6:08 pm

Hi,
I am experiencing an interesting issue. I have a mesh which on sides have a partially transparent texture, mesh has another parts below, which should be visible.
From one side, everything is fine - I can see nontransparent parts from the texture and below the other parts of the mesh. Unfortunately from the other side, it displays the transparent texture and it doesnt display anything else behind.
Please see screenshot

Image

Does anyone give me an advice, what might be wrong here?
0 x

User avatar
Kojack
OGRE Moderator
OGRE Moderator
Posts: 7152
Joined: Sun Jan 25, 2004 7:35 am
Location: Brisbane, Australia
x 19

Re: Alpha blending

Post by Kojack » Sun Sep 07, 2014 8:30 pm

Looks like your material is doing depth writing or isn't in the transparent queue. What's the oar's material script look like?

A couple of possible fixes:
- make sure the oars are being put in the transparent queue so they render after the boats (set scene_blend alpha_blend in the pass and disable depth_write)
- or enable depth rejection to cull any transparent pixel in the oars. That is better for performance, but it may leave a semi transparent halo around the oars.
0 x

kubatp
Gnome
Posts: 354
Joined: Tue Jan 06, 2009 1:12 pm
x 7

Re: Alpha blending

Post by kubatp » Mon Sep 08, 2014 8:00 am

Hi Kojack,
thank you for reply.
My first question is simple - as far as I understand from your reply, there is no way to have transparent and solid textures in the same material?
The mesh currently uses just one material

Code: Select all

material Units.NavalTransport
{
	technique
	{
		pass
		{
		    scene_blend alpha_blend
			
		    fragment_program_ref unitcolor_ps_cg 
			{
			    param_named_auto displayed custom 1
			    param_named_auto pColor custom 2
			}			
			
			texture_unit
			{
				texture Units.NavalTransport.png
				tex_address_mode mirror
			}
			texture_unit
			{
				texture damage.png
			}
			texture_unit
			{
				texture Units.NavalTransportAlpha.png
			}

		}
	}
}
and this CG pixel shader

Code: Select all

float4 main(
	uniform float4 displayed,
	uniform float4 pColor,	
    uniform sampler2D texture : register(s0),
    uniform sampler2D texture2 : register(s1),
    uniform sampler2D alpha : register(s2),
	float2 uv0		: TEXCOORD0
	) : COLOR
{
   const float3 darkerColor = {0.222, 0.707, 0.071};
   float4 oColor;
   float4 oColorInitial = tex2D( texture, uv0);   
   float4 alphaColor = tex2D(alpha, uv0);   

   oColor = lerp(pColor, oColorInitial, oColorInitial.a); 
   
   if (displayed.x < 0.5)
   {
		uv0[0] = uv0[0] * 0.5 + displayed.y;
		uv0[1] = uv0[1] * 0.5 + displayed.z;
		float4 damaged = tex2D( texture2, uv0);      
		oColor = lerp(oColor, damaged, damaged.a * displayed.w);
   }
   
    if (displayed.x == 0.7
		|| displayed.x == 0.3)
	{
		if (oColorInitial.a == 1)
		{
			oColor = dot(darkerColor, oColor);           
		}
	}     
    
    oColor.a = alphaColor.a;
    return oColor;
}

0 x

Post Reply