diff options
author | Sebastian Park <SebPark03@gmail.com> | 2024-04-17 11:17:35 -0400 |
---|---|---|
committer | Sebastian Park <SebPark03@gmail.com> | 2024-04-17 11:17:35 -0400 |
commit | 1d5c17db40e6bddf88c718d498eabbff0efbf4dd (patch) | |
tree | 4a7ceb2f5295e3195a46beff96f4ad2172f81cf0 /resources/shaders/shader.vert | |
parent | 8d7dc367a3261e3043d87535a61c630a7faca0d8 (diff) |
Refraction stuff. Also refractor shading equation.
Diffstat (limited to 'resources/shaders/shader.vert')
-rwxr-xr-x | resources/shaders/shader.vert | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/resources/shaders/shader.vert b/resources/shaders/shader.vert index 90ebdf8..bc6cb2e 100755 --- a/resources/shaders/shader.vert +++ b/resources/shaders/shader.vert @@ -17,16 +17,20 @@ out vec3 normal_worldSpace; out vec3 camera_worldSpace; out vec3 pos; out vec3 refrPos; +out float refrProb; out vec2 uv; -vec3 getRefrPos() { - float depth = -1.f; +vec4 getRefrPos() { + float depth = -1.f; // TODO: Pass as uniform 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))); + float r0 = pow((n_i - n_t) / (n_i + n_t), 2.f); // variable required to calculate probability of reflection + float prob_to_refl = r0 + ((1 - r0) * pow((1 - cos_theta_i), 5.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; @@ -36,12 +40,12 @@ vec3 getRefrPos() { float dist = position.y - depth; float depthScale = dist / w_t.y; vec3 groundContactPoint = -(w_t * depthScale) + position; - return groundContactPoint; + return vec4(groundContactPoint, 1.f - prob_to_refl); } 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); + return vec4(0, 0, 0, 0); } } @@ -62,7 +66,9 @@ void main() { groundContactPoint = vec3(model * vec4(position, 1)); uv = vec2((position.x + 81.f) / (162.f), groundContactPoint.z); // uv = vec2(normal); - refrPos = getRefrPos(); + vec4 refrPos_and_prob = getRefrPos(); + refrPos = vec3(refrPos_and_prob); + refrProb = clamp(refrPos_and_prob.w, 0.f, 1.f); gl_Position = proj * view * model * vec4(position, 1); } |