Merge branch 'master' of https://git.wmi.amu.edu.pl/s452622/GRK-Projekt
This commit is contained in:
commit
fe4bad6a19
@ -3,28 +3,35 @@
|
|||||||
|
|
||||||
in vec3 fragPos;
|
in vec3 fragPos;
|
||||||
in vec3 interpNormal;
|
in vec3 interpNormal;
|
||||||
in float v_fresnel;
|
|
||||||
uniform vec3 cameraPos;
|
uniform vec3 cameraPos;
|
||||||
in vec3 incident;
|
|
||||||
uniform samplerCube bubble;
|
uniform samplerCube bubble;
|
||||||
|
uniform vec3 lightPos;
|
||||||
|
|
||||||
layout (binding = 0) uniform samplerCube tex_map;
|
layout (binding = 0) uniform samplerCube tex_map;
|
||||||
|
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
float ratio = 1.33 / 1.00;
|
float ratio = 1.33 / 1.00;
|
||||||
vec3 I = normalize(fragPos - cameraPos);
|
vec3 I = normalize(fragPos - cameraPos);
|
||||||
vec3 Refract = refract(I, normalize(interpNormal), ratio);
|
vec3 Refract = refract(I, normalize(interpNormal), ratio);
|
||||||
vec3 R = reflect(I, normalize(interpNormal));
|
vec3 Reflect = reflect(I, normalize(interpNormal));
|
||||||
vec3 flip = reflect(normalize(-fragPos), normalize(interpNormal));
|
vec3 flip = reflect(normalize(-fragPos), normalize(interpNormal));
|
||||||
|
|
||||||
|
|
||||||
vec4 flipColor = texture( tex_map, flip );
|
vec4 flipColor = texture( tex_map, flip );
|
||||||
vec4 refractionColor = texture( tex_map, Refract );
|
vec4 refractionColor = texture(tex_map, Refract);
|
||||||
vec4 reflectionColor = texture( tex_map, R );
|
vec4 reflectionColor = texture(tex_map, Reflect);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//vec4 color = vec4(mix(flipColor,reflectionColor,0).rgb,1.0);
|
//vec4 color = vec4(mix(flipColor,reflectionColor,0).rgb,1.0);
|
||||||
gl_FragColor = vec4(mix( flipColor,refractionColor,0).rgb,0.5);
|
|
||||||
|
vec4 envColor = vec4(mix( flipColor,refractionColor,0).rgb,0.5);
|
||||||
|
|
||||||
|
vec3 lightDir = normalize(lightPos-fragPos);
|
||||||
|
vec3 V = normalize(cameraPos-fragPos);
|
||||||
|
vec3 normal = normalize(interpNormal);
|
||||||
|
float diffuse = max(0,dot(normal,normalize(lightDir)));
|
||||||
|
vec3 R = reflect(-normalize(lightDir),normal);
|
||||||
|
float ambient = 0.5;
|
||||||
|
float specular = pow(max(0,dot(R,V)),10);
|
||||||
|
gl_FragColor = (envColor*(ambient + (1-ambient)*diffuse)+vec4(1)*specular*0.2);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
@ -7,33 +7,19 @@ out vec3 fragPos;
|
|||||||
out vec3 TexCoords;
|
out vec3 TexCoords;
|
||||||
out vec3 incident;
|
out vec3 incident;
|
||||||
out float v_fresnel;
|
out float v_fresnel;
|
||||||
|
|
||||||
uniform vec3 viewPos;
|
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 modelMatrix;
|
||||||
uniform mat4 modelViewProjectionMatrix;
|
uniform mat4 modelViewProjectionMatrix;
|
||||||
|
|
||||||
layout (binding = 0) uniform samplerCube tex_map;
|
layout (binding = 0) uniform samplerCube tex_map;
|
||||||
|
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
|
|
||||||
vec4 vertex = modelMatrix * vec4( vertexPosition, 1.0 );
|
vec4 vertex = modelMatrix * vec4( vertexPosition, 1.0 );
|
||||||
vec4 camera = vec4( viewPos, 1.0 );
|
vec4 camera = vec4( viewPos, 1.0 );
|
||||||
incident = normalize( vec3( vertex - camera ) );
|
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;
|
interpNormal = mat3(transpose(inverse(modelMatrix))) * vertexNormal;
|
||||||
fragPos = (modelMatrix * vec4(vertexPosition, 1.0)).xyz;
|
fragPos = (modelMatrix * vec4(vertexPosition, 1.0)).xyz;
|
||||||
gl_Position = modelViewProjectionMatrix * vec4(vertexPosition, 1.0);
|
gl_Position = modelViewProjectionMatrix * vec4(vertexPosition, 1.0);
|
||||||
|
|
||||||
}
|
}
|
@ -7,7 +7,6 @@
|
|||||||
#include <cmath>
|
#include <cmath>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <random>
|
#include <random>
|
||||||
|
|
||||||
#include "Shader_Loader.h"
|
#include "Shader_Loader.h"
|
||||||
#include "Render_Utils.h"
|
#include "Render_Utils.h"
|
||||||
#include "Texture.h"
|
#include "Texture.h"
|
||||||
@ -15,15 +14,18 @@
|
|||||||
#include "SOIL/stb_image_aug.h"
|
#include "SOIL/stb_image_aug.h"
|
||||||
|
|
||||||
GLuint skyboxProgram, skyboxBuffer;
|
GLuint skyboxProgram, skyboxBuffer;
|
||||||
GLuint cubeProgram, cubeBuffer;
|
GLuint bubbleProgram;
|
||||||
GLuint programColor;
|
GLuint programColor;
|
||||||
GLuint programTexture;
|
GLuint programTexture;
|
||||||
|
|
||||||
GLuint textureSubmarine;
|
GLuint textureSubmarine;
|
||||||
GLuint textureBubble;
|
GLuint textureBubble;
|
||||||
GLuint textureFish;
|
GLuint textureFish;
|
||||||
|
|
||||||
unsigned int cubemapTexture, skyboxVAO;
|
unsigned int cubemapTexture, skyboxVAO;
|
||||||
unsigned int cubeVAO, cubeVBO;
|
unsigned int cubeVAO, cubeVBO;
|
||||||
std::vector<glm::vec3> array[100];
|
|
||||||
|
std::vector<glm::vec3> bubbleArray[300];
|
||||||
float old_x, old_y = -1;
|
float old_x, old_y = -1;
|
||||||
glm::vec3 cursorDiff;
|
glm::vec3 cursorDiff;
|
||||||
glm::vec3 lightDir = glm::normalize(glm::vec3(1.0f, -10.f, -1.0f));
|
glm::vec3 lightDir = glm::normalize(glm::vec3(1.0f, -10.f, -1.0f));
|
||||||
@ -61,39 +63,6 @@ glm::vec3(-15.0f, -8.0f, -6.0f),
|
|||||||
glm::vec3(-18.0f, -10.0f, -10.0f),
|
glm::vec3(-18.0f, -10.0f, -10.0f),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
std::random_device rd; // obtain a random number from hardware
|
|
||||||
std::mt19937 gen(rd()); // seed the generator
|
|
||||||
std::uniform_int_distribution<> distr(-50, 50); // define the range
|
|
||||||
|
|
||||||
|
|
||||||
std::vector<glm::vec3> genBubbleKeyPoints(){
|
|
||||||
float random1 = distr(gen);
|
|
||||||
float random2 = distr(gen);
|
|
||||||
std::vector<glm::vec3> bubbleKeyPoints({
|
|
||||||
glm::vec3(random1 , -50.0f, random2),
|
|
||||||
glm::vec3(random1 , 50.0f, random2)
|
|
||||||
}
|
|
||||||
);
|
|
||||||
return bubbleKeyPoints;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
void generateArray() {
|
|
||||||
|
|
||||||
for (int i = 0; i < 100; i++) {
|
|
||||||
array[i] = genBubbleKeyPoints();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
std::vector<glm::quat> keyRotation;
|
std::vector<glm::quat> keyRotation;
|
||||||
|
|
||||||
std::vector<Core::Node> fish;
|
std::vector<Core::Node> fish;
|
||||||
@ -206,6 +175,28 @@ bool isInBoundaries(glm::vec3 nextPosition) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
std::random_device rd; // obtain a random number from hardware
|
||||||
|
std::mt19937 gen(rd()); // seed the generator
|
||||||
|
std::uniform_int_distribution<> distr(-skyboxVerticeParameter, skyboxVerticeParameter); // define the range
|
||||||
|
|
||||||
|
std::vector<glm::vec3> genBubbleKeyPoints() {
|
||||||
|
float random1 = distr(gen);
|
||||||
|
float random2 = distr(gen);
|
||||||
|
std::vector<glm::vec3> bubbleKeyPoints({
|
||||||
|
glm::vec3(random1 , -skyboxVerticeParameter, random2),
|
||||||
|
glm::vec3(random1 , skyboxVerticeParameter, random2)
|
||||||
|
}
|
||||||
|
);
|
||||||
|
return bubbleKeyPoints;
|
||||||
|
};
|
||||||
|
|
||||||
|
void generateBubbleArray() {
|
||||||
|
|
||||||
|
for (int i = 0; i < 300; i++) {
|
||||||
|
bubbleArray[i] = genBubbleKeyPoints();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void keyboard(unsigned char key, int x, int y)
|
void keyboard(unsigned char key, int x, int y)
|
||||||
{
|
{
|
||||||
float angleSpeed = 10.f;
|
float angleSpeed = 10.f;
|
||||||
@ -242,9 +233,6 @@ void keyboard(unsigned char key, int x, int y)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void mouse(int x, int y)
|
void mouse(int x, int y)
|
||||||
{
|
{
|
||||||
if (old_x >= 0) {
|
if (old_x >= 0) {
|
||||||
@ -340,8 +328,6 @@ glm::mat4 animationMatrix(float time, glm::vec3 change, std::vector<glm::vec3> k
|
|||||||
|
|
||||||
void drawObjectTexture(Core::RenderContext context, glm::mat4 modelMatrix, GLuint textureId, GLuint program)
|
void drawObjectTexture(Core::RenderContext context, glm::mat4 modelMatrix, GLuint textureId, GLuint program)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
glUseProgram(program);
|
glUseProgram(program);
|
||||||
|
|
||||||
glUniform3f(glGetUniformLocation(program, "lightDir"), lightDir.x, lightDir.y, lightDir.z);
|
glUniform3f(glGetUniformLocation(program, "lightDir"), lightDir.x, lightDir.y, lightDir.z);
|
||||||
@ -357,7 +343,6 @@ void drawObjectTexture(Core::RenderContext context, glm::mat4 modelMatrix, GLuin
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void renderScene()
|
void renderScene()
|
||||||
{
|
{
|
||||||
cameraMatrix = createCameraMatrix();
|
cameraMatrix = createCameraMatrix();
|
||||||
@ -379,7 +364,6 @@ void renderScene()
|
|||||||
glEnable(GL_BLEND);
|
glEnable(GL_BLEND);
|
||||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||||
|
|
||||||
|
|
||||||
glm::mat4 submarineInitialTransformation = 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.25f));
|
glm::mat4 submarineInitialTransformation = 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.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;
|
||||||
|
|
||||||
@ -392,15 +376,9 @@ void renderScene()
|
|||||||
|
|
||||||
glm::vec3 change0 = glm::vec3(0, 0, 0);
|
glm::vec3 change0 = glm::vec3(0, 0, 0);
|
||||||
|
|
||||||
|
for (int j = 0; j < 100; j++) {
|
||||||
|
drawObjectTexture(bubbleContext, animationMatrix(time + j, change0, bubbleArray[j], glm::vec3(0.04f), 0.2f), cubemapTexture, bubbleProgram);
|
||||||
|
|
||||||
for (int j = 0; j < 50; j++) {
|
|
||||||
drawObjectTexture(bubbleContext, animationMatrix(time + j, change0, array[j], glm::vec3(0.1f), 0.99f), cubemapTexture, cubeProgram);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
for (int i = 0; i < 5; i++) {
|
for (int i = 0; i < 5; i++) {
|
||||||
if (time > -10) {
|
if (time > -10) {
|
||||||
@ -411,11 +389,8 @@ void renderScene()
|
|||||||
|
|
||||||
time -= 6;
|
time -= 6;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
//drawObjectTexture(bubbleContext, submarineInitialTransformation, cubemapTexture, bubbleProgram);
|
||||||
|
|
||||||
drawObjectTexture(submarineContext, submarineModelMatrix, textureSubmarine, programTexture);
|
drawObjectTexture(submarineContext, submarineModelMatrix, textureSubmarine, programTexture);
|
||||||
glutSwapBuffers();
|
glutSwapBuffers();
|
||||||
}
|
}
|
||||||
@ -521,7 +496,7 @@ void init()
|
|||||||
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");
|
bubbleProgram = shaderLoader.CreateProgram((char*)"shaders/bubble.vert", (char*)"shaders/bubble.frag");
|
||||||
cubemapTexture = loadCubemap();
|
cubemapTexture = loadCubemap();
|
||||||
|
|
||||||
loadModelToContext("models/submarine.obj", submarineContext);
|
loadModelToContext("models/submarine.obj", submarineContext);
|
||||||
@ -535,7 +510,7 @@ void init()
|
|||||||
textureSubmarine = Core::LoadTexture("textures/submarine.png");
|
textureSubmarine = Core::LoadTexture("textures/submarine.png");
|
||||||
loadModelToContext("models/sphere.obj", bubbleContext);
|
loadModelToContext("models/sphere.obj", bubbleContext);
|
||||||
textureBubble = Core::LoadTexture("textures/bubble.png");
|
textureBubble = Core::LoadTexture("textures/bubble.png");
|
||||||
generateArray();
|
generateBubbleArray();
|
||||||
initCube();
|
initCube();
|
||||||
initSkybox();
|
initSkybox();
|
||||||
|
|
||||||
@ -546,7 +521,7 @@ void shutdown()
|
|||||||
shaderLoader.DeleteProgram(programColor);
|
shaderLoader.DeleteProgram(programColor);
|
||||||
shaderLoader.DeleteProgram(programTexture);
|
shaderLoader.DeleteProgram(programTexture);
|
||||||
shaderLoader.DeleteProgram(skyboxProgram);
|
shaderLoader.DeleteProgram(skyboxProgram);
|
||||||
shaderLoader.DeleteProgram(cubeProgram);
|
shaderLoader.DeleteProgram(bubbleProgram);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -572,11 +547,7 @@ int main(int argc, char** argv)
|
|||||||
glutIdleFunc(idle);
|
glutIdleFunc(idle);
|
||||||
|
|
||||||
glutSetCursor(GLUT_CURSOR_NONE);
|
glutSetCursor(GLUT_CURSOR_NONE);
|
||||||
|
|
||||||
|
|
||||||
glutMainLoop();
|
glutMainLoop();
|
||||||
|
|
||||||
shutdown();
|
shutdown();
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user