8Bit alpha texture

Anything and everything that's related to OGRE or the wider graphics field that doesn't fit into the other forums.
Post Reply
Shem
Gnoblar
Posts: 13
Joined: Fri Feb 16, 2018 9:32 am

8Bit alpha texture

Post by Shem » Wed Mar 14, 2018 6:02 pm

I have seen this topic being discussed here many times but I am unable to find a cure to my illness.
I have an 8bit alpha image dynamically created in memory every frame.
I am trying to use it to 'punch holes' in an rtt texture on a material programmatically. I was successful in doing so with a static 32 bit alpha image (white rgb) but since I try to reduce dma to gpu I need to do this using an 8bit image when I use a dynamic image.

I have this in code:

Code: Select all

		
		m_AlphaTexture8Bit =
			TextureManager::getSingleton().createManual(
				"AlphaTex8Bit",
				ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME,
				TEX_TYPE_2D,
				width, height,
				0,
				PF_A8,
				TU_DYNAMIC_WRITE_ONLY_DISCARDABLE
			);
			
		Ogre::MaterialPtr renderMat =
			Ogre::MaterialManager::getSingleton().create(
				"RttMat",
				Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
		TextureUnitState* ptus;
		renderMat->getTechnique(0)->getPass(0)->setSceneBlending(SBT_TRANSPARENT_ALPHA);
		ptus = renderMat->getTechnique(0)->getPass(0)->createTextureUnitState("RttTex");
		ptus = renderMat->getTechnique(0)->getPass(0)->createTextureUnitState("AlphaTex8Bit");
		ptus->setIsAlpha(true);			
			
			


I have tried using all sort of Colour Operations and Alpha Operations on the material texture units. All have failed.

Thanks in advance
0 x

Shem
Gnoblar
Posts: 13
Joined: Fri Feb 16, 2018 9:32 am

Re: 8Bit alpha texture

Post by Shem » Thu Mar 15, 2018 11:21 am

If I use an 8Bit png it works. 8Bit dynamic texture fails.

Code: Select all

		ptus = renderMat->getTechnique(0)->getPass(0)->createTextureUnitState("Material_alpha_blend.png"); //works
		//ptus = renderMat->getTechnique(0)->getPass(0)->createTextureUnitState("AlphaTex8Bit");//fails
		ptus->setColourOperation(LBO_ALPHA_BLEND);
		ptus = renderMat->getTechnique(0)->getPass(0)->createTextureUnitState("RttTex");
		ptus->setColourOperationEx(LBX_BLEND_CURRENT_ALPHA);
The RttTex is also dynamic so what am I missing?
0 x

Shem
Gnoblar
Posts: 13
Joined: Fri Feb 16, 2018 9:32 am

Re: 8Bit alpha texture

Post by Shem » Thu Mar 15, 2018 11:46 am

Finally !!! After so many hours (and days).

Saving the dynamic PF_A8 image to disk I noticed that it was converted to 32bit. This in turn got me thinking that the alpha blend texture should also be 32bit even though it should all be 8bit.

This is the code:

Code: Select all

		m_AlphaTexture8Bit =
			TextureManager::getSingleton().createManual(
				"AlphaTex8Bit",
				ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME,
				TEX_TYPE_2D,
				width, height,
				0,
				PF_A8R8G8B8,
				TU_DYNAMIC_WRITE_ONLY_DISCARDABLE
			);

		//Create screen rect
		m_ScreenRect = new Rectangle2D(true);
		m_ScreenRect->setCorners(-1.0, 1.0, 1.0, -1.0);//Use this to cover the whole screen
		m_ScreenRect->setBoundingBox(Ogre::AxisAlignedBox::BOX_INFINITE);
		m_ScreenRect->setVisible(false);
		m_SceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(m_ScreenRect);

		//Create screen material and bing technique to rtt texture
		Ogre::MaterialPtr renderMat =
			Ogre::MaterialManager::getSingleton().create(
				"RttMat",
				Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
		TextureUnitState* ptus;
		
		ptus = renderMat->getTechnique(0)->getPass(0)->createTextureUnitState("AlphaTex8Bit");
		ptus->setColourOperation(LBO_ALPHA_BLEND);
		ptus = renderMat->getTechnique(0)->getPass(0)->createTextureUnitState("RttTex");
		ptus->setColourOperationEx(LBX_BLEND_CURRENT_ALPHA);
I think this would have solved this issue as well:
viewtopic.php?t=77948
0 x

paroj
OGRE Team Member
OGRE Team Member
Posts: 739
Joined: Sun Mar 30, 2014 2:51 pm
x 112
Contact:

Re: 8Bit alpha texture

Post by paroj » Thu Mar 15, 2018 1:41 pm

the specified format is just a hint, see:
https://ogrecave.github.io/ogre/api/1.1 ... 9db4bac3a0
the manager reserves the right to create a different format if the one you select is not available in this context.
so you have to check the returned texture to get the actual format, which depends on the RenderSystem. The GL* Systems should support 8bit alpha textures.
1 x

Shem
Gnoblar
Posts: 13
Joined: Fri Feb 16, 2018 9:32 am

Re: 8Bit alpha texture

Post by Shem » Thu Mar 15, 2018 2:32 pm

the specified format is just a hint, see:
https://ogrecave.github.io/ogre/api/1.1 ... 9db4bac3a0
I think I read this in one of the posts in this forum but did not think it would apply to me. I'm using OpenGL 3+ and a Quadro k4000. Saving the Ogre::Image to disk is what alerted me to the issue and that happens before blitting to the texture.

In any case, thanks for clearing that up paoj
0 x

Post Reply