Sign in to follow this  
Gazoo

Clever Texture Lookup suggestions...

Recommended Posts

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

Share this post


Link to post
Share on other sites
surely u only need to do

rgbaData = texRECT(textureData, float2(dataArrayPosition,0));

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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].

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this