# Conflicts:
#	cw 6/src/main_6_1.cpp
This commit is contained in:
Michal Zaporski 2022-01-23 17:53:09 +01:00
commit 03b82de106
4 changed files with 22 additions and 3 deletions

View File

@ -11,9 +11,11 @@ in float visibility;
void main()
{
vec2 modifiedTexCoord = vec2(interpTexCoord.x, 1.0 - interpTexCoord.y); // Poprawka dla tekstur Ziemi, ktore bez tego wyswietlaja sie 'do gory nogami'
vec3 color = texture2D(textureSampler, modifiedTexCoord).rgb;
vec4 rgba = texture2D(textureSampler, modifiedTexCoord).rgba;
if(rgba.a < 0.1) discard; // don't render the pixel if it's transparent
vec3 normal = normalize(interpNormal);
float diffuse = max(dot(normal, -lightDir), 0.0);
gl_FragColor = vec4(color * diffuse, 1.0);
gl_FragColor = rgba * diffuse;
gl_FragColor = mix(vec4(skyColor, 1.0), gl_FragColor, visibility);
}

View File

@ -57,6 +57,7 @@ GLuint textureSecondFish;
GLuint textureThirdFish;
GLuint textureSeaTurtle;
GLuint textureCrab;
GLuint bubbleTexture;
GLuint textureSand;
GLuint textureBoards;
@ -146,6 +147,15 @@ void drawObjectTexture(Core::RenderContext context, glm::mat4 modelMatrix, GLuin
glUseProgram(0);
}
void drawTranslucentObjects() {
glEnable(GL_BLEND); // enable blending
drawObjectTexture(sphereContext, glm::translate(glm::vec3(0, 5, 0)) * glm::scale(glm::vec3(5.0f, 5.0f, 5.0f)), bubbleTexture);
glDisable(GL_BLEND); // disable blending
}
void renderScene()
{
// Aktualizacja macierzy widoku i rzutowania
@ -153,7 +163,7 @@ void renderScene()
perspectiveMatrix = Core::createPerspectiveMatrix();
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glClearColor(0.0f, 0.1f, 0.3f, 1.0f);
glClearColor(skyColor.x, skyColor.y, skyColor.z, 1.0f);
float time = glutGet(GLUT_ELAPSED_TIME) / 1000.f;
@ -177,6 +187,8 @@ void renderScene()
drawObjectColor(coralContext, glm::translate(glm::vec3(0, -14, 8)) * glm::rotate(glm::radians(270.f), glm::vec3(1, 0, 0)) * glm::scale(glm::vec3(0.1f)), glm::vec3(0.85f, 0.0255f, 0.6027f));
drawObjectColor(gorgonianCoralContext, glm::translate(glm::vec3(0, -14, 16)) * glm::rotate(glm::radians(270.f), glm::vec3(1, 0, 0)) * glm::scale(glm::vec3(0.07f)), glm::vec3(0.f, 1.f, 0.f));
drawTranslucentObjects();
drawObjectTexture(shipwreckContext, glm::translate(glm::vec3(20, -15, 0)) * glm::rotate(glm::radians(255.f), glm::vec3(1, 0, 0)) * glm::scale(glm::vec3(0.003f)), textureBoards);
glutSwapBuffers();
@ -199,9 +211,13 @@ void init()
{
srand(time(0));
glEnable(GL_DEPTH_TEST);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
programColor = shaderLoader.CreateProgram("shaders/shader_color.vert", "shaders/shader_color.frag");
programTexture = shaderLoader.CreateProgram("shaders/shader_tex.vert", "shaders/shader_tex.frag");
loadModelToContext("models/sub.obj", shipContext);
loadModelToContext("models/sphere.obj", sphereContext);
loadModelToContext("models/ship.obj", shipContext);
loadModelToContext("models/seafloor.obj", seafloorContext);
loadModelToContext("models/skybox.obj", skyboxContext);
loadModelToContext("models/first_fish.obj", firstFishContext);
@ -212,6 +228,7 @@ void init()
loadModelToContext("models/coral_tree.obj", coralTreeContext);
loadModelToContext("models/coral.obj", coralContext);
loadModelToContext("models/gorgonian_coral.obj", gorgonianCoralContext);
bubbleTexture = Core::LoadTexture("textures/bubble.png");
loadModelToContext("models/shipwreck.obj", shipwreckContext);
textureSkybox = Core::LoadTexture("textures/skybox.png");
textureFirstFish = Core::LoadTexture("textures/first_fish.png");

BIN
cw 6/textures/bubble.pdn Normal file

Binary file not shown.

BIN
cw 6/textures/bubble.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 173 KiB