View Full Version : rotating point sprites

milankoko

07-27-2008, 08:29 AM

I am trying to rotate a point sprite based on its normal and eye position. Here is what I got:

- coordinates of every point inside point sprite [-1,1] € R^2 space.

- center of point sprite

- point sprite normal

Now I have to check for if every (i,j)€[-1,1] is inside a 3D rotated circle - rotated ellipse in 2D projection. I could make do with an equation for rotated circle in arbitrary plane and check if (i,j) are inside a rotated ellipse. I have no idea how to calculate this or if its even possible.

I would welcome any other suggestions for making this work.

dletozeun

07-27-2008, 11:31 AM

If you have a point and a normal, you have the equation of the plane in which the circle or the ellipse is. Then you must compute two vectors on the plane to parametrized the equation of the circle or the ellipse using the center of the sprite as the origin.

But I am not sure to understand what represents your values i and j. They are scalar values and you want to check their location in 3D space...

milankoko

07-27-2008, 12:30 PM

I can calculate the plane on which the circle should lie. other parts are giving me headaches.

I'll try to describe the problem again. i and j are coordinates inside a sqaure in which I have to draw ellipse.

____________(1,1)

|...............|

|...............|

|.......*C......| C = center of point sprite. it has coordinates in 3D

|...............|

|___________|

(-1,-1)

So I have to test for every pair (i,j) from [-1,1]€R^2 if it falls into projection of that rotated ellipse around C or not. If it falls I draw it, otherwise not. Is it clearer now?

dletozeun

07-28-2008, 03:34 AM

Ok I got it now, so (i,j) is you ellipse parametrization inside the the square.

Conics are very far from me at the moment so i can only help you in a general way.

First I assume you are using a sahder to perform these operations that seems to be done per fragment.

Second, you will have to compute the normal at each sprite (what you have done already) plus a tangent vector which is a vector on the sprite. In you case the tangent vector could be one of the sprite edge. normals and tangent should be normalized and given to your vertex shader in object space.

You will also need the matrix Mw that transforms your vertices from object space to world space (actually, this one contains all translation, rotation, scale operations)

Then you will have to transform your tangent and normals vectors in world space and vertices too. This is important to have all the needed data in the SAME space.

So, say that (i,j,n) are the sprite basis vectors (stored in world space after Mw matrix multiplication - n is the normal vector) and (x,y,z) the world basis vectors.

Your vertices coordinates are in world space after multiplying then by the matrix Mw and you need them in the sprite space to check if then a fragment is in the ellipse or not. So you have to compute the matrix P that transform world coordinates into sprite space coordinates.

This matrix contains in each columns the vectors i,j and n respectively.

then:

sprite_space_coord = inverse(P) * world_space_coord.

after that, you use the coordinates sprite_space_coord to check if they are in the ellipse or not.

I hope this is quite understandable, don't hesitate to ask more questions. :)

milankoko

07-28-2008, 11:49 AM

thanks for this extensive post. But I do not think it addressed my problem completely. Its that projected ellipse that is giving me headaches. I was thinking I could do with some approximations even. Is there some sort of equation for a unit circle on an arbitrary plane in 3D space? I think that would suit me nicely.

This is what I want to do:

http://img369.imageshack.us/img369/1110/sampleig2.th.png (http://img369.imageshack.us/my.php?image=sampleig2.png)

dletozeun

07-28-2008, 01:16 PM

Don't try to calcule a circle equation in 3D space, this would surely give you headache. :)

A plane equation in 3D looks like this : ax + by + cz + d = 0 where a,b,c,d are reals. the plane equation is given by the sprite normal and a point on the sprite.

But, may be you have to read about linear algebra applied to 3D graphics, there are useful book dedicated to math for 3D. I think this could help you a lot to figure out.

CatDog

07-28-2008, 03:03 PM

What I see on the lower half of the picture is not possible with point sprites.

CatDog

oc2k1

07-28-2008, 07:53 PM

Sure, but there is a good approximation possible:

Calculate the view vector in texturespace, and use the tangent and bitangent, to shear, scale and rotate the texture coordinates.

In that case the vertex shader has to calculate the bounding box.

Only the Z values could be wrong, but thers could be also calculated with the fragment shader...

CatDog

07-29-2008, 01:07 AM

Ok. :)

Maybe I'm just old fashioned, but I wouldn't call that a "sprite" anymore.

CatDog

ZbuffeR

07-29-2008, 04:17 AM

Well a good old texture mapping would be enough...

milankoko

07-29-2008, 06:21 AM

Thanks for everyones opinions. I'm not convinced calculating bounding box is my only solution. What if I transform (i,j) into world space coordinates, rotate them appropriately and check if that world space point is inside the unit sphere around center point?

I imagine I would have to rotate the world space (i,j) point for angle that is the difference between normal vector and vector between eye position and center of point sprite. How do I get those angles to know how much to rotate around y and x axes?

scratt

07-29-2008, 08:46 PM

Why not just do it with billboards instead?

If you use some QUADS in a GPU buffer it's going to be as fast as PointSprites anyway, and a lot simpler.... unless I am missing something about your requirements, or this is a purely academic exercise....

I have often wondered about doing this by 'swizzling' the texture matrix in a shader, but can't help but think it's going to look a little messy.

dletozeun

07-30-2008, 12:28 AM

What if I transform (i,j) into world space coordinates, rotate them appropriately and check if that world space point is inside the unit sphere around center point?

I don't have a complete comprehension of your problem I think, But what you say looks very complicated, since you have to store a matrix for each sprite, to know their orientation relative to world space...

check if that world space point is inside the unit sphere around center point

I don't understand what you mean here, I though we were talking about discs not sphere...

The problem is just, you have a space bound to a sprite where it is easy to define the circle equation or an ellipse one. You do that because, it would very tricky to define the same thing in world space and would change for every sprite transformation.

Then all your points are in world space after modeling transformations, so you just need to move them from this last space to the sprite space.

You can do it just knowing the sprite space vectors in world space and this is done in a precomputational step when you compute normal and a tangent on each normal in object space.

milankoko

08-02-2008, 12:48 AM

I chose point sprites because I am dealing with very large datasets a need every byte of memory I can get from the GPU.

Yes, still no spheres, only discs. My mistake, sorry.

How do I calculate tangent and bitangent? What exactly do they tell me?

Now I had another idea. First I could calculate each fragments point in world space coordinates calculate distance to the plane of the disc, defined by a normal vector. if distance is less than some delta, then i could check if fragment should be displayed by calculating distance to center of point sprite: less than 1 its in, otherwise not. sound feasible?

dletozeun

08-02-2008, 11:57 AM

I don't know, I even don't know what point sprites are used for.

If tangent, binormal orientation on the tangent plane doesn't matter:

To find an arbitrary tangent, you can compute the cross product between the normal and the y axis for example and you will be sure that the resulting vector is orthogonal to the normal.

But you need to check if the normal is not parallel to y, otherwise, cross product is undefined. You can check it with various ways:

for example, test if x and z normal components are zero.

if the normal is parallel to y then, you do the same thing with the x axis and if it still fails, with the z axis. If it fails three time, you normal is the nil vector and you have a problem.

And DON'T forget to do all this job in a precomputational step, in object space especially if you have large data sets. Thus tangent and normal are independant of the point sprites orientation and you will then transform them with the modelview matrix.

Powered by vBulletin® Version 4.2.2 Copyright © 2015 vBulletin Solutions, Inc. All rights reserved.