Bonjour,

Je rencontre un soucis depuis 2 jours pour texturer mon terrain.

La texture s'affiche comme ceci. Les bosses sont des élévations générée avec du bruit de Perlin.

Nom : texture.jpg
Affichages : 456
Taille : 161,4 Ko

Mon vecteur décrivant les points et les coordonées de texture est de cette forme : sommets du terrain / coordonées de texture

Comme ce sont des triangles qui composent le terrain j'ai mis comme coordonnées : 0,0 / 0.5,1 / 1,1

Je ne comprends vraiment pas ce qu'il se passe.

Voici le code de mes 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
15
16
17
#version 330 core
layout (location = 0) in vec3 position;
layout (location = 2) in vec2 texCoord;
 
out vec2 TexCoord;
 
uniform mat4 model;
uniform mat4 view;
uniform mat4 projection;
 
void main()
{
 gl_Position = projection * view * model *vec4(position, 1.0f);
 
	TexCoord = texCoord;
	//TexCoord = vec2(texCoord.x, 1.0 - texCoord.y);
}
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
#version 330 core
in vec3 ourColor;
in vec2 TexCoord;
 
out vec4 color;
 
// Texture samplers
uniform sampler2D ourTexture1;
 
 
void main()
{
	color = texture(ourTexture1, TexCoord);
}
Et voici la routine précédé du bind de texture

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
 
glBindVertexArray(VAO);	
	long int b = vertices_terrain.size(); // offset
 
	for (int i = 0; i < b; i += 3)
	{
		vertices_terrain.push_back(0.0f);
		vertices_terrain.push_back(0.0f);
		vertices_terrain.push_back(0.5f);
		vertices_terrain.push_back(1.0f);
		vertices_terrain.push_back(1.0f);
		vertices_terrain.push_back(0.0f);
	}
 
 
	glBindBuffer(GL_ARRAY_BUFFER, VBO_TERRAIN);
	glBufferData(GL_ARRAY_BUFFER, sizeof(GLfloat) * vertices_terrain.size(), &vertices_terrain[0], GL_STATIC_DRAW);
 
	glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, EBO_TERRAIN);
	glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(GLuint) * faces_terrain.size(), &faces_terrain[0], GL_STATIC_DRAW);
 
	glVertexAttribPointer(0, 3, GL_FLOAT, GL_TRUE, 0 * sizeof(GLfloat), (GLvoid*)0);
	glEnableVertexAttribArray(0);
	// Color attribute
	//// TexCoord attribute
	glVertexAttribPointer(2, 2, GL_FLOAT, GL_TRUE, 0 * sizeof(GLfloat), (GLvoid*)(b * sizeof(GLfloat)));
	glEnableVertexAttribArray(2);
 
 
	GLuint texture1;
	glGenTextures(1, &texture1);
	glBindTexture(GL_TEXTURE_2D, texture1); // All upcoming GL_TEXTURE_2D operations now have effect on our texture object
 
	// Set our texture parameters
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);	// Set texture wrapping to GL_REPEAT
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
 
	// Set texture filtering
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
 
	// Load, create texture and generate mipmaps
	int width, height;
	unsigned char* image = SOIL_load_image("../imgp0913.jpg", &width, &height, 0, SOIL_LOAD_RGB);
	glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, image);
	glGenerateMipmap(GL_TEXTURE_2D);
	SOIL_free_image_data(image);
	glBindTexture(GL_TEXTURE_2D, 0);
 
	while (!glfwWindowShouldClose(window))
	{
		glfwPollEvents();
		glClearColor(0.2f, 0.3f, 0.3f, 1.0f);
		glClear(GL_COLOR_BUFFER_BIT);
 
		glm::mat4 view;
		glm::mat4 model3;
 
		// Projection
		model3 = glm::scale(model3, glm::vec3(0.9f));
		model3 = glm::rotate(model3, -20.0f, glm::vec3(1.0f, 0.0f, 0.0f));
		view = glm::translate(view, glm::vec3(0.0f, 0.0f, -10.0f));
 
		glm::mat4 projection;
		projection = glm::perspective(20.0f, (GLfloat)WINDOW_WIDTH / (GLfloat)WINDOW_HEIGHT, 0.1f, 100.0f);
 
		// Get the uniform locations
		GLint modelLoc = glGetUniformLocation(shader.Program, "model");
		GLint viewLoc = glGetUniformLocation(shader.Program, "view");
		GLint projLoc = glGetUniformLocation(shader.Program, "projection");
 
		// Pass the matrices to the shader
		glUniformMatrix4fv(modelLoc, 1, GL_FALSE, glm::value_ptr(model3));
		glUniformMatrix4fv(viewLoc, 1, GL_FALSE, glm::value_ptr(view));
		glUniformMatrix4fv(projLoc, 1, GL_FALSE, glm::value_ptr(projection));
 
		glActiveTexture(GL_TEXTURE0);
		glBindTexture(GL_TEXTURE_2D, texture1);
		glUniform1i(glGetUniformLocation(shader.Program, "ourTexture1"), 0);
 
		shader.Use();	
 
		glBindVertexArray(VAO);
 
		glDrawElements(GL_TRIANGLES, faces_terrain.size(), GL_UNSIGNED_INT, 0);
 
		glBindVertexArray(0);
	glfwSwapBuffers(window);
}
Lorsque que change les coordonnées de texture, la bande marron augmente, il y a plus de détail mais à un moment ça stagne et ça continue à ressembler à rien du tout.

Merci de votre aide