Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimization for intersections on Triangle #4

Open
yarbelk opened this issue Feb 3, 2016 · 1 comment
Open

Optimization for intersections on Triangle #4

yarbelk opened this issue Feb 3, 2016 · 1 comment

Comments

@yarbelk
Copy link

yarbelk commented Feb 3, 2016

There is an optimization you can make for you Triangle type, though it sort of prevents using Triangle literals.

type Triangle struct {
    V1, V2, V3 Vector
    Box        Box
    intersection func(Ray) HIt
}

func NewTriangle(....) Triangle {
    t.intersection = t.generateInsersectionFunction()
    return t
}

func (t *Triangle) generateInsersectionFunction() {
    // Precalculate things like determinants etc here, return the function with these pre-computed
}

func (t *Triangle) Intersection(r Ray)  {
    if t.intersection == nil { t.generateIntersectionFunction()}
    return t.intersection(r)
}

a useful optimization if you are doing a lots of intersections.

@fogleman
Copy link
Owner

fogleman commented Feb 3, 2016

The Compile function would be appropriate for this.

Care to submit a pull request? Would like to see performance numbers before/after.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants