billboard scene node : constant size ?

You are an experienced programmer and have a problem with the engine, shaders, or advanced effects? Here you'll get answers.
No questions about C++ programming or topics which are answered in the tutorials!
polylux
Posts: 267
Joined: Thu Aug 27, 2009 12:39 pm
Location: EU

Post by polylux »

agamemnus, once again, if you don't wanna do it with shaders, just use the distance from the camera to the object and scale it respectively.
beer->setMotivationCallback(this);
agamemnus
Posts: 283
Joined: Sun Jan 31, 2010 6:06 pm

Post by agamemnus »

I'm looking to avoid that kind of overhead. I don't want to re-scale all my billboard scene nodes once per frame... first the engine scales them down, then I scale them back up? Not very efficient.
polylux
Posts: 267
Joined: Thu Aug 27, 2009 12:39 pm
Location: EU

Post by polylux »

Like I said, the simplest and most-straightforward approach. Plus, scaling a billboard is not too much effort.
beer->setMotivationCallback(this);
sudi
Posts: 1686
Joined: Fri Aug 26, 2005 8:38 pm

Post by sudi »

Like i said before...

Code: Select all

create a scenenode.
create a meshbuffer holding a unit quad(easy scaling)
on render
   save the current projection and view matrix
   set a projection, view, and model to Identity
   project the 3d position of the billboard to the screen
   if billboard on screen
      render the quad at this position with desired size (can be done with a simple world matrix)
   restore view and projection matrix
We're programmers. Programmers are, in their hearts, architects, and the first thing they want to do when they get to a site is to bulldoze the place flat and build something grand. We're not excited by renovation:tinkering,improving,planting flower beds.
agamemnus
Posts: 283
Joined: Sun Jan 31, 2010 6:06 pm

Post by agamemnus »

Sudi wrote:Like i said before...

Code: Select all

create a scenenode.
create a meshbuffer holding a unit quad(easy scaling)
on render
   save the current projection and view matrix
   set a projection, view, and model to Identity
   project the 3d position of the billboard to the screen
   if billboard on screen
      render the quad at this position with desired size (can be done with a simple world matrix)
   restore view and projection matrix
set a projection, view, and model to Identity
You've already lost me there, so...
hendu
Posts: 2600
Joined: Sat Dec 18, 2010 12:53 pm

Post by hendu »

serengeor wrote:I taught that you might know some starter friendly tutorials, but eh, I will google them up when I need, its not like it would be hard for me :)
Nvidia has excellent docs. It's what I learned on, and I plan on continuing to write in Cg.

Also, I use cgc to compile them to whatever I need, thus there's no Cg dep on my final app. It can compile to almost any profile, glsl, hlsl, ARB assembly etc.
serengeor
Posts: 1712
Joined: Tue Jan 13, 2009 7:34 pm
Location: Lithuania

Post by serengeor »

hendu wrote:
serengeor wrote:I taught that you might know some starter friendly tutorials, but eh, I will google them up when I need, its not like it would be hard for me :)
Nvidia has excellent docs. It's what I learned on, and I plan on continuing to write in Cg.

Also, I use cgc to compile them to whatever I need, thus there's no Cg dep on my final app. It can compile to almost any profile, glsl, hlsl, ARB assembly etc.
I'm only interested in GLSL for now.

Edit: I think this would be a good place to start.
Working on game: Marrbles (Currently stopped).
agamemnus
Posts: 283
Joined: Sun Jan 31, 2010 6:06 pm

Post by agamemnus »

I looked at the billboard scene node draw function. Perhaps I could add something after "driver->setTransform(video::ETS_WORLD, core::IdentityMatrix);" to set the transformation such that the node is a constant size? Any ideas?

Code: Select all

void CBillboardSceneNode::render()
{
	video::IVideoDriver* driver = SceneManager->getVideoDriver();
	ICameraSceneNode* camera = SceneManager->getActiveCamera();

	if (!camera || !driver)
		return;

	// make billboard look to camera

	core::vector3df pos = getAbsolutePosition();

	core::vector3df campos = camera->getAbsolutePosition();
	core::vector3df target = camera->getTarget();
	core::vector3df up = camera->getUpVector();
	core::vector3df view = target - campos;
	view.normalize();

	core::vector3df horizontal = up.crossProduct(view);
	if ( horizontal.getLength() == 0 )
	{
		horizontal.set(up.Y,up.X,up.Z);
	}
	horizontal.normalize();
	horizontal *= 0.5f * Size.Width;

	core::vector3df vertical = horizontal.crossProduct(view);
	vertical.normalize();
	vertical *= 0.5f * Size.Height;

	view *= -1.0f;

	for (s32 i=0; i<4; ++i)
		vertices[i].Normal = view;

	vertices[0].Pos = pos + horizontal + vertical;
	vertices[1].Pos = pos + horizontal - vertical;
	vertices[2].Pos = pos - horizontal - vertical;
	vertices[3].Pos = pos - horizontal + vertical;

	// draw

	if ( DebugDataVisible & scene::EDS_BBOX )
	{
		driver->setTransform(video::ETS_WORLD, AbsoluteTransformation);
		video::SMaterial m;
		m.Lighting = false;
		driver->setMaterial(m);
		driver->draw3DBox(BBox, video::SColor(0,208,195,152));
	}

	driver->setTransform(video::ETS_WORLD, core::IdentityMatrix);

	driver->setMaterial(Material);

	driver->drawIndexedTriangleList(vertices, 4, indices, 2);
}
sudi
Posts: 1686
Joined: Fri Aug 26, 2005 8:38 pm

Post by sudi »

Well if you want to change the Billboard scenenode then just set the Projection matrix to orthogonal before rendering the billboard. But don't forget to change it back after rendering the billboard
We're programmers. Programmers are, in their hearts, architects, and the first thing they want to do when they get to a site is to bulldoze the place flat and build something grand. We're not excited by renovation:tinkering,improving,planting flower beds.
agamemnus
Posts: 283
Joined: Sun Jan 31, 2010 6:06 pm

Post by agamemnus »

Makes sense...

I can create a duplicate billboard scene node type with that kind of projection.

Anyway... looking at the code, got a Q. Does it make sense to do all those transformation operations PER NODE?
sudi
Posts: 1686
Joined: Fri Aug 26, 2005 8:38 pm

Post by sudi »

Actually all those transformation operations are done per vertex by your graphics card.

If i remember right opengl has two matrix slots one for the projection view and one for the model matrix. normally you only change the model matrix per node which makes sense since every model probably has a different location in the 3d world. The other matrix is only reset if you change the transform of view or projection...

btw i am probably wrong about the matrix slots^^
We're programmers. Programmers are, in their hearts, architects, and the first thing they want to do when they get to a site is to bulldoze the place flat and build something grand. We're not excited by renovation:tinkering,improving,planting flower beds.
agamemnus
Posts: 283
Joined: Sun Jan 31, 2010 6:06 pm

Post by agamemnus »

Wouldn't it make sense to keep the other transformations and set the target and up vector only once, though? Or is that not enough?
sudi
Posts: 1686
Joined: Fri Aug 26, 2005 8:38 pm

Post by sudi »

what?
We're programmers. Programmers are, in their hearts, architects, and the first thing they want to do when they get to a site is to bulldoze the place flat and build something grand. We're not excited by renovation:tinkering,improving,planting flower beds.
agamemnus
Posts: 283
Joined: Sun Jan 31, 2010 6:06 pm

Post by agamemnus »

Like... "horizontal = up.crossProduct(view);"
Post Reply