diff options
author | Sebastian Park <SebPark03@gmail.com> | 2024-04-17 03:10:27 -0400 |
---|---|---|
committer | Sebastian Park <SebPark03@gmail.com> | 2024-04-17 03:10:27 -0400 |
commit | 9b436e67cdc5ee896c3c2fec90499e400a9e524e (patch) | |
tree | 45366352db1024722bbe7db07792c4148683afa9 /resources/shaders/shader.vert | |
parent | 0b0629450e2553b2f890094290528b565d607e38 (diff) |
Do realtime refraction kinda.
Diffstat (limited to 'resources/shaders/shader.vert')
-rwxr-xr-x | resources/shaders/shader.vert | 45 |
1 files changed, 44 insertions, 1 deletions
diff --git a/resources/shaders/shader.vert b/resources/shaders/shader.vert index 15e6833..90ebdf8 100755 --- a/resources/shaders/shader.vert +++ b/resources/shaders/shader.vert @@ -7,6 +7,8 @@ uniform mat4 proj; uniform mat4 view; uniform mat4 model; uniform mat4 inverseView; +//uniform float width; +//uniform float height; // TODO: Pass in width and height as uniform uniform mat3 inverseTransposeModel; @@ -14,12 +16,53 @@ out vec3 normal_cameraSpace; out vec3 normal_worldSpace; out vec3 camera_worldSpace; out vec3 pos; +out vec3 refrPos; +out vec2 uv; + +vec3 getRefrPos() { + float depth = -1.f; + vec3 w_o = pos - camera_worldSpace; + float cos_theta_i = dot(-w_o, normal_worldSpace); + float n_i = 1; + float n_t = 1.33f; + float determinant = 1.f - (pow((n_i / n_t), 2.f) * (1.f - pow(cos_theta_i, 2.f))); + + if (determinant >= 0) { + float cos_theta_t = sqrt(determinant); + vec3 w_t = (n_i / n_t) * w_o + ((n_i / n_t) * cos_theta_i - cos_theta_t) * normal_worldSpace; +// Ray reflectedRay(i.hit, w_t); +// float attenuation = (!entering && attenuateRefract) ? std::pow(M_E, (-(ray.o - i.hit).norm()) * mat.ior) : 1; +// L += traceRay(reflectedRay, scene, true, n_t, !is_in_refractor) * attenuation / threshold; + float dist = position.y - depth; + float depthScale = dist / w_t.y; + vec3 groundContactPoint = -(w_t * depthScale) + position; + return groundContactPoint; + } else { +// Eigen::Vector3f w_i = w_o - 2 * w_o.dot(intersectNormal) * incidenceNormal; +// Ray reflectedRay(i.hit, w_i); +// L += traceRay(reflectedRay, scene, true, current_ior, false) / threshold; + return vec3(0, 0, 0); + } +} void main() { + float depth = -2.f; + float dist = position.y - depth; + float width = 81.f * 2.f; + float length = 81.f * 2.f; + normal_cameraSpace = normalize(inverse(transpose(mat3(view))) * inverseTransposeModel * normal); camera_worldSpace = vec3(inverseView * vec4(0.f, 0.f, 0.f, 1.f)); normal_worldSpace = normal; - pos = position; + pos = vec3(model * vec4(position, 1.f)); //vec3(model * vec4(objSpacePos, 1.f)); +// pos = position; + + float depthScale = dist / normal.y; + vec3 groundContactPoint = -(normal * depthScale) + position; // carries down to ground + groundContactPoint = vec3(model * vec4(position, 1)); + uv = vec2((position.x + 81.f) / (162.f), groundContactPoint.z); +// uv = vec2(normal); + refrPos = getRefrPos(); gl_Position = proj * view * model * vec4(position, 1); } |