create sphere with nice skybox texture
This commit is contained in:
parent
ce82c3f8ec
commit
f03ed1fa4b
@ -1,16 +1,16 @@
|
||||
#version 410 core
|
||||
out vec4 FragColor;
|
||||
#version 330 core
|
||||
out vec4 gl_FragColor;
|
||||
|
||||
in vec3 Normal;
|
||||
in vec3 Position;
|
||||
uniform sampler2D textureSampler;
|
||||
in vec3 fragPos;
|
||||
in vec3 interpNormal;
|
||||
|
||||
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);
|
||||
vec3 I = normalize(fragPos - cameraPos);
|
||||
vec3 R = reflect(I, normalize(interpNormal));
|
||||
gl_FragColor = vec4(texture(skybox, R).rgb, 1.0);
|
||||
}
|
@ -1,17 +1,16 @@
|
||||
#version 410 core
|
||||
layout (location = 0) in vec3 aPos;
|
||||
layout (location = 1) in vec3 aNormal;
|
||||
#version 330 core
|
||||
layout(location = 0) in vec3 vertexPosition;
|
||||
layout(location = 1) in vec3 vertexNormal;
|
||||
|
||||
out vec3 Normal;
|
||||
out vec3 Position;
|
||||
out vec3 interpNormal;
|
||||
out vec3 fragPos;
|
||||
|
||||
uniform mat4 model;
|
||||
uniform mat4 view;
|
||||
uniform mat4 projection;
|
||||
uniform mat4 modelMatrix;
|
||||
uniform mat4 modelViewProjectionMatrix;
|
||||
|
||||
void main()
|
||||
{
|
||||
Normal = mat3(transpose(inverse(model))) * aNormal;
|
||||
Position = vec3(model * vec4(aPos, 1.0));
|
||||
gl_Position = projection * view * vec4(Position, 1.0);
|
||||
gl_Position = modelViewProjectionMatrix * vec4(vertexPosition, 1.0);
|
||||
interpNormal = (modelMatrix * vec4(vertexNormal, 0.0)).xyz;
|
||||
fragPos = (modelMatrix*vec4(vertexPosition,1)).xyz;
|
||||
}
|
@ -325,9 +325,9 @@ void drawObjectColor(Core::RenderContext context, glm::mat4 modelMatrix, glm::ve
|
||||
glUseProgram(0);
|
||||
}
|
||||
|
||||
void drawObjectTexture(Core::RenderContext context, glm::mat4 modelMatrix, GLuint textureId)
|
||||
void drawObjectTexture(Core::RenderContext context, glm::mat4 modelMatrix, GLuint textureId, GLuint program)
|
||||
{
|
||||
GLuint program = programTexture;
|
||||
|
||||
|
||||
glUseProgram(program);
|
||||
|
||||
@ -359,7 +359,9 @@ void renderScene()
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
glBindTexture(GL_TEXTURE_CUBE_MAP, cubemapTexture);
|
||||
glDrawArrays(GL_TRIANGLES, 0, 36);
|
||||
//glUseProgram(skyboxProgram);
|
||||
|
||||
|
||||
//glUseProgram(cubeProgram);
|
||||
//glBindVertexArray(0);
|
||||
//glBindVertexArray(cubeVAO);
|
||||
//glActiveTexture(GL_TEXTURE0);
|
||||
@ -374,6 +376,11 @@ void renderScene()
|
||||
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 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, textureBubble, cubeProgram);
|
||||
|
||||
|
||||
glm::vec3 change1 = glm::vec3(0, 3, 0);
|
||||
glm::vec3 change2 = glm::vec3(0, 0, 0);
|
||||
@ -385,19 +392,19 @@ void renderScene()
|
||||
glm::vec3 change8 = glm::vec3(0, 1, 1);
|
||||
for (int i = 0; i < 5; i++) {
|
||||
if (time > -10) {
|
||||
drawObjectTexture(fishContext, animationMatrix(time + 15, change1, fishKeyPoints, glm::vec3(0.25f), 1.f), textureFish);
|
||||
drawObjectTexture(fishContext, animationMatrix(time + 15, change2, fishKeyPoints, glm::vec3(0.25f), 1.f), textureFish);
|
||||
drawObjectTexture(fishContext, animationMatrix(time + 15, change3, fishKeyPoints, glm::vec3(0.25f), 1.f), textureFish);
|
||||
drawObjectTexture(fishContext, animationMatrix(time + 15, change4, fishKeyPoints, glm::vec3(0.25f), 1.f), textureFish);
|
||||
drawObjectTexture(bubbleContext, animationMatrix(time + 15, change5, bubbleKeyPoints, glm::vec3(0.01f), 0.2f), textureBubble);
|
||||
drawObjectTexture(bubbleContext, animationMatrix(time + 15, change6, bubbleKeyPoints, glm::vec3(0.01f), 0.2f), textureBubble);
|
||||
drawObjectTexture(bubbleContext, animationMatrix(time + 15, change7, bubbleKeyPoints, glm::vec3(0.01f), 0.2f), textureBubble);
|
||||
drawObjectTexture(fishContext, animationMatrix(time + 15, change1, fishKeyPoints, glm::vec3(0.25f), 1.f), textureFish, programTexture);
|
||||
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.01f), 0.2f), GL_TEXTURE_CUBE_MAP, skyboxProgram);
|
||||
//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);
|
||||
time -= 6;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
drawObjectTexture(submarineContext, submarineModelMatrix, textureSubmarine);
|
||||
drawObjectTexture(submarineContext, submarineModelMatrix, textureSubmarine, programTexture);
|
||||
glutSwapBuffers();
|
||||
}
|
||||
|
||||
@ -526,6 +533,8 @@ void shutdown()
|
||||
shaderLoader.DeleteProgram(programColor);
|
||||
shaderLoader.DeleteProgram(programTexture);
|
||||
shaderLoader.DeleteProgram(skyboxProgram);
|
||||
shaderLoader.DeleteProgram(cubeProgram);
|
||||
|
||||
}
|
||||
|
||||
void idle()
|
||||
|
Loading…
Reference in New Issue
Block a user