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 6245093
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T12:26:42+00:00 2026-05-24T12:26:42+00:00

So I’m trying to rewrite my ray tracer in C# and I’ve been getting

  • 0

So I’m trying to rewrite my ray tracer in C# and I’ve been getting these odd artifacts.
At first I might have thought that they were the black-spot artifacts that are due to not adding Epsilon to the shadow ray as described here.

However I am adding an epsilon and the spots aren’t black (but I am adding an ambient).
Here is an example picture (I made the background yellow so it stands out a bit)

Artifact Image

Here is my lighting code:

private Vector4 CalculateBlinnPhongLight(Ray ray, Intersection its)
    {
        Vector4 blinnPhongColor = Color.Blue.ToVector4();
        //Step 1: Calculate intersection point. Since our direction was never normalized we need to do it here.
        Microsoft.Xna.Framework.Vector3 itsPoint = ray.Origin + ray.Direction*its.TimeInterval.StartTime;
        //Step 2: Calculate half vector h - bisector of angle of v (from intersection to eye) and l (intersection to light)
        Microsoft.Xna.Framework.Vector3 v = -1 * ray.Direction; v.Normalize();
        //Step 3: For ecah light in the scene grab it's contribution
        foreach (Light light in Lights)
        {
            //Step 4: Setup unit vectors for Blinn Phong Lighting model: pg.84
            Microsoft.Xna.Framework.Vector3 l = light.Position - itsPoint; l.Normalize();
            Microsoft.Xna.Framework.Vector3 h = v + l; h.Normalize();
            Microsoft.Xna.Framework.Vector3 n = its.Normal;
            //Step 5: Shadow-Check - send shadow ray and see if it intersects with anything
            if  (IsInShadow(l, itsPoint) )
            {
                continue;
                //TO DO: Check if the material is dielectric (see through)
            }
            //Step 6: Calculate light attenuation
            //TODO:

            //Step 7: Perform Blinn Phong calculation
            //color = color + diffuse * I * max(0, n.l)
            //color = color + specular * I * max(0, n.h)^phong
            blinnPhongColor += its.ClosestNode.Material.DiffuseColor.ToVector4() * light.Color.ToVector4() * Math.Max(0, Microsoft.Xna.Framework.Vector3.Dot(n, l));
            blinnPhongColor += its.ClosestNode.Material.SpecularColor.ToVector4() * light.Color.ToVector4() * (float)Math.Pow(Math.Max(0, Vector3.Dot(n, h)), its.ClosestNode.Material.PhongExponent);
        }
        //Step 8: Add ambient Color
        blinnPhongColor += its.ClosestNode.Material.AmbientColor.ToVector4() * AmbientColor.ToVector4();
        return blinnPhongColor;
    }

    private bool IsInShadow(Microsoft.Xna.Framework.Vector3 dirToLight, Microsoft.Xna.Framework.Vector3 itsPoint)
    {
        //Step 1: Need to add epsilon go itsPoint otherwise we might intersect ourselves
        Microsoft.Xna.Framework.Vector3 epsItsPoint = itsPoint + 0.000001f*dirToLight;
        Ray shadowRay = new Ray(epsItsPoint, dirToLight);
        return ! this.Root.IntersectRay(shadowRay).Hit;
    }

It’s perhaps worth noting that my ray Direction’s are not unit vectors. I’ve done this purposefully based on the instructions on the book I am reading so that when I can transform the ray by the transformation matrices I give to each primitive to allow easy instancing.

  • 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-24T12:26:44+00:00Added an answer on May 24, 2026 at 12:26 pm

    Since those artifacts are getting the ambient light contribution, but are receiving neither the specular nor the diffuse, it is almost certainly your IsInShadow calculation. Depending on how you defined your sphere, there are various precision errors you should be hitting.

    To verify that it is your shadow calculation, replace the diffuse and specular contributions with a single constant contribution. If the artifacts go away, then that is your issue. If they do not go away, then there is an error in both light contributions (unlikely), and you can verify this by repositioning the light in your scene.

    Also, you really don’t need to normalize your shadow ray, and not doing so spares you a division calculation, which is usually where those sorts of precision errors occur.

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

Sidebar

Related Questions

I have a small JavaScript validation script that validates inputs based on Regex. I
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I have been unable to fix a problem with Java Unicode and encoding. The
I'm trying to create an if statement in PHP that prevents a single post
I am trying to loop through a bunch of documents I have to put
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
I am trying to understand how to use SyndicationItem to display feed which is

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.