The triangle base projection texture

A place to show off your latest screenshots and for people to comment on them. Only start a new thread here if you have some nice images to show off!
User avatar
akilar
Greenskin
Posts: 138
Joined: Wed Jun 20, 2007 11:42 am
Location: Taiwan
x 17

The triangle base projection texture

Post by akilar »

Hi! folks:

The add frustum pass projection texture have some weak point:
1.Increase Triangle count(Multi Pass)
2.maybe project over two

I use unique triangle base to project the texture, it's can solve these problem,
it's weak point:
1.Need to do Dynamic collision(AABB with Triangles).(maybe bullet btBvhTriangleMeshShape processAllTriangles is the best solution)
2.lock vertex buffer and texture coordinate buffer.

how to do:
1.Do collide process to get the intersect triangles.
2.Lock and fill vertex buffer.
3.lock and fill Recalculate UV to texture coordinate buffer.

the Recalculate UV formula is here:
TranslateMatrix*ScaleMatrix*RotMatrix*DestUV;

the sample code is here:

Code: Select all

bool FillHardwareBuffers(const std::vector<Ogre::Real>& NewVertexBuffer)
{
	if(!NewVertexBuffer.size())
		return false;

	Ogre::HardwareVertexBufferSharedPtr spVertexBuffer = mRenderOp.vertexData->vertexBufferBinding->getBuffer(VERTEX_DECLARATION_POSITION);	
	Ogre::Real* pRealPos = static_cast<Ogre::Real*>(spVertexBuffer->lock(Ogre::HardwareBuffer::HBL_DISCARD));
	if(pRealPos)
	{	
		memcpy(pRealPos, &(NewVertexBuffer)[0], mRenderOp.vertexData->vertexCount*3*sizeof(Ogre::Real));
		spVertexBuffer->unlock();
	}
	Ogre::HardwareVertexBufferSharedPtr spTexcoordsVertexBuffer = mRenderOp.vertexData->vertexBufferBinding->getBuffer(
		VERTEX_DECLARATION_TEXTURE_COORDINATES);
	Ogre::Real* pRealUV = static_cast<Ogre::Real*>(spTexcoordsVertexBuffer->lock(Ogre::HardwareBuffer::HBL_DISCARD));
	if(pRealUV)
	{	
		Ogre::Matrix4 RotMat = Ogre::Matrix4::IDENTITY;
		RotMat.makeTransform(Ogre::Vector3::ZERO, Ogre::Vector3::UNIT_SCALE,
			Ogre::Quaternion(Ogre::Degree(-90.0f), Ogre::Vector3::UNIT_X));

		Ogre::Matrix4 TransMat = Ogre::Matrix4::IDENTITY;
		TransMat.setTrans(Ogre::Vector3(0.5f, 0.5f, 0.0f));
		Ogre::Vector3 Size = mBox.getHalfSize();				
		Ogre::Vector3 ScaleFactor;
		ScaleFactor.x = -0.5f / Size.x; 
		ScaleFactor.y = -0.5f / Size.z; 
		ScaleFactor.z = 1.0f /(1000.0f+10.0f);
		Ogre::Matrix4 ScaleMat = Ogre::Matrix4::IDENTITY;
		ScaleMat.setScale(ScaleFactor);
				
		std::vector<Ogre::Real>::const_iterator it = NewVertexBuffer.begin();
		Ogre::Vector3 DestUVW;
		while(it != NewVertexBuffer.end())
		{	
			DestUVW.x = (*it);
			DestUVW.y = (*(it+1));
			DestUVW.z = (*(it+2));
			DestUVW = TransMat*ScaleMat*RotMat*DestUVW;
			*pRealUV++ = DestUVW.x;
			*pRealUV++ = DestUVW.y;
			it += 3;
		}
		spTexcoordsVertexBuffer->unlock();
	}
	return true;
}
the demo video is here:


welcome to my blogger, thanks. :D
http://makedreamvsogre.blogspot.com/
User avatar
duststorm
Minaton
Posts: 921
Joined: Sat Jul 31, 2010 6:29 pm
Location: Belgium
x 80

Re: The triangle base projection texture

Post by duststorm »

It works very well, but I wonder: is this technique not disastrous for the framerate?
What do you feed it with the newVertexBuffer? From what I can see, I assume you only change vertex uv coordinates, so are the pixel values of the decal you want to project somewhere in the texture already?
Developer @ MakeHuman.org
User avatar
Xavyiy
OGRE Expert User
OGRE Expert User
Posts: 847
Joined: Tue Apr 12, 2005 2:35 pm
Location: Albacete - Spain
x 87

Re: The triangle base projection texture

Post by Xavyiy »

Pretty cool akilar.

A wiki entry would be perfect ;)

Xavier
User avatar
duststorm
Minaton
Posts: 921
Joined: Sat Jul 31, 2010 6:29 pm
Location: Belgium
x 80

Re: The triangle base projection texture

Post by duststorm »

Developer @ MakeHuman.org
User avatar
akilar
Greenskin
Posts: 138
Joined: Wed Jun 20, 2007 11:42 am
Location: Taiwan
x 17

Re: The triangle base projection texture

Post by akilar »

Yes, It's the same technique.
duststorm wrote:This blogpost seems very related: http://blog.wolfire.com/2009/06/how-to-project-decals/
User avatar
akilar
Greenskin
Posts: 138
Joined: Wed Jun 20, 2007 11:42 am
Location: Taiwan
x 17

Re: The triangle base projection texture

Post by akilar »

Thanks for your response.
Xavyiy wrote:Pretty cool akilar.

A wiki entry would be perfect ;)

Xavier
fd9_
Halfling
Posts: 64
Joined: Wed Aug 20, 2008 9:20 pm
x 22

Re: The triangle base projection texture

Post by fd9_ »

Can you provide the full source code for the demo?
User avatar
akilar
Greenskin
Posts: 138
Joined: Wed Jun 20, 2007 11:42 am
Location: Taiwan
x 17

Re: The triangle base projection texture

Post by akilar »

Sorry, other source code is commerical use, you can see the http://www.ogre3d.org/tikiwiki/tiki-ind ... e=Cookbook
to known how process immediate process hardware buffer, just call FillHardwareBuffers function to process fill position and texture coordinates buffer.
fd9_ wrote:Can you provide the full source code for the demo?