From 9900ffe840ee0e9f914b0e7956a4e80ffb553e9e Mon Sep 17 00:00:00 2001 From: talha Date: Tue, 16 Apr 2024 02:04:23 +0500 Subject: Added refraction, albeit slightly limited --- source/shaders/refr.fs.glsl | 15 +++++++++++++++ source/shaders/refr.vs.glsl | 20 ++++++++++++++++++++ 2 files changed, 35 insertions(+) create mode 100644 source/shaders/refr.fs.glsl create mode 100644 source/shaders/refr.vs.glsl (limited to 'source/shaders') diff --git a/source/shaders/refr.fs.glsl b/source/shaders/refr.fs.glsl new file mode 100644 index 0000000..6747ded --- /dev/null +++ b/source/shaders/refr.fs.glsl @@ -0,0 +1,15 @@ +#version 330 core + +in vec3 Normal; +in vec3 Position; + +uniform samplerCube skybox; +uniform vec3 cameraPos; +out vec4 FragColor; + +void main() { + float refr_ratio = 1.0/1.52; + vec3 I = normalize(Position - cameraPos); + vec3 R = refract(I, normalize(Normal), refr_ratio); + FragColor = vec4(texture(skybox, R).rgb, 1.0); +}; diff --git a/source/shaders/refr.vs.glsl b/source/shaders/refr.vs.glsl new file mode 100644 index 0000000..0554f0a --- /dev/null +++ b/source/shaders/refr.vs.glsl @@ -0,0 +1,20 @@ +#version 330 core +layout(location=0) in vec3 aPos; +layout(location=1) in vec3 aNormal; + +uniform mat4 View; +uniform mat4 Model; +uniform mat4 Projection; + +out vec3 Normal; +out vec3 Position; + +void main() { + // @note: This is the calculation for getting the normal vector + // one that is unaffected by non-uniform scaling that is. + // look at the lighting chapter in learnopengl.com to understand this more + Normal = mat3(transpose(inverse(Model))) * aNormal; + Position = vec3(Model * vec4(aPos, 1.0)); + gl_Position = Projection * View * Model * vec4(aPos, 1.0); +}; + -- cgit v1.2.3