Volume Rendering

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?



// 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();
}

Beauty

06-03-2011 20:35:22

Hi ochensati,
nice to see your here in our Mogre community. :D

I am trying to get the ogre example code working with mogre.
Can you give us a link to the C++ code?

I admit that I do not have much experience with either, but would be happy to donate the code back when I am finished.
Everybody started from a basic level. So don't care.
It's nice that you want to publish ported code to our community. Just post it in the forum and I will add it to the wiki.

I understand that simplerenderable is not accessable from mogre
Do you know if SimpleRenderable is accessable by Ogre (C++) ?
Maybe this is a new entry for our TODO list.

I'm not shure what you want to do.
Billboards are "just" planes of 2 triangles which shows a texture.

Do you want to build a custom object?
In this case the class ManualObject is very fine and much more easy to handle than direct access to the buffers.
Look to its wiki page. There I added useful information about the usage of ManualObjects.
http://www.ogre3d.org/tikiwiki/ManualObject

volume texture
Do you mean 3D textures?
(2D textures are pictures. 3D textures define a material as 3D structure, which is useful e.g. for correct display of wooden looking objects.)
In case of 3D textures I have no idea. I just know it from a lesson in my university, but I never read about this for Ogre. (An exception is an Ogre fork which is specialised for fully destructable worlds.)

... Now I searched for this feature and it seems so that Ogre contains this feature. :shock:
You will get interesting search results when you search for site:ogre3d.org TEX_TYPE_3D in Google.

If you don't find a solution, write a post in the Ogre main forum.
It's a common Ogre question (independent of Mogre) and in the main forum are much more people who can help you.

Did you look to the ogre.log file?
Maybe there is an interesting warning or error inside.

By the way - it's interesting to see the PixelUtil class. I didn't know before.

Related to the buffer programming - maybe you find useful information here:
http://www.ogre3d.org/tikiwiki/Vertex+and+Index+Buffers