PDA

View Full Version : Accessing tex and texcoord after a texture2D operation.



hamdi.rakkez
10-19-2015, 10:40 AM
Hi all,

When using this :

vec4 tmp = texture2D(tex, texcoord)

How can I get tex(sampler2D) and texcoord(vec2) from tmp ???

Thank you.

carsten neumann
10-19-2015, 11:37 AM
Short answer: you cannot.

Longer answer: you still cannot, because the vec4 tmp only stores the (RGBA) values sampled from the texture, but not any information about which texture or where on the texture these values are sampled from. If you really need these values you'll have to store them somewhere where they are accessible when you need them again - or alternatively store enough information to recompute the values.

Alfonse Reinheart
10-19-2015, 12:15 PM
I'm curious as to why you would need to. `tex` is a sampler, which by its nature must be a global uniform (or you're using bindless textures). So you almost certainly know where it is.

hamdi.rakkez
10-20-2015, 03:00 AM
In fact I have fonc1() which deals with texture and modifies it, but in the main I have ""vec4 color = texture2D(tex, v_texcoord.st)""

The problem is that vec4 color will take the original texture without fonc1() modifications, and that's not what I want.




vec4 fonc1()
{
do smth
....
return tmp;
}

void main ()
{

vec4 color = texture2D(tex, v_texcoord.st)

}

Alfonse Reinheart
10-20-2015, 11:00 AM
Then you should call `fonc1` and then don't access the texture. Just use the function's return value for the color.