|
Post by matthew on Dec 1, 2020 23:33:22 GMT
Maybe I've been working to long today. I can't seem to solve this problem though I assume it is trivial. Any suggestions?
My best idea was to add a HasShadow property and then, in IsShadowed, I use that property for the object to opt-out but it didn't work. I guess there is something more that I'm not seeing...
public bool IsShadowed(Point point)
{
bool isShadowed = false;
foreach (var light in Lights)
{
var v = new Vector(light.Position - point);
var distance = v.Magnitude;
var direction = v.Normalize;
var r = new Ray(point, direction);
var intersections = Intersect(r);
var h = intersections.Hit;
if ((h != null) && (h.t < distance) && (h.Object.HasShadow))
{
isShadowed = true;
break;
}
}
return isShadowed;
}
|
|
|
Post by matthew on Dec 2, 2020 15:28:35 GMT
I guess I had it right after all and the problem was in the scene description for the water surface. That's embarrassing! ¯\(°_o)/¯ It took a lot of tweaking this morning...
// Floor of scene
var floor = new Plane();
floor.Material.Pattern = new CheckersPattern(new Color (0, 0.4, 0.4), new Color(0, 0.8, 0.8));
floor.Material.Pattern.Transform = Matrix.Scaling(0.2, 0.2, 0.2);
floor.Material.Color = Color.Blue;
floor.Material.Specular = 0;
// Water of scene
var water = new Plane();
water.HasShadow = false;
water.Transform = Matrix.Translation(0, 2, 0);
water.Material.Color = new Color(0, .5, 1);
water.Material.Ambient = 0.1;
water.Material.Diffuse = 0.1;
water.Material.Specular = 0.5;
water.Material.Shininess = 300;
water.Material.Reflective = 1;
water.Material.Transparency = 0.3;
water.Material.RefractiveIndex = 1.333;
// Middle Sphere
var middle = new Sphere();
middle.Transform = Matrix.Translation(-0.5, 1, 0.5);
middle.Material.Color = new Color(0.1, 1, 0.5);
middle.Material.Diffuse = 0.7;
middle.Material.Specular = 0.3;
middle.Material.Reflective = 1;
// Right Sphere
var right = new Sphere();
right.Transform = Matrix.Translation(1.5, 0.5, -0.5) *
Matrix.Scaling(0.5, 0.5, 0.5);
right.Material.Color = new Color(0.5, 1, 0.1);
right.Material.Diffuse = 0.7;
right.Material.Specular = 0.3;
// Left Sphere
var left = new Sphere();
left.Transform = Matrix.Translation(-1.5, 0.33, -0.75) *
Matrix.Scaling(0.33, 0.33, 0.33);
left.Material.Color = new Color(1, 0.8, 0.1);
left.Material.Diffuse = 0.7;
left.Material.Specular = 0.3;
var world = new World();
world.Lights.Add(new PointLight(new Point(-10, 4.9, -10), Color.White));
world.Objects.Add(floor);
world.Objects.Add(water);
world.Objects.Add(middle);
world.Objects.Add(right);
world.Objects.Add(left);
var camera = new Camera(400, 200, Math.PI / 3);
camera.Transform = Matrix.ViewTransform(new Point(0, 0.5, 10), Point.PointY, Vector.VectorY);
|
|