reflection

This commit is contained in:
Nigel Barink 2022-10-16 20:27:25 +02:00
parent e7a119f0dd
commit 6667d75455
3 changed files with 20 additions and 6 deletions

View File

@ -1,13 +1,19 @@
#version 460 core
out vec4 FragColor;
in vec3 Normal;
in vec3 Position;
uniform vec3 cameraPos;
uniform samplerCube skybox;
in vec2 TexCoords;
uniform sampler2D texture_diffuse1;
void main()
{
FragColor = texture( texture_diffuse1, TexCoords) ;
vec3 I = normalize(Position - cameraPos);
vec3 R = reflect(I, normalize(Normal));
FragColor = vec4(texture(skybox,R).rgb, 1.0); // texture( texture_diffuse1, TexCoords) ;
}

View File

@ -8,10 +8,15 @@ uniform mat4 view;
uniform mat4 projection;
out vec2 TexCoords;
out vec3 Normal;
out vec3 Position;
void main(){
void main()
{
Normal = mat3(transpose(inverse(model))) * aNormal;
Position = vec3(model* vec4(aPos, 1.0));
gl_Position = projection * view * model * vec4(aPos , 1.0);
TexCoords = aTexCoords;
gl_Position = projection * view * model * vec4(aPos , 1.0);
}

View File

@ -186,7 +186,7 @@ void Skybox_pass (GLuint& SkyboxVAO, Shader& skyboxShader, Cubemap& skycubemap)
glDepthMask(GL_TRUE);
}
void drawScene_pass(Shader& shader, Model& Object)
void drawScene_pass(Shader& shader, Model& Object, Cubemap& skybox)
{
//glClearColor(0.1f, 0.1f, 0.1f, 1.0f);
//glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
@ -194,6 +194,9 @@ void drawScene_pass(Shader& shader, Model& Object)
shader.use();
shader.setVec3("cameraPos", camera.Position);
skybox.Bind();
shader.setMat4("model", model);
shader.setMat4("view", view);
shader.setMat4("projection", projection);
@ -374,7 +377,7 @@ while(!glfwWindowShouldClose(window))
Skybox_pass(SkyboxVAO, skyboxShader, skybox);
drawScene_pass(shader, backpack);
drawScene_pass(shader, backpack, skybox);
outline_pass(outlineShader, backpack);