I am trying to get the Ardor3D terrain system to work on SM3.0 hardware.
The current GLSL fragment shader uses a single vec2 array to pass an xy coordinate array to the fragment shader.
Since dynamic indexed homogeneous arrays only work with SM4.0 + hardware, to make it work on SM3.0, I need to replace it with a 1D floating texture.
The current array looks like this: uniform vec2 sliceOffset[8];
and opens as follows: vec2 offset = sliceOffset[int(unit)];
I am very experienced with OpenGL and GLSL, so I am having some problems with the conversion.
So far I have done this: Create a 1D texture - width = 8 - format = RGBA32F
Create 1D buffer for texture
- width = 8 * 4 = 32 floats or 32 * 4 = 32 bytes
- fill the float buffer as follows:
[x0,y0,0,0,x1,y1,0,0,x2,y2,0,0,x3,y3,0,0,x4,y4,0,0,x5,y5,0,0,x6,y6,0,0,x7,y7,0,0]
Create a 1D sampler for texture
- min filter = nearest, no mip cards
- mag filter = nearest
- wrap mode = clamp to edge
In GLSL, I define a sampler as: uniform sampler1D sliceOffset;
And he turns to him:
vec2 getSliceOffset(float unit) { float texCoord = (unit * 2.0f + 1.0f) / (2.0f * 8.0f); vec2 offset = texture1D(sliceOffset, texCoord); return offset; }
But he is broken.
What am I doing wrong?