kinda phong frag shader
This commit is contained in:
+25
-1
@@ -16,7 +16,31 @@ float dither(vec2 uv) {
|
||||
return (rand(uv) * 2.0 - 1.0) / 256.0;
|
||||
}
|
||||
|
||||
const vec3 objectColor = vec3(1.0, 1.0, 1.0);
|
||||
const vec3 lightColor = vec3(1.0, 1.0, 1.0);
|
||||
const float ambientStrength = 0.1;
|
||||
const float specularStrength = 0.5;
|
||||
const float shininess = 32.0;
|
||||
|
||||
void main()
|
||||
{
|
||||
color = vec4(0.5 * normal + 0.5, 1.0);
|
||||
vec3 norm = normalize(normal);
|
||||
vec3 viewDir = normalize(cameraPosition - worldPositions);
|
||||
|
||||
vec3 ambient = ambientStrength * lightColor * objectColor;
|
||||
vec3 result = ambient;
|
||||
|
||||
for (int i = 0; i < 3; i++) {
|
||||
vec3 lightDir = normalize(lightPositions[i] - worldPositions);
|
||||
float diff = max(dot(norm, lightDir), 0.0);
|
||||
vec3 diffuse = diff * lightColor;
|
||||
|
||||
vec3 halfwayDir = normalize(lightDir + viewDir);
|
||||
float spec = pow(max(dot(norm, halfwayDir), 0.0), shininess);
|
||||
vec3 specular = specularStrength * spec * lightColor;
|
||||
|
||||
result += (diffuse + specular) * objectColor;
|
||||
}
|
||||
|
||||
color = vec4(result, 1.0);
|
||||
}
|
||||
|
||||
+1
-1
@@ -407,7 +407,7 @@ void updateNodeTransformations(SceneNode* node, glm::mat4 transformationThusFar)
|
||||
void renderNode(SceneNode* node) {
|
||||
glUniformMatrix4fv(3, 1, GL_FALSE, glm::value_ptr(node->currentTransformationMatrix));
|
||||
glUniformMatrix4fv(4, 1, GL_FALSE, glm::value_ptr(node->modelMatrix));
|
||||
glUniformMatrix4fv(5, 1, GL_FALSE, glm::value_ptr(node->normalMatrix));
|
||||
glUniformMatrix3fv(5, 1, GL_FALSE, glm::value_ptr(node->normalMatrix));
|
||||
|
||||
GLint lightPosLoc = shader->getUniformFromName("lightPositions");
|
||||
glUniform3fv(lightPosLoc, 3, glm::value_ptr(lightCoords[0]));
|
||||
|
||||
Reference in New Issue
Block a user