Reading from 2 textures in vertex shader

I am trying to implement a Particle System using GLSL. I have run into some troubles rendering the final result of the calculations. An outline of my program is as follows:
1: On start of particle system I render the initial positions and velocities to two separate textures using an Frame Buffer Object (FBO) with the two textures attached as render targets.

2: I intend to use a Vertex Buffer Object for rendering the Particel System as GL_POINTS. Basically I give an index array to the VBO with consecutive numebers and an array with zeros as positions. When rendering the VBO I use a vertex shader that reads the textures with initial positions and velocities in order to calculate the current position using a uniform variable for the time parameter.

The problem is that I cannot get anything to show in my scene. My prime suspition is that I do not get sensible data from the to sampler2D texture look-ups. I have just set one sampler2D to 0 and the other to 1. How can I be sure that I am reading from the correct textures? I would also be thankful for any good pointers or conceptual description of how I should procede to achieve what I want.

Funny, I have just run into the exact same problem when trying to access two 1D textures in my vertex shader.

I use the following to set up each one

glGenTextures(1,&LiveActivations);
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_BLEND);
glBindTexture(GL_TEXTURE_1D,LiveActivations);
glTexImage1D(GL_TEXTURE_1D, 0, 1, 64, 0, GL_RED, GL_FLOAT, activation); glTexParameteri(GL_TEXTURE_1D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); glTexParameteri(GL_TEXTURE_1D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
glTexParameteri(GL_TEXTURE_1D,GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_1D,GL_TEXTURE_WRAP_T,GL_CLAMP_TO_EDGE);

Problem is that when I try to texture lookup in shader, the last shader I have set using the above code, becomes my uniform texture. The one initialized first is not accessible. No compilation errors.

Eirik, I wonder if we’re having the same problem? How exactly are you initializing your shaders? And are either one of them accessible in your shader or both have garbage data?

It really seems that there is only garbage data. My shaders are initialized by setting the two sampler2D uniforms to 0 and 1 respectively. I think the problem has to do with which texture units are bound, but have not been able to verify this.
My code us as follows:

glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, v0_p0_fbo_.getRenderTargetId(0));

glActiveTexture(GL_TEXTURE1);
glBindTexture(GL_TEXTURE_2D, v0_p0_fbo_.getRenderTargetId(1));

The shader code lookes like this:

uniform float t;// The time since last step.
uniform vec4 a;// The acceleration.

uniform sampler2D v0_tex;
uniform sampler2D p0_tex;

void main()
{
gl_TexCoord[0].xy = gl_MultiTexCoord0.xy;
vec4 v0_val = texture2D(v0_tex, gl_TexCoord[0].st);
vec4 p0_val = texture2D(p0_tex, gl_TexCoord[0].st);

vec4 p = p0_val+v0_val*t+0.5*a*t*t;
p.w = 1.0;
gl_Position = gl_ModelViewProjectionMatrix*p;
gl_FrontColor = gl_Color;
}

does it work if you have textures in fragment shader only? do you glUniform1i the samplers?

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.