create bubbles with good rotation

This commit is contained in:
Thyme1 2022-01-02 02:22:53 +01:00
parent fb55f586f5
commit 62f81b5d34
9 changed files with 40 additions and 6 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 723 KiB

After

Width:  |  Height:  |  Size: 304 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 274 KiB

After

Width:  |  Height:  |  Size: 251 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 462 KiB

After

Width:  |  Height:  |  Size: 275 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 588 KiB

After

Width:  |  Height:  |  Size: 288 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 525 KiB

After

Width:  |  Height:  |  Size: 311 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 338 KiB

After

Width:  |  Height:  |  Size: 346 KiB

View File

@ -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);
}

View File

@ -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);

View File

@ -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;
}
}