public LightRay( Color3 RadiantIntensity, Ray GeneratedRay, Vector Normal, float Pdf ) { this.RadiantIntensity = RadiantIntensity; this.GeneratedRay = GeneratedRay; this.Normal = Normal; this.Pdf = Pdf; }
protected override void Trace( Ray ModelRay, ref ShapeHitList Hits ) { Vector oc = Center - ModelRay.Origin; float l2oc = Vector.DotProduct( oc, oc ); float dp = Vector.DotProduct( ModelRay.Direction, ModelRay.Direction ); if ( l2oc <= RadiusSquared ) // Inside the sphere { float tca = Vector.DotProduct( oc, ModelRay.Direction ); float l2hc = ( RadiusSquared - l2oc ) / dp + tca * tca; float t = tca + (float)Math.Sqrt( l2hc ); Hits.Add( t, SphereInsideFaceIndex ); } else { float tca = Vector.DotProduct( oc, ModelRay.Direction ) / dp; if ( tca >= 0.0f ) { float l2hc = ( RadiusSquared - l2oc ) / dp + tca * tca; float t = tca - (float)Math.Sqrt( l2hc ); if ( l2hc > 0.0f ) // Hits Sphere { Hits.Add( t, SphereOutsideFaceIndex ); } } } }
internal override sealed void Trace( Ray ModelRay, ShapeHitCollection ShapeHits ) { Debug.Assert( ShapeHits != null ); ShapeHitList Hits = new ShapeHitList( ShapeHits ); Trace( ModelRay, ref Hits ); }
internal void Trace( Ray WorldRay, ShapeHitCollection ShapeHits, SimpleGeometryHitCollection GeometryHits, List<ObjectHit> ObjectHits ) { Debug.Assert( ShapeHits != null ); Debug.Assert( GeometryHits != null ); Debug.Assert( ObjectHits != null ); Trace( WorldRay, new GeometryTracer( ShapeHits, GeometryHits ), new ObjectHitCollection( ObjectHits ) ); }
public SimpleGeometryHit( Matrix ModelToWorld, Ray ModelRay ) { Debug.Assert( ModelToWorld != null ); this.Type = GeometryType.Model; this.ModelToWorld = ModelToWorld; this.ModelRay = ModelRay; }
public void Trace( SceneObjects Objects, Ray WorldRay ) { if ( Objects == null ) { throw new ArgumentNullException( "Objects" ); } Objects.Trace( WorldRay, ShapeHits, GeometryHits, ObjectHits ); }
internal override sealed SimpleGeometryHit Trace( Ray WorldRay, ShapeHitCollection Hits, SimpleGeometryHitCollection GeometryHits ) { Debug.Assert( Hits != null ); Debug.Assert( GeometryHits != null ); Hits.AdvanceBaseIndex(); Trace( WorldRay, Hits ); return ( Hits.Count == Hits.Base ) ? null : GeometryHits.Next(); }
internal override SimpleGeometryHit Trace( Ray WorldRay, ShapeHitCollection Hits, SimpleGeometryHitCollection GeometryHits ) { Debug.Assert( Hits != null ); Debug.Assert( GeometryHits != null ); Hits.AdvanceBaseIndex(); Ray ModelRay = WorldToModel * WorldRay; Shape.Trace( ModelRay, Hits ); return ( Hits.Count == Hits.Base ) ? null : GeometryHits.Next( ModelToWorld, ModelRay ); }
protected override Color3 ShadeHits( Ray WorldRay, IReadOnlyList<ObjectHit> Hits ) { Color4 total = Color4.Transparent; for ( int i = 0; i < Hits.Count && total.A != 1.0f; i++ ) { ObjectHit hit = Hits[i]; IShadableObject Obj = hit.Object as IShadableObject; if ( hit.Distance < Epsilon || Obj == null ) { continue; } Color3 term = Color3.Black; float alpha; Point worldHit = WorldRay.Endpoint( hit.Distance ); Vector worldViewer = WorldRay.Direction; Point modelHit = hit.ModelHit( worldHit ); Vector modelViewer = hit.ModelViewer( worldViewer ); Shaders Shades = Obj.Shaders( hit.FaceHit ); if ( Shades.Translucent != null ) { alpha = Shades.Translucent.Alpha( worldHit, modelHit, hit.AdditionalData ); } else { alpha = 1.0f; } if ( Shades.Emissive != null ) { term = Shades.Emissive.Emissive( worldHit, modelHit, hit.AdditionalData ); } if ( Shades.Indirect != null ) { Normal.Set( Shades.Normal, worldHit, modelHit, hit.ModelToWorld, hit.AdditionalData ); term += Shades.Indirect.Indirect( worldHit, modelHit, hit.AdditionalData, worldViewer, modelViewer, Normal, Rng, NextTracer ); } Color4 termWithAlpha = new Color4( term, alpha ); total = Color4.Over( total, termWithAlpha ); } return total.Reduce(); }
internal void Trace( Ray WorldRay, ShapeHitCollection ShapeHits, SimpleGeometryHitCollection GeometryHits, List<ObjectHit> ObjectHits ) { Debug.Assert( ShapeHits != null ); Debug.Assert( GeometryHits != null ); Debug.Assert( ObjectHits != null ); ObjectHits.Clear(); GeometryHits.Clear(); ShapeHits.Clear(); SceneTracer Tracer = new SceneTracer( ShapeHits, GeometryHits, ObjectHits ); Trace( WorldRay, Tracer ); }
public SimpleGeometryHit Next( Matrix ModelToWorld, Ray ModelRay ) { Debug.Assert( ModelToWorld != null ); if ( Count == Hits.Count ) { Hits.Add( new SimpleGeometryHit( ModelToWorld, ModelRay ) ); return Hits[Count++]; } Hits[Count].Set( ModelToWorld, ModelRay ); return Hits[Count++]; }
public IReadOnlyList<ObjectHit> Trace( SceneBase Scene, Ray WorldRay, bool SortHits ) { if ( Scene == null ) { throw new ArgumentNullException( "Scene" ); } Scene.Trace( WorldRay, ShapeHits, GeometryHits, ObjectHits ); if ( SortHits ) { ObjectHits.Sort(); } return ObjectHits; }
public bool Visible( Ray WorldRay, float DistanceToLight ) { IReadOnlyList<ObjectHit> Hits = Tracer.Trace( Scene, WorldRay, false ); float DistanceToClosestObject = float.PositiveInfinity; for ( int i = 0; i < Hits.Count && DistanceToLight < DistanceToClosestObject; i++ ) { if ( Hits[i].Distance < Epsilon ) { continue; } DistanceToClosestObject = Math.Min( Hits[i].Distance, DistanceToClosestObject ); } return DistanceToLight < DistanceToClosestObject; }
protected override void Trace( Ray ModelRay, ref ShapeHitList Hits ) { float dp = Vector.DotProduct( ModelRay.Direction, Normal ); float distance = -Vector.DotProduct( ModelRay.Origin - P0, Normal ) / dp; // If the distnace traveled is less than zero, misses the plane if ( distance <= 0.0f ) { return; } if ( dp > 0.0f ) // Hits front { Hits.Add( distance, PlaneFrontFaceIndex ); } else // Hits back { Hits.Add( distance, PlaneBackFaceIndex ); } }
public Color3 Trace( Ray WorldRay, float PreferredContinueProbability = 1.0f ) { if ( DoRussianRouletteTermination ) { PreferredContinueProbability = Math.Max( Math.Min( MaximumTerminationProbability, PreferredContinueProbability ), MinimumTerminationProbability ); if ( PreferredContinueProbability == 0.0f || PreferredContinueProbability < Rng.NextDouble() ) { return Color3.Black; } } WorldRay = new Ray( WorldRay.Origin, WorldRay.Direction.Normalize() ); IReadOnlyList<ObjectHit> Hits = Tracer.Trace( Scene, WorldRay, true ); if ( Hits.Count == 0 ) { return Color3.Black; } return ( !DoRussianRouletteTermination ) ? ShadeHits( WorldRay, Hits ) : ShadeHits( WorldRay, Hits ) / PreferredContinueProbability; }
protected abstract void Trace( Ray WorldRay, GeometryTracer Tracer, ObjectHitCollection ObjectHits );
public GeometryHitCollection Trace( GeometryBase Geometry, Ray WorldRay ) { if ( Geometry == null ) { throw new ArgumentNullException( "Geometry" ); } SimpleGeometryHit GeomHit = Geometry.Trace( WorldRay, ShapeHits, GeometryHits ); return new GeometryHitCollection( ShapeHits, GeomHit ); }
internal abstract void Trace( Ray ModelRay, ShapeHitCollection ShapeHits );
internal abstract SimpleGeometryHit Trace( Ray WorldRay, ShapeHitCollection Hits, SimpleGeometryHitCollection GeometryHits );
protected abstract void Trace( Ray ModelRay, ref ShapeHitList Hits );
protected override void Trace( Ray WorldRay, GeometryTracer Tracer, ObjectHitCollection ObjectHits ) { GeometryHitCollection GeometryHits = Tracer.Trace( Geometry, WorldRay ); for ( int i = 0; i < GeometryHits.Count; i++ ) { ObjectHits.Add( CreateObjectHit( GeometryHits[i] ) ); } }
protected override void Trace( Ray WorldRay, SceneTracer Tracer ) { Tracer.Trace( Objects, WorldRay ); }
protected abstract void Trace( Ray WorldRay, SceneTracer Tracer );
protected abstract Color3 ShadeHits( Ray WorldRay, IReadOnlyList<ObjectHit> Hits );
internal void Trace( Ray WorldRay, ShapeHitCollection ShapeHits, SimpleGeometryHitCollection GeometryHits, List<ObjectHit> ObjectHits ) { Debug.Assert( ShapeHits != null ); Debug.Assert( GeometryHits != null ); Debug.Assert( ObjectHits != null ); for ( int i = 0; i < Objects.Count; i++ ) { Objects[i].Trace( WorldRay, ShapeHits, GeometryHits, ObjectHits ); } }