Jump to content

  • Log In with Google      Sign In   
  • Create Account


GLSL 330 sampler2D array access via vertex attribute?

  • You cannot reply to this topic
2 replies to this topic

#1 Grumple   Members   -  Reputation: 164

Like
0Likes
Like

Posted 13 August 2014 - 02:06 PM

Hello,

 

After a lot of programming and debugging I feel like a dumb ass.   I set up an entire billboard shader system around instancing, and as part of that design I was passing a vertex attribute representing the texture unit to sample from for a given billboard instance.   

 

After setting all of this up I was getting strange artifacts, and found that GLSL 330 only officially supports constant (compile-time) index into a uniform sampler2D array?

 

Is there any nice way around this limitation short of compiling against a newer version of GLSL?  Is there at least a way to check if the local driver supports the sampler index as vertex attribute through an extension or something?  I tested my implementation on an NVidia card and it worked despite the spec, but ATI (as usual) seems more strict.

 

For now I have patched the problem by manually branching *shudder* based on the index and accessing the equivalent sampler via a constant in my fragment shader.  

 

For example:

        if(passModelTexIndex == 0) 
        { 
            fragColor = texture2D(texturesArray_Uni[0], passTexCoords); 
        } 
        else if(passModelTexIndex == 1) 
        { 
            fragColor = texture2D(texturesArray_Uni[1], passTexCoords); 
        } 
        else 
        { 
            fragColor = vec4(0.0, 0.0, 0.0, 1.0); 
        } 


Sponsor:

#2 TheChubu   Crossbones+   -  Reputation: 4062

Like
0Likes
Like

Posted 13 August 2014 - 03:00 PM

Hmm, I'm not sure, I never tried it but I don't see why you wouldn't be able to select the texture with an uniform as index since that was the whole idea for texture arrays (ie, upload everything then select texture on the fly).

 

Have a look at this http://www.opengl.org/wiki/Array_Texture in "Access in Shaders" section. Also here http://www.opengl.org/wiki/Sampler_(GLSL) in "Basic Texture Access"


Edited by TheChubu, 13 August 2014 - 03:01 PM.

"I AM ZE EMPRAH OPENGL 3.3 THE CORE, I DEMAND FROM THEE ZE SHADERZ AND MATRIXEZ"

 

My journals: dustArtemis ECS framework and Making a Terrain Generator


#3 Grumple   Members   -  Reputation: 164

Like
0Likes
Like

Posted 14 August 2014 - 07:12 AM

Your link might be a workable option, but having read a bit more I think I might be confusing people with my description.

 

I think the real compatibility issue is more generalized to accessing a uniform array from within the fragment shader using a non-constant index.   The index variable I am using is originally received in the vertex shader as an attribute (in), and passed to the fragment shader (out),  The fragment shader then  uses that to index into the uniform array of texture samplers.   

 

What I've found in hindsight is that glsl 330 doesn't like using any form of variable as an index into said uniform array, even though NVidia seems to allow it.  =/







PARTNERS