ochensati
03-03-2011 21:38:42
I am trying to get the ogre example code working with mogre. I admit that I do not have much experience with either, but would be happy to donate the code back when I am finished. I understand that simplerenderable is not accessable from mogre, so I am planning on just setting up a set of billboards.
Right now, I have just loaded the ogre head and am trying to assign the volume texture to the ogre head. I can show the untextured ogrehead just fine, but when I apply the texture, the ogrehead disappears. Can you tell me what I am doing wrong?
Right now, I have just loaded the ogre head and am trying to assign the volume texture to the ogre head. I can show the untextured ogrehead just fine, but when I apply the texture, the ogrehead disappears. Can you tell me what I am doing wrong?
// Create dynamic texture
ptex = TextureManager.Singleton.CreateManual("DynaTex", "General", TextureType.TEX_TYPE_3D, 64, 64, 64, 0, PixelFormat.PF_A8R8G8B8);
// Load ogre head
Entity head = sceneMgr.CreateEntity("head", "ogrehead.mesh");
fnode.AttachObject(head);
generateCloud();
MaterialPtr material = CreateVolumeMaterial("DynaTex");
head.SetMaterial(material );
root.RenderOneFrame();
}
private MaterialPtr CreateVolumeMaterial(string TextureName)
{
// Create a brand new private material
if (!ResourceGroupManager.Singleton.ResourceGroupExists("VolumeRenderable"))
{
ResourceGroupManager.Singleton.CreateResourceGroup("VolumeRenderable");
}
MaterialPtr material = MaterialManager.Singleton.Create(TextureName, "VolumeRenderable", false); // Manual, loader
// Remove pre-created technique from defaults
material.RemoveAllTechniques();
// Create a techinique and a pass and a texture unit
Technique technique = material.CreateTechnique();
Pass pass = technique.CreatePass();
TextureUnitState textureUnit = pass.CreateTextureUnitState();
// Set pass parameters
pass.SetSceneBlending(SceneBlendType.SBT_TRANSPARENT_ALPHA);
pass.DepthWriteEnabled = false;
pass.CullingMode=CullingMode.CULL_NONE;
pass.LightingEnabled=false;
// Set texture unit parameters
textureUnit.SetTextureAddressingMode(TextureUnitState.TextureAddressingMode.TAM_CLAMP );
textureUnit.SetTextureName(TextureName,TextureType. TEX_TYPE_3D);
textureUnit.SetTextureFiltering(TextureFilterOptions. TFO_TRILINEAR);
return material;
}
private unsafe void generateCloud()
{
HardwarePixelBufferSharedPtr buffer = ptex.GetBuffer(0, 0);
buffer.Lock(HardwareBuffer.LockOptions.HBL_NORMAL);
PixelBox pb = buffer.CurrentLock;
IntPtr pbptr = pb.data;
UInt32* pData = (UInt32*)pbptr;
for (uint z = pb.box.front; z < pb.box.back; z++)
{
for (uint y = pb.box.top; y < pb.box.bottom; y++)
{
for (uint x = pb.box.left; x < pb.box.right; x++)
{
if (z == pb.box.front || z == (pb.box.back - 1) || y == pb.box.top || y == (pb.box.bottom - 1) ||
x == pb.box.left || x == (pb.box.right - 1))
{
// On border, must be zero
pData[x] = 0;
}
else
{
PixelUtil.PackColour(new ColourValue(1, 0, 0), PixelFormat.PF_A8R8G8B8, pData+x);
}
}
pData += pb.rowPitch;
}
pData += pb.SliceSkip;
}
buffer.Unlock();
}