COMPGROUPS.NET | Search | Post Question | Groups | Stream | About | Register

Texture projection

• Email
• Follow

```Hi Guys,

I'm not sure if the subject title is the correct term for what I am
trying to achieve.. and I don't even know if what I am trying to
achieve is possible.. but I think it should be! I will try to explain
what I am trying to do as clearly as I can but apologise now if it's
not very clear :)

I have a textured quad in model space and I have some vertices also in
model space. They are both orientated towards the eye point and the
textured quad is infront of the vertices.

What I want to do is blend/project the texture colours from the quad
on to the vertices behind it.

Now I have used a stencil to ensure only the areas of the screen where
the vertices are present get drawn and everything looks fine whilst I
don't move my eye position.

The problem is of course that once I move the eye position this all
goes horribly wrong as the vertices no longer fall behind the quad in
question that is providing the colour information.

The effect I am aiming for is to ideally never draw the quad itself
but use the colour information from it to project the colours on to
the vertices behind where the textured quad would be. So say the
texture is simply red on the left side and blue on the right side, I
want any vertices behind the left side of the quad to be red.. even if
my current viewing position does not place the vertex directly behind

I will always know these 4 things:

1) The model coordinates of the vertices.
2) The model coordinates of the quad.
3) The model coordinates of the eye point to allow the vertices to be
aligned behind the quad (this is the important one!)
4) The model coordinates of the current eye point.

Anybody have any pointers or am I trying to achieve the impossible?

I guess the question is can I blend two things from one view vector
and then display those results despite currently looking from a
completely different view vector?

Cheers

Mark
```
 0

See related articles to this posting

```mchristyuk wrote:

> Anybody have any pointers or am I trying to achieve the impossible?

You don't need the intermediate quad, you just project the texture on the
target geometry. The technique is very old. So old, that the tutorial on
opengl.org still show screenshots using MWM :)

http://www.opengl.org/resources/code/samples/mjktips/projtex/index.html

Wolfgang

```
 0

```Hi Wolfgang,

Thanks for the quick reply. I guess the problem in searching these
things out is the "correct terminology" for what I was trying to
achieve.

I will take a dig around the site and see what I can come up with.

Many thanks once again.

Mark
```
 0

```Hi Wolfgang,

I've got that working now many thanks. But it does lead me of course
on to another question :)

The issue I have is that the vertices I wanted to project on to are
GL_POINTS which when textured only apply a single colour across the
whole of their surface. If I use GL_POINT_SPRITES then the texture
gets shrunk down so that it fits on to the vertex as a whole.

Is there no way to get GL_POINT_SPRITES to behave like a small quad
that would only get textured with a subset of your texture?

Is my only alternative to give in to geometry shaders and get the card
to send out a camera aligned quad in place of the GL_POINT?

Before I was using the textured quad, a stencil and depth buffering
turned off to effectively apply a portion of a texture to a large
GL_POINT.. do you think that can be combined with the texture
projection approach?

Many Thanks

Mark
```
 0

```mchristyuk wrote:

> Hi Wolfgang,
>
> I've got that working now many thanks. But it does lead me of course
> on to another question :)
>
> The issue I have is that the vertices I wanted to project on to are
> GL_POINTS which when textured only apply a single colour across the
> whole of their surface. If I use GL_POINT_SPRITES then the texture
> gets shrunk down so that it fits on to the vertex as a whole.
>
> Is there no way to get GL_POINT_SPRITES to behave like a small quad
> that would only get textured with a subset of your texture?
>
> Is my only alternative to give in to geometry shaders and get the card
> to send out a camera aligned quad in place of the GL_POINT?
>
> Before I was using the textured quad, a stencil and depth buffering
> turned off to effectively apply a portion of a texture to a large
> GL_POINT.. do you think that can be combined with the texture
> projection approach?

Points are not really suited for projective texturing. They lack something
more important than area, namely a directed surface. You could project the
texture from anywhere, so how to decide in which direction to apply on a
point.

Simply drawing screen aligned quads won't help either. Try to imagine what
happens if the projective point of origin is in the plane defined by the
quad: This situation actually has no solution.

So you need to rethink your concept a little bit. I think you want to draw
spheres instead of points, and this is, what I suggest you do. Don't worry
about the vertex count. As long as you stay under a million and turn back
face culling on you should be just fine :)

Wolfgang
--
OpenGL tip #42:
How to exactly map texture texels to screen pixels:
<http://preview.tinyurl.com/cgndc8>
```
 0

```Hi Wolfgang,

Yes points are a problem. The issue I have is that I am dealing with
point clouds in the 10's of millions numbers which is why I was keen
on a solution to points. The direction of the surface is not an issue
with the application I am working on..

I'm going to investigate your sphere suggestion as I will only be
wanting to implement this "texturing" when at very close quarters to
the vertices so the number count should be much lower.

Many thanks once again for the hints and guidance :)

Cheers

Mark
```
 0

```On Feb 2, 10:02=A0pm, mchristyuk <mark.christ...@gmail.com> wrote:
> Hi Wolfgang,
>
> Yes points are a problem. The issue I have is that I am dealing with
> point clouds in the 10's of millions numbers which is why I was keen
> on a solution to points. The direction of the surface is not an issue
> with the application I am working on..
>

Stencil should work. Draw your points with
stencil enabled and write a stencil value
there (eg. '1').

Now switch to 2d and draw a quad with write
enabled only where stencil value is 1

--
<\___/>
/ O O \
\_____/  FTB.

http://www.topaz3d.com/  - New 3D editor for real time simulation
```
 0

```Hi Fungus,

Thanks for the pointer there. I've got it working now with the spheres
but as you can expect performance is a little poor.

I'm hoping to move the rendering over to quads at some point in the
future so this seems like a good enough time to start that process.

Cheers

Mark
```
 0

```Hi Fungus,

I've had the texture projection working well in the fixed pipe line
but wanted to move it over to the shaders to allow me a little more
versatility. I know this is possible as there are plenty of examples
and talk from people who have done this. However despite following
these examples to the letter my rendering doesn't seem to work out
right.. I think I know where the problem is but I'm unsure of how to
solve it and was hoping you could again give me a pointer with your
greater knowledge of all things OpenGL? :)

With my fixed pipeline I do the following:

gl.glMatrixMode(GL.GL_TEXTURE);
gl.glTranslatef(0.5f, 0.5f, 0.0f); //Bias
gl.glScalef(0.25f, -0.25f, 1.0f); //Scale
glu.gluPerspective(45, frameX / frameY, 0.1f, distance * 2.0f);

glu.gluLookAt(0,0,0,imageCentre.x,imageCentre.y,imageCentre.z,up.x,up.y,up.z);

float eyePlaneS[] = new float[]{1.0f, 0.0f, 0.0f, 0.0f};
float eyePlaneT[] = new float[]{0.0f, 1.0f, 0.0f, 0.0f};
float eyePlaneR[] = new float[]{0.0f, 0.0f, 1.0f, 0.0f};
float eyePlaneQ[] = new float[]{0.0f, 0.0f, 0.0f, 1.0f};

//set up texture generation mode and set the corresponding planes
gl.glTexGeni(GL.GL_S, GL.GL_TEXTURE_GEN_MODE, GL.GL_EYE_LINEAR);
gl.glTexGenfv(GL.GL_S, GL.GL_EYE_PLANE, eyePlaneS, 0);
gl.glTexGeni(GL.GL_T, GL.GL_TEXTURE_GEN_MODE, GL.GL_EYE_LINEAR);
gl.glTexGenfv(GL.GL_T, GL.GL_EYE_PLANE, eyePlaneT, 0);
gl.glTexGeni(GL.GL_R, GL.GL_TEXTURE_GEN_MODE, GL.GL_EYE_LINEAR);
gl.glTexGenfv(GL.GL_R, GL.GL_EYE_PLANE, eyePlaneR, 0);
gl.glTexGeni(GL.GL_Q, GL.GL_TEXTURE_GEN_MODE, GL.GL_EYE_LINEAR);
gl.glTexGenfv(GL.GL_Q, GL.GL_EYE_PLANE, eyePlaneQ, 0);

gl.glEnable(GL.GL_TEXTURE_GEN_S);
gl.glEnable(GL.GL_TEXTURE_GEN_T);
gl.glEnable(GL.GL_TEXTURE_GEN_R);
gl.glEnable(GL.GL_TEXTURE_GEN_Q);

As I said this works fine.. from my understanding to achieve the same
in the shaders I have to:
1) Access the texture matrix that I setup in the above code
2) Transform the texture coordinates in the vertex shader
3) Apply the texture in the fragment shader

I think it is my step 2 that is going wrong.. and I can see what's
wrong.. but can't quite get my head round why or what to do.

Here is the code for my fragment shader:

uniform sampler2D	tex;
void main()
{
// Suppress the reverse projection.
if( gl_TexCoord[0].q>0.0 )
{
gl_FragColor = texture2DProj(tex,gl_TexCoord[0]);
}
}

And here is my vertex shader:

void main()
{
vec4 ecPosition=  gl_Vertex * gl_ModelViewMatrix;
gl_Position = ftransform();
gl_TexCoord[0] = gl_TextureMatrix[0] * ecPosition;
}

The data I am displaying is in an Octree and I glTranslate to each
node before rendering it. The shader is setup before the Octree is
rendered.

1) If I use this vertex shader then I have a weird local projection
problem applied on each node of the Octree and the texture is repeated
across each node rather than across the whole tree as one texture.
2) If I substitute gl_Position for ecPosition then the texture is
applied in a global fashion to the Octree (correct) but moves and
rotates with the camera movement.
3) If I substitue gl_Vertex for ecPosition then the texture is visible
in the correct projection.. but applied to each node locally rather
than over the whole data set globally.. e.g. I have the same texture
repeating again and again at a fraction of its correct size on each
Node.

All the examples I have seen generate the TexCoord[0] value using
gl_Vertex * gl_ModelViewMatrix.. but it just doesn't work for me...

What's the obvious thing I appear to have missed?

Cheers

Mark
```
 0

8 Replies
602 Views

Similar Articles

12/7/2013 6:04:00 AM
[PageSpeed]

Similar Artilces:

Perspective projection
I am trying to understand perspective projection but can't get my mind around this idea. I've spent the past three days just reading and reading about this but still just can't get it. From what I can tell, the basic formula is x' = fX/Z, where f is the focal length. I've looked at multiple sites and they all have this drawing of the xyz axis with a vector intersecting an image plane at x', and the vector continuing on to X, and they use similar triangles f/Z = x'/X to figure out the values. X is supposed to be the real world point, and x' is the point..., or a link to a website that explains this well would be appreciated. This seems like something you either get or like me, don't get. Thank You, Bob <usr2202@saaa.org> wrote: > From what I can tell, the basic formula is x' = fX/Z, where f is the > focal length. Or, more symmetrically written: x' / z' = X / Z where z' is the focal length (== distance of the projection plane from the eye point, orthogonal to the plane). This shows more readily how the theorems about similar triangles apply. > f/Z = x'/X to figure out the values. X is supposed

Spherical projection
Hi everybody, I try to obtain a spherical projection of an image projected to a sphere. In other words: the input image becomes warped as if it had been mapped to a sphere and the sphere reprojected to the plane. How can I do this without using the map toolbox? The aim is to write the code in C++ that's why I can't (and I don't want) to use the map toolbox or other fancy MATLAB functions. Projection should be stereographic. I've written a general warp function that warps an Input image according to vector field U,V. I've found formulas for stereographic projection. But I struggle obtaining a map that does the correct warping (the map should look like the one under "stereographic projection" on ttp://www.uwgb.edu/dutchs/structge/sphproj.htm). Btw: the warp functions is correct, I've used it for many other things... Can anybody help?

glFrustum and projection question
Ok, from ogl documentation: void glFrustum( GLdouble left, GLdouble right, GLdouble bottom, GLdouble top, GLdouble znear, GLdouble zfar ); .... "The (left, bottom, znear) and (right, top, znear) parameters specify the points on the near clipping plane that are mapped to the lower-left and upper-right corners of the window, respectively, assuming that the eye is located at (0, 0, 0). ..." So, if the screen is at the near clipping plane, If I move my near clipping plane closer to the eye, and keep the left, right, top, and bottom the same, I would think it would produce

3D to 2D projection
I am trying to map a hemisphere to a circle, i.e getting subplot (1,2,2) from subplot(1,2,1) of the code below. Is there a set transformation matrix that exist to do this mapping without needing to specify view([0 90]) ? My overall task is to fill each square or even trapezoid on the 'walls' of the hemisphere with an image and then project them to a 2D circular image. I am not quite sure how to do that! Any advice on the data structures and transformations to use will be greatly appreciated. ---------------------- n = 18; % n is the number of points in the drawing of the

Plane Projection to Surface
Hi everyone, I've been stuck on this problem for the past three weeks, I'm a new user to MATLAB so I'm not very familiar with a lot of the functions in the program. My problem is that I have a surface but I only know it's projections in the xy, yz and xz planes the object (I have data points in each of the planes) has symmetry in the planes at 90 degrees. Here is a link to the 3D projection of the planes: https://dl.getdropbox.com/u/869767/geophys/graph.jpg It doesn't seem like a very hard task but I'm not able to get a surface from these projections :( Thanks in advance for your help! "Raminder Singh " <r_samra@hotmail.com> wrote in message <h89dvf\$nft\$1@fred.mathworks.com>... > Hi everyone, > > I've been stuck on this problem for the past three weeks, I'm a new user to MATLAB so I'm not very familiar with a lot of the functions in the program. My problem is that I have a surface but I only know it's projections in the xy, yz and xz planes the object (I have data points in each of the planes) has symmetry in the planes at 90 degrees. Here is a link to the 3D projection of the planes: https

back projection algoritm..help
Hello, I have problem with understand histogram back-projection algoritm. Anybody understand this algoritm and can solve it ? Thanks for help. "lukas ser" <el_nino@mathworks.com> wrote in message <fe661j\$fg7\$1@fred.mathworks.com>... > Hello, > > I have problem with understand histogram back-projection > algoritm. Anybody understand this algoritm and can solve it > ? > Thanks for help. Hello, If you can give me some written references about the algorithm I might be able to help you.

Oblique Projection Plots
Hello everyone, I would like to create an oblique projection plot (also known as cabinet projection) of three dimensional point data. In an oblique projection, two axes are perpendicular while the third runs at an arbitrary angle. This is the kind of projection usually applied when drawing three dimensional objects on graph paper (draw a two dimensional house, add lines of equal length starting from each corner at a 45 degree angle, draw the house again at the offset defined by these lines, et voila). It is extremely simple to compute and makes it possible to read values from a three dimensional chart (as there is no skewing going on) which is a lot harder when using the usual projection. I have not been able to set the camera in a Matlab plot to get this projection, although it is possible in principle: The camera needs to be shifted upwards and right without changing the camera angle, the object then appears in cabinet projection in the lower left corner of the screen. Does anyone have an idea on how to get this projection in Matlab? Thanks in advance Regards Jake

Plotting a projection vector
I have 10 samples vectors with length 192 for two classes C1 and C2. I then project these 10 samples to 1-dimension using the fisher descriminant: y1 = w^t * x y2 = w^t * x w is found with the steps described in the theory about the descriminant (using the 2-class case). y1 and y2 has length 10 and are points on w from the two classes. If I plot y1 and y2 they are well separated. But actually they are just points on w. How do I plot w as a linear function? If would be nice if it was possible to plot its direction relative to the cartesian x and y axis.

vertical and horizontal projection #3
\$1@fred.mathworks.com>, > marwan salih <marwan_salih@mathworks.com> wrote: <SNIP> > > I'm not sure what you mean by "vertical and horizontal projection" ? > Is that like finding the "bounding box" ? <SNIP> Not usually, conventionally the vertical projection is simply the sum (or possibly the mean value) of all of the rows, and the horizontal projection is the same operation applied to the columns. It is often used to identify spatially restricted objects within an image. In some respects it can be considered to be a very restricted form of the Radon transform of the image. Regards Dave Robinson "Dave Robinson" <dave.robinson@somewhere.biz> wrote in message <fcdi27\$fid\$1@fred.mathworks.com>... > Not usually, conventionally the vertical projection is > simply the sum (or possibly the mean value) of all of the > rows, and the horizontal projection is the same operation > applied to the columns. It is often used to identify > spatially restricted objects within an image. > > In some respects it can be considered to be a very > restricted form of the Radon transform of the image

Cylindrical Equal Area projection
Now I'm doing data processing with AMSR L3 soil moisture data which is projected into the cylindrical equal area (CEA), and I found a solution from Fanning webpage, but I think this is not my case. Please, see below. This is I got from his webpage. AMSR=Map_Proj_Init(103, \$ ; Albers Equal-Area Conic Projection SEMIMAJOR_AXIS=6371228L, \$ SEMIMINOR_AXIS=6371228L,\$ ;sphere_radius = 6371228, \$ CENTER_LONGITUDE=0.0, \$ CENTER_LATITUDE=0.0, \$ STANDARD_PAR1=60, \$ STANDARD_PAR2=-59.5, \$ FALSE_EASTING=0., FALSE_NORTHING... 25km. Is this because fanning's case is only for the brightness temperature? I heard that IDL8.0 provides CEA projection option, but mine is 7.0. Please, help me. Sincerely, Bryan