From: Luke Lau Date: Tue, 13 Nov 2018 12:15:08 +0000 (+0000) Subject: Fix refelctivity + refraction X-Git-Tag: cs7gv3-a3~20 X-Git-Url: http://git.lukelau.me/?p=opengl.git;a=commitdiff_plain;h=bd433c5ca7fcf3ce60bdc8db6fc0c76b547fe10b Fix refelctivity + refraction --- diff --git a/material.cpp b/material.cpp index c10820c..d55386f 100644 --- a/material.cpp +++ b/material.cpp @@ -22,7 +22,8 @@ Material::Material(const aiMaterial &ai, GLuint progId): progId(progId) { ai.Get(AI_MATKEY_SHININESS, shininess); ai.Get(AI_MATKEY_REFLECTIVITY, reflectivity); ai.Get(AI_MATKEY_REFRACTI, refractiveIndex); - ai.Get(AI_MATKEY_OPACITY, opacity); + if (ai.Get(AI_MATKEY_OPACITY, opacity) == aiReturn_FAILURE) + opacity = 1.f; ai.Get(AI_MATKEY_COLOR_AMBIENT, ambient); ai.Get(AI_MATKEY_COLOR_DIFFUSE, diffuse); @@ -38,7 +39,8 @@ Material::Texture::Texture(const std::string &fileName) { } void Material::bind() const { - glUniform4f(glGetUniformLocation(progId, "material.ambient"), ambient.r, ambient.g, ambient.b, ambient.a); + /* glUniform4f(glGetUniformLocation(progId, "material.ambient"), ambient.r, ambient.g, ambient.b, ambient.a); */ + glUniform4f(glGetUniformLocation(progId, "material.ambient"), 0.2, 0.2, 0.2, 1); glUniform4f(glGetUniformLocation(progId, "material.diffuse"), diffuse.r, diffuse.g, diffuse.b, diffuse.a); glUniform4f(glGetUniformLocation(progId, "material.specular"), specular.r, specular.g, specular.b, specular.a); glUniform1f(glGetUniformLocation(progId, "material.shininess"), shininess); diff --git a/models/mirrorCube.blend b/models/mirrorCube.blend index 2d5388f..be4f84a 100644 Binary files a/models/mirrorCube.blend and b/models/mirrorCube.blend differ diff --git a/models/mirrorCube.dae b/models/mirrorCube.dae index 78313fa..8476755 100644 --- a/models/mirrorCube.dae +++ b/models/mirrorCube.dae @@ -5,8 +5,8 @@ Blender User Blender 2.79.0 commit date:2018-03-22, commit time:14:10, hash:f4dc9f9 - 2018-11-08T03:10:17 - 2018-11-08T03:10:17 + 2018-11-13T12:14:34 + 2018-11-13T12:14:34 Z_UP @@ -105,6 +105,9 @@ brickwall_normal.jpg + + brickwall.jpg + @@ -136,9 +139,94 @@ 50 + + 1 1 1 1 + + + 1 + + + 1.6 + + + + + + + + + + + + + + + + + + 0 0 0 1 + + + 0 0 0 1 + + + 0.64 0.64 0.64 1 + + + 0.5 0.5 0.5 1 + + + 50 + - 1 1 1 0.2 + 1 1 1 0.04907978 + + 1.1 + + + + + + + + + + brickwall_jpg + + + + + brickwall_jpg-surface + + + + + brickwall_normal_jpg + + + + + brickwall_normal_jpg-surface + + + + + + 0 0 0 1 + + + 0 0 0 1 + + + + + + 0.5 0.5 0.5 1 + + + 50 + 1.6 @@ -158,6 +246,12 @@ + + + + + + @@ -236,7 +330,7 @@ - + @@ -244,6 +338,48 @@ + + + + 1 1 -1 1 -1 -1 -1 -0.9999998 -1 -0.9999997 1 -1 1 0.9999995 1 0.9999994 -1.000001 1 -1 -0.9999997 1 -1 1 1 + + + + + + + + + + 0 0 -1 0 0 1 1 0 -2.38419e-7 0 -1 -4.76837e-7 -1 2.38419e-7 -1.49012e-7 2.68221e-7 1 2.38419e-7 0 0 -1 0 0 1 1 -5.96046e-7 3.27825e-7 -4.76837e-7 -1 0 -1 2.38419e-7 -1.19209e-7 2.08616e-7 1 0 + + + + + + + + + + 0 0 1 1 0 1 1 0 0 1 0 0 1 0 0 1 0 0 1 0 0 1 0 0 0 0 1 1 0 1 1 0 0 1 0 0 0 0 1 0 1 1 1 0 1 1 0 1 1 0 1 1 0 1 1 0 1 1 0 1 0 0 1 0 1 1 1 0 1 1 0 1 + + + + + + + + + + + + + + +

0 0 0 2 0 1 3 0 2 7 1 3 5 1 4 4 1 5 4 2 6 1 2 7 0 2 8 5 3 9 2 3 10 1 3 11 2 4 12 7 4 13 3 4 14 0 5 15 7 5 16 4 5 17 0 6 18 1 6 19 2 6 20 7 7 21 6 7 22 5 7 23 4 8 24 5 8 25 1 8 26 5 9 27 6 9 28 2 9 29 2 10 30 6 10 31 7 10 32 0 11 33 3 11 34 7 11 35

+
+
+
@@ -268,7 +404,23 @@ 1 0 0 2.692266 0 1 0 0 0 0 1 0 0 0 0 1 - + + + + + + + + + + 1 0 0 -2.993813 0 1 0 0 0 0 1 0 0 0 0 1 + + + + + + + diff --git a/texturefrag.glsl b/texturefrag.glsl index 24a54d5..ddd951e 100644 --- a/texturefrag.glsl +++ b/texturefrag.glsl @@ -56,6 +56,13 @@ void main() { if (!material.hasNormalMap) normal = defNormal; + vec4 ambient = material.ambient * texture(material.diffuseMap, texCoord); + if (!material.hasTexture) + ambient = material.ambient; + + ambient = mix(ambient, reflection(), material.reflectivity); + ambient = mix(ambient, refraction(), 1 - material.opacity); + vec3 lightDir = normalize(lightPos - fragPos); vec4 diffTex = texture(material.diffuseMap, texCoord); @@ -63,11 +70,8 @@ void main() { diffTex = material.diffuse; diffTex = mix(diffTex, reflection(), material.reflectivity); - diffTex = mix(diffTex, refraction(), 1 - material.opacity); - vec4 ambient = material.ambient * diffTex; - vec4 diffuse = max(0, dot(lightDir, normal)) * diffTex; vec3 viewDir = normalize(viewPos - fragPos); @@ -80,6 +84,5 @@ void main() { vec4 specular = pow(max(0, dot(viewDir, reflectDir)), material.shininess) * specTex; FragColor = (ambient + diffuse + specular) * lightColor; - }