diff --git a/shader.fs b/shader.fs index d8cafaf..029dce1 100644 --- a/shader.fs +++ b/shader.fs @@ -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) ; } \ No newline at end of file diff --git a/shader.vs b/shader.vs index 3afcf99..d26840f 100644 --- a/shader.vs +++ b/shader.vs @@ -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); } diff --git a/src/main.cpp b/src/main.cpp index 7e40305..ca49c0e 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -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);