GithubHelp home page GithubHelp logo

raytracer's People

Contributors

bheisler avatar inokawa avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

raytracer's Issues

Why does a plane, that's facing 0,0,0, with origin, 0,0,-10, have a negative z in its normal?

Shouldn't its normal be 0,0,1?

In your example scene, the back wall has a normal of 0,0,-1

Backstory: I'm using your code and implementing triangles using https://www.scratchapixel.com/lessons/3d-basic-rendering/ray-tracing-rendering-a-triangle/ray-triangle-intersection-geometric-solution as reference. I got it to work and then realized my normals were going opposite than I thought (mind boggling). Anyway, I was under the impression that the normal was the direction an object's plane was facing.

Fresnel reflections

Hi,

I'm trying to implement my own toy ray tracer in Rust, but I am having lot's of trouble with the Fresnel calculations. Out of frustration I just tried to just copy your fresnel function, but I only get 0.04 or 0.03999999 as a result. I isolated the function and wrote some tests but I am unable to get the function to work correctly. Can you help me?

I copied this function:
https://github.com/bheisler/raytracer/blob/master/src/rendering.rs#L267-L287

The test results for a 0 degree angle are correct (I think 0.04 is correct when the IOR = 1.5). I also test a 90 degree angle and smaller angles, but the result stays around 0.04.

---- helpers::tests::test_fresnel_ratio_half_at_around_80_deg_on_normal stdout ----
Normal Vector3 [0.0, 0.0, -1.0]
 Angle of incidence: Vector3 [1.0, 0.0, 0.2]
ior: 1.5
ratio: 0.04000000000000001
0.04000000000000001
thread 'helpers::tests::test_fresnel_ratio_half_at_around_80_deg_on_normal' panicked at 'assertion failed: ratio > 0.499999', src\helpers.rs:184:9
note: Run with `RUST_BACKTRACE=1` for a backtrace.

---- helpers::tests::test_fresnel_ratio_one_at_perpendicular_of_normal stdout ----
Normal Vector3 [0.0, 0.0, -1.0]
 Angle of incidence: Vector3 [1.0, 0.0, 0.0]
ior: 1.5
ratio: 0.040000000000000015
0.040000000000000015
thread 'helpers::tests::test_fresnel_ratio_one_at_perpendicular_of_normal' panicked at 'assertion failed: ratio > 0.99999999', src\helpers.rs:171:9

Any ideas?

Edit:

I also tried the following. With this code I got values between 1 and 1000 or more...

let mut n1 = 1.0;
    let mut n2 = ior;

    let cos_theta_incidence = normal_normalized.dot(angle_of_incidence_normalized);
    let sin_theta_incidence = (1.0 - cos_theta_incidence * cos_theta_incidence).sqrt();

    if cos_theta_incidence > 0.0 {
        n1 = ior;
        n2 = 1.0;
    }

    let sin_theta_transmittance = n1 * (sin_theta_incidence / n2);
    let cos_theta_transmittance = (1.0 - sin_theta_transmittance * sin_theta_transmittance).sqrt();

    let n1_cos_theta_transmittance = n1 * cos_theta_transmittance;
    let n2_cos_theta_transmittance = n2 * cos_theta_transmittance;
    let n1_cos_theta_incidence = n1 * cos_theta_incidence;
    let n2_cos_theta_incidence = n2 * cos_theta_incidence;

    let s_polarized_sqrt = (n1_cos_theta_incidence - n2_cos_theta_transmittance)
        / (n1_cos_theta_incidence + n2_cos_theta_transmittance);
    let s_polarized = s_polarized_sqrt * s_polarized_sqrt;

    let p_polarized_sqrt = (n2_cos_theta_incidence - n1_cos_theta_transmittance)
        / (n2_cos_theta_incidence + n1_cos_theta_transmittance);
    let p_polarized = p_polarized_sqrt * p_polarized_sqrt;

    fresnel_ratio = (s_polarized + p_polarized) / 2.0;

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.