GLSL double texture lookup problem...

Started by
4 comments, last by mp3butcher 14 years, 1 month ago
Hello, Im trying to create a n1*m1 texture containing colors representing textcoord in a second texture n2*m2: For this I wrote a simple fragment shader: <code> uniform sampler2DRect colortexture; uniform sampler2DRect indexTexture; uniform vec2 sizecolortexture; void main(){ //1st texture lookup retrieving color representing 2D tex coord in RG vec4 inputVal = texture2DRect(indexTexture, gl_TexCoord[0].st); //scale texcoord to texture size inputVal.x*=sizecolortexture.x; inputVal.y*=sizecolortexture.y; vec4 col= texture2DRect(colortexture, inputVal.xy); gl_FragColor=col; } </code> But it doesnt work...:( I don't seem to make any errors in the code as i can display the two textures separatly. I's like that texture lookup on texcoord resulting from an other texlookup is not working?I dont know well glsl spec but it seems like all textures lookups are vectorized independently at compilation...?! Any idea or info about that? Thanks by advance [Edited by - mp3butcher on March 1, 2010 4:29:19 PM]
Advertisement
Methinks you want texture2D instead. Also, try things like:
gl_FragColor=vec4(0.0,0.0,1.0,1.0);
to see if the problem really is in the shader.

[size="1"]And a Unix user said rm -rf *.* and all was null and void...|There's no place like 127.0.0.1|The Application "Programmer" has unexpectedly quit. An error of type A.M. has occurred.
[size="2"]

Yeah it works..the shader outputs me whatever i want: the 1st texture the 2nd texture too... but not the double indirection result i wanna render....:(
I will give a try with square textures (texture2d) as you mentionned but im afraid it will be the same problem:(
Can you post a better description of the result you're getting? "It doesn't work" is not really very helpful for debugging.

Also post maybe your actual program multitexture setup, to make sure you're setting up the samplers properly? Can you try to mix the two textures together using the gl_TexCoord[0] uv for both (just as a debug) to make sure that your GLSL actually has proper access to both textures?



[size=2]My Projects:
[size=2]Portfolio Map for Android - Free Visual Portfolio Tracker
[size=2]Electron Flux for Android - Free Puzzle/Logic Game
okay,
It's a kind of approximation problem when i multiply the inputVal by the colortexturesize.
I make a simple test:
bind 2 textures 512*512 on the same image containing a color gradient from black to red+green=yellow:
the results would be the same image....
But the result is a very coarse gradient with only 4 differents colors....

Note for myself : Stop with these damned *&#@ texturerectangle!!!<br><br>Here's my input 512² image attached to indexTexture and colortexture<br><img src="http://img696.imageshack.us/img696/8753/debgrad.png" width=30%><br><br>Here's my output:(<br><br><img src="http://img684.imageshack.us/img684/6868/grad.png" width=30%><br><br>Any idea how to correct it?<br><br><!--EDIT--><span class=editedby><!--/EDIT-->[Edited by - mp3butcher on March 2, 2010 5:19:01 AM]<!--EDIT--></span><!--/EDIT-->
..arf i obtain exactly the same bad result with a normal texture2d lookup and this fragment shader

//unuseuduniform sampler2D colorTexture;
uniform sampler2D indexTexture;

void main(){
vec4 pos = texture2D(indexTexture, gl_TexCoord[0].st);
vec4 col= texture2D(indexTexture,pos.xy);
gl_FragColor=col;
}

plize help

[Edited by - mp3butcher on March 2, 2010 6:46:57 AM]

This topic is closed to new replies.

Advertisement