2 pièce(s) jointe(s)
Multitexturing et shaders = problème!
Hello!
Je me crée un shader de peau pour un personnage féminin (futur jeu).
J'ai besoin pour ça de plusieurs textures utilisant les mêmes UV:
1. albedo (couleur) de la peau + alpha
2. gloss map, depth map, et 2 slots libres pour bricoler.
(à l'avenir : 3. normal map, height map...)
Mais j'ai un problème d'accès aux map depuis le shader, si j'accède à l'un je perd l'autre et vice versa.
Les extensions multitexture sont définie et supportées.
Voici les shaders et comment j'initialize les textures.
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13
| varying vec3 normal, lightVec, eyeVec;
varying vec4 position;
uniform vec3 lightDir;
uniform vec3 cameraPos;
void main()
{
normal = gl_NormalMatrix * gl_Normal;
lightVec = gl_NormalMatrix * lightDir;
eyeVec = gl_NormalMatrix * cameraPos;
position = gl_Vertex;
gl_TexCoord[0] = gl_MultiTexCoord0;
gl_Position = ftransform();
} |
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
| varying vec3 normal, lightVec, eyeVec;
varying vec4 position;
uniform sampler2D tex, tex1;
void main()
{
// gloss map, etc...
// vec4 color1 = texture2D(tex,glTexCoord[0].st);
// albedo de la peau
vec4 albedo = texture2D(tex1,gl_TexCoord[1].st);
vec3 n = normalize(normal);
vec3 L = normalize(lightVec);
vec3 E = -normalize(eyeVec-position.xyz);
// ambient
vec4 color = gl_LightSource[0].ambient * albedo;
// diffuse avec color bleeding
float lambertTerm = max(dot(n,L), 0.0);
color += gl_LightSource[0].diffuse * vec4(lambertTerm*1.3,lambertTerm*1.1,lambertTerm,1.0);
// speculaire
vec3 R = reflect(-L, n);
float specular = pow(max(dot(R, E), 0.0), gl_FrontMaterial.shininess);
color += gl_LightSource[0].specular * specular;
gl_FragColor = color;
} |
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
| glClientActiveTextureARB(GL_TEXTURE0_ARB);
glTexCoordPointer(2, GL_FLOAT, 0, &uv[0]);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glClientActiveTextureARB(GL_TEXTURE1_ARB);
glTexCoordPointer(2, GL_FLOAT, 0, &uv[0]);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glActiveTextureARB( GL_TEXTURE0_ARB );
glEnable( GL_TEXTURE_2D );
glBindTexture( GL_TEXTURE_2D, texture.at(1));
glActiveTextureARB( GL_TEXTURE1_ARB );
glEnable( GL_TEXTURE_2D );
glBindTexture( GL_TEXTURE_2D, texture.at(0));
GLint texture1Loc = glGetUniformLocation(program,"tex");
GLint texture2Loc = glGetUniformLocation(program,"tex1");
glUseProgram (program);
glUniform1i(texture1Loc, texture.at(1));
glUniform1i(texture2Loc, texture.at(0)); |
Le problème c'est que si je "décommente" la ligne color1= texture2D...
albedo prend ses valeurs dans l'autre texture et je n'ai plus accès à la première texture.
ex: A. accès à une seule texture (image correcte)
http://www.developpez.net/forums/att...1&d=1184931604 B. Accès à la 2ème texture (image foireuse) http://www.developpez.net/forums/att...1&d=1184931610