| 2008-12-08 04:36:58 | Bit of code takes care of alpha channel transparency for avatars. |
|---|---|
| Posted By: Virtual World Join Date: 2008-10-19 Location: WESTERN SAHARA |
During testing with the idealistviewer I noticed alpha channel worked and was respected when applied to prims. When trying to get a mesh avatar in the viewer to work the alpha channel wasn't respected and showed black.
Teravus pointed something out, after a bit of experimenting with the code I made the following changes in order to make it work. There was a section commented out in BaseIdealistViewer.cs:
// Test Avatar Ruth mesh
{
av.GetMesh(0).GetMeshBuffer(j).Material.Texture1 = texDriver; AnimatedMesh av = smgr.GetMesh("sydney2.x");int mbcount = av.GetMesh(0).MeshBufferCount;for (int j = 0; j < mbcount; j++)Texture texDriver = driver.GetTexture(j.ToString() + "-" + avatarMaterial);if (texDriver != null)else av.GetMesh(0).GetMeshBuffer(j).Material.Texture1 = driver.GetTexture(avatarMaterial); av.GetMesh(0).GetMeshBuffer(j).Material.SpecularColor = av.GetMesh(0).GetMeshBuffer(j).Material.AmbientColor = av.GetMesh(0).GetMeshBuffer(j).Material.EmissiveColor = av.GetMesh(0).GetMeshBuffer(j).Material.Shininess = 0.80f; } new Color(255, 150, 150, 150);new Color(255, 110, 110, 110);new Color(255, 125, 125, 125);// We need to flip the normals since it's a boned mesh. smgr.MeshManipulator.FlipSurfaces(av.GetMesh(0));
I put in this line:
av.GetMesh(0).GetMeshBuffer(j).Material.MaterialType = MaterialType.TransparentAlphaChannelRef;
also had to change "sydney2.x" with the name of the model I'm using
The result looks like this: // Test Avatar Ruth mesh {
av.GetMesh(0).GetMeshBuffer(j).Material.Texture1 = texDriver;
AnimatedMesh av = smgr.GetMesh("avatarmodel.x");int mbcount = av.GetMesh(0).MeshBufferCount;for (int j = 0; j < mbcount; j++)Texture texDriver = driver.GetTexture(j.ToString() + "-" + avatarMaterial);if (texDriver != null)else av.GetMesh(0).GetMeshBuffer(j).Material.Texture1 = driver.GetTexture(avatarMaterial); av.GetMesh(0).GetMeshBuffer(j).Material.MaterialType = av.GetMesh(0).GetMeshBuffer(j).Material.SpecularColor = av.GetMesh(0).GetMeshBuffer(j).Material.AmbientColor = av.GetMesh(0).GetMeshBuffer(j).Material.EmissiveColor = av.GetMesh(0).GetMeshBuffer(j).Material.Shininess = 0.80f; } MaterialType.TransparentAlphaChannelRef;new Color(255, 150, 150, 150);new Color(255, 110, 110, 110);new Color(255, 125, 125, 125);// We need to flip the normals since it's a boned mesh. smgr.MeshManipulator.FlipSurfaces(av.GetMesh(0)); avmeshsntest = smgr.AddAnimatedMeshSceneNode(av); avmeshsntest.JointMode = JointUpdateOnRenderMode.Control;//avmeshsntest.SetMaterialFlag(MaterialFlag.NormalizeNormals,true); // Read the Binary Asset Animation format. System.IO.
{
BinaryReader br = new BinaryReader(File.Open(m_startupDirectory + "\\" + Util.MakePath("media", "materials", "textures", "") + "\\coolfile.an",FileMode.Open));byte[] arr = new byte[(int)br.BaseStream.Length + 20];int pos = 0;int length = (int)br.BaseStream.Length;int)br.BaseStream.Length)-1);
arr = br.ReadBytes(((
}
I hope one of the programmers can integrate this in the code so alpha transparency will work for avatars in general. This isn't a big fix as my avatar is now 3 times the size of a sim and upside down below the terrain but it does have perfect alpah channel transparency working. |
| 2008-12-10 02:37:23 | Re: Bit of code takes care of alpha channel transparency for avatars. |
|---|---|
| Posted By: Virtual World Join Date: 2008-10-19 Location: WESTERN SAHARA | Made improvements in regards to TransparentAlphaChannelRef; This parameter didn't seem to be the correct one to use in order to create avatars because of the way it reads alpha channels. The main reason for this is because how it handles blending. It reads the texture in pixels, value between 0 and 256. If the value is over 127 it places a pixel on the mesh, if it's under 127 it doesn't. The text below gives more information.
To render a logo with sharp edges uses video::EMT_TRANSPARENT_ALPHA_CHANNEL_REF To render a logo with blunt (blended) edges uses instead video::EMT_TRANSPARENT_ALPHA_CHANNEL
//! Makes the material transparent based on the texture alpha channel. When using EMT_TRANSPARENT_ALPHA_CHANNEL_REF, the result for the test I am doing with an avatar wasn't very good, the black dissapeared and became transparent yes but the borders weren't good at all. They looked dirty, black aven, in particular at the places where hair is used for the avatar. It doesn't provide proper transparency. Then I found out about EMT_TRANSPARENT_ALPHA_CHANNEL this function uses a blending technique for the alpha channel which results in a much cleaner blend between the alpha and the actual texture map. The hair really looks good and the alpha channel is full respected. It could be that (like the description says) transparentalphachannelref is better for plants and leaves etc... because it loads faster but it can't be used for things like hair or textures where you have a lot of detail and need smooth edges. After a lot of testing I got a model in the idealistviewer with a decent alpha channel that gives great quality. Only problem I have now is the entire model seems to be semi transparent, I can look through it, the textures are applied ok but when using materialtype.transparentalphachannel the model turns into an object you can see through. I don't have a clue how to make it look solid, it does look solid when using transparentalphachannelref but not with transparentalphachannel.
|

