J'ai essayé de réaliser une carte de hauteur avec GLSL. Pour cela, j'ai besoin d'envoyer ma photo à VertexShader et d'obtenir le composant gris.sampler2D uniforme dans Vertex Shader
glActiveTexture(GL_TEXTURE0);
Texture.bind();
glUniform1i(mShader.getUniformLocation("heightmap"), 0);
mShader.getUniformLocation utilise glGetUniformLocation et bon travail pour d'autres valeurs uniformes, qui ont utilisé dans le fragment, Vertex Shaders. Mais pour heightmapretour-1 ...
Code VertexShader:
#version 330 core
layout (location = 0) in vec3 position;
layout (location = 1) in vec4 color;
layout (location = 2) in vec2 texCoords;
layout (location = 3) in vec3 normal;
out vec3 Normal;
out vec3 FragPos;
out vec2 TexCoords;
out vec4 ourColor;
uniform mat4 model;
uniform mat4 view;
uniform mat4 projection;
uniform sampler2D heightmap;
void main()
{
float bias = 0.25;
float h = 0.0;
float scale = 5.0;
h = scale * ((texture2D(heightmap, texCoords).r) - bias);
vec3 hnormal = vec3(normal.x*h, normal.y*h, normal.z*h);
vec3 position1 = position * hnormal;
gl_Position = projection * view * model * vec4(position1, 1.0f);
FragPos = vec3(model * vec4(position, 1.0f));
Normal = mat3(transpose(inverse(model))) * normal;
ourColor = color;
TexCoords = texCoords;
}
peut être algorithme d'obtenir la hauteur est mauvaise, mais l'erreur à l'obtention uniformlocation arrête mon travail .. Qu'est-ce que est faux? Des idées?
UPD: texCoords (pas TexCoords) bien sûr utilise dans
h = scale * ((texture2D(heightmap, texCoords).r) - bias);
mon erreur, mais il ne résout pas le problème. Ayant la même erreur ..
votre changement dans le code est maintenant compilable/linkable sans problèmes. L'uniforme est trouvé sur ma configuration (nVidia). Utilisez-vous 'glGetUniformLocation' après que votre shader est lié? – Spektre