Sign in to follow this  
billconan

glsl texture indexing and debugging.

Recommended Posts

hello everyone, i'm working on my glsl shader. i transfer some data to the gpu for rendering via texture maps. the shader runs perfectly, if the texture maps are small, but generates weird results when the texture map is large. after some detecting, i believe the problem is texture map indexing. the data i tell the gpu is a 1D array on a 2D texture. i use the integer index of the array to get the value. so i have to convert the integer index into a 2D texture coordinate. in my code, this is done by this code: //where "height" is the height of the texture map and "4094" is the width of the texture map. vec2 getTexCoord(unsigned short index,int height) { int k=int(index)/4094; float iny=(float(k)+0.5)/float(height); float inx=(float(int(index)-k*4094)+0.5)/4094.0; return vec2(inx,iny); } but may be due to the float point precision, the texture coordinate was wrong. i'm wondering how people compute the texture coordinate? another question, for debugging, i know i need to output values as colors. normally i do this gl_color=vec4(value/k,0,0,1); but apparently, this is not accurate. because i only use one of the four channels of the color vector. and i will be only see a value between 0-255. is there any better way of converting a value into a color? thanks.

Share this post


Link to post
Share on other sites
Correct me if I'm wrong but unsigned short is not supported in GLSL 1.50 and in all lower versions as well. I recommend you stick to strict GLSL syntax. Put #version 110 or 120 or something at the top of your shaders.

Share this post


Link to post
Share on other sites
Use the ["source"] tags (remove the "") to post your code.

Here's a problem:
Quote:
Original post by billconan
int k=int(index)/4094;
float iny=(float(k)+0.5)/float(height);

'k' will always be either 0 or 1 (assuming index is in the [0 4094) range)
I think you meant "int k = int(index)/float(4094.0f);

That aside, what's all that weird (and unreadable) casting to every single value?

Cheers
Dark Sylinc

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