albedo with refractions and reflactions of the cubemap

This commit is contained in:
Nigel Barink 2022-10-17 11:56:27 +02:00
parent 4f4eb2f496
commit 71c942d88e
3 changed files with 16 additions and 13 deletions

View File

@ -19,24 +19,20 @@ const float diamond_ri = 2.42;
void main()
{
// Regular shading
FragColor = texture( texture_diffuse1, TexCoords) ;
vec4 albeno = texture( texture_diffuse1, TexCoords) ;
// Reflective shading
/*
vec3 I = normalize(Position - cameraPos);
vec3 R = reflect(I, normalize(Normal));
FragColor = vec4(texture(skybox,R).rgb, 1.0);
*/
vec4 reflections = vec4(texture(skybox,R).rgb, 1.0);
// Refractive shading
/*
float ratio = air_ri/water_ri;
vec3 I = normalize(Position-cameraPos);
vec3 R = refract(I, normalize(Normal), ratio);
FragColor = vec4(texture(skybox, R).rgb, 1.0);
*/
float ratio = air_ri/diamond_ri;
vec3 I2 = normalize(Position-cameraPos);
vec3 R2 = refract(I2, normalize(Normal), ratio);
vec4 refractions = vec4(texture(skybox, R2).rgb, 1.0);
FragColor = vec4(albeno.rgb + (refractions.rgb * 0.5) + (reflections.rgb * 0.8), 1.0);
}

View File

@ -10,7 +10,9 @@ Cubemap::~Cubemap(){
}
void Cubemap::Bind(){
glBindTexture(GL_TEXTURE_CUBE_MAP, id);
};
void Cubemap::Unbind(){

View File

@ -188,12 +188,17 @@ void Skybox_pass (GLuint& SkyboxVAO, Shader& skyboxShader, Cubemap& skycubemap)
void drawScene_pass(Shader& shader, Model& Object, Cubemap& skybox)
{
shader.use();
shader.setVec3("cameraPos", camera.Position);
glActiveTexture(GL_TEXTURE11);
skybox.Bind();
glActiveTexture(GL_TEXTURE0);
shader.setMat4("model", model);
shader.setMat4("view", view);
shader.setMat4("projection", projection);
shader.setInt("skybox",11);
Object.Draw(shader);
}