Apollonio

01-07-2016, 10:21 AM

Hi everyone

given:

- a textured point sprite (a circle) in 3D space with a normal

- a texture atlas with each sprite being a different rotation of that circle along X/Y axes (Z useless). first row all Y rotation, first column all X, and all the other combinations along the sheet.

I'd like to offset the right sprite for the point from the texture atlas given the position of the camera in the world.

I want to use textured sprites instead of quads for achieve maximum performance and given that i'm using VBO all the work must be done in vertex/fragment shader.

I'm bumping into several problems and would like to ask about some hints on this.

:biggrin-new:

(READ THIS ONLY AS AN EXTRA AND IF YOU HAVE TIME)

I write here some of the approaches I've thinked of and tryed.

- build a solidal system of axes to the normal (being the positive Z-axis, 1,0,0 for example). Get the angles between normal and the projection of the camera vector (from camera to the point, all in 3D) in the x-z plane, and y-z plane. These represent my rotation around Y and X axis (not properly, a sort of approximation).

problem -> this system works only on some cases and if you keep looking at the point (obviously). For example if you move near the X-Y plane looking at the point, you will get values not representative of the current rotation.

- given an X-Y-Z plane like up here, where Z is the normal vector, compute in which part of the unit circle the camera vector falls...then just map a sector to a sprite (i don't need many rotations...).

In this case i don't have any idea about how to check in which sector on the sphere the point falls, nor mapping efficiently without an horrible if if if else....

given:

- a textured point sprite (a circle) in 3D space with a normal

- a texture atlas with each sprite being a different rotation of that circle along X/Y axes (Z useless). first row all Y rotation, first column all X, and all the other combinations along the sheet.

I'd like to offset the right sprite for the point from the texture atlas given the position of the camera in the world.

I want to use textured sprites instead of quads for achieve maximum performance and given that i'm using VBO all the work must be done in vertex/fragment shader.

I'm bumping into several problems and would like to ask about some hints on this.

:biggrin-new:

(READ THIS ONLY AS AN EXTRA AND IF YOU HAVE TIME)

I write here some of the approaches I've thinked of and tryed.

- build a solidal system of axes to the normal (being the positive Z-axis, 1,0,0 for example). Get the angles between normal and the projection of the camera vector (from camera to the point, all in 3D) in the x-z plane, and y-z plane. These represent my rotation around Y and X axis (not properly, a sort of approximation).

problem -> this system works only on some cases and if you keep looking at the point (obviously). For example if you move near the X-Y plane looking at the point, you will get values not representative of the current rotation.

- given an X-Y-Z plane like up here, where Z is the normal vector, compute in which part of the unit circle the camera vector falls...then just map a sector to a sprite (i don't need many rotations...).

In this case i don't have any idea about how to check in which sector on the sphere the point falls, nor mapping efficiently without an horrible if if if else....