Таким образом, я могу передать все версии и координаты текстуры в шейдер, используя буферы.
Мой Теперь проблема заключается в том, как установить правильный цвет в пиксельном шейдере.
Формы, заданные классом загрузчика, имеют сетку и материал, которые определяются следующим образом:
Код: Выделить всё
typedef struct {
std::string name;
float ambient[3];
float diffuse[3];
float specular[3];
float transmittance[3];
float emission[3];
float shininess;
float ior; // index of refraction
float dissolve; // 1 == opaque; 0 == fully transparent
// illumination model (see http://www.fileformat.info/format/material/)
int illum;
std::string ambient_texname;
std::string diffuse_texname;
std::string specular_texname;
std::string normal_texname;
std::map unknown_parameter;
} material_t;
typedef struct
{
std::vector positions;
std::vector normals;
std::vector texcoords;
std::vector indices;
} mesh_t;
Например, диффузный цвет будет установлен следующим образом:
Код: Выделить всё
GLuint diffColLocation = glGetUniformLocation(programmId, "diffuseColor");
glUniform3f(diffColLocation, this->material.diffuse[0], this->material.diffuse[1], this->material.diffuse[2]);
Код: Выделить всё
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, this->ambientTextureID);
glUniform1i(this->diffuseTextureUniformIndex, 0);
glActiveTexture(GL_TEXTURE0 + 1);
glBindTexture(GL_TEXTURE_2D, this->diffuseTextureID);
glUniform1i(this->diffuseTextureUniformIndex, 0);
etc.
Мой пиксельный шейдер сейчас выглядит так:
Код: Выделить всё
#version 150 core
#extension GL_ARB_explicit_attrib_location: enable
// output to the (default) FBO in color buffer 0
layout (location = 0) out vec4 outColor;
in vec2 fragTextCoords;
uniform sampler2D ambientTex;
uniform sampler2D diffuseTex;
uniform sampler2D specularTex;
uniform vec3 ambientColor;
uniform vec3 diffuseColor;
uniform vec3 specularColor;
// main entry point for the fragment shader
void main() {
//vec3 tempColor ambientColor + diffuseTex * specularTex; //Is that correct?
//outcolor = tempColor * texture(diffuseTex, fragTextCoords); //Then this?
outcolor = texture(diffuseTex, fragTextCoords);
}
Подробнее здесь: https://stackoverflow.com/questions/237 ... ith-opengl
Мобильная версия