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 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
  • 2 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. 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

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
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
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
this is what i have right now Drawing an RSS feed into the php,
I am trying to render a haml file in a javascript response like so:
I am doing a simple coin flipping experiment for class that involves flipping a
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this

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.