Clever Texture Lookup suggestions...

Started by
3 comments, last by RAZORUNREAL 16 years, 10 months ago
Hey all, Just a general GPGPU question. I am currently using the GPU to simulate a collection of bees, something I've described a bit in my previous posts if anyone is interested. However - what I'm doing is not that important. More important is, in my Cg programs I use texRECT() to make a texture lookup in my cg programs. Given a single number I'd like to look up that pixel in a texture. Previously I've done this by passing the texture size to the Cg program as a parameter and writing a function that calculates its position. Something like this (where the tex size is known to be 64):


float4 fetchData(int dataArrayPosition, samplerRECT textureData)

{
	float intTextureCoordX, intTextureCoordY, rgbaIndex, returnNr;

	float4 rgbaData;

	intTextureCoordY = dataArrayPosition/64;
	intTextureCoordY = floor(intTextureCoordY);
	intTextureCoordX = fmod((float) dataArrayPosition,64);
	
	rgbaData = texRECT(textureData, float2(intTextureCoordX,intTextureCoordY)); 

	return rgbaData;
}


I'm basically interested in better ways of doing this. Perhaps Cg can wrap texcoordinates for me or something? I don't honestly know :) If anybody has any suggestions like alternatives or improvements, please let me know... Regards, Gazoo
Advertisement
surely u only need to do

rgbaData = texRECT(textureData, float2(dataArrayPosition,0));
Uhhhh no?

Using your method the lookup will never actually perform lookups outside the "bottom" row of a texture where Y is 0. At least that has been my experience with your suggestion...

I believe I'll stick with my own solution, unless someone else has anything to add?

Regards,

Gazoo
You could do the division in the vertex shader and just use the interpolated values there. As for the modulo thing, you can actually setup wrapping in the GL using glTexParameter. Same goes for the rounding, which should be equivalent to using GL_NEAREST filtering. The manpage on the opengl.org site is quite insightful if you need any more help.
It should be possible to pull his off without shaders even. Just turn off filtering, turn on wrapping, and set your tex coords to [dataArrayPosition, dataArrayPosition / 64].
___________________________________________________David OlsenIf I've helped you, please vote for PigeonGrape!

This topic is closed to new replies.

Advertisement