/// Recursivly raytrace to get the color resulting from the reflected /// light component for the specified collisionPoint. private Color ReflectionColor( V3 incidentVec, V3 collisionPoint, V2 collisionUV, Object3D collidedObj, int depth ) { if (!collidedObj.Material.IsReflective()) { return(Color.Black); } V3 normal = collidedObj.Normal(collisionPoint, collisionUV); Ray reflectionRay = new Ray( origin: collisionPoint, direction: incidentVec.ReflectedVector(normal), originObject: collidedObj ); Color reflectionColor = Raytrace(reflectionRay, depth - 1); if (reflectionColor == null) { return(Color.Black); } return(collidedObj.Material.Reflection * reflectionColor); }
/// Computes the diffuse and specular components of the Phong /// reflection model. /// @Note Avoids code duplication in ComputePointLight and /// ComputeDirectionalLight. private Color ComputeDiffuseSpecular( Light l, Object3D obj, V3 p, V2 uv, V3 incidentVec ) { V3 normalVec = obj.Normal(p, uv); V3 reflectedVec = incidentVec.ReflectedVector(normalVec); reflectedVec.Normalize(); V3 viewingVec = CameraPos - p; viewingVec.Normalize(); Color diffuseIllu = ComputeDiffuse( l, incidentVec, normalVec, obj, uv ); Color specularIllu = ComputeSpecular( l, reflectedVec, normalVec, obj, uv ); return diffuseIllu + specularIllu; }
/// Computes the diffuse and specular components of the Phong /// reflection model. /// @Note Avoids code duplication in ComputePointLight and /// ComputeDirectionalLight. private Color ComputeDiffuseSpecular( Light l, Object3D obj, V3 p, V2 uv, V3 incidentVec ) { V3 normalVec = obj.Normal(p, uv); V3 reflectedVec = incidentVec.ReflectedVector(normalVec); reflectedVec.Normalize(); V3 viewingVec = CameraPos - p; viewingVec.Normalize(); Color diffuseIllu = ComputeDiffuse( l, incidentVec, normalVec, obj, uv ); Color specularIllu = ComputeSpecular( l, reflectedVec, normalVec, obj, uv ); return(diffuseIllu + specularIllu); }
/// Recursivly raytrace to get the color resulting from the reflected /// light component for the specified collisionPoint. private Color ReflectionColor( V3 incidentVec, V3 collisionPoint, V2 collisionUV, Object3D collidedObj, int depth ) { if (!collidedObj.Material.IsReflective()) { return Color.Black; } V3 normal = collidedObj.Normal(collisionPoint, collisionUV); Ray reflectionRay = new Ray( origin: collisionPoint, direction: incidentVec.ReflectedVector(normal), originObject: collidedObj ); Color reflectionColor = Raytrace(reflectionRay, depth - 1); if (reflectionColor == null) { return Color.Black; } return collidedObj.Material.Reflection * reflectionColor; }