   [Cg]vertex textures, FBO and point sprites == weird behavior
  This is a rather long post, but please bear with me. You'll see some really weird stuff... like how changing the color in the fragment shader will end up changing the positions of the vertices.I'm rendering point sprites to a 16 bit floating point texture (16 bits because I want to blend the sprites). These point sprites are being modified by a vertex shader that changes their coords according to the RGBA values of a previously calculated texture.My OpenGL calls to draw the point sprites are pretty straightforward. Notice how the coords of the point sprites are all between [0, 1], so I can use the point sprites' positions as texture coords in the vertex shader. glDisable(GL_DEPTH_TEST);glEnable(GL_BLEND);glBlendFunc(GL_ONE,GL_ONE);   //stuff needed for perspective correct distance attenuationint viewport[4];float mat[16];glGetFloatv(GL_PROJECTION_MATRIX, mat);glGetIntegerv (GL_VIEWPORT, viewport);float H = viewport[2];float h = 2.0f / mat[0];float D0 = sqrt(2.0f)*H/h;float k = 1.0f /(1.0f + 2* sqrt(1/ mat [0]));float atten[] = {0.0f, 0.0f, sqrt(1/D0)*k};float maxSize = 0.0f; //set point sprite parametersglPointParameterfv(GL_POINT_DISTANCE_ATTENUATION, atten);glGetFloatv(GL_POINT_SIZE_MAX_ARB, &maxSize);glPointParameterf(GL_POINT_SIZE_MAX_ARB, maxSize);glPointParameterf(GL_POINT_SIZE_MIN_ARB, 1.0f);glPointParameterfEXT(GL_POINT_SPRITE_COORD_ORIGIN, GL_LOWER_LEFT);glTexEnvf(GL_POINT_SPRITE_ARB, GL_COORD_REPLACE_ARB, GL_TRUE);   //draw the point sprites glEnable (GL_POINT_SPRITE_ARB);   float deltaX = 1.0f / texX;   float deltaY = 1.0f / texY;   glBegin(GL_POINTS);   for(int i = 0; i < texX; i++)   { for(int j = 0; j < texY; j++) {   glVertex3f(i*deltaX, j*deltaY, 0.0f); }   }  glEnd();glDisable(GL_POINT_SPRITE_ARB);   glDisable(GL_BLEND);glEnable(GL_DEPTH_TEST);As you can see from the vertex shader code below, it's all pretty simple. I read out the coords from the texture intTex. If the w-coord = 0, I set the z-coord to 1, so the vertex will get clipped by OpenGL, otherwise I pass it on to the fragment shader.void main(  float4 Position : POSITION,    float2 tc : TEXCOORD0,    out float4 oPosition   : POSITION,    out float2 otc   : TEXCOORD0,    uniform sampler2D   intTex,    uniform float4x4    ViewProjMatrix){otc = tc;float2 xy = float2(Position.x, Position.y);float4 oCoords = tex2D(intTex, xy);if(oCoords.w == 0.0) {oPosition.z = 1.0;}else {oPosition = mul(ViewProjMatrix, oCoords);}}the fragment shader code is even simpler. I'm just texturing the point sprite.void main(float2 tc : TEXCOORD0,   out float4 oColor  : COLOR,   uniform sampler2D  circleTex){oColor = tex2D(circleTex, tc);}And here's the result. 250k point sprites being rendered, textured and blended along a straight line at 2 fps. Not exactly what I had in mind.Baffled by this result I decided to do some testing. The first thing I tried was coloring the point sprites instead of texturing 'em. The fragment shader ended up looking like below. Everything else remained unchanged.void main(float2 tc   : TEXCOORD0,   out float4 oColor    : COLOR,   uniform sampler2D    circleTex){oColor = float4(1.0, 1.0, 1.0, 1.0);}And I had another go at rendering at what I was fearing would be another straight line. To my surprise the result was completely correct. This is what it looked like. 250k point sprites being rendered and blended at their correct positions at +200 fps.Needles to say I was more than a bit surprised... changing the fragment shader had an enormous impact on the positions of the point sprites. Is this even supposed to be possible?So I did another litte experiment. I changed the fragment shader back to its original form, so that once again it would texture fragments. I then added a single line to the vertex shader. Now the vertex shader still does a vertex texture fetch, but ignores the result. Instead I just transform the positions of the vertices.void main(  float4 Position : POSITION,    float2 tc : TEXCOORD0,    out float4 oPosition : POSITION,    out float2 otc : TEXCOORD0,    uniform sampler2D  intTex,    uniform float4x4   ViewProjMatrix){otc = tc;float2 xy = float2(Position.x, Position.y);float4 oCoords = tex2D(intTex, xy);if(oCoords.w == 0.0) {oPosition.z = 1.0;}else {oPosition = mul(ViewProjMatrix, oCoords);}   oPosition = mul(ViewProjMatrix, Position);}This was the result. All point sprites were put in their expected locations and correctly blended and textured.Anyway, does this make sense to anyone? I've shown how changing the fragment shader has an impact on the location of the point sprites and how making a minor change to the vertex shader will allow correct texturing.Does anyone what's going on here? Full code is available on request.[Edited by - Shai on December 10, 2006 8:05:31 AM]
  Hello Shai! How's it going?Have you tryed to check the assembly of those shaders? Whether there aren't any weird stuff goind on because of the branching and so. What GPU&drivers are you running on?How does your "intTex" texture look like? The framerate on the first screenshot definetely suggests that there is something strange going on, therefore it probably reverts to SW render..   ;  hey MePHyst0, I'm getting closer to finding the problem. It probably has something to do with the way I pass a texture to the fragment shader. More info about it here.   