View Full Version : GLSL & textures
07-31-2007, 12:07 AM
I tried to simulate multi-texturing in the fragment shader.
I wanted the code to be generic so I pass by uniform the number of textures I use.
I checked the uniform and it's value was 1.
when I use the uniform as test variable in the loop I don't get any result. when I use the constant 1 as the test variable it works.
is it because using constant in the loop causes unrolling of the loop and then the array access is defined by constants?
if not, do u have any ideas how to work around this strange behaviour?
07-31-2007, 12:55 AM
You tried to "simulate" multi-texturing in fragment shaders?
Why that? Multi-texturing is available in fragment shaders.
Show your shader code and the texture sampler setup.
What's your graphics hardware?
Did you get any compile or link errors in the GLSL info logs?
07-31-2007, 06:09 AM
Use different shaders for each number of passes, It's not possible to index uniform vars or texturesampler by a dynamic value on shadermodel 3.0 cards.
07-31-2007, 06:18 AM
the code is something like this:
uniform int nTextures;
uniform sampler2D texUnit0;
void TextureFunction(inout vec4 Color)
for(int iTexture = 0; iTexture < nTextures; ++iTexture)
I checked that nTextures equals 1 but setting the
color. when I rewrite the code and write instead nTextures the costant 1, it works fine. in the
future I plan to change the sampler2D to be an array too, currently it's onky the texture
coordinations. but it shouldn't matter, it suppose to work the same if nTextures is one.
I also added to the function the line
vec4 v = gl_TexCoord, to be sure the array
is defined correctly, since there are no dynamic allocations in GLSL as far as I understood, but
it didn't help.
07-31-2007, 08:21 AM
iTexture is a dynamic variable that counts up, The problem is that the gl_TexCoord is an array of uniform variables.
The only case that works, is if it'spossible to unroll the for loop (replace the var by static values) or if the the loopvar didn't index uniforms.
You could load the offset without problems from another texture (not fast), but using a uniform array like a 1Dtexture with nearest filter isn't possible.
07-31-2007, 10:02 AM
Originally posted by oc2k1:
It's not possible to index uniform vars or texturesampler by a dynamic value on shadermodel 3.0 cards. I don't know about texture sampler variables but for other variables (like an array of mat4 uniforms) it should be possible to use a dynamic variable e.g. an attribute variable to index this mat4 array. AFAIK this should also be possible on SM2.0 cards.
Otherwise you wouldn't be able to do hardware skinning!
07-31-2007, 10:05 AM
It's possible in a vertexshader, but not in a fragmentshader
Powered by vBulletin® Version 4.2.2 Copyright © 2016 vBulletin Solutions, Inc. All rights reserved.