LWJGL sending information to shaders via texture

I’m trying to do something about my lighting calculations, because they really look poor. Sending all the light data as uniforms really seems stupid. I would much rather send it to shaders via texture. I’m kinda done, but the problem is that opengl caps float values to 1,1,1,1. For example, if I want to send value 10, I cannot, because it gets capped to 1.

Is there a way to fix it?

Here is the glteximage

GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGBA, 1, 1, 0, GL11.GL_RGBA, GL11.GL_FLOAT, makeLightData());

EDIT-
I think I will make a tutorial out of this post later on once I figured everything out…

divide it by the max value.
For example if your highest value is 100, divide all values by 100.

*You don’t need textures to use float buffer data in the shader, Opengl 3.0 has a feature wich allows you to upload this buffer drectly, this way you also can send int / byte buffers.

Yes I know of that, but for this game I was hoping to make it run on almost all machines people have nowadays, so I thought I would try to make it with textures first.

About the 0,1 I will just tell the shader the size of the level and when shaders get that float, it will times it by the level size.

Ok I got into kinda another problem. When I get 2 samplers, for example:


uniform sampler2D u_texture;
uniform sampler1D u_lights;

I get this GLSL validation error:

[quote]Validation failed! - Different sampler types for same sample texture unit in fragment shader.
[/quote]
Any ideas how I go about fixing it?

I already tried this before validating, linking the shader, in between those, after those and none of it helps.


GL20.glUniform1i(getUniformLocation("u_texture"), 1);
		GL20.glUniform1i(getUniformLocation("u_lights"), 2);

EDIT-
Ok I fixed it. Here is the link that helped me.

I think I got one last mystery problem.

I fill texture:

GL11.glTexImage1D(target, 0, ARBTextureRg.GL_R16F, 2, 0, GL11.GL_RGBA, GL11.GL_FLOAT, makeLightData());

with this data:


		buffer.put(1f).put(0).put(0).put(0);
		buffer.put(0).put(1).put(0).put(0);

As you can see I make 2 pixel wide texture, which’s first pixel is red, and second pixel is green.

In fragment shader, I multiply the output of my game color by this:


	vec4 col = texture(u_lights, 0.0);

so that I know what kind of color I’m picking from my 1d texture.
The problem is that when texcoord is 0.0, it picks the red color. When texoord is 1.0, it still picks the red texel. Any suggestions?

EDIT-
I fixed it.
I needed to do image for GL_RED so that I only had 1 component / texel.

GL11.glTexImage1D(target, 0, ARBTextureRg.GL_R16F, 2, 0, GL11.GL_RED, GL11.GL_FLOAT, makeLightData());

ARBTextureRg.GL_R16F allows to send floats bigger than 1. That means you can send 10 or 800 or 10055 or whatever you want and that value will arrive to the shader.

Also, trying to access 1.0 texel basically tells GLSL to access texel of 0.0, because it probably does inputTexel%1, which means it is capped to 1.0.

So now I can basically send an array of floats to shaders via texture and access that array by doing:


float index=float(i) / arraySize;
texture(u_lights, index).r;

There is a lot to explain so I will just write a tutorial in a few days.