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

  • Home
  • SEARCH
  • 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 123397
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T04:16:48+00:00 2026-05-11T04:16:48+00:00

I’m trying to write a simple raytracer as a hobby project and it’s all

  • 0

I’m trying to write a simple raytracer as a hobby project and it’s all working fine now, except I can’t get soft-shadows to work at all. My idea of soft-shadows is that the lightsource is considered to have a location and a radius. To do a shadow test on this light I take the point where the primary ray hit an object in the scene and cast an n-amount of rays towards the lightsource where each new ray has a random component to every axis, where the random component varies between -radius and radius.

If such a ray hits an object in the scene, I increment a hitcounter (if a ray hits multiple objects, it still only increments with one). If it makes it to the lightsource without collisions, I add the distance of the primary ray’s intersect point to the lightsource’s center to a variable.

When n samples have been taken, I calculate the ratio of rays that have collided and multiply the color of the light by this ratio (so a light with color 1000,1000,1000 will become 500,500,500 with a ratio of 0.5, where half the rays have collided). Then I calculate the average distance to the lightsource by dividing the distance variable of earlier by the amount of non-colliding rays. I return that variable and the function exits.

The problem is: it doesn’t work. Not quite at least. What it looks like can be seen here. You can see it sort of resembles soft-shadows, if you squint real hard.

I don’t get it, am I making some sort of fundamental flaw here, or is it something tiny? I’m fairly sure the problem is in this method, because when I count the number of partially lit pixels produced directly by this method, there are only about 250, when there should be a lot more. And when you look closely at the picture, you can see there’s some partially lit pixels, suggesting the rest of the code processes the partially lit pixels just fine.

Here’s the actual light for soft-shadows class:

using System; using System.Collections.Generic; using System.Linq; using System.Text;  namespace MyFirstRayTracer {   public class AreaLight : ILight   {     private const int _radius = 5;     private const int _samples = 16;     public Color Color { get; set; }     public Vector Location { get; set; }     #region ILight Members      public float GetLightingInformation(Vector point, ISceneObject[] scene, out Color color)     {       int intersectCount = 0;       float distance = -1;       for(int i = 0; i < _samples; i++)       {     bool intersects = false;     float rand = 0;     rand = _radius - (float)(new Random().NextDouble()*(2*_radius));     foreach (ISceneObject obj in scene)     {       Vector iPoint;        Vector loc = new Vector(Location.X + rand, Location.Y + rand, Location.Z + rand);        if (!obj.Intersect(new Ray(point, loc), out iPoint))       {         distance += (Location - point).SqLength;        }       else       {         intersects = true;         distance -= (Location - point).SqLength;       }     }     if (intersects)       intersectCount++;       }       float factor = 1-((float)intersectCount/_samples);        color = new Color(factor*Color.R, factor*Color.G, factor*Color.B);        return (float)Math.Sqrt(distance / (_samples - intersectCount));     }       #endregion   } } 
  • 1 1 Answer
  • 1 View
  • 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. 2026-05-11T04:16:49+00:00Added an answer on May 11, 2026 at 4:16 am

    Try generating a different ‘rand’ for each component of ‘loc’. As is, your jittered points all lie on a line.

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

Sidebar

Ask A Question

Stats

  • Questions 141k
  • Answers 141k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Response.OutputStream.Write(...) Or if you have a MemoryStream: MemoryStream ms =… May 12, 2026 at 8:00 am
  • Editorial Team
    Editorial Team added an answer Martin Fowler offers an analysis of MVC and MVP, and… May 12, 2026 at 8:00 am
  • Editorial Team
    Editorial Team added an answer I always liked the pattern: public void GuiMethod(object param) {… May 12, 2026 at 8:00 am

Related Questions

I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I am currently running into a problem where an element is coming back from
Seemingly simple, but I cannot find anything relevant on the web. What is the
Does anyone know how can I replace this 2 symbol below from the string
Configuring TinyMCE to allow for tags, based on a customer requirement. My config is

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.