diff --git a/grafika_projekt/models/skybox/back.jpg b/grafika_projekt/models/skybox/back.jpg index 11bb9ed..470a679 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 3b414f6..893f394 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 f0a2adf..4e17b77 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 3fa7115..5750b91 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 f6f11cb..8963037 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 c37de73..4db3c2a 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 6419677..b5ce72a 100644 --- a/grafika_projekt/shaders/bubble.frag +++ b/grafika_projekt/shaders/bubble.frag @@ -1,17 +1,53 @@ #version 330 core - -in vec3 fragPos; +in vec3 v_refraction; +in vec3 v_reflection; +in float v_fresnel; +in vec3 fragPos; in vec3 interpNormal; -in vec3 TexCoords; -uniform vec3 cameraPos; +in vec3 incident; + +in float deep; uniform samplerCube skybox; + + +uniform vec3 lightPos; +uniform vec3 cameraPos; +uniform vec3 lightColor; +uniform vec3 objectColor; + +const float etaR = 1.14; +const float etaG = 1.12; +const float etaB = 1.10; +const float F = ((1.0 - etaG) * (1.0 - etaG)) / ((1.0 + etaG) * (1.0 + etaG)); void main() { + vec3 n = normalize(interpNormal); + vec3 l = normalize(lightPos-fragPos); + vec3 e = normalize(cameraPos-fragPos); + vec3 h = (e+l) / length(e+l); float ratio = 1.01/1.0; + + // + vec3 i = incident; + //float ratio = F + (1.0 - F) * pow(1.0 - dot(-i, n), 2); + vec3 refractR = vec3(vec4(refract(i, n, etaR), 1.0)); + vec3 refractG = vec3(vec4(refract(i, n, etaG), 1.0)); + vec3 refractB = vec3(vec4(refract(i, n, etaB), 1.0)); + vec3 reflectDir = vec3(vec4(reflect(i, n), 1.0)); + + + vec3 I = normalize(fragPos - cameraPos); // vec3 R = refract(I, normalize(interpNormal),ratio); vec3 R = reflect(I, normalize(interpNormal)); - gl_FragColor = vec4(texture(skybox, R).rgb,1.0); + + + vec4 refractionColor = texture( skybox, normalize( v_refraction ) ); + vec4 reflectionColor = texture( skybox, normalize( v_reflection ) ); + + gl_FragColor = vec4(mix( refractionColor, reflectionColor, v_fresnel ).rgba); + + } \ No newline at end of file diff --git a/grafika_projekt/shaders/bubble.vert b/grafika_projekt/shaders/bubble.vert index 2151edd..3dfd4ce 100644 --- a/grafika_projekt/shaders/bubble.vert +++ b/grafika_projekt/shaders/bubble.vert @@ -4,15 +4,42 @@ layout(location = 1) in vec3 vertexNormal; out vec3 interpNormal; out vec3 fragPos; -out vec3 TexCoords; +out vec3 incident; +out float deep; +out vec3 v_reflection; +out vec3 v_refraction; +out float v_fresnel; uniform mat4 modelMatrix; uniform mat4 modelViewProjectionMatrix; +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)); + + void main() { - interpNormal = mat3(transpose(inverse(modelMatrix))) * vertexNormal; + vec4 vertex = modelMatrix * vec4( vertexPosition, 1.0 ); + vec4 camera = vec4( viewPos, 1.0 ); + incident = normalize( vec3( vertex - camera ) ); + + vec3 norm = mat3(transpose(inverse(modelMatrix))) * vertexNormal; + v_refraction = refract( incident, norm, Eta ); + v_reflection = reflect( incident, norm ); + + v_fresnel = R0 + (1.0 - R0) * pow( (1.0 - dot( -incident, vertexNormal ) ), 5.0); + + + interpNormal = vertexNormal; + fragPos = vec3(modelMatrix * vec4(vertexPosition, 1.0)); gl_Position = modelViewProjectionMatrix * vec4(vertexPosition, 1.0); - TexCoords = fragPos; + deep = vertexPosition.y; } \ No newline at end of file diff --git a/grafika_projekt/src/main.cpp b/grafika_projekt/src/main.cpp index 76087ee..68b7ab3 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, textureBubble, cubeProgram); + drawObjectTexture(bubbleContext, bubbleInitialTransformation, cubemapTexture, cubeProgram); glm::vec3 change1 = glm::vec3(0, 3, 0);