Getting a billboard unaffected by perspective

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
EvilDavo
Posts: 17
Joined: Sun Sep 27, 2009 12:20 pm
Location: Australia

Getting a billboard unaffected by perspective

Post by EvilDavo »

I want to draw a 2D image that looks the same size no matter how far away it is, but still has depth as if 3D (like a billboard ).

I tried to do this with a billboard node, and just updated the image size based on the distance to the camera. It flickers from being imprecise, and I'm sure there's a cleaner, more efficient way to do it.

Any suggestions?
Thx
DtD
Posts: 264
Joined: Mon Aug 11, 2008 7:05 am
Location: Kansas
Contact:

Post by DtD »

Use 2d images?

~DtD
EvilDavo
Posts: 17
Joined: Sun Sep 27, 2009 12:20 pm
Location: Australia

Post by EvilDavo »

But then you don't get depth. I want the depth, as if part of the 3D world, but to be drawn with a constant size no matter where you look at it.

Basically, to behave exactly like a billboard, but with constant size
Abraxas)
Posts: 227
Joined: Sun Oct 18, 2009 7:24 am

Post by Abraxas) »

You can resize the bill depending on camera distance. I do that sow hen I zoom out, models get gradually replaced by little icons.
BlindSide
Admin
Posts: 2821
Joined: Thu Dec 08, 2005 9:09 am
Location: NZ!

Post by BlindSide »

I don't understand. If it doesn't change size then how is depth perceived?

Maybe getScreenCoordinatesFrom3DPosition will help but I'm unsure how you want to show "depth".
ShadowMapping for Irrlicht!: Get it here
Need help? Come on the IRC!: #irrlicht on irc://irc.freenode.net
roelor
Posts: 240
Joined: Wed Aug 13, 2008 8:06 am

Post by roelor »

I think he meanth correct position x&y on screen.

I'd probally know a way, but since I'm fairly new to irrlicht I would solve it the difficult way...

(get the direction to the point, place a billboard a fixed distance in that point. find out about drawing order later on. Do (almost) everything with the math.h libary...)
Ulf
Posts: 281
Joined: Mon Jun 15, 2009 8:53 am
Location: Australia

Post by Ulf »

Blindside wrote:I don't understand. If it doesn't change size then how is depth perceived?
That's exactly what I first thought.

Then I understood.. I think!

As an example, he wants some text to appear above every character (e.g. their name) in a 3D world.
He doesn't want the billboard to shrink as it moves in distance. He wants it the same size. The character may be smaller but the billboard should not be affected by depth. He wants a static size billboard.

I haven't even used billboards, I didn't actually know what they were before. But that's the only way I could understand it.

So actually, I suppose he needs the billboard to get large as it moves deeper.

So, what Abraxas) was saying is the answer.
I can hear birds chirping
:twisted:

I live in the Eye of Insanity.
BlindSide
Admin
Posts: 2821
Joined: Thu Dec 08, 2005 9:09 am
Location: NZ!

Post by BlindSide »

If that's the case then he should go with draw2DImage and getScreenCoordinatesFrom3DPosition.
ShadowMapping for Irrlicht!: Get it here
Need help? Come on the IRC!: #irrlicht on irc://irc.freenode.net
Ulf
Posts: 281
Joined: Mon Jun 15, 2009 8:53 am
Location: Australia

Post by Ulf »

Ok cool. That's something I could also use in my 2D engine I suppose.
Though.. I don't really need depth. Maybe if I implement isometric projection.
Hope that helps you EvilDavo
I can hear birds chirping
:twisted:

I live in the Eye of Insanity.
EvilDavo
Posts: 17
Joined: Sun Sep 27, 2009 12:20 pm
Location: Australia

Post by EvilDavo »

Sorry for my being confusing.
I seem to be that way when it comes to forum stuff.

Anyway, ur right Ulf about the size thing. My thinking was, I wanted it to have static size, but also be occluded by walls and such - so a brick wall in front would block it. 2D wouldn't do that. Unless it could use depth buffer or something. That's why I wanted to go with billboards, they're simpler.

I reckon Abraxas)'s idea is right - that's what I was thinking initially anyway, to scale the billboard based on distance to make it look like it's a static size. Guess I just need to improve the maths on it to stop it from "flickering" the scale of the image as I move or look around.

Sorry, that probably still doesn't make sense. This is a really annoying problem to explain.

I might just have to live with the "flicker", it's not that bad.
Thx for suggestions, and helping me think about the problem more clearly. I'll keep watching this post just incase there are any new ideas.
Ulf
Posts: 281
Joined: Mon Jun 15, 2009 8:53 am
Location: Australia

Post by Ulf »

EvilDavo wrote:Sorry, that probably still doesn't make sense. This is a really annoying problem to explain.
It makes sense.

Your original quote
I tried to do this with a billboard node, and just updated the image size based on the distance to the camera. It flickers from being imprecise, and I'm sure there's a cleaner, more efficient way to do it.
So I suppose you had the right idea, but we forgot the real problem is flickering.
Guess I just need to improve the maths on it to stop it from "flickering" the scale of the image as I move or look around.
Maybe that is true in some way.
But how do you mean flickering.
When the perspective is not moving and the objects (billboards) are stationary, do you get flickering of all the billboards?
I can hear birds chirping
:twisted:

I live in the Eye of Insanity.
EvilDavo
Posts: 17
Joined: Sun Sep 27, 2009 12:20 pm
Location: Australia

Post by EvilDavo »

When the perspective is not moving and the objects (billboards) are stationary, do you get flickering of all the billboards?
No. It's not a technical problem. It's the small inaccuracy. So moving camera a little, it might suddenly appear 1 pixel bigger. Then moving again makes it return to the right size. It flickers between the two when moving or looking around with camera. I have a suspicion it can't be calculated in a way that doesn't have this effect.

The whole reason I wanted this was for something remotely like the way Blender draws vertex points. They seem to be billboards, as they intersect geometry. I just looked closer again, and realised that they "flicker" too in a similar way. Suddenly I don't feel so bad about the flickering.

On the bright side
For larger images, the flicker effect is negligible, just using

Code: Select all

float x;
x = camera->getPosition().distanceFrom( billboard->getPosition() );
x *= 0.005; // make it smaller
billboard->setSize( dimension2d<f32> (x,x) );
Thx for the help. Nothing gets your head around a problem better than trying to explain it to people and discuss it. Sorry to have wasted your time.
sio2
Competition winner
Posts: 1003
Joined: Thu Sep 21, 2006 5:33 pm
Location: UK

Post by sio2 »

remotely like the way Blender draws vertex points. They seem to be billboards, as they intersect geometry
You have a 3D position for your vertex. Put it through the World*View*Projection matrix to obtain a clipspace coord. Set the Z of each corner of your 2D screenspace billboard to clipspace Z and the billboard will then always be the same size on-screen but will effectively be placed at the same clipspace Z position in the scene as the vertex it is attached to and should therefore be (almost) correctly depth-tested against the scene.

If you're happy with your current solution then maybe you should stick to that. My solution requires a bit of messsing about with mesh vertices, maybe your own billboard shader, and setting correct device state.
EvilDavo
Posts: 17
Joined: Sun Sep 27, 2009 12:20 pm
Location: Australia

Post by EvilDavo »

Something like this?

Code: Select all

vector3df point( 5,5,2 );

matrix4 viewMatrix;
viewMatrix = driver->getTransform( ETS_VIEW ); // get view projection matrix


viewMatrix.transformVect( point ); // transform the point by the view matrix.

// point is now in viewspace

...
Well... that's as far as I got. Bit confused with:
Set the Z of each corner of your 2D screenspace billboard to clipspace Z
How do you affect the 2D screenspace of some 3D geometry?
Post Reply