It's working!

This commit is contained in:
Ben
2019-03-01 16:57:11 +00:00
parent 320fc6cf9b
commit 063a7ab947
4 changed files with 16 additions and 16 deletions

View File

@@ -10,7 +10,7 @@ out vec4 outColour;
vec3 viewPos = vec3(0.0, 0.0, 0.0);
vec3 objectColour = vec3(1.0, 1.0, 1.0);
vec3 lightColour = vec3(0.7, 0.0, 0.65);
vec3 lightColour = vec3(0.7, 0.3, 0.65);
// vec3 lightColour = vec3(0.3, 0.85, 1.0);
void main() {
@@ -21,7 +21,7 @@ void main() {
vec3 diffuse = diff * lightColour;
float specularStrength = 0;
float specularStrength = 1;
vec3 viewDir = normalize(viewPos - FragPos);
vec3 reflectDir = reflect(-lightDir, normal);
@@ -30,7 +30,7 @@ void main() {
vec3 specular = specularStrength * spec * lightColour;
float ambientStrength = 0.4;
float ambientStrength = 0.1;
vec3 ambient = ambientStrength * lightColour;
vec3 result = (ambient + diffuse + specular) * objectColour;

View File

@@ -29,7 +29,7 @@ int main (int argc, char** argv) {
Shader shader;
shader.load("./resources/shaders/phong").attatch().link().use();
Mesh mesh{ "./resources/test1.obj" };
Mesh mesh{ "./resources/lucy.obj" };
mesh.setup();
SDL_Event e;

View File

@@ -91,7 +91,7 @@ void Mesh::render(Shader& shader) {
// Model matrice
glm::mat4 model = glm::mat4(1.0f);
model = glm::translate(model, { -17.0f, -17.0f, -17.0f });
model = glm::translate(model, { -170.0f, -170.0f, -170.0f });
model = glm::rotate(model, glm::radians(-160.0f + this->rotation), glm::vec3(0.0f, 1.0f, 0.0f));
// Gets uniform for model matrice, to be used later
GLint uniTrans = glGetUniformLocation(shader.getProgram(), "model");

View File

@@ -22,13 +22,12 @@ void OBJLtoGLM(ObjLMesh& mesh,
mesh.attrib.vertices[3 * index.vertex_index + 1],
mesh.attrib.vertices[3 * index.vertex_index + 2]
};
outVert.push_back(vertex);
outNorm.push_back({
mesh.attrib.normals[3 * index.normal_index + 0],
mesh.attrib.normals[3 * index.normal_index + 1],
mesh.attrib.normals[3 * index.normal_index + 2]
});
// outNorm.push_back({
// mesh.attrib.normals[3 * index.normal_index + 0],
// mesh.attrib.normals[3 * index.normal_index + 1],
// mesh.attrib.normals[3 * index.normal_index + 2]
// });
// outTexCoord.push_back({
// mesh.attrib.texcoords[2 * index.texcoord_index + 0],
@@ -36,15 +35,16 @@ void OBJLtoGLM(ObjLMesh& mesh,
// 0.0f
// });
// if (uniqueVertices.count(vertex) == 0) {
// uniqueVertices[vertex] = static_cast<uint32_t>(outVert.size());
// }
if (uniqueVertices.count(vertex) == 0) {
uniqueVertices[vertex] = static_cast<uint32_t>(outVert.size());
outVert.push_back(vertex);
}
outIndices.push_back(outIndices.size());
outIndices.push_back(uniqueVertices[vertex]);
}
}
// ComputeNormals(outNorm, outVert, outIndices);
ComputeNormals(outNorm, outVert, outIndices);
}
void ComputeNormals(std::vector<glm::vec3>& normals,