Beispiel #1
0
        /// Recursivly raytrace to get the color resulting from the refracted
        /// light component for the specified collisionPoint.
        private Color RefractionColor(
            V3 incidentVec, V3 collisionPoint, V2 collisionUV,
            Object3D collidedObj, int depth
            )
        {
            if (!collidedObj.Material.IsTransparent())
            {
                return(Color.Black);
            }

            V3 normal = collidedObj.Normal(collisionPoint, collisionUV);

            Ray refractionRay = new Ray(
                origin: collisionPoint,
                direction: incidentVec.RefractedVector(
                    normalVec: normal,
                    n1: Scene.RefractiveIndex,
                    n2: collidedObj.Material.RefractiveIndex
                    ),
                originObject: null
                );

            Color refractionColor = Raytrace(refractionRay, depth - 1);

            if (refractionColor == null)
            {
                return(Color.Black);
            }

            return(collidedObj.Material.Transparency * refractionColor);
        }
        /// Recursivly raytrace to get the color resulting from the refracted
        /// light component for the specified collisionPoint.
        private Color RefractionColor(
            V3 incidentVec, V3 collisionPoint, V2 collisionUV,
            Object3D collidedObj, int depth
        )
        {
            if (!collidedObj.Material.IsTransparent()) { return Color.Black; }

            V3 normal = collidedObj.Normal(collisionPoint, collisionUV);

            Ray refractionRay = new Ray(
                origin: collisionPoint,
                direction: incidentVec.RefractedVector(
                    normalVec: normal,
                    n1: Scene.RefractiveIndex,
                    n2: collidedObj.Material.RefractiveIndex
                ),
                originObject: null
            );

            Color refractionColor = Raytrace(refractionRay, depth - 1);
            if (refractionColor == null) { return Color.Black; }

            return collidedObj.Material.Transparency * refractionColor;
        }