I have an idea for a shader that needs a bunch of float values per vertex, and I’d like to be able to change these values on the fly.
I’ve had an older system that adjusts vertex information every frame, but that tends to be really slow when there are allot of vertexes.
Another way to use this information seems to be a texture lookup in the vertex shader. For each vertex, there is a pixel of information in the texture. This way, instead of uploading a new geom every frame, all I have to do is change the texture.
So I create a ram image of a 1d texture using the following code:
positionTimeTexure.setupTexture(
Texture.TT1dTexture,
1,
particleCount,
1,
Texture.TFloat,
Texture.FRgba12
)
positionTimeTexure.setMagfilter(Texture.FTNearest)
positionTimeTexure.setMinfilter(Texture.FTNearest)
positionTimeTexure.setWrapU(Texture.WMClamp)
positionTimeTexure.setWrapV(Texture.WMClamp)
self.positionTimeRamImage = self.positionTimeTexure.modifyRamImage()
numComp = self.positionTimeTexure.getNumComponents()
then use setElement to set each a position value into the rgb and a time value into the alpha.
for texelIndex in range( particleCount ):
positionTimeRamImage.setElement(
texelIndex,
position.getX()
)
positionTimeRamImage.setElement(
texelIndex + 1,
position.getY()
)
positionTimeRamImage.setElement(
texelIndex + 2,
position.getZ()
)
positionTimeRamImage.setElement(
texelIndex + 3,
startTime
)
Then in the vertex shader I get that information with:
tex1D( k_positionPosTime, vertexIndex / numberOfVertexs );
So what I’ve found is that the texture lookup is always transparent black, or 0.0, 0.0, 0.0, 0.0.
Am I creating the texture wrong? Is there a better way to create a float texture like this?
~~Adam