@@ -49,19 +49,20 @@ private struct RayTraversalResult
4949
5050 public Raytracer ( ) { }
5151
52- private Color computeSpecular ( float vDotR , float mGls , Color sourceSpec , float matSpec )
52+ private RgbColor computeSpecular ( float vDotR , float mGls , RgbColor sourceSpec , float matSpec )
5353 {
54- return sourceSpec . Multiply ( ( float ) Math . Pow ( vDotR , mGls ) * matSpec ) ;
54+ float factor = ( float ) Math . Pow ( vDotR , mGls ) * matSpec ;
55+ return sourceSpec * factor ;
5556 }
5657
57- private Color computeDiffuse ( float nDotL , Color sourceDiff , Color matDiff )
58+ private RgbColor computeDiffuse ( float nDotL , RgbColor sourceDiff , RgbColor matDiff )
5859 {
59- return sourceDiff . Multiply ( nDotL ) . Multiply ( matDiff ) ;
60+ return sourceDiff * nDotL * matDiff ;
6061 }
6162
62- private Color trace ( Ray ray , int depth )
63+ private RgbColor trace ( Ray ray , int depth )
6364 {
64- if ( Scene == null ) return Color . black ;
65+ if ( Scene == null ) return RgbColor . Black ;
6566
6667 mIntersector . Ray = ray ;
6768
@@ -86,7 +87,7 @@ private Color trace(Ray ray, int depth)
8687 }
8788 }
8889
89- Color lit = Color . black ;
90+ RgbColor lit = RgbColor . Black ;
9091
9192 if ( closest != null && mIntersector . Result == Intersector . IntersectionResult . Hit )
9293 {
@@ -114,26 +115,26 @@ private Color trace(Ray ray, int depth)
114115 if ( ComputeSpecular )
115116 {
116117 float vDotR = v . Dot ( r ) ;
117- Color spec = ( vDotR > 0 )
118+ RgbColor spec = ( vDotR > 0 )
118119 ? computeSpecular ( vDotR , mat . Gloss , light . getColor ( ) , mat . Specular )
119- : Color . black ;
120- lit = lit . Add ( spec ) ;
120+ : RgbColor . Black ;
121+ lit = lit + spec ;
121122 }
122123
123124 if ( ComputeDiffuse )
124125 {
125126 float nDotL = n . Dot ( l ) ;
126- Color diff = ( nDotL > 0 )
127+ RgbColor diff = ( nDotL > 0 )
127128 ? computeDiffuse ( nDotL , light . getColor ( ) , mat . Color )
128- : Color . black ;
129- lit = lit . Add ( diff ) ;
129+ : RgbColor . Black ;
130+ lit = lit + diff ;
130131 }
131132
132133 if ( GlobalReflection && refl > 0 && depth < TraceDepth )
133134 {
134135 Ray reflected = new Ray ( intersectionPoint , r ) ;
135- Color acc = trace ( reflected , depth + 1 ) ;
136- lit = lit . Add ( acc . Multiply ( refl ) . Multiply ( mat . Color ) ) ;
136+ RgbColor acc = trace ( reflected , depth + 1 ) ;
137+ lit += acc * refl * mat . Color ;
137138 }
138139 }
139140 }
@@ -227,13 +228,13 @@ private void RenderChunk(Point start, Point end, byte[] pixels, int stride)
227228 dir . Normalize ( ) ;
228229 Ray ray = new Ray ( Camera . Eye , dir ) ;
229230
230- Color c = trace ( ray , 1 ) ;
231+ RgbColor c = trace ( ray , 1 ) ;
231232
232233 // Write into pixel array (thread-safe)
233234 int index = iter . Cursor . Y * stride + iter . Cursor . X * 4 ;
234- pixels [ index + 0 ] = ( byte ) ( c . b * 255 ) ;
235- pixels [ index + 1 ] = ( byte ) ( c . g * 255 ) ;
236- pixels [ index + 2 ] = ( byte ) ( c . r * 255 ) ;
235+ pixels [ index + 0 ] = ( byte ) ( c . B * 255 ) ;
236+ pixels [ index + 1 ] = ( byte ) ( c . G * 255 ) ;
237+ pixels [ index + 2 ] = ( byte ) ( c . R * 255 ) ;
237238 pixels [ index + 3 ] = 255 ; // full opacity
238239
239240 // Thread-safe progress update
0 commit comments