diff options
author | talha <talha@talhaamir.xyz> | 2024-04-16 02:04:23 +0500 |
---|---|---|
committer | talha <talha@talhaamir.xyz> | 2024-04-16 02:04:23 +0500 |
commit | 9900ffe840ee0e9f914b0e7956a4e80ffb553e9e (patch) | |
tree | a14afd9826f1b0b9c2cf24c9958f2646c82321db /source/shaders | |
parent | 6cc8297634377bffc1dce05f1df754ac4e54177a (diff) |
Added refraction, albeit slightly limited
Diffstat (limited to 'source/shaders')
-rw-r--r-- | source/shaders/refr.fs.glsl | 15 | ||||
-rw-r--r-- | source/shaders/refr.vs.glsl | 20 |
2 files changed, 35 insertions, 0 deletions
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); +}; + |