Skip to main content
GameDev.net gamedev.net
🔒 Locked

GLSL value halfed?

Started by svnstrk Sep 6, 2010 at 3:26 PM 6 replies 1.3k views
Original Post
svnstrk
svnstrk
hi,

im having problem with my GLSL. so i kept my data in the openGL side by using unsigned char*. its basically an 8 bit data so it will fit the ALPHA8 or GL_RED. i send the data GPU memory by using this:

glTexImage3D(GL_TEXTURE_3D, 0, GL_ALPHA8, textureWidth, textureHeight,
textureDepth, 0, GL_ALPHA, GL_UNSIGNED_BYTE, index3D);

i also has tested using GL_RED instead of GL_ALPHA8. on the GLSL side, i call the value by using this

currIndex = vCurrIndex.a;

or .r if i kept it as RED value. however the data value seems to be halfed. When I check it using this:

if ( currIndex < 0.5) {
color = vec4(1.0, 0.0, 1.0, 1.0); // pink
} else color = vec4(0.0, 1.0, 0.0, 1.0); // green

it all turned up green. but if i put a higher treshold, let say 0.6, there are a few part is pink.

I already check the data before it was sent to the GPU, and its a correct data between 0-255 (converted to unsigned char). Any idea why its halfed? Did i do something wrong back there?


thanks in advance
AndyEsser
AndyEsser
If you're sending it as unsigned char, then 0.5 won't mean much.

Because of rounding, you'll find that anything with a value above 0 will be shown as green (and since there are possible values of 0 - 255, that'll be most of them).

Change your

currIndex < 0.5

to

currIndex < 128

and see if the results you are getting make any more sense.

Also have you tried removing the if() and instead having:

color = vec4(currIndex / 255, currIndex / 255, currIndex / 255, 1.0);

You should get a greyscale image, with each pixel representing a value between 0 - 255 (with 0 being black, and 255 being white)
svnstrk
svnstrk
well didnt GLSL automatically convert my value from 0-255 to 0-1? i did the comparison in GLSL side, and i cant get anything with threshhold 128. but i got lots of pink if i do 0.6 and up. im quite sure theres a problem with index 0-0.5 but im not sure why. it looks like one bit of my value is gone.

any idea?
karwosts
karwosts
svnstrk you are correct your unsigned char's should be converted to 0-1 floats inside the shader.

The data isn't really being halved is it? It looks like from your comment all your data is in the range of 0.5-1.0 (you said it's all green, which is the case when currIndex is NOT less than 0.5).

I would try to break it down a little more, maybe explicitly send all 0's for your data and see if currentIndex comes out as 0.0, or send all 255 and see if the data is about 1.0. If you really send 0 and it comes out as 0.5 then we can look a little deeper and see what's going on.
[size=2]My Projects:
[size=2]Portfolio Map for Android - Free Visual Portfolio Tracker
[size=2]Electron Flux for Android - Free Puzzle/Logic Game
AndyEsser
AndyEsser
My apologies, that was a really stupid suggestion of mine.
svnstrk
svnstrk
yeah so i noticed that its a logic error. my data is not halVed but i just dont get where my mistake is. here is the code, its pretty much but very simple to understand.


Before i send the data to GLSL, these are facts that i found:
the currIndex is normally distributed from 0-1, contains 225 items. so the currIndex should loop from 0 to 1 with 1/225 addition each loop. which means there are 128 items below 128.

here is the first glsl code:

the resulting image is green, yellow, and greenish yellow. there are a little bit blue part, but no yellowish blue or pink. no white at all. which means that there are part where the sphIndex is less than 0.2, but at that part, the currIndex does not lower than 0.5.

Now I expect that some part should be pink, means that in that part, sphIndex is low (below 0.2) but the currIndex does not reach 0.5 (0.21 - 0.49). But I just cant find this color.

its pure logic if anyone have some time to spare, maybe a little help where i did wrong in my code, would be very great.

thanks in advance
karwosts
karwosts
Sorry that shader is way too confusing to figure out what you're trying to do.

I think you ought to try to break this down more to isolate the issue. I'd forget all these 'indexes' and just try to render out your texture in grayscale (or slices of it if its 3d) and try to look at it and see what's the problem if you suspect that your texture data is wrong. I don't get what any of these 'indexes' are for, what you're doing with that loop, what depth is supposed to represent, where you're getting your texcoords from.

Maybe it makes sense to you, but I think your 'debug' shader is too complicated to actually figure out what's going on, you've got too many moving parts in there.
[size=2]My Projects:
[size=2]Portfolio Map for Android - Free Visual Portfolio Tracker
[size=2]Electron Flux for Android - Free Puzzle/Logic Game
svnstrk
svnstrk
well apparently i found out the problem, you cant access texture using x,y,z, but when i did it with s,t,r it just works. really weird but lesson learned.

thx for any help :)

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.