transparency problem

A place for users of OGRE to discuss ideas and experiences of utilitising OGRE in their games / demos / applications.
Post Reply
andreahmed
Kobold
Posts: 38
Joined: Wed Dec 31, 2014 2:26 am
x 2

transparency problem

Post by andreahmed »

I have the following shader with two passes and scene blend but I see those faces marked in black..

how would I maintain transparency and not see these faces in the picture ?

The material does two passes on cull faces anticlockwise and the other pass cull faces clockwise.

The shader does a dot product between the normal and the camera position and then modulate the transparency based on that result.

Code: Select all

#version 100
precision highp int;
precision highp float;

uniform float time;
uniform float touchX;
uniform float touchY;
uniform float touchZ;
uniform float line;



varying float  lightDiffuse;

void main()
{

    float rampLight =lightDiffuse;

    float light = (1.0 - rampLight) * 1.0;
    vec4 lightColor = vec4(1.0,1.0,1.0, 1.0);
    vec4 diffuseColor = lightColor * light;

    vec4 c;
    if(rampLight < 0.0 )
    {
        discard;
    }
    diffuseColor = smoothstep(vec4(0.0, 0.0, 0.0, 0.0), vec4(0.8, 0.8, 0.8, 0.8), vec4(diffuseColor));
    gl_FragColor = diffuseColor;

}




material Router
{
    technique
    {
        pass
        {

            scene_blend alpha_blend
            depth_write on
            depth_check on
            cull_hardware anticlockwise

            vertex_program_ref movingline_101_vs 
            {

            }

            fragment_program_ref movingline_101_fs
            {

            }
        }


        pass
        {


            scene_blend alpha_blend
            cull_hardware clockwise
            depth_write on
            depth_check on

            vertex_program_ref movingline_101_vs 
            {

            }

            fragment_program_ref movingline_101_fs
            {

            }
        }

    }
}
Image
xrgo
OGRE Expert User
OGRE Expert User
Posts: 1148
Joined: Sat Jul 06, 2013 10:59 pm
Location: Chile
x 168

Re: transparency problem

Post by xrgo »

This seems to be related: viewtopic.php?f=5&t=93737
The only solution I can see is to render without transparency (instead of transparent use black) and use ADD as scene blending
andreahmed
Kobold
Posts: 38
Joined: Wed Dec 31, 2014 2:26 am
x 2

Re: transparency problem

Post by andreahmed »

can you tell me the solution with the material script as an example ?

Thanks a lot for your fast reply
xrgo
OGRE Expert User
OGRE Expert User
Posts: 1148
Joined: Sat Jul 06, 2013 10:59 pm
Location: Chile
x 168

Re: transparency problem

Post by xrgo »

mmmm I don't use material scripts since years.. (using Ogre 2.1) but it might be something like this:

your shader must look like this:

Code: Select all

float NdotV = clamp( dot( nNormal, viewDir ), 0.0, 1.0 );
      float incidence = pow(1.0 - NdotV, 5);
      gl_FragColor.xyz = vec3(incidence);
      gl_FragColor.w = 1.0;
      
For the script I think you just have to change scene_blend alpha_blend for scene_blend add
andreahmed
Kobold
Posts: 38
Joined: Wed Dec 31, 2014 2:26 am
x 2

Re: transparency problem

Post by andreahmed »

Thanks for your fast reply

I have the following material

Code: Select all

material Router
{
    technique
    {
        pass
        {

            scene_blend add
            
 
            vertex_program_ref movingline_101_vs 
            {

            }

            fragment_program_ref movingline_101_fs
            {

            }
        }
 

    }
}
and the fragment shader

Code: Select all

varying float  lightDiffuse;

void main()
{

	float rampLight =lightDiffuse;
	
    float light = (1.0 - rampLight) * 1.0;
    vec4 lightColor = vec4(1.0,1.0,1.0, 1.0);
    vec4 diffuseColor = lightColor * light;
  
   
      float incidence = pow(1.0 - rampLight, 5);
      gl_FragColor.xyz = vec3(incidence);
      gl_FragColor.w = 1.0;

	  
	diffuseColor = smoothstep(vec4(0.0, 0.0, 0.0, 0.0), vec4(0.9, 0.9, 0.9, 0.9), vec4(diffuseColor));
    //gl_FragColor = diffuseColor;
     
}
but still I have the same artificats :S
xrgo
OGRE Expert User
OGRE Expert User
Posts: 1148
Joined: Sat Jul 06, 2013 10:59 pm
Location: Chile
x 168

Re: transparency problem

Post by xrgo »

is it just one object??
what if you remove the scene_blend entirely, does it look black? without the artifact?
andreahmed
Kobold
Posts: 38
Joined: Wed Dec 31, 2014 2:26 am
x 2

Re: transparency problem

Post by andreahmed »

yes it looks black, and its just one object in the scene. and there are no artifcats because there is no transparency
xrgo
OGRE Expert User
OGRE Expert User
Posts: 1148
Joined: Sat Jul 06, 2013 10:59 pm
Location: Chile
x 168

Re: transparency problem

Post by xrgo »

mmm I didn't know that add behaved that way (never actually used it xD), but it makes sense... so the only solution that comes to my mind is that you render only that object (without any scene_blend add/alpha so it looks black) in to a separate texture (you can use visibility mask or rendergroups), and then mix it with the rest of the scene in post process, that way you can use add and not get the artifact... pseudo code:

Code: Select all

vec4 restOfTheScene = texture( sceneSampler, uv0);
vec4 mySuperObject = texture( mySuperObjectSampler, uv0);
gl_FragColor = restOfTheScene + mySuperObject; //since its black and white it will look fine just by adding 
andreahmed
Kobold
Posts: 38
Joined: Wed Dec 31, 2014 2:26 am
x 2

Re: transparency problem

Post by andreahmed »

how would I render an object to a texture ? or should I render the scene into a texture ?
xrgo
OGRE Expert User
OGRE Expert User
Posts: 1148
Joined: Sat Jul 06, 2013 10:59 pm
Location: Chile
x 168

Re: transparency problem

Post by xrgo »

mm I don't have any code, its a bit different 2.1. Try to understand the compositor sample, or the ssao sample. its going to take you a while =/ but its a very useful knowledge, compositor is useful for may things =).
Maybe someone else has a code/script were they render the scene in two passes and then mixed them in post process? please!
Post Reply