PDA

View Full Version : different sampler but the same effect



huaner
05-07-2007, 12:40 AM
Hi:
i downloaded IDE of shaderDesgin. but i came across some questions. the code as fellow:


vertex:
void main()
{
gl_TexCoord[0] = gl_MultiTexCoord0;
gl_TexCoord[1] = gl_MultiTexCoord0;
gl_Position = ftransform();
}
fragment:
uniform sampler2D TextureUnit0;
uniform sampler2D TextureUnit1;
void main()
{
vec4 value1 = texture2D(TextureUnit0, gl_TexCoord[0]);
vec4 value2 = texture2D(TextureUnit1, gl_TexCoord[1]);

gl_FragColor = value1;
// gl_FragColor = value2;

}the problem is :that i found the effect of value2 and value1 is the same. whether the load texture is wrong or texture coordninate? but when put the shader in procedure, it's all right.May i didn't bind the second texture ?
thanks

predaeus
05-07-2007, 01:11 AM
Depends on what you are trying to achieve, but often you would want

gl_TexCoord[1] = gl_MultiTexCoord1;in your vertex shader.

Apart from that we can't tell anything because we don't know how you bind textures to the uniform samplers and what texture coordinates you are setting.

huaner
05-07-2007, 02:04 AM
Apart from that we can't tell anything because we don't know how you bind textures to the uniform samplers and what texture coordinates you are setting. hi:
thank you for your reply. I bind the texture by the Textures which is below the Project menu. then i choose two textures; at last, refresh and accept it. but i just found the second didin't appear Texture Preview dialog. why?
aslo you mention "texture coordinates you are setting", Are texture coordinates set in vertex shader? At same time i rectify gl_TexCoord[1] = gl_MultiTexCoord1
but the effect is aslo wrong.

predaeus
05-07-2007, 05:05 AM
Sorry I hardly know anything about shaderdesigner. Maybe somebody else can clarify.

ZbuffeR
05-07-2007, 07:26 AM
With multiple textures there is something strange with this tool, you have to manually add one or more custom uniform or something.
I had this problem and solved it, but I don't really remember how :-(

yooyo
05-08-2007, 07:00 AM
@huaner:
You shader code snippet will be optimised by driver's GLSL compiler and propably it will discard value2 and TextureUnit1 as unused variables.
I don't know what did you do in your app but samplers should have texture unit number, not texture ID. So.. bind texture to unit and then bind texture unit index to sampler.