Jump to content

  • Log In with Google      Sign In   
  • Create Account

Awesome job so far everyone! Please give us your feedback on how our article efforts are going. We still need more finished articles for our May contest theme: Remake the Classics

#Actualic0de

Posted 15 December 2012 - 09:50 AM

Thanks. So when I do that, how do I access each individual texture from a GLSL fragment shader?


you will have two uniform sampler2Ds in your fragment program and you will access each with the stander texture2D function the only difference is that you will have two uniforms instead of one. You will send textures to your shader like so:
//Sample code used for normal mapping
glActiveTexture(GL_TEXTURE0);
glUniform1i(texture_location, 0);
glBindTexture(GL_TEXTURE_2D, dTex);


glActiveTexture(GL_TEXTURE1);
glUniform1i(normal_texture_location, 1);
glBindTexture(GL_TEXTURE_2D, dNorm);

glActiveTexture(GL_TEXTURE2);
glUniform1i(height_texture_loc, 2);
glBindTexture(GL_TEXTURE_2D, dHeight);

and use them like so

//simple multiplicative blending example
varying vec2 texCoord;

uniform sampler2D texture1;
uniform sampler2D texture2;
uniform sampler2D texture3;

void main()
{
vec4 sample1 = texture2D(texture1, texCoord);
vec4 sample2 = texture2D(texture2, texCoord);
vec4 sample3 = texture2D(texture3, texCoord);

gl_FragColor = sample1 * sample2 * sample3;
}

#4ic0de

Posted 15 December 2012 - 09:50 AM

Thanks. So when I do that, how do I access each individual texture from a GLSL fragment shader?


you will have two uniform sampler2Ds in your fragment program and you will access each with the stander texture2D function the only difference is that you will have two uniforms instead of one. You will send textures to your shader like so:
//Sample code used for normal mapping
glActiveTexture(GL_TEXTURE0);
glUniform1i(texture_location, 0);
glBindTexture(GL_TEXTURE_2D, dTex);


glActiveTexture(GL_TEXTURE1);
glUniform1i(normal_texture_location, 1);
glBindTexture(GL_TEXTURE_2D, dNorm);

glActiveTexture(GL_TEXTURE2);
glUniform1i(height_texture_loc, 2);
glBindTexture(GL_TEXTURE_2D, dHeight);

and use them like so

//simple multiplicative blending example
varying vec2 texCoord;

uniform sampler2D texture1;
uniform sampler2D texture2;
uniform sampler2D texture3;

void main()
{
vec4 sample1 = texture2D(texture1, texCoord);
vec4 sample2 = texture2D(texture2, texCoord);
vec4 sample3 = texture2D(texture3, texCoord);

gl_FragColor = sample1 * sample2 * sample3;
}

#3ic0de

Posted 15 December 2012 - 09:49 AM

Thanks. So when I do that, how do I access each individual texture from a GLSL fragment shader?


you will have two uniform sampler2Ds in your fragment program and you will access each with the stander texture2D function the only difference is that you will have two uniforms instead of one. You will send textures to your shader like so:
//Sample code used for normal mapping
glActiveTexture(GL_TEXTURE0);
glUniform1i(texture_location, 0);
glBindTexture(GL_TEXTURE_2D, dTex);


glActiveTexture(GL_TEXTURE1);
glUniform1i(normal_texture_location, 1);
glBindTexture(GL_TEXTURE_2D, dNorm);

glActiveTexture(GL_TEXTURE2);
glUniform1i(height_texture_loc, 2);
glBindTexture(GL_TEXTURE_2D, dHeight);

and use them like so

[code=auto:0]
//simple multiplicative blending example
varying vec2 texCoord;

uniform sampler2D texture1;
uniform sampler2D texture2;
uniform sampler2D texture3;

void main()
{
vec4 sample1 = texture2D(texture1, texCoord);
vec4 sample2 = texture2D(texture2, texCoord);
vec4 sample3 = texture2D(texture3, texCoord);

gl_FragColor = sample1 * sample2 * sample3;
}

#2ic0de

Posted 15 December 2012 - 09:49 AM

Thanks. So when I do that, how do I access each individual texture from a GLSL fragment shader?


you will have two uniform sampler2Ds in your fragment program and you will access each with the stander texture2D function the only difference is that you will have two uniforms instead of one. You will send textures to your shader like so:
//Sample code used for normal mapping
glActiveTexture(GL_TEXTURE0);
glUniform1i(texture_location, 0);
glBindTexture(GL_TEXTURE_2D, dTex);


glActiveTexture(GL_TEXTURE1);
glUniform1i(normal_texture_location, 1);
glBindTexture(GL_TEXTURE_2D, dNorm);

glActiveTexture(GL_TEXTURE2);
glUniform1i(height_texture_loc, 2);
glBindTexture(GL_TEXTURE_2D, dHeight);

and use them like so

[code=auto:0]
//simple multiplicative blending example
varying vec2 texCoord;

uniform sampler2D texture1;
uniform sampler2D texture2;
uniform sampler2D texture3;

void main()
{
vec4 sample1 = texture2D(texture1, texCoord);
vec4 sample2 = texture2D(texture2, texCoord);
vec4 sample3 = texture2D(texture3, texCoord);

gl_FragColor = sample1 * sample2 * sample3;
}

#1ic0de

Posted 15 December 2012 - 09:44 AM

Thanks. So when I do that, how do I access each individual texture from a GLSL fragment shader?


you will have two uniform sampler2Ds in your fragment program and you will access each with the stander texture2D function the only difference is that you will have two uniforms instead of one. You will send textures to your shader like so:
//Sample code used for normal mapping
glActiveTexture(GL_TEXTURE0);
glUniform1i(texture_location, 0);
glBindTexture(GL_TEXTURE_2D, dTex);


glActiveTexture(GL_TEXTURE1);
glUniform1i(normal_texture_location, 1);
glBindTexture(GL_TEXTURE_2D, dNorm);

glActiveTexture(GL_TEXTURE2);
glUniform1i(height_texture_loc, 2);
glBindTexture(GL_TEXTURE_2D, dHeight);

PARTNERS