My shader requires diffuse and normal map textures. How to implement it? I didn't find answer in
previous topic.
Is it possible to use sf::Shader with multiple textures as a raw shader for custom OpenGL geometry?
Now I can only load 1 texture, and if I comment sf::Texture::bind(), I will recive black model.
//staff with vertices
std::vector<GLfloat> vertices(3 * 3 * model->nfaces(), 0);
GLuint vao = 0;
glGenVertexArrays(1, &vao);
glBindVertexArray(vao);
glEnableVertexAttribArray(0);
GLuint vertexbuffer = 0;
glGenBuffers(1, &vertexbuffer);
glBindBuffer(GL_ARRAY_BUFFER, vertexbuffer);
glBufferData(GL_ARRAY_BUFFER, sizeof(GLfloat)*vertices.size(), vertices.data(), GL_STATIC_DRAW);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, (void*)0);
//textures
sf::Texture texdif= model->diffusemapT;
sf::Texture::bind(&texdif);
sf::Texture texnormal = model->normalmapT;
glEnable(GL_TEXTURE_2D);
sf::Texture::bind(&texnormal);
//shader
sf::Shader shader;
if (!shader.loadFromFile("Vertex_shader.glsl", "Fragment_shader.glsl")) return 0;
sf::Shader::bind(&shader);
//drawning
shader.setUniform("diffuse", texdif);
shader.setUniform("tangentnm", texnormal);
glDrawArrays(GL_TRIANGLES, 0, vertices.size());
window.display();
Now I use shader only with 1 texture. For code above I get normal map on my model, because it was loaded later. But I want to use this shader:
#version 330 core
out vec3 color;
// Interpolated values from the vertex shaders
in vec3 Normal_cameraspace;
in vec3 LightDirection_cameraspace;
in vec3 tangent_cameraspace;
in vec3 bitangent_cameraspace;
in vec2 UV;
// Textures
uniform sampler2D tangentnm;
uniform sampler2D diffuse;
void main() {
vec3 n = normalize(Normal_cameraspace);
mat3 D = mat3(normalize(tangent_cameraspace), normalize(bitangent_cameraspace), n);
n = normalize((D*normalize(texture(tangentnm, UV).rgb * 2 - 1)));
vec3 l = normalize(LightDirection_cameraspace);
float cosTheta = clamp(dot(n,l), 0, 1);
color = texture(diffuse, UV).xyz*(0.1 + 1.3*cosTheta);
}
SFML 2.5.1, OpenGL 4.6