Custom texture Wrapping PER instance in a GLSL shader?

I have a pixel / vertex shader currently working with instanced geometry.

I want to introduce a custom uv wrapping / extend mode PER instance via an array/ chop being passed in.

For clarification:

I’m trying to add this code to my vertex shader:

glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_MIRRORED_REPEAT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_MIRRORED_REPEAT);

however I get errors like this:

Vertex Shader Compile Results:

0(62) : error C1008: undefined variable "glTexParameteri" 0(62) : error C1008: undefined variable "GL_TEXTURE_2D" 0(62) : error C1008: undefined variable "GL_TEXTURE_WRAP_S" 0(62) : error C1008: undefined variable "GL_REPEAT" 0(63) : error C1008: undefined variable "glTexParameteri" 0(63) : error C1008: undefined variable "GL_TEXTURE_2D" 0(63) : error C1008: undefined variable "GL_TEXTURE_WRAP_T" 0(63) : error C1008: undefined variable "GL_REPEAT"

It doesn’t seem to recognize any of this - which leads me to believe I’m probably trying to do something that is wrong in an obvious way - however this is my first time diving into glsl so a bit stumped!

Any help would be greatly appreciated.

Thanks,
Lucas

Lucas, those parameter lines are C code, not GLSL. Those parameters are set on Texture Units (or textures? I always forget) and can’t be changed in a shader.

In TouchDesigner, those are set in parameters: for each Sample Name, fold down the Top menu and you’ll see the texture params.

Bruce

Hey - thanks for the reply.

Some people on the facebook group did tell me the same thing - which was extremely helpful.
Since then I’ve been looking at doing this in the pixel shader too which seems like the easiest / best place to implement this.

To your point about the touch designer drop down - I use this param roll out often but my goal was to do this PER instance not to all the geo instances so I needed control of this in glsl.

I have since figured out the code for the 4 modes necessary:

[code] // EXTEND
texCoord0 = clamp(texCoord0,0,1);

// REPEAT
texCoord0 = fract(texCoord0);

// MIRROR REPEAT
texCoord0 = fract(texCoord0*0.5)*2.0;
texCoord0 = 1 - abs(texCoord0-1);

// BLACK OUTSIDE
//I set this to the "default" in touch via those drop downs, so to achieve this I simply do not modify texCoord0[/code]

but I am still having trouble accessing the current instance ID in the glsl pixel shader.
I have successfully accessed this in the vertex shader, and I have read on the GLSL help docs page:

[url]Write a GLSL Material - Derivative

that this can be accessed in the pixel shader by declaring and accessing this variable?

// Pixel shader flat in int vInstanceID;

However so far it seems to be acting across the entire set of instances still, not PER instance.

Any thoughts?

The way it used to be: look back through my posts and you may find it - is that instance ID is available in the vertex shader and you need to pass it through to the fragment shader. That’s pretty trivial.

Yes! you’re right and I just realized why I was not having any luck doing this literally just now.

In the vertex shader, I had to have my instance index declared as an out variable.
Then in my pixel shader have that same variable declared as an in variable.
Then it worked.

For anyone out there who’s interested these are the pertinent bits:

In Vertex Shader, before main{}

flat out int i;

In Vertex Shader, inside of main{}

i = gl_InstanceID + uTDInstanceIDOffset; gl_InstanceID, and uTDInstanceIDOffset are already defined for users internally somehow, so that’s it.


Then in the pixel shader - before main{}

flat in int i; then within main you can simply access this variable and use it however you’d like.

Thanks for the clarification Bruce!