This commit is contained in:
Michal Zaporski 2022-02-08 21:41:19 +01:00
commit 565dd071f3

View File

@ -304,6 +304,21 @@ void secondRenderingPass() {
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
}
void renderRocks(bool causticPass) {
// Rocks
drawObjectTexture(rockContext, glm::translate(glm::vec3(30, -13, 40)) * glm::rotate(glm::radians(270.f), glm::vec3(1, 0, 0)) * glm::scale(glm::vec3(6.f)), causticPass ? textureRockBrown : caustics[causticIndex]);
drawObjectTexture(rockContext, glm::translate(glm::vec3(-25, -15, 20)) * glm::rotate(glm::radians(270.f), glm::vec3(1, 0, 0)) * glm::scale(glm::vec3(3.f)), causticPass ? textureRockGray2 : caustics[causticIndex]);
drawObjectTexture(rockContext, glm::translate(glm::vec3(-30, -16, -30)) * glm::rotate(glm::radians(270.f), glm::vec3(1, 0, 0)) * glm::scale(glm::vec3(5.f)), causticPass ? textureRockGray2 : caustics[causticIndex]);
drawObjectTexture(rockContext, glm::translate(glm::vec3(1, -13, -15)) * glm::rotate(glm::radians(270.f), glm::vec3(1, 0, 0)) * glm::scale(glm::vec3(3.f)), causticPass ? textureRockBrown : caustics[causticIndex]);
drawObjectTexture(rockContext, glm::translate(glm::vec3(35, -20, -25)) * glm::rotate(glm::radians(270.f), glm::vec3(1, 0, 0)) * glm::scale(glm::vec3(4.f)), causticPass ? textureRockGray : caustics[causticIndex]);
// Stones
drawObjectTexture(stoneContext, glm::translate(glm::vec3(20, -14, 20)) * glm::rotate(glm::radians(270.f), glm::vec3(1, 0, 0)) * glm::scale(glm::vec3(3.f)), causticPass ? textureRockBrown : caustics[causticIndex]);
drawObjectTexture(stoneContext, glm::translate(glm::vec3(-15, -15, 10)) * glm::rotate(glm::radians(270.f), glm::vec3(1, 0, 0)) * glm::scale(glm::vec3(4.f)), causticPass ? textureRockBrown : caustics[causticIndex]);
drawObjectTexture(stoneContext, glm::translate(glm::vec3(-20, 25, -10)) * glm::rotate(glm::radians(270.f), glm::vec3(1, 0, 0)) * glm::scale(glm::vec3(5.f)), causticPass ? textureRockGray : caustics[causticIndex]);
}
void renderObjects(bool causticPass) {
float time = glutGet(GLUT_ELAPSED_TIME) / 1000.f;
// Aktualizacja macierzy widoku i rzutowania
@ -324,8 +339,18 @@ void renderObjects(bool causticPass) {
glEnable(GL_TEXTURE_2D);
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
glBindTexture(GL_TEXTURE_2D, caustics[causticIndex]);
renderRocks(causticPass);
glDepthMask(GL_TRUE);
glDepthFunc(GL_LESS);
glDisable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
return;
}
renderRocks(causticPass);
glm::mat4 shipModelMatrix = glm::translate(cameraPos + cameraDir * 0.5f) * glm::mat4_cast(glm::inverse(cameraRotation)) * shipInitialTransformation;
drawObjectTexture(shipContext, shipModelMatrix, textureSubmarine);
drawObjectTexture(seafloorContext, glm::translate(glm::vec3(0,-15,0)) * glm::scale(glm::vec3(5.f)), textureSand);
@ -333,11 +358,11 @@ void renderObjects(bool causticPass) {
drawObjectTexture(skyboxContext, glm::translate(cameraPos) * glm::translate(glm::vec3(0, -15, 0)) * glm::scale(glm::vec3(1.f)), textureSkybox);
// Animals
renderSeaTurtles(time, causticPass ? textureSeaTurtle : caustics[causticIndex]);
renderCrabs(time, causticPass ? textureCrab : caustics[causticIndex]);
renderSeahorses(time, causticPass ? textureCrab : caustics[causticIndex]);
renderSharks(time, causticPass ? textureShark : caustics[causticIndex]);
renderDolphins(time, causticPass ? textureShark : caustics[causticIndex]);
renderSeaTurtles(time, textureSeaTurtle);
renderCrabs(time, textureCrab);
renderSeahorses(time, textureCrab);
renderSharks(time, textureShark);
renderDolphins(time, textureShark);
// Fish
for (int i = 0; i < 15; i++) drawObjectTexture(firstFishContext, glm::translate(glm::vec3(firstFishPositions[i][0], firstFishPositions[i][1], firstFishPositions[i][2])) * glm::eulerAngleY(time / 3) * glm::translate(glm::vec3(-20, 0, 0)) * glm::rotate(glm::radians(cos(8 * time) * 8), glm::vec3(0, 1, 0)) * glm::scale(glm::vec3(0.6f)), textureFirstFish);
@ -359,27 +384,8 @@ void renderObjects(bool causticPass) {
// Shipwreck
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);
// Rocks
drawObjectTexture(rockContext, glm::translate(glm::vec3(30, -13, 40)) * glm::rotate(glm::radians(270.f), glm::vec3(1, 0, 0)) * glm::scale(glm::vec3(6.f)), causticPass ? textureRockBrown : caustics[causticIndex]);
drawObjectTexture(rockContext, glm::translate(glm::vec3(-25, -15, 20)) * glm::rotate(glm::radians(270.f), glm::vec3(1, 0, 0)) * glm::scale(glm::vec3(3.f)), causticPass ? textureRockGray2 : caustics[causticIndex]);
drawObjectTexture(rockContext, glm::translate(glm::vec3(-30, -16, -30)) * glm::rotate(glm::radians(270.f), glm::vec3(1, 0, 0)) * glm::scale(glm::vec3(5.f)), causticPass ? textureRockGray2 : caustics[causticIndex]);
drawObjectTexture(rockContext, glm::translate(glm::vec3(1, -13, -15)) * glm::rotate(glm::radians(270.f), glm::vec3(1, 0, 0)) * glm::scale(glm::vec3(3.f)), causticPass ? textureRockBrown : caustics[causticIndex]);
drawObjectTexture(rockContext, glm::translate(glm::vec3(35, -20, -25)) * glm::rotate(glm::radians(270.f), glm::vec3(1, 0, 0)) * glm::scale(glm::vec3(4.f)), causticPass ? textureRockGray : caustics[causticIndex]);
// Stones
drawObjectTexture(stoneContext, glm::translate(glm::vec3(20, -14, 20)) * glm::rotate(glm::radians(270.f), glm::vec3(1, 0, 0)) * glm::scale(glm::vec3(3.f)), causticPass ? textureRockBrown : caustics[causticIndex]);
drawObjectTexture(stoneContext, glm::translate(glm::vec3(-15, -15, 10)) * glm::rotate(glm::radians(270.f), glm::vec3(1, 0, 0)) * glm::scale(glm::vec3(4.f)), causticPass ? textureRockBrown : caustics[causticIndex]);
drawObjectTexture(stoneContext, glm::translate(glm::vec3(-20, 25, -10)) * glm::rotate(glm::radians(270.f), glm::vec3(1, 0, 0)) * glm::scale(glm::vec3(5.f)), causticPass ? textureRockGray : caustics[causticIndex]);
//drawObjectTexture(starfishContext, glm::rotate(glm::radians(270.f), glm::vec3(1, 0, 0)) * glm::scale(glm::vec3(0.2f)), textureStarfish);
//drawObjectTexture(steeringWheelContext, glm::rotate(glm::radians(250.f), glm::vec3(1, 0, 0)) * glm::scale(glm::vec3(0.4f)), textureBoards);
if(causticPass) {
glDepthMask(GL_TRUE);
glDepthFunc(GL_LESS);
glDisable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
}
}
void renderScene()