diff --git a/grafika_projekt/models/skybox/back.jpg b/grafika_projekt/models/skybox/back.jpg index 470a679..11bb9ed 100644 Binary files a/grafika_projekt/models/skybox/back.jpg and b/grafika_projekt/models/skybox/back.jpg differ diff --git a/grafika_projekt/models/skybox/bottom.jpg b/grafika_projekt/models/skybox/bottom.jpg index 893f394..3b414f6 100644 Binary files a/grafika_projekt/models/skybox/bottom.jpg and b/grafika_projekt/models/skybox/bottom.jpg differ diff --git a/grafika_projekt/models/skybox/front.jpg b/grafika_projekt/models/skybox/front.jpg index 4e17b77..f0a2adf 100644 Binary files a/grafika_projekt/models/skybox/front.jpg and b/grafika_projekt/models/skybox/front.jpg differ diff --git a/grafika_projekt/models/skybox/left.jpg b/grafika_projekt/models/skybox/left.jpg index 5750b91..3fa7115 100644 Binary files a/grafika_projekt/models/skybox/left.jpg and b/grafika_projekt/models/skybox/left.jpg differ diff --git a/grafika_projekt/models/skybox/right.jpg b/grafika_projekt/models/skybox/right.jpg index 8963037..f6f11cb 100644 Binary files a/grafika_projekt/models/skybox/right.jpg and b/grafika_projekt/models/skybox/right.jpg differ diff --git a/grafika_projekt/models/skybox/top.jpg b/grafika_projekt/models/skybox/top.jpg index 4db3c2a..c37de73 100644 Binary files a/grafika_projekt/models/skybox/top.jpg and b/grafika_projekt/models/skybox/top.jpg differ diff --git a/grafika_projekt/shaders/bubble.frag b/grafika_projekt/shaders/bubble.frag index cf7fa23..8d5d87a 100644 --- a/grafika_projekt/shaders/bubble.frag +++ b/grafika_projekt/shaders/bubble.frag @@ -3,11 +3,24 @@ in vec3 fragPos; in vec3 interpNormal; +in float v_fresnel; uniform vec3 cameraPos; -uniform samplerCube skybox; +in vec3 incident; +uniform samplerCube bubble; layout (binding = 0) uniform samplerCube tex_map; void main() { + float ratio = 1.33 / 1.00; + vec3 I = normalize(fragPos - cameraPos); + vec3 R = refract(I, normalize(interpNormal), ratio); + vec3 r = reflect(normalize(-fragPos), normalize(interpNormal)); - gl_FragColor = texture(tex_map, r); + + + vec4 reflectionColor = texture( tex_map, r ); + vec4 refractionColor = texture( tex_map, R ); + + + + gl_FragColor = vec4(mix( reflectionColor,refractionColor,0 ).rgba); } \ No newline at end of file diff --git a/grafika_projekt/shaders/bubble.vert b/grafika_projekt/shaders/bubble.vert index c450855..170563c 100644 --- a/grafika_projekt/shaders/bubble.vert +++ b/grafika_projekt/shaders/bubble.vert @@ -5,12 +5,33 @@ layout(location = 1) in vec3 vertexNormal; out vec3 interpNormal; out vec3 fragPos; out vec3 TexCoords; +out vec3 incident; +out float v_fresnel; +uniform vec3 viewPos; + + +// Indices of refraction +const float Air = 1.0; +const float Glass = 4; //1.51714;//4 + +// Air to glass ratio of the indices of refraction (Eta) +const float Eta = Air / Glass; + +// see http://en.wikipedia.org/wiki/Refractive_index Reflectivity +const float R0 = ((Air - Glass) * (Air - Glass)) / ((Air + Glass) * (Air + Glass)); + + uniform mat4 modelMatrix; uniform mat4 modelViewProjectionMatrix; layout (binding = 0) uniform samplerCube tex_map; void main() { + + vec4 vertex = modelMatrix * vec4( vertexPosition, 1.0 ); + vec4 camera = vec4( viewPos, 1.0 ); + incident = normalize( vec3( vertex - camera ) ); + v_fresnel = R0 + (1.0 - R0) * pow( (1.0 - dot( -incident, vertexNormal ) ), 5.0); interpNormal = mat3(transpose(inverse(modelMatrix))) * vertexNormal; fragPos = (modelMatrix * vec4(vertexPosition, 1.0)).xyz; gl_Position = modelViewProjectionMatrix * vec4(vertexPosition, 1.0); diff --git a/grafika_projekt/src/main.cpp b/grafika_projekt/src/main.cpp index 68b7ab3..b438e74 100644 --- a/grafika_projekt/src/main.cpp +++ b/grafika_projekt/src/main.cpp @@ -379,7 +379,7 @@ void renderScene() glm::mat4 bubbleInitialTransformation = glm::translate(glm::vec3(0, -0.5, -0.4)) * glm::rotate(glm::radians(180.0f), glm::vec3(0, 1, 0)) * glm::scale(glm::vec3(0.5f)); - drawObjectTexture(bubbleContext, bubbleInitialTransformation, cubemapTexture, cubeProgram); + //drawObjectTexture(bubbleContext, bubbleInitialTransformation, cubemapTexture, cubeProgram); glm::vec3 change1 = glm::vec3(0, 3, 0); @@ -396,9 +396,9 @@ void renderScene() drawObjectTexture(fishContext, animationMatrix(time + 15, change2, fishKeyPoints, glm::vec3(0.25f), 1.f), textureFish, programTexture); drawObjectTexture(fishContext, animationMatrix(time + 15, change3, fishKeyPoints, glm::vec3(0.25f), 1.f), textureFish, programTexture); drawObjectTexture(fishContext, animationMatrix(time + 15, change4, fishKeyPoints, glm::vec3(0.25f), 1.f), textureFish, programTexture); - drawObjectTexture(bubbleContext, animationMatrix(time + 15, change5, bubbleKeyPoints, glm::vec3(0.1f), 0.2f), cubemapTexture, cubeProgram); - //drawObjectTexture(bubbleContext, animationMatrix(time + 15, change6, bubbleKeyPoints, glm::vec3(0.01f), 0.2f), GL_TEXTURE_CUBE_MAP, skyboxProgram); - //drawObjectTexture(bubbleContext, animationMatrix(time + 15, change7, bubbleKeyPoints, glm::vec3(0.01f), 0.2f), GL_TEXTURE_CUBE_MAP, skyboxProgram); + drawObjectTexture(bubbleContext, animationMatrix(time + 15, change5, bubbleKeyPoints, glm::vec3(0.01f), 0.2f), cubemapTexture, cubeProgram); + drawObjectTexture(bubbleContext, animationMatrix(time + 15, change6, bubbleKeyPoints, glm::vec3(0.01f), 0.2f), cubemapTexture, cubeProgram); + drawObjectTexture(bubbleContext, animationMatrix(time + 15, change7, bubbleKeyPoints, glm::vec3(0.01f), 0.2f), cubemapTexture, cubeProgram); time -= 6; } }