Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7409455
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T06:05:07+00:00 2026-05-29T06:05:07+00:00

I’m trying to render the mount scene from Eric Haines’ Standard Procedural Database (SPD)

  • 0

I’m trying to render the “mount” scene from Eric Haines’ Standard Procedural Database (SPD), but the refraction part just doesn’t want to co-operate. I’ve tried everything I can think of to fix it.

This one is my render (with Watt’s formula):

My render.
(source: philosoraptor.co.za)

This is my render using the “normal” formula:

Normal formula.
(source: philosoraptor.co.za)

And this one is the correct render:

Correct render.
(source: philosoraptor.co.za)

As you can see, there are only a couple of errors, mostly around the poles of the spheres. This makes me think that refraction, or some precision error is to blame.

Please note that there are actually 4 spheres in the scene, their NFF definitions (s x_coord y_coord z_coord radius) are:

s -0.8 0.8 1.20821 0.17
s -0.661196 0.661196 0.930598 0.17
s -0.749194 0.98961 0.930598 0.17
s -0.98961 0.749194 0.930598 0.17

That is, there is a fourth sphere behind the more obvious three in the foreground. It can be seen in the gap left between these three spheres.

Here is a picture of that fourth sphere alone:

'Fourth' sphere.
(source: philosoraptor.co.za)

And here is a picture of the first sphere alone:

'First' sphere.
(source: philosoraptor.co.za)

You’ll notice that many of the oddities present in both my version and the correct version is missing. We can conclude that these effects are the result of interactions between the spheres, the question is which interactions?

What am I doing wrong? Below are some of the potential errors I’ve already considered:

  • Refraction vector formula.

As far as I can tell, this is correct. It’s the same formula used by several websites and I verified the derivation personally. Here’s how I calculate it:

double sinI2 = eta * eta * (1.0f - cosI * cosI);

Vector transmit = (v * eta) + (n * (eta * cosI - sqrt(1.0f - sinI2)));

transmit = transmit.normalise();

I found an alternate formula in 3D Computer Graphics, 3rd Ed by Alan Watt. It gives a closer approximation to the correct image:

double etaSq = eta * eta;
double sinI2 = etaSq * (1.0f - cosI * cosI);
Vector transmit = (v * eta) + (n * (eta * cosI - (sqrt(1.0f - sinI2) / etaSq)));
transmit = transmit.normalise();

The only difference is that I’m dividing by eta^2 at the end.

  • Total internal reflection.

I tested for this, using the following conditional before the rest of my intersection code:

if (sinI2 <= 1)
  • Calculation of eta.

I use a stack-like approach for this problem:

        /* Entering object. */
        if (r.normal.dot(r.dir) < 0)
        {
           double eta1 = r.iorStack.back();
           double eta2 = m.ior;
           eta = eta1 / eta2;

           r.iorStack.push_back(eta2);
        }
        /* Exiting object. */
        else
        {
           double eta1 = r.iorStack.back();
           r.iorStack.pop_back();
           double eta2 = r.iorStack.back();

           eta = eta1 / eta2;
        }

As you can see, this stores the previous objects that contained this ray in a stack. When exiting the code pops the current IOR off the stack and uses that, along with the IOR under it to compute eta. As far as I know this is the most correct way to do it.

This works for nested transmitting objects. However, it breaks down for intersecting transmitting objects. The problem here is that you need to define the IOR for the intersection independently, which the NFF file format does not do. It’s unclear then, what the “correct” course of action is.

  • Moving the new ray’s origin.

The new ray’s origin has to be moved slightly along the transmitted path so that it doesn’t intersect at the same point as the previous one.

p = r.intersection + transmit * 0.0001f;

p += transmit * 0.01f;

I’ve tried making this value smaller (0.001f) and (0.0001f) but that makes the spheres appear solid. I guess these values don’t move the rays far enough away from the previous intersection point.

EDIT: The problem here was that the reflection code was doing the same thing. So when an object is reflective as well as refractive then the origin of the ray ends up in completely the wrong place.

  • Amount of ray bounces.

I’ve artificially limited the amount of ray bounces to 4. I tested raising this limit to 10, but that didn’t fix the problem.

  • Normals.

I’m pretty sure I’m calculating the normals of the spheres correctly. I take the intersection point, subtract the centre of the sphere and divide by the radius.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T06:05:08+00:00Added an answer on May 29, 2026 at 6:05 am

    So after more than I year, I finally figured out what was going on here. Clear minds and all that. I was completely off track with the formula. I’m instead using a formula by Heckbert now, which I am sure is correct because I proved it myself using geometry and discrete math.

    Here’s the correct vector calculation:

    double c1 = v.dot(n) * -1;
    double c1Sq = pow(c1, 2);
    
    /* Heckbert's formula requires eta to be eta2 / eta1, so I have to flip it here. */
    eta = 1 / eta;
    double etaSq = pow(eta, 2);
    
    if (etaSq + c1Sq >= 1)
    {
       Vector transmit = (v / eta) + (n / eta) * (c1 - sqrt(etaSq - 1 + c1Sq));
       transmit = transmit.normalise();
    ...
    }
    else
    {
       /* Total internal reflection. */
    }
    

    In the code above, eta is eta1 (the IOR of the surface from which the ray is coming) over eta2 (the IOR of the destination surface), v is the incident ray and n is the normal.

    There was another problem, which confused the problem some more. I had to flip the normal when exiting an object (which is obvious – I missed it because the other errors were obscuring it).

    Lastly, my line of sight algorithm (to determine whether a surface is illuminated by a point light source) was not properly passing through transparent surfaces.

    So now my images line up properly 🙂

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I am trying to render a haml file in a javascript response like so:
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
For some reason, after submitting a string like this Jack’s Spindle from a text
Seemingly simple, but I cannot find anything relevant on the web. What is the
I have a French site that I want to parse, but am running into
I am currently running into a problem where an element is coming back from

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.