I read few topics about the same problem of alpha blending, but I didn't find a good solution for my problem. Further the last one was in 2009, so I think a new discution should help a lot of people.
I notice that I'm not sure the method I use is the best method. Let me explain what I want to do.
Note : Sorry for my english, it is not perfect.
I'm focusing on a character's hair rendering. My aim is to have this :
So I import my head into Ogre. In the file leonard.mesh, all the hairs are in the same mesh.
Each vertex of the mesh has texture coordinates which define :
- the position in the texture
- and the position in the transparency map associated
I write the file leonard.material to specify my own fragment shader. In it, I pick up the alpha factor into the transparency map and I associate it to the texture color.
Code: Select all
#version 330
uniform sampler2D texture, transparencyMap;
void main(void)
{
vec4 alphaColor = texture2D(transparencyMap, gl_TexCoord[0].st); // the color onto the transparency map
vec3 rgbColor = vec3(texture2D(texture, gl_TexCoord[0].st));
float alphaFactor = alphaColor.r;
gl_FragColor = vec4(rgbColor, alphaFactor);
}
Therefore, I would like to :
- 1 : Sort my vertices by alpha factor.
- 2 : Draw all the opaque pixels with depth-test active.
- 3 : Turn the depth-tes OFF.
- 4 : Draw the transparent pixel.
- 5 : Turn the depth-test ON for the followings elements of the scene.
I spoke about vertices because a lot of guys said me that alpha blending is a CPU operation.
One part of this problem is I don't know how to split my different vertices from the Ogre entity, and I don't know how to say to Ogre to draw these vertices with a certain order.
Moreover, I don't know if my method is the good one. But I read everywhere that there is not a good solution to this problem.
I hope you will enjoy my topic and find some solutions with me.
Have a good day !