bubbles #10

Merged
s452667 merged 20 commits from bubbles into master 2022-01-08 19:56:25 +01:00
6 changed files with 3040 additions and 0 deletions
Showing only changes of commit ba468047ba - Show all commits

Binary file not shown.

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,16 @@
#version 410 core
out vec4 FragColor;
in vec3 Normal;
in vec3 Position;
uniform vec3 cameraPos;
uniform samplerCube skybox;
void main()
{
float ratio = 1.00 / 1.52;
vec3 I = normalize(Position - cameraPos);
vec3 R = refract(I, normalize(Normal), ratio);
FragColor = vec4(texture(skybox, R).rgb, 1.0);
}

View File

@ -0,0 +1,17 @@
#version 410 core
layout (location = 0) in vec3 aPos;
layout (location = 1) in vec3 aNormal;
out vec3 Normal;
out vec3 Position;
uniform mat4 model;
uniform mat4 view;
uniform mat4 projection;
void main()
{
Normal = mat3(transpose(inverse(model))) * aNormal;
Position = vec3(model * vec4(aPos, 1.0));
gl_Position = projection * view * vec4(Position, 1.0);
}

View File

@ -14,10 +14,13 @@
#include "SOIL/stb_image_aug.h" #include "SOIL/stb_image_aug.h"
GLuint skyboxProgram, skyboxBuffer; GLuint skyboxProgram, skyboxBuffer;
GLuint cubeProgram, cubeBuffer;
GLuint programColor; GLuint programColor;
GLuint programTexture; GLuint programTexture;
GLuint textureSubmarine; GLuint textureSubmarine;
GLuint textureBubble;
unsigned int cubemapTexture, skyboxVAO; unsigned int cubemapTexture, skyboxVAO;
unsigned int cubeVAO, cubeVBO;
float old_x, old_y = -1; float old_x, old_y = -1;
glm::vec3 cursorDiff; glm::vec3 cursorDiff;
@ -33,6 +36,7 @@ glm::mat4 cameraMatrix, perspectiveMatrix;
Core::Shader_Loader shaderLoader; Core::Shader_Loader shaderLoader;
Core::RenderContext submarineContext; Core::RenderContext submarineContext;
Core::RenderContext bubbleContext;
std::string skyboxTextures[6] = { std::string skyboxTextures[6] = {
"models/skybox/right.jpg", "models/skybox/right.jpg",
@ -46,6 +50,51 @@ std::string skyboxTextures[6] = {
float skyboxVerticeParameter = 20.0f; float skyboxVerticeParameter = 20.0f;
float skyboxBoundary = 19.5f; float skyboxBoundary = 19.5f;
float cubeVertices[] = {
// positions // normals
-0.5f, -0.5f, -0.5f, 0.0f, 0.0f, -1.0f,
0.5f, -0.5f, -0.5f, 0.0f, 0.0f, -1.0f,
0.5f, 0.5f, -0.5f, 0.0f, 0.0f, -1.0f,
0.5f, 0.5f, -0.5f, 0.0f, 0.0f, -1.0f,
-0.5f, 0.5f, -0.5f, 0.0f, 0.0f, -1.0f,
-0.5f, -0.5f, -0.5f, 0.0f, 0.0f, -1.0f,
-0.5f, -0.5f, 0.5f, 0.0f, 0.0f, 1.0f,
0.5f, -0.5f, 0.5f, 0.0f, 0.0f, 1.0f,
0.5f, 0.5f, 0.5f, 0.0f, 0.0f, 1.0f,
0.5f, 0.5f, 0.5f, 0.0f, 0.0f, 1.0f,
-0.5f, 0.5f, 0.5f, 0.0f, 0.0f, 1.0f,
-0.5f, -0.5f, 0.5f, 0.0f, 0.0f, 1.0f,
-0.5f, 0.5f, 0.5f, -1.0f, 0.0f, 0.0f,
-0.5f, 0.5f, -0.5f, -1.0f, 0.0f, 0.0f,
-0.5f, -0.5f, -0.5f, -1.0f, 0.0f, 0.0f,
-0.5f, -0.5f, -0.5f, -1.0f, 0.0f, 0.0f,
-0.5f, -0.5f, 0.5f, -1.0f, 0.0f, 0.0f,
-0.5f, 0.5f, 0.5f, -1.0f, 0.0f, 0.0f,
0.5f, 0.5f, 0.5f, 1.0f, 0.0f, 0.0f,
0.5f, 0.5f, -0.5f, 1.0f, 0.0f, 0.0f,
0.5f, -0.5f, -0.5f, 1.0f, 0.0f, 0.0f,
0.5f, -0.5f, -0.5f, 1.0f, 0.0f, 0.0f,
0.5f, -0.5f, 0.5f, 1.0f, 0.0f, 0.0f,
0.5f, 0.5f, 0.5f, 1.0f, 0.0f, 0.0f,
-0.5f, -0.5f, -0.5f, 0.0f, -1.0f, 0.0f,
0.5f, -0.5f, -0.5f, 0.0f, -1.0f, 0.0f,
0.5f, -0.5f, 0.5f, 0.0f, -1.0f, 0.0f,
0.5f, -0.5f, 0.5f, 0.0f, -1.0f, 0.0f,
-0.5f, -0.5f, 0.5f, 0.0f, -1.0f, 0.0f,
-0.5f, -0.5f, -0.5f, 0.0f, -1.0f, 0.0f,
-0.5f, 0.5f, -0.5f, 0.0f, 1.0f, 0.0f,
0.5f, 0.5f, -0.5f, 0.0f, 1.0f, 0.0f,
0.5f, 0.5f, 0.5f, 0.0f, 1.0f, 0.0f,
0.5f, 0.5f, 0.5f, 0.0f, 1.0f, 0.0f,
-0.5f, 0.5f, 0.5f, 0.0f, 1.0f, 0.0f,
-0.5f, 0.5f, -0.5f, 0.0f, 1.0f, 0.0f
};
float skyboxVertices[] = { float skyboxVertices[] = {
-skyboxVerticeParameter, skyboxVerticeParameter, -skyboxVerticeParameter, -skyboxVerticeParameter, skyboxVerticeParameter, -skyboxVerticeParameter,
-skyboxVerticeParameter, -skyboxVerticeParameter, -skyboxVerticeParameter, -skyboxVerticeParameter, -skyboxVerticeParameter, -skyboxVerticeParameter,
@ -212,12 +261,22 @@ void renderScene()
glActiveTexture(GL_TEXTURE0); glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_CUBE_MAP, cubemapTexture); glBindTexture(GL_TEXTURE_CUBE_MAP, cubemapTexture);
glDrawArrays(GL_TRIANGLES, 0, 36); glDrawArrays(GL_TRIANGLES, 0, 36);
glUseProgram(skyboxProgram);
glBindVertexArray(0);
glBindVertexArray(cubeVAO);
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_CUBE_MAP, cubemapTexture);
glDrawArrays(GL_TRIANGLES, 0, 36);
glBindVertexArray(0); glBindVertexArray(0);
glm::mat4 submarineInitialTransformation = glm::translate(glm::vec3(-1, 0, -0.5)) * glm::rotate(glm::radians(180.0f), glm::vec3(0, 1, 0)) * glm::scale(glm::vec3(0.25f)); glm::mat4 submarineInitialTransformation = glm::translate(glm::vec3(-1, 0, -0.5)) * glm::rotate(glm::radians(180.0f), glm::vec3(0, 1, 0)) * glm::scale(glm::vec3(0.25f));
glm::mat4 submarineModelMatrix = glm::translate(cameraPos + cameraDir) * glm::mat4_cast(glm::inverse(rotation)) * submarineInitialTransformation; glm::mat4 submarineModelMatrix = glm::translate(cameraPos + cameraDir) * glm::mat4_cast(glm::inverse(rotation)) * submarineInitialTransformation;
//drawObjectColor(fishContext, fishModelMatrix, glm::vec3(0.6f)); //drawObjectColor(fishContext, fishModelMatrix, glm::vec3(0.6f));
drawObjectTexture(submarineContext, submarineModelMatrix, textureSubmarine); drawObjectTexture(submarineContext, submarineModelMatrix, textureSubmarine);
glm::mat4 bubbleInitialTransformation = glm::translate(glm::vec3(1, 0, -0.5)) * glm::rotate(glm::radians(180.0f), glm::vec3(0, 1, 0)) * glm::scale(glm::vec3(0.005f));
drawObjectTexture(bubbleContext, bubbleInitialTransformation, textureBubble);
glutSwapBuffers(); glutSwapBuffers();
} }
@ -284,16 +343,34 @@ void initSkybox()
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 3 * sizeof(float), (void*)0); glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 3 * sizeof(float), (void*)0);
} }
void initCube()
{
glGenVertexArrays(1, &cubeVAO);
glGenBuffers(1, &cubeVBO);
glBindVertexArray(cubeVAO);
glBindBuffer(GL_ARRAY_BUFFER, cubeVBO);
glBufferData(GL_ARRAY_BUFFER, sizeof(cubeVertices), &cubeVertices, GL_STATIC_DRAW);
glEnableVertexAttribArray(0);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 6 * sizeof(float), (void*)0);
glEnableVertexAttribArray(1);
glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 6 * sizeof(float), (void*)(3 * sizeof(float)));
}
void init() void init()
{ {
glEnable(GL_DEPTH_TEST); glEnable(GL_DEPTH_TEST);
programColor = shaderLoader.CreateProgram((char*) "shaders/shader_color.vert", (char*) "shaders/shader_color.frag"); programColor = shaderLoader.CreateProgram((char*) "shaders/shader_color.vert", (char*) "shaders/shader_color.frag");
programTexture = shaderLoader.CreateProgram((char*) "shaders/shader_tex.vert", (char*) "shaders/shader_tex.frag"); programTexture = shaderLoader.CreateProgram((char*) "shaders/shader_tex.vert", (char*) "shaders/shader_tex.frag");
skyboxProgram = shaderLoader.CreateProgram((char *) "shaders/skybox.vert", (char *) "shaders/skybox.frag"); skyboxProgram = shaderLoader.CreateProgram((char *) "shaders/skybox.vert", (char *) "shaders/skybox.frag");
cubeProgram = shaderLoader.CreateProgram((char*)"shaders/bubble.vert", (char*)"shaders/bubble.frag");
cubemapTexture = loadCubemap(); cubemapTexture = loadCubemap();
loadModelToContext("models/submarine.obj", submarineContext); loadModelToContext("models/submarine.obj", submarineContext);
textureSubmarine = Core::LoadTexture("textures/submarine.png"); textureSubmarine = Core::LoadTexture("textures/submarine.png");
loadModelToContext("models/sphere.obj", bubbleContext);
textureBubble = Core::LoadTexture("textures/fish.png");
initCube();
initSkybox(); initSkybox();
} }
void shutdown() void shutdown()
@ -309,6 +386,7 @@ void idle()
} }
int main(int argc, char** argv) int main(int argc, char** argv)
{ {
glutInit(&argc, argv); glutInit(&argc, argv);