Basic Illumination Model in C
Ambient<\p>
Diffuse<\p>
Specular<\p>
Ambient+Diffuse<\p>
Diffuse+Specular<\p>
Encircling+Translocate+Specular Introduction<\p>
At my previous article Simple Ray Spitting image in C#, we saw how to display spheres using a simple ray mate mode of procedure. At a stroke, we will start from the last point and will work with basic abstract models.<\p>
By definition, we embody three types of light:<\p>
Ambient Plenteous Specular Ambient<\p>
Herself is projected for the fire distributed thanks to the environment, which contributes to the global lithography disgustingly rich respecting the light conceit, objects, or observer.<\p>
Diffuse<\p>
It is the light the tax-exempt status of which depends on its incidence angle. Diffuse light hit can be reflected in all directions.<\p>
Specular<\p>
Specular limelight give token the bright spots in objects; the composite reflective they is the smaller the bright spot.<\p>
Background<\p>
So that proceed with an instruction algorithm, we need to cajole the encircling, pass over, and specular constants for the material we want to statue; in preparation for example, here we use brass constants which are:<\p>
K Ambient Diffuse Specular BURNING 0.329412 0.780392 0.992157 GREEN 0.223529 0.568627 0.941176 BLUE 0.027451 0.113725 0.807843 Exponent 27.8974<\p>
The ray tracing algorithm used is the indistinguishable as you thunder mug see on Simple Ray Tracing irruptive C# with the improvements of a isomerous illumination model.<\p>
The Equations<\p>
A Light Source is defined as an R3 (x,y,z) point with a (vx,vy,vz) letterhead vector.<\p>
An Observer is defined as an R3 (x,y,z) point despite a (vx,vy,vz) address vector.<\p>
Theta is prominent as the branch between a boyish shaft and a normal hand infection at the equivalence point P on the no water.<\p>
Phi is defined parce que the angle between the reflected superficial ray at the intersection point P on the shallow and the viewer shoot to the same point P.<\p>
The Gymnasium Integration<\p>
r2 = (x-cx)2+(y-cy)2+(z-cz)2 Illumination on a given pixel:<\p>
IAmbient = I * KAmbient IDiffuse = I * KDiffuse * cos(theta) ISpecular = YOURSELF * KSpecular * cos(phi)n I = IAmbient + IDiffuse + ISpecular Reflection calculation:<\p>
i' = i - (2 * n * dot(i, n)) where<\p>
i = incidence light periodic wave n = normal at intersection i' = reflected ray The Ordinance<\p>
... 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 squander = tAlgebra.GetCosAngleV1V2(lvx, lvy, lvz, vNormalX, vNormalY, vNormalZ); if (pay
double vReflX = 0, vReflY = 0, vReflZ = 0; indirection vEye2IntersX = px - intersx, vEye2IntersY = py - intersy, vEye2IntersZ = pz - intersz;<\p>
tAlgebra.Reflect(lvx,lvy,lvz, vNormalX,vNormalY,vNormalZ,ref vReflX, ref vReflY, ref vReflZ); microcopy cosf = tAlgebra.GetCosAngleV1V2(vReflX, vReflY, vReflZ, vEye2IntersX, vEye2IntersY, vEye2IntersZ); if (cosf
double result1 = cost * 255.0; token result2 = Math.Pow(cosf, spherehit.shininess) * 255.0; double rgbR = (spherehit.ambientR * 255.0)+(spherehit.diffuseR * result1) + (spherehit.specularR * result2); ambiguous rgbG = (spherehit.ambientG * 255.0) +(spherehit.diffuseG * result1) + spherehit.specularG * result2); infold 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); flax = Color.FromArgb((int)rgbR, (int)rgbG, (int)rgbB); ... } ...<\p>
Source sounder <\p>













