public override bool Scatter(Vector3 normal, Ray ray) { Vector3 outwardNor; double cos, niByNt, reflectProb; var rDn = Vector3.Dot(ray.direction, normal); if (rDn > 0) { outwardNor = normal * (-1f); niByNt = reflectiveIdx; cos = reflectiveIdx * rDn; } else { outwardNor = normal; niByNt = 1 / reflectiveIdx; cos = -rDn; } Vector3 refractedDir; if (Vector3.Refract(ray.direction, outwardNor, niByNt, out refractedDir)) { reflectProb = Schlik(cos); ray.origin = ray.GetHitPiont(); ray.direction = CoreRandom.Sample() < reflectProb?Vector3.Reflect(ray.direction, normal) : refractedDir; } else { ray.origin = ray.GetHitPiont(); ray.direction = Vector3.Reflect(ray.direction, normal); } return(true); }
public virtual bool Scatter(Ray ray) { Vector3 geoNor = GetGeoNormal(ray.GetHitPiont()); if (material.Scatter(geoNor, ray)) { ray.hitPos = float.PositiveInfinity; ray.hitDepth--; return(true); } else { ray.hitDepth = 0; return(false); } }
public override bool Scatter(Vector3 normal, Ray ray) { Vector3 scatteredDir = Vector3.Reflect(ray.direction, normal); scatteredDir += roughness * CoreRandom.SampleUnitSphere(); if (Vector3.Dot(scatteredDir, normal) > 0) { ray.origin = ray.GetHitPiont(); ray.direction = scatteredDir; return(true); } else { return(false); } }
public override bool Scatter(Vector3 normal, Ray ray) { ray.origin = ray.GetHitPiont(); ray.direction = normal + CoreRandom.SampleUnitSphere(); return(true); }