<?xml version="1.0"?><?xml-stylesheet type="text/xsl" href="http://code.msdn.microsoft.com/rss.xsl"?><rss version="2.0"><channel><title>Basic Illumination Model in C#</title><link>http://code.msdn.microsoft.com/andalmeida0001/Project/ProjectRss.aspx</link><description>Implementing Ambient, Diffuse and Specular lights</description><item><title>UPDATED WIKI: Home</title><link>http://code.msdn.microsoft.com/andalmeida0001/Wiki/View.aspx?title=Home&amp;version=7</link><description>&lt;div class="wikidoc"&gt;
&lt;b&gt;Resource Page Description&lt;/b&gt;&lt;br /&gt;Implementing Ambient, Diffuse and Specular lights
&lt;br /&gt; &lt;br /&gt;&lt;b&gt;Introduction&lt;/b&gt;&lt;br /&gt; &lt;br /&gt;In this short article we will discuss and implement a basic illumination model using raytracing. &lt;br /&gt; &lt;br /&gt;By definition we have 3 types of light: &lt;br /&gt; &lt;br /&gt;*Ambient &lt;br /&gt;*Diffuse &lt;br /&gt;*Specular &lt;br /&gt; &lt;br /&gt;&lt;b&gt;Ambient&lt;/b&gt;&lt;br /&gt; &lt;br /&gt;It is considered as the light distributed by the environment, which contributes to the global illumination independently of the light position, objects or observer.&lt;br /&gt; &lt;br /&gt;&lt;b&gt;Diffuse&lt;/b&gt;&lt;br /&gt; &lt;br /&gt;It is the light which contribution depends on its incidence angle. Diffuse light hit can be reflected in all directions.&lt;br /&gt; &lt;br /&gt;&lt;b&gt;Specular&lt;/b&gt;&lt;br /&gt; &lt;br /&gt;Specular lights represents the bright spots in the objects, as more reflective we get smaller bright spot.&lt;br /&gt; &lt;br /&gt;&lt;b&gt;Background&lt;/b&gt;&lt;br /&gt; &lt;br /&gt;To proceed with an illumination model algorithm we need to get the ambient, diffuse and specular constants for the material we want to model, for example here we use brass constants which are:&lt;br /&gt; &lt;br /&gt;&lt;ul&gt;
&lt;li&gt;          Ambient / Diffuse / Specular*&lt;/li&gt;
&lt;/ul&gt;RED      0.329412 0.780392 0.992157 &lt;br /&gt;GREEN  0.223529 0.568627 0.941176 &lt;br /&gt;BLUE    0.027451 0.113725 0.807843 &lt;br /&gt; &lt;br /&gt;Brass exponent: 27.8974 &lt;br /&gt; &lt;br /&gt;&lt;b&gt;The Equations&lt;/b&gt;&lt;br /&gt; &lt;br /&gt;*Light Source is defined as an R3 (x,y,z) point with a (vx,vy,vz) direction vector.&lt;br /&gt; &lt;br /&gt;*Observer is defined as an R3 (x,y,z) point with a (vx,vy,vz) direction vector.&lt;br /&gt; &lt;br /&gt;*Theta is defined as the angle between light ray and normal vector at the intersection point P on surface.&lt;br /&gt; &lt;br /&gt;*Phi is defined as the angle between the reflected light ray at intersection point P on surface and the viewer ray to the same point P.&lt;br /&gt; &lt;br /&gt;&lt;b&gt;The Sphere Equation&lt;/b&gt;&lt;br /&gt; &lt;br /&gt;&lt;pre&gt;
(r)2 = (x-cx)2+(y-cy)2+(z-cz)2
&lt;/pre&gt; &lt;br /&gt;where &lt;br /&gt; &lt;br /&gt;*r is the sphere radius&lt;br /&gt;*(cx,cy,cz) is the center of the sphere&lt;br /&gt; &lt;br /&gt;Illumination equation on a given pixel:&lt;br /&gt; &lt;br /&gt;IAmbient = I * KAmbient &lt;br /&gt;IDiffuse = I * KDiffuse * cos(theta) &lt;br /&gt;ISpecular = I * KSpecular * cos(phi)n &lt;br /&gt;I = IAmbient + IDiffuse + ISpecular &lt;br /&gt; &lt;br /&gt;Reflection equation:&lt;br /&gt; &lt;br /&gt;i' = i - (2 * n * dot(i, n)) &lt;br /&gt; &lt;br /&gt;where&lt;br /&gt; &lt;br /&gt;*i = incidence light ray &lt;br /&gt;*n = normal at intersection &lt;br /&gt;*i' = reflected ray &lt;br /&gt; &lt;br /&gt;&lt;b&gt;The Code&lt;/b&gt;&lt;br /&gt; &lt;br /&gt;&lt;pre&gt;
...
if (spherehit != null)
     {
     double intersx  = px + t * vx, intersy = py + t * vy,
                       intersz = pz + t * vz;
     double vNormalX = intersx - spherehit.cx,
                       vNormalY=intersy - spherehit.cy,
                       vNormalZ=intersz - spherehit.cz;
     double cost     = tAlgebra.GetCosAngleV1V2(lvx, lvy, lvz, vNormalX,
                       vNormalY, vNormalZ);
     if (cost &amp;lt; 0) cost = 0;
 
     double vReflX = 0, vReflY = 0, vReflZ = 0;
     double vEye2IntersX = px - intersx, vEye2IntersY = py - intersy,
                           vEye2IntersZ = pz - intersz;
 
     tAlgebra.Reflect(lvx,lvy,lvz, vNormalX,vNormalY,vNormalZ,ref vReflX,
                      ref vReflY, ref vReflZ);
     double cosf = tAlgebra.GetCosAngleV1V2(vReflX, vReflY, vReflZ,
                   vEye2IntersX, vEye2IntersY, vEye2IntersZ);
     if (cosf &amp;lt; 0) cosf = 0;
 
     double result1 = cost * 255.0;
     double result2 = Math.Pow(cosf, spherehit.shininess) * 255.0;
     double rgbR = (spherehit.ambientR * 255.0)+(spherehit.diffuseR *
                    result1) + (spherehit.specularR * result2);
     double rgbG = (spherehit.ambientG * 255.0) +(spherehit.diffuseG *
                    result1) + spherehit.specularG * result2);
     double rgbB = (spherehit.ambientB * 255.0) +(spherehit.diffuseB *
                    result1) + (spherehit.specularB * result2);
     rgbR = Math.Min(rgbR, 255);
     rgbG = Math.Min(rgbG, 255);
     rgbB = Math.Min(rgbB, 255);
     color = Color.FromArgb((int)rgbR, (int)rgbG, (int)rgbB);
     ...
     }
...
&lt;/pre&gt; &lt;br /&gt;Mode details and resulting images at:&lt;br /&gt; &lt;br /&gt;&lt;a href="http://www.codeproject.com/KB/graphics/Basic_Illumination_Model.aspx" class="externalLink"&gt;http://www.codeproject.com/KB/graphics/Basic_Illumination_Model.aspx&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt;&lt;br /&gt;
&lt;/div&gt;</description><author>andalmeida</author><pubDate>Fri, 28 Nov 2008 17:02:33 GMT</pubDate><guid isPermaLink="false">UPDATED WIKI: Home 20081128P</guid></item><item><title>UPDATED WIKI: Home</title><link>http://code.msdn.microsoft.com/andalmeida0001/Wiki/View.aspx?title=Home&amp;version=6</link><description>&lt;div class="wikidoc"&gt;
&lt;b&gt;Introduction&lt;/b&gt;&lt;br /&gt; &lt;br /&gt;In this short article we will discuss and implement a basic illumination model using raytracing. &lt;br /&gt; &lt;br /&gt;By definition we have 3 types of light: &lt;br /&gt; &lt;br /&gt;*Ambient &lt;br /&gt;*Diffuse &lt;br /&gt;*Specular &lt;br /&gt; &lt;br /&gt;&lt;b&gt;Ambient&lt;/b&gt;&lt;br /&gt; &lt;br /&gt;It is considered as the light distributed by the environment, which contributes to the global illumination independently of the light position, objects or observer.&lt;br /&gt; &lt;br /&gt;&lt;b&gt;Diffuse&lt;/b&gt;&lt;br /&gt; &lt;br /&gt;It is the light which contribution depends on its incidence angle. Diffuse light hit can be reflected in all directions.&lt;br /&gt; &lt;br /&gt;&lt;b&gt;Specular&lt;/b&gt;&lt;br /&gt; &lt;br /&gt;Specular lights represents the bright spots in the objects, as more reflective we get smaller bright spot.&lt;br /&gt; &lt;br /&gt;&lt;b&gt;Background&lt;/b&gt;&lt;br /&gt; &lt;br /&gt;To proceed with an illumination model algorithm we need to get the ambient, diffuse and specular constants for the material we want to model, for example here we use brass constants which are:&lt;br /&gt; &lt;br /&gt;&lt;ul&gt;
&lt;li&gt;          Ambient / Diffuse / Specular*&lt;/li&gt;
&lt;/ul&gt;RED      0.329412 0.780392 0.992157 &lt;br /&gt;GREEN  0.223529 0.568627 0.941176 &lt;br /&gt;BLUE    0.027451 0.113725 0.807843 &lt;br /&gt; &lt;br /&gt;Brass exponent: 27.8974 &lt;br /&gt; &lt;br /&gt;&lt;b&gt;The Equations&lt;/b&gt;&lt;br /&gt; &lt;br /&gt;*Light Source is defined as an R3 (x,y,z) point with a (vx,vy,vz) direction vector.&lt;br /&gt; &lt;br /&gt;*Observer is defined as an R3 (x,y,z) point with a (vx,vy,vz) direction vector.&lt;br /&gt; &lt;br /&gt;*Theta is defined as the angle between light ray and normal vector at the intersection point P on surface.&lt;br /&gt; &lt;br /&gt;*Phi is defined as the angle between the reflected light ray at intersection point P on surface and the viewer ray to the same point P.&lt;br /&gt; &lt;br /&gt;&lt;b&gt;The Sphere Equation&lt;/b&gt;&lt;br /&gt; &lt;br /&gt;&lt;pre&gt;
(r)2 = (x-cx)2+(y-cy)2+(z-cz)2
&lt;/pre&gt; &lt;br /&gt;where &lt;br /&gt; &lt;br /&gt;*r is the sphere radius&lt;br /&gt;*(cx,cy,cz) is the center of the sphere&lt;br /&gt; &lt;br /&gt;Illumination equation on a given pixel:&lt;br /&gt; &lt;br /&gt;IAmbient = I * KAmbient &lt;br /&gt;IDiffuse = I * KDiffuse * cos(theta) &lt;br /&gt;ISpecular = I * KSpecular * cos(phi)n &lt;br /&gt;I = IAmbient + IDiffuse + ISpecular &lt;br /&gt; &lt;br /&gt;Reflection equation:&lt;br /&gt; &lt;br /&gt;i' = i - (2 * n * dot(i, n)) &lt;br /&gt; &lt;br /&gt;where&lt;br /&gt; &lt;br /&gt;*i = incidence light ray &lt;br /&gt;*n = normal at intersection &lt;br /&gt;*i' = reflected ray &lt;br /&gt; &lt;br /&gt;&lt;b&gt;The Code&lt;/b&gt;&lt;br /&gt; &lt;br /&gt;&lt;pre&gt;
...
if (spherehit != null)
     {
     double intersx  = px + t * vx, intersy = py + t * vy,
                       intersz = pz + t * vz;
     double vNormalX = intersx - spherehit.cx,
                       vNormalY=intersy - spherehit.cy,
                       vNormalZ=intersz - spherehit.cz;
     double cost     = tAlgebra.GetCosAngleV1V2(lvx, lvy, lvz, vNormalX,
                       vNormalY, vNormalZ);
     if (cost &amp;lt; 0) cost = 0;
 
     double vReflX = 0, vReflY = 0, vReflZ = 0;
     double vEye2IntersX = px - intersx, vEye2IntersY = py - intersy,
                           vEye2IntersZ = pz - intersz;
 
     tAlgebra.Reflect(lvx,lvy,lvz, vNormalX,vNormalY,vNormalZ,ref vReflX,
                      ref vReflY, ref vReflZ);
     double cosf = tAlgebra.GetCosAngleV1V2(vReflX, vReflY, vReflZ,
                   vEye2IntersX, vEye2IntersY, vEye2IntersZ);
     if (cosf &amp;lt; 0) cosf = 0;
 
     double result1 = cost * 255.0;
     double result2 = Math.Pow(cosf, spherehit.shininess) * 255.0;
     double rgbR = (spherehit.ambientR * 255.0)+(spherehit.diffuseR *
                    result1) + (spherehit.specularR * result2);
     double rgbG = (spherehit.ambientG * 255.0) +(spherehit.diffuseG *
                    result1) + spherehit.specularG * result2);
     double rgbB = (spherehit.ambientB * 255.0) +(spherehit.diffuseB *
                    result1) + (spherehit.specularB * result2);
     rgbR = Math.Min(rgbR, 255);
     rgbG = Math.Min(rgbG, 255);
     rgbB = Math.Min(rgbB, 255);
     color = Color.FromArgb((int)rgbR, (int)rgbG, (int)rgbB);
     ...
     }
...
&lt;/pre&gt; &lt;br /&gt;Mode details and resulting images at:&lt;br /&gt; &lt;br /&gt;&lt;a href="http://www.codeproject.com/KB/graphics/Basic_Illumination_Model.aspx" class="externalLink"&gt;http://www.codeproject.com/KB/graphics/Basic_Illumination_Model.aspx&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt;&lt;br /&gt;
&lt;/div&gt;</description><author>andalmeida</author><pubDate>Fri, 28 Nov 2008 16:55:38 GMT</pubDate><guid isPermaLink="false">UPDATED WIKI: Home 20081128P</guid></item><item><title>UPDATED WIKI: Home</title><link>http://code.msdn.microsoft.com/andalmeida0001/Wiki/View.aspx?title=Home&amp;version=5</link><description>&lt;div class="wikidoc"&gt;
&lt;b&gt;Introduction&lt;/b&gt;&lt;br /&gt; &lt;br /&gt;In this short article we will discuss and implement a basic illumination model using raytracing. &lt;br /&gt; &lt;br /&gt;By definition we have 3 types of light: &lt;br /&gt; &lt;br /&gt;*Ambient &lt;br /&gt;*Diffuse &lt;br /&gt;*Specular &lt;br /&gt; &lt;br /&gt;&lt;b&gt;Ambient&lt;/b&gt;&lt;br /&gt; &lt;br /&gt;It is considered as the light distributed by the environment, which contributes to the global illumination independently of the light position, objects or observer.&lt;br /&gt; &lt;br /&gt;&lt;b&gt;Diffuse&lt;/b&gt;&lt;br /&gt; &lt;br /&gt;It is the light which contribution depends on its incidence angle. Diffuse light hit can be reflected in all directions.&lt;br /&gt; &lt;br /&gt;&lt;b&gt;Specular&lt;/b&gt;&lt;br /&gt; &lt;br /&gt;Specular lights represents the bright spots in the objects, as more reflective we get smaller bright spot.&lt;br /&gt; &lt;br /&gt;&lt;b&gt;Background&lt;/b&gt;&lt;br /&gt; &lt;br /&gt;To proceed with an illumination model algorithm we need to get the ambient, diffuse and specular constants for the material we want to model, for example here we use brass constants which are:&lt;br /&gt; &lt;br /&gt;&lt;ul&gt;
&lt;li&gt;          Ambient / Diffuse / Specular*&lt;/li&gt;
&lt;/ul&gt;RED      0.329412 0.780392 0.992157 &lt;br /&gt;GREEN  0.223529 0.568627 0.941176 &lt;br /&gt;BLUE    0.027451 0.113725 0.807843 &lt;br /&gt; &lt;br /&gt;Brass exponent: 27.8974 &lt;br /&gt; &lt;br /&gt;&lt;b&gt;The Equations&lt;/b&gt;&lt;br /&gt; &lt;br /&gt;*Light Source is defined as an R3 (x,y,z) point with a (vx,vy,vz) direction vector.&lt;br /&gt; &lt;br /&gt;*Observer is defined as an R3 (x,y,z) point with a (vx,vy,vz) direction vector.&lt;br /&gt; &lt;br /&gt;*Theta is defined as the angle between light ray and normal vector at the intersection point P on surface.&lt;br /&gt; &lt;br /&gt;*Phi is defined as the angle between the reflected light ray at intersection point P on surface and the viewer ray to the same point P.&lt;br /&gt; &lt;br /&gt;&lt;b&gt;The Sphere Equation&lt;/b&gt;&lt;br /&gt;&lt;pre&gt;
(r)2 = (x-cx)2+(y-cy)2+(z-cz)2
&lt;/pre&gt;where &lt;br /&gt; &lt;br /&gt;*r is the sphere radius&lt;br /&gt;*(cx,cy,cz) is the center of the sphere&lt;br /&gt; &lt;br /&gt;Illumination equation on a given pixel:&lt;br /&gt; &lt;br /&gt;IAmbient = I * KAmbient &lt;br /&gt;IDiffuse = I * KDiffuse * cos(theta) &lt;br /&gt;ISpecular = I * KSpecular * cos(phi)n &lt;br /&gt;I = IAmbient + IDiffuse + ISpecular &lt;br /&gt; &lt;br /&gt;Reflection equation:&lt;br /&gt; &lt;br /&gt;i' = i - (2 * n * dot(i, n)) &lt;br /&gt; &lt;br /&gt;where&lt;br /&gt; &lt;br /&gt;*i = incidence light ray &lt;br /&gt;*n = normal at intersection &lt;br /&gt;*i' = reflected ray &lt;br /&gt; &lt;br /&gt;&lt;b&gt;The Code&lt;/b&gt;&lt;br /&gt; &lt;br /&gt;...&lt;br /&gt;if (spherehit != null)&lt;br /&gt;     {&lt;br /&gt;     double intersx  = px + t * vx, intersy = py + t * vy,&lt;br /&gt;                       intersz = pz + t * vz;&lt;br /&gt;     double vNormalX = intersx - spherehit.cx,&lt;br /&gt;                       vNormalY=intersy - spherehit.cy,&lt;br /&gt;                       vNormalZ=intersz - spherehit.cz;&lt;br /&gt;     double cost     = tAlgebra.GetCosAngleV1V2(lvx, lvy, lvz, vNormalX,&lt;br /&gt;                       vNormalY, vNormalZ);&lt;br /&gt;     if (cost &amp;lt; 0) cost = 0;&lt;br /&gt; &lt;br /&gt;     double vReflX = 0, vReflY = 0, vReflZ = 0;&lt;br /&gt;     double vEye2IntersX = px - intersx, vEye2IntersY = py - intersy,&lt;br /&gt;                           vEye2IntersZ = pz - intersz;&lt;br /&gt; &lt;br /&gt;     tAlgebra.Reflect(lvx,lvy,lvz, vNormalX,vNormalY,vNormalZ,ref vReflX,&lt;br /&gt;                      ref vReflY, ref vReflZ);&lt;br /&gt;     double cosf = tAlgebra.GetCosAngleV1V2(vReflX, vReflY, vReflZ,&lt;br /&gt;                   vEye2IntersX, vEye2IntersY, vEye2IntersZ);&lt;br /&gt;     if (cosf &amp;lt; 0) cosf = 0;&lt;br /&gt; &lt;br /&gt;     double result1 = cost * 255.0;&lt;br /&gt;     double result2 = Math.Pow(cosf, spherehit.shininess) * 255.0;&lt;br /&gt;     double rgbR = (spherehit.ambientR * 255.0)+(spherehit.diffuseR *&lt;br /&gt;                    result1) + (spherehit.specularR * result2);&lt;br /&gt;     double rgbG = (spherehit.ambientG * 255.0) +(spherehit.diffuseG *&lt;br /&gt;                    result1) + spherehit.specularG * result2);&lt;br /&gt;     double rgbB = (spherehit.ambientB * 255.0) +(spherehit.diffuseB *&lt;br /&gt;                    result1) + (spherehit.specularB * result2);&lt;br /&gt;     rgbR = Math.Min(rgbR, 255);&lt;br /&gt;     rgbG = Math.Min(rgbG, 255);&lt;br /&gt;     rgbB = Math.Min(rgbB, 255);&lt;br /&gt;     color = Color.FromArgb((int)rgbR, (int)rgbG, (int)rgbB);&lt;br /&gt;     ...&lt;br /&gt;     }&lt;br /&gt;...&lt;br /&gt; &lt;br /&gt;&lt;a href="http://www.codeproject.com/KB/graphics/Basic_Illumination_Model.aspx" class="externalLink"&gt;http://www.codeproject.com/KB/graphics/Basic_Illumination_Model.aspx&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt;&lt;br /&gt;
&lt;/div&gt;</description><author>andalmeida</author><pubDate>Fri, 28 Nov 2008 16:53:19 GMT</pubDate><guid isPermaLink="false">UPDATED WIKI: Home 20081128P</guid></item><item><title>UPDATED WIKI: Home</title><link>http://code.msdn.microsoft.com/andalmeida0001/Wiki/View.aspx?title=Home&amp;version=4</link><description>&lt;div class="wikidoc"&gt;
&lt;b&gt;Introduction&lt;/b&gt;&lt;br /&gt; &lt;br /&gt;In this short article we will discuss and implement a basic illumination model using raytracing. &lt;br /&gt; &lt;br /&gt;By definition we have 3 types of light: &lt;br /&gt; &lt;br /&gt;*Ambient &lt;br /&gt;*Diffuse &lt;br /&gt;*Specular &lt;br /&gt; &lt;br /&gt;&lt;b&gt;Ambient&lt;/b&gt;&lt;br /&gt; &lt;br /&gt;It is considered as the light distributed by the environment, which contributes to the global illumination independently of the light position, objects or observer.&lt;br /&gt; &lt;br /&gt;&lt;b&gt;Diffuse&lt;/b&gt;&lt;br /&gt; &lt;br /&gt;It is the light which contribution depends on its incidence angle. Diffuse light hit can be reflected in all directions.&lt;br /&gt; &lt;br /&gt;&lt;b&gt;Specular&lt;/b&gt;&lt;br /&gt; &lt;br /&gt;Specular lights represents the bright spots in the objects, as more reflective we get smaller bright spot.&lt;br /&gt; &lt;br /&gt;&lt;b&gt;Background&lt;/b&gt;&lt;br /&gt; &lt;br /&gt;To proceed with an illumination model algorithm we need to get the ambient, diffuse and specular constants for the material we want to model, for example here we use brass constants which are:&lt;br /&gt; &lt;br /&gt;&lt;ul&gt;
&lt;li&gt;          Ambient / Diffuse / Specular*&lt;/li&gt;
&lt;/ul&gt;RED      0.329412 0.780392 0.992157 &lt;br /&gt;GREEN  0.223529 0.568627 0.941176 &lt;br /&gt;BLUE    0.027451 0.113725 0.807843 &lt;br /&gt; &lt;br /&gt;Brass exponent: 27.8974 &lt;br /&gt; &lt;br /&gt;&lt;b&gt;The Equations&lt;/b&gt;&lt;br /&gt; &lt;br /&gt;*Light Source is defined as an R3 (x,y,z) point with a (vx,vy,vz) direction vector.&lt;br /&gt; &lt;br /&gt;*Observer is defined as an R3 (x,y,z) point with a (vx,vy,vz) direction vector.&lt;br /&gt; &lt;br /&gt;*Theta is defined as the angle between light ray and normal vector at the intersection point P on surface.&lt;br /&gt; &lt;br /&gt;*Phi is defined as the angle between the reflected light ray at intersection point P on surface and the viewer ray to the same point P.&lt;br /&gt; &lt;br /&gt;&lt;b&gt;The Sphere Equation&lt;/b&gt;&lt;br /&gt; &lt;br /&gt;(r)2 = (x-cx)2{&lt;u&gt;}(y-cy)2{&lt;/u&gt;}(z-cz)2&lt;br /&gt; &lt;br /&gt;where &lt;br /&gt; &lt;br /&gt;*r is the sphere radius&lt;br /&gt;*(cx,cy,cz) is the center of the sphere&lt;br /&gt; &lt;br /&gt;Illumination equation on a given pixel:&lt;br /&gt; &lt;br /&gt;IAmbient = I * KAmbient &lt;br /&gt;IDiffuse = I * KDiffuse * cos(theta) &lt;br /&gt;ISpecular = I * KSpecular * cos(phi)n &lt;br /&gt;I = IAmbient + IDiffuse + ISpecular &lt;br /&gt; &lt;br /&gt;Reflection equation:&lt;br /&gt; &lt;br /&gt;i' = i - (2 * n * dot(i, n)) &lt;br /&gt; &lt;br /&gt;where&lt;br /&gt; &lt;br /&gt;*i = incidence light ray &lt;br /&gt;*n = normal at intersection &lt;br /&gt;*i' = reflected ray &lt;br /&gt; &lt;br /&gt;&lt;b&gt;The Code&lt;/b&gt;&lt;br /&gt; &lt;br /&gt;...&lt;br /&gt;if (spherehit != null)&lt;br /&gt;     {&lt;br /&gt;     double intersx  = px + t * vx, intersy = py + t * vy,&lt;br /&gt;                       intersz = pz + t * vz;&lt;br /&gt;     double vNormalX = intersx - spherehit.cx,&lt;br /&gt;                       vNormalY=intersy - spherehit.cy,&lt;br /&gt;                       vNormalZ=intersz - spherehit.cz;&lt;br /&gt;     double cost     = tAlgebra.GetCosAngleV1V2(lvx, lvy, lvz, vNormalX,&lt;br /&gt;                       vNormalY, vNormalZ);&lt;br /&gt;     if (cost &amp;lt; 0) cost = 0;&lt;br /&gt; &lt;br /&gt;     double vReflX = 0, vReflY = 0, vReflZ = 0;&lt;br /&gt;     double vEye2IntersX = px - intersx, vEye2IntersY = py - intersy,&lt;br /&gt;                           vEye2IntersZ = pz - intersz;&lt;br /&gt; &lt;br /&gt;     tAlgebra.Reflect(lvx,lvy,lvz, vNormalX,vNormalY,vNormalZ,ref vReflX,&lt;br /&gt;                      ref vReflY, ref vReflZ);&lt;br /&gt;     double cosf = tAlgebra.GetCosAngleV1V2(vReflX, vReflY, vReflZ,&lt;br /&gt;                   vEye2IntersX, vEye2IntersY, vEye2IntersZ);&lt;br /&gt;     if (cosf &amp;lt; 0) cosf = 0;&lt;br /&gt; &lt;br /&gt;     double result1 = cost * 255.0;&lt;br /&gt;     double result2 = Math.Pow(cosf, spherehit.shininess) * 255.0;&lt;br /&gt;     double rgbR = (spherehit.ambientR * 255.0)+(spherehit.diffuseR *&lt;br /&gt;                    result1) + (spherehit.specularR * result2);&lt;br /&gt;     double rgbG = (spherehit.ambientG * 255.0) +(spherehit.diffuseG *&lt;br /&gt;                    result1) + spherehit.specularG * result2);&lt;br /&gt;     double rgbB = (spherehit.ambientB * 255.0) +(spherehit.diffuseB *&lt;br /&gt;                    result1) + (spherehit.specularB * result2);&lt;br /&gt;     rgbR = Math.Min(rgbR, 255);&lt;br /&gt;     rgbG = Math.Min(rgbG, 255);&lt;br /&gt;     rgbB = Math.Min(rgbB, 255);&lt;br /&gt;     color = Color.FromArgb((int)rgbR, (int)rgbG, (int)rgbB);&lt;br /&gt;     ...&lt;br /&gt;     }&lt;br /&gt;...&lt;br /&gt; &lt;br /&gt;&lt;a href="http://www.codeproject.com/KB/graphics/Basic_Illumination_Model.aspx" class="externalLink"&gt;http://www.codeproject.com/KB/graphics/Basic_Illumination_Model.aspx&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt;&lt;br /&gt;
&lt;/div&gt;</description><author>andalmeida</author><pubDate>Fri, 28 Nov 2008 16:51:24 GMT</pubDate><guid isPermaLink="false">UPDATED WIKI: Home 20081128P</guid></item><item><title>UPDATED WIKI: Home</title><link>http://code.msdn.microsoft.com/andalmeida0001/Wiki/View.aspx?title=Home&amp;version=3</link><description>&lt;div class="wikidoc"&gt;
&lt;b&gt;Introduction&lt;/b&gt;&lt;br /&gt; &lt;br /&gt;In this short article we will discuss and implement a basic illumination model using raytracing. &lt;br /&gt; &lt;br /&gt;By definition we have 3 types of light: &lt;br /&gt; &lt;br /&gt;*Ambient &lt;br /&gt;*Diffuse &lt;br /&gt;*Specular &lt;br /&gt; &lt;br /&gt;&lt;b&gt;Ambient&lt;/b&gt;&lt;br /&gt; &lt;br /&gt;It is considered as the light distributed by the environment, which contributes to the global illumination independently of the light position, objects or observer.&lt;br /&gt; &lt;br /&gt;&lt;b&gt;Diffuse&lt;/b&gt;&lt;br /&gt; &lt;br /&gt;It is the light which contribution depends on its incidence angle. Diffuse light hit can be reflected in all directions.&lt;br /&gt; &lt;br /&gt;&lt;b&gt;Specular&lt;/b&gt;&lt;br /&gt; &lt;br /&gt;Specular lights represents the bright spots in the objects, as more reflective we get smaller bright spot.&lt;br /&gt; &lt;br /&gt;&lt;b&gt;Background&lt;/b&gt;&lt;br /&gt; &lt;br /&gt;To proceed with an illumination model algorithm we need to get the ambient, diffuse and specular constants for the material we want to model, for example here we use brass constants which are:&lt;br /&gt; &lt;br /&gt;&lt;b&gt;K / Ambient / Diffuse / Specular&lt;/b&gt;&lt;br /&gt;RED  0.329412 0.780392 0.992157 &lt;br /&gt;GREEN 0.223529 0.568627 0.941176 &lt;br /&gt;BLUE 0.027451 0.113725 0.807843 &lt;br /&gt; &lt;br /&gt;Brass exponent: 27.8974 &lt;br /&gt; &lt;br /&gt;&lt;b&gt;The Equations&lt;/b&gt;&lt;br /&gt; &lt;br /&gt;*Light Source is defined as an R3 (x,y,z) point with a (vx,vy,vz) direction vector.&lt;br /&gt; &lt;br /&gt;*Observer is defined as an R3 (x,y,z) point with a (vx,vy,vz) direction vector.&lt;br /&gt; &lt;br /&gt;*Theta is defined as the angle between light ray and normal vector at the intersection point P on surface.&lt;br /&gt; &lt;br /&gt;*Phi is defined as the angle between the reflected light ray at intersection point P on surface and the viewer ray to the same point P.&lt;br /&gt; &lt;br /&gt;&lt;b&gt;The Sphere Equation&lt;/b&gt;&lt;br /&gt; &lt;br /&gt;{(r)2 = (x-cx)2&lt;u&gt;(y-cy)2&lt;/u&gt;(z-cz)2}&lt;br /&gt; &lt;br /&gt;where &lt;br /&gt; &lt;br /&gt;*r is the sphere radius&lt;br /&gt;*(cx,cy,cz) is the center of the sphere&lt;br /&gt; &lt;br /&gt;Illumination equation on a given pixel:&lt;br /&gt; &lt;br /&gt;IAmbient = I * KAmbient &lt;br /&gt;IDiffuse = I * KDiffuse * cos(theta) &lt;br /&gt;ISpecular = I * KSpecular * cos(phi)n &lt;br /&gt;I = IAmbient + IDiffuse + ISpecular &lt;br /&gt; &lt;br /&gt;Reflection equation:&lt;br /&gt; &lt;br /&gt;i' = i - (2 * n * dot(i, n)) &lt;br /&gt; &lt;br /&gt;where&lt;br /&gt; &lt;br /&gt;*i = incidence light ray &lt;br /&gt;*n = normal at intersection &lt;br /&gt;*i' = reflected ray &lt;br /&gt; &lt;br /&gt;&lt;b&gt;The Code&lt;/b&gt;&lt;br /&gt; &lt;br /&gt;...&lt;br /&gt;if (spherehit != null)&lt;br /&gt;     {&lt;br /&gt;     double intersx  = px + t * vx, intersy = py + t * vy,&lt;br /&gt;                       intersz = pz + t * vz;&lt;br /&gt;     double vNormalX = intersx - spherehit.cx,&lt;br /&gt;                       vNormalY=intersy - spherehit.cy,&lt;br /&gt;                       vNormalZ=intersz - spherehit.cz;&lt;br /&gt;     double cost     = tAlgebra.GetCosAngleV1V2(lvx, lvy, lvz, vNormalX,&lt;br /&gt;                       vNormalY, vNormalZ);&lt;br /&gt;     if (cost &amp;lt; 0) cost = 0;&lt;br /&gt; &lt;br /&gt;     double vReflX = 0, vReflY = 0, vReflZ = 0;&lt;br /&gt;     double vEye2IntersX = px - intersx, vEye2IntersY = py - intersy,&lt;br /&gt;                           vEye2IntersZ = pz - intersz;&lt;br /&gt; &lt;br /&gt;     tAlgebra.Reflect(lvx,lvy,lvz, vNormalX,vNormalY,vNormalZ,ref vReflX,&lt;br /&gt;                      ref vReflY, ref vReflZ);&lt;br /&gt;     double cosf = tAlgebra.GetCosAngleV1V2(vReflX, vReflY, vReflZ,&lt;br /&gt;                   vEye2IntersX, vEye2IntersY, vEye2IntersZ);&lt;br /&gt;     if (cosf &amp;lt; 0) cosf = 0;&lt;br /&gt; &lt;br /&gt;     double result1 = cost * 255.0;&lt;br /&gt;     double result2 = Math.Pow(cosf, spherehit.shininess) * 255.0;&lt;br /&gt;     double rgbR = (spherehit.ambientR * 255.0)+(spherehit.diffuseR *&lt;br /&gt;                    result1) + (spherehit.specularR * result2);&lt;br /&gt;     double rgbG = (spherehit.ambientG * 255.0) +(spherehit.diffuseG *&lt;br /&gt;                    result1) + spherehit.specularG * result2);&lt;br /&gt;     double rgbB = (spherehit.ambientB * 255.0) +(spherehit.diffuseB *&lt;br /&gt;                    result1) + (spherehit.specularB * result2);&lt;br /&gt;     rgbR = Math.Min(rgbR, 255);&lt;br /&gt;     rgbG = Math.Min(rgbG, 255);&lt;br /&gt;     rgbB = Math.Min(rgbB, 255);&lt;br /&gt;     color = Color.FromArgb((int)rgbR, (int)rgbG, (int)rgbB);&lt;br /&gt;     ...&lt;br /&gt;     }&lt;br /&gt;...&lt;br /&gt; &lt;br /&gt; &lt;br /&gt;
&lt;/div&gt;</description><author>andalmeida</author><pubDate>Fri, 28 Nov 2008 16:49:02 GMT</pubDate><guid isPermaLink="false">UPDATED WIKI: Home 20081128P</guid></item><item><title>UPDATED WIKI: Home</title><link>http://code.msdn.microsoft.com/andalmeida0001/Wiki/View.aspx?title=Home&amp;version=2</link><description>&lt;div class="wikidoc"&gt;
&lt;b&gt;Introduction&lt;/b&gt;&lt;br /&gt; &lt;br /&gt;In this short article we will discuss and implement a basic illumination model using raytracing. &lt;br /&gt; &lt;br /&gt;By definition we have 3 types of light: &lt;br /&gt; &lt;br /&gt;*Ambient &lt;br /&gt;*Diffuse &lt;br /&gt;*Specular &lt;br /&gt; &lt;br /&gt;&lt;b&gt;Ambient&lt;/b&gt;&lt;br /&gt; &lt;br /&gt;It is considered as the light distributed by the environment, which contributes to the global illumination independently of the light position, objects or observer.&lt;br /&gt; &lt;br /&gt;&lt;b&gt;Diffuse&lt;/b&gt;&lt;br /&gt; &lt;br /&gt;It is the light which contribution depends on its incidence angle. Diffuse light hit can be reflected in all directions.&lt;br /&gt; &lt;br /&gt;&lt;b&gt;Specular&lt;/b&gt;&lt;br /&gt; &lt;br /&gt;Specular lights represents the bright spots in the objects, as more reflective we get smaller bright spot.&lt;br /&gt; &lt;br /&gt;&lt;b&gt;Background&lt;/b&gt;&lt;br /&gt; &lt;br /&gt;To proceed with an illumination model algorithm we need to get the ambient, diffuse and specular constants for the material we want to model, for example here we use brass constants which are:&lt;br /&gt; &lt;br /&gt;&lt;b&gt;K / Ambient / Diffuse / Specular&lt;/b&gt;&lt;br /&gt;RED  0.329412 0.780392 0.992157 &lt;br /&gt;GREEN 0.223529 0.568627 0.941176 &lt;br /&gt;BLUE 0.027451 0.113725 0.807843 &lt;br /&gt; &lt;br /&gt;Brass exponent: 27.8974 &lt;br /&gt; &lt;br /&gt;&lt;b&gt;The Equations&lt;/b&gt;&lt;br /&gt; &lt;br /&gt;*Light Source is defined as an R3 (x,y,z) point with a (vx,vy,vz) direction vector.&lt;br /&gt; &lt;br /&gt;*Observer is defined as an R3 (x,y,z) point with a (vx,vy,vz) direction vector.&lt;br /&gt; &lt;br /&gt;*Theta is defined as the angle between light ray and normal vector at the intersection point P on surface.&lt;br /&gt; &lt;br /&gt;*Phi is defined as the angle between the reflected light ray at intersection point P on surface and the viewer ray to the same point P.&lt;br /&gt; &lt;br /&gt;&lt;b&gt;The Sphere Equation&lt;/b&gt;&lt;br /&gt; &lt;br /&gt;(r)2 = (x-cx)2&lt;u&gt;(y-cy)2&lt;/u&gt;(z-cz)2 &lt;br /&gt; &lt;br /&gt;where &lt;br /&gt; &lt;br /&gt;*r is the sphere radius&lt;br /&gt;*(cx,cy,cz) is the center of the sphere&lt;br /&gt; &lt;br /&gt;Illumination equation on a given pixel:&lt;br /&gt; &lt;br /&gt;IAmbient = I * KAmbient &lt;br /&gt;IDiffuse = I * KDiffuse * cos(theta) &lt;br /&gt;ISpecular = I * KSpecular * cos(phi)n &lt;br /&gt;I = IAmbient + IDiffuse + ISpecular &lt;br /&gt; &lt;br /&gt;Reflection equation:&lt;br /&gt; &lt;br /&gt;i' = i - (2 * n * dot(i, n)) &lt;br /&gt; &lt;br /&gt;where&lt;br /&gt; &lt;br /&gt;*i = incidence light ray &lt;br /&gt;*n = normal at intersection &lt;br /&gt;*i' = reflected ray &lt;br /&gt; &lt;br /&gt;&lt;b&gt;The Code&lt;/b&gt;&lt;br /&gt; &lt;br /&gt;...&lt;br /&gt;if (spherehit != null)&lt;br /&gt;     {&lt;br /&gt;     double intersx  = px + t * vx, intersy = py + t * vy,&lt;br /&gt;                       intersz = pz + t * vz;&lt;br /&gt;     double vNormalX = intersx - spherehit.cx,&lt;br /&gt;                       vNormalY=intersy - spherehit.cy,&lt;br /&gt;                       vNormalZ=intersz - spherehit.cz;&lt;br /&gt;     double cost     = tAlgebra.GetCosAngleV1V2(lvx, lvy, lvz, vNormalX,&lt;br /&gt;                       vNormalY, vNormalZ);&lt;br /&gt;     if (cost &amp;lt; 0) cost = 0;&lt;br /&gt; &lt;br /&gt;     double vReflX = 0, vReflY = 0, vReflZ = 0;&lt;br /&gt;     double vEye2IntersX = px - intersx, vEye2IntersY = py - intersy,&lt;br /&gt;                           vEye2IntersZ = pz - intersz;&lt;br /&gt; &lt;br /&gt;     tAlgebra.Reflect(lvx,lvy,lvz, vNormalX,vNormalY,vNormalZ,ref vReflX,&lt;br /&gt;                      ref vReflY, ref vReflZ);&lt;br /&gt;     double cosf = tAlgebra.GetCosAngleV1V2(vReflX, vReflY, vReflZ,&lt;br /&gt;                   vEye2IntersX, vEye2IntersY, vEye2IntersZ);&lt;br /&gt;     if (cosf &amp;lt; 0) cosf = 0;&lt;br /&gt; &lt;br /&gt;     double result1 = cost * 255.0;&lt;br /&gt;     double result2 = Math.Pow(cosf, spherehit.shininess) * 255.0;&lt;br /&gt;     double rgbR = (spherehit.ambientR * 255.0)+(spherehit.diffuseR *&lt;br /&gt;                    result1) + (spherehit.specularR * result2);&lt;br /&gt;     double rgbG = (spherehit.ambientG * 255.0) +(spherehit.diffuseG *&lt;br /&gt;                    result1) + spherehit.specularG * result2);&lt;br /&gt;     double rgbB = (spherehit.ambientB * 255.0) +(spherehit.diffuseB *&lt;br /&gt;                    result1) + (spherehit.specularB * result2);&lt;br /&gt;     rgbR = Math.Min(rgbR, 255);&lt;br /&gt;     rgbG = Math.Min(rgbG, 255);&lt;br /&gt;     rgbB = Math.Min(rgbB, 255);&lt;br /&gt;     color = Color.FromArgb((int)rgbR, (int)rgbG, (int)rgbB);&lt;br /&gt;     ...&lt;br /&gt;     }&lt;br /&gt;...&lt;br /&gt; &lt;br /&gt; &lt;br /&gt;
&lt;/div&gt;</description><author>andalmeida</author><pubDate>Fri, 28 Nov 2008 16:48:15 GMT</pubDate><guid isPermaLink="false">UPDATED WIKI: Home 20081128P</guid></item></channel></rss>