Bonjour, voulant développer un shader de bump mapping j'ai commencé par recuperer celui present sur codessources et l'ai modifié pour l'appliquer dans une application opengl, mais le shader n'agit pas sur les textures. J'ai tout vérifié mais je n'arrive pas à trouver! Pouvez-vous m'aider ?


Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
 
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <iostream>
#include <GL/glew.h>
#include <GL/glut.h>
#include <GL/glaux.h>
#include <math.h>
#include <time.h>
#include "fonctshader.h"
#include "bmp.h"
 
 
using namespace std;
 
 
 
 
char presse;
GLint xold, yold, anglex = 0.0, angley = 0.0;
float UVdecal = 0;
GLuint water=0;
GLint loc;
GLubyte * bytes;
GLhandleARB b;
UINT Tex_id[10];//le tableau de textures 
float position[] = { 100.0, 100.0, 100.0, 0.0};
 
void mouse(int button, int state,int x,int y)
{ 
	/* si on appuie sur le bouton gauche */
	if (button == GLUT_LEFT_BUTTON && state == GLUT_DOWN)
	{
		presse = 1; /* le booleen presse passe a 1 (vrai) */
		xold = x; /* on sauvegarde la position de la souris */
		yold=y;
	}
	/* si on relache le bouton gauche */
	if (button == GLUT_LEFT_BUTTON && state == GLUT_UP) 
		presse=0;
	/* le booleen presse passe a 0 (faux) */
	glutPostRedisplay();
}
 
void mousemotion(int x,int y)
{
	if (presse) /* si le bouton gauche est presse */
	{ /* on modifie les angles de rotation de l'objet en fonction de la position
	  actuelle de la souris et de la dernière position sauvegardée */
		anglex=anglex+(x-xold);
		angley=angley+(y-yold);
		glutPostRedisplay();
		/* on demande un rafraichissement de l'affichage */
	}
	xold=x; yold=y;
	/* sauvegarde des valeurs courante de le position de la souris */
	glutPostRedisplay();
}
 
 
 
 
float lpos[4] = {1,0.5,1,0};
 
void redimensionnement(int w, int h) {
 
	// Prevent a divide by zero, when window is too short
	// (you cant make a window of zero width).
	if(h == 0)
		h = 1;
 
	float ratio = 1.0* w / h;
 
	// Reset the coordinate system before modifying
	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
 
	// Set the viewport to be the entire window
    glViewport(0, 0, w, h);
 
	// Set the correct perspective.
	gluPerspective(45,ratio,1,1000);
	glMatrixMode(GL_MODELVIEW);
 
 
}
float a = 0;
 
 
 
void processNormalKeys(unsigned char key, int x, int y) {
 
	if (key == 27) 
		exit(0);
}
 
 
 
 
 
 
 
void createTexture(GLubyte * bytes, GLuint* num)
{
    glGenTextures(1, num);
    glBindTexture(GL_TEXTURE_2D, *num);
    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
	glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 256, 256, 0, GL_RGB ,GL_UNSIGNED_BYTE,bytes);
 
}
 
 
void renderScene(void) {
	glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);       
 glLoadIdentity(); 
 
 gluLookAt(250*sin((float)clock()/2000),300,250*cos((float)clock()/2000),0,0,0,0,1,0);
 
 float position[] = {100*sin(-(float)clock()/1000),2.0,100*cos(-(float)clock()/1000),0.0};
 glLightfv(GL_LIGHT0, GL_POSITION, position);
 
 glDisable(GL_LIGHTING);
 glDisable(GL_TEXTURE_2D);
 glColor3f(1,0,0);
 glPointSize(5);
 glBegin(GL_POINTS);
 glVertex3fv(position);
 glEnd();
 glEnable(GL_TEXTURE_2D);
 glEnable(GL_LIGHTING);
 
 glColor3f(1,1,1);
 glUseProgram(b);
 glNormal3f(0,1,0);
 glBegin(GL_QUADS);
 glMultiTexCoord2fARB(GL_TEXTURE0_ARB, 0.0f, 0.0f);
 glMultiTexCoord2fARB(GL_TEXTURE1_ARB, 0.0f, 0.0f);
 glVertex3f(-100,0,-100);
 
 glMultiTexCoord2fARB(GL_TEXTURE0_ARB, 1.0f, 0.0f);
 glMultiTexCoord2fARB(GL_TEXTURE1_ARB, 1.0f, 0.0f);
 glVertex3f( 100,0,-100);
 
 glMultiTexCoord2fARB(GL_TEXTURE0_ARB, 1.0f, 1.0f);
 glMultiTexCoord2fARB(GL_TEXTURE1_ARB, 1.0f, 1.0f);
 glVertex3f( 100,0, 100);
 
 glMultiTexCoord2fARB(GL_TEXTURE0_ARB, 0.0f, 1.0f);
 glMultiTexCoord2fARB(GL_TEXTURE1_ARB, 0.0f, 1.0f);
 glVertex3f(-100,0, 100);
 glEnd();
 glUseProgram(0);
 
	glutSwapBuffers();
}
 
 
 
 
 
int main(int argc, char **argv) {
 
	glutInit(&argc, argv);
	glutInitDisplayMode(GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGBA);
	glutInitWindowPosition(100,100);
	glutInitWindowSize(320,320);
	glutCreateWindow("MM 2004-05");
 
	glutDisplayFunc(renderScene);
	glutIdleFunc(renderScene);
	glutReshapeFunc(redimensionnement);
	glutKeyboardFunc(processNormalKeys);
	glutMouseFunc(mouse);
	glutMotionFunc(mousemotion);
 
 
CBmp::CreateTexture("wall.bmp",Tex_id,0,true);
CBmp::CreateTexture("Bumpwall.bmp",Tex_id,1,true);
 
glewInit();
 
glActiveTextureARB=(PFNGLACTIVETEXTUREARBPROC)wglGetProcAddress("glActiveTextureARB");
 glMultiTexCoord2fARB=(PFNGLMULTITEXCOORD2FARBPROC)wglGetProcAddress("glMultiTexCoord2fARB");
  if(!glActiveTextureARB || !glMultiTexCoord2fARB) // Check if your OpenGL version support Multitexturing
{
cout <<"This OpenGL version does not support Multitexturing!"<< endl;
 
 } 
 
  if (!glewIsSupported("GL_ARB_texture_env_dot3"))
	{
		fprintf(stderr,"votre carte ne supporte pas l'extension GL_ARB_texture_env_dot3\n");
		exit(0);
	}
 
 
 glActiveTextureARB(GL_TEXTURE0_ARB);
 glEnable(GL_TEXTURE_2D);
 glBindTexture(GL_TEXTURE_2D,  Tex_id[0]);
 
 
 
 glActiveTextureARB(GL_TEXTURE1_ARB);
glEnable(GL_TEXTURE_2D);
 glBindTexture(GL_TEXTURE_2D,  Tex_id[1]);
 
 ///////////Shaders
 
 setShaders("FShader.frag","VShader.vert",b);
 
 int my_sampler_uniform_location;
 glUseProgram(b);
 
 my_sampler_uniform_location = glGetUniformLocationARB(b, "Texture0");
 glActiveTexture(GL_TEXTURE0 + 0);
 glBindTexture(GL_TEXTURE_2D, Tex_id[0]);
 glUniform1i(my_sampler_uniform_location, 0);
 
 my_sampler_uniform_location = glGetUniformLocationARB(b, "Texture1");
 glActiveTexture(GL_TEXTURE0 + 1);
 glBindTexture(GL_TEXTURE_2D, Tex_id[1]);
 glUniform1i(my_sampler_uniform_location, 1);
 glUseProgram(0);
 
 ///////////Lighting
 glLightfv(GL_LIGHT0, GL_POSITION, position);
 glEnable(GL_LIGHTING);
 glEnable(GL_LIGHT0);
 
 ///////////diver
 glClearColor(0,0,0,0);
 glEnable(GL_DEPTH_TEST);
 
glutMainLoop();
 
	return 0;
}

Les shaders :
Vertex:

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
 
varying vec3 normal,lightVec,viewVec;
 
void main()
{
	normal=gl_NormalMatrix*gl_Normal;
	viewVec=-(gl_ModelViewMatrix*gl_Vertex).xyz;
	lightVec=(gl_LightSource[0].position).xyz+viewVec;	
 
	gl_Position=ftransform();
	gl_FrontColor = gl_Color;
	gl_TexCoord[0]= gl_MultiTexCoord0; 
	gl_TexCoord[1]= gl_MultiTexCoord1;
}

Fragment :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
29
30
31
varying vec3 normal,lightVec,viewVec;
 
uniform sampler2D Texture0;
uniform sampler2D Texture1;
 
void main()
{
	vec4 color=gl_Color;	
 
	vec3 N=vec3(texture2D(Texture1,gl_TexCoord[1].st));
	N.x=N.x-0.5;
	N.y=N.y-0.5;
	N.z=N.z-0.5;
      N=normalize(N);
 
	vec3 L=normalize(lightVec);		
	vec3 V=normalize(viewVec);	
	vec3 R=normalize(2.0*dot(N,V)*N-V);
 
	float LdotN=dot(L,N);
	float LdotR=dot(L,R);
 
	// diffuse
      if(LdotN<=0.5)color=gl_Color*LdotN*2.0;
 
	// speculaire
	else if(LdotR>0.7)color=gl_Color*LdotR*1.5-0.05;
 
 
	gl_FragColor=color*texture2D(Texture0,gl_TexCoord[0].st);
}
J'ai joint le resultat obtenu et ce que je devrai avoir

Merci.

[ATTACH]Nom : bumpmapmauvais.jpg
Affichages : 89
Taille : 28,6 Ko[/ATTACH]Nom : bumpmapbon.jpg
Affichages : 109
Taille : 242,6 Ko