public override bool Scatter(RayComponent ray, ref HitInfo result, ref ScatterInfo info) { float fuzz = Value.fuzz; Color albedo = Value.albedo; Vector3 reflected = math.reflect(ray.Value.direction, result.normal); info.direction = reflected + fuzz * RandomUtility.RandomInUnitSphere(); info.attenuation = albedo; info.position = result.position; return(false); }
public override bool Scatter(RayComponent ray, ref HitInfo result, ref ScatterInfo scatterInfo) { scatterInfo.attenuation = Color.white; scatterInfo.position = result.position; float refIdx = Value.refractiveIndex; float ni_over_nt; Vector3 outwardNormal; float cosine = math.dot(ray.Value.direction, result.normal); if (cosine > 0.0f) { outwardNormal = -result.normal; ni_over_nt = refIdx; cosine = ni_over_nt * cosine / math.length(ray.Value.direction); } else { outwardNormal = result.normal; ni_over_nt = 1.0f / refIdx; cosine = -cosine / math.length(ray.Value.direction); } float reflectProb = 1.0f; Vector3 refracted; if (MathUtility.Refract(ray.Value.direction, outwardNormal, ni_over_nt, out refracted)) { reflectProb = MathUtility.FresnelSchlick(cosine, refIdx); } if (RandomUtility.RandomNDF() < reflectProb) { scatterInfo.direction = math.reflect(ray.Value.direction, result.normal); } else { scatterInfo.direction = refracted; } return(true); }
public static bool Hit(RayComponent r, float min, float max, AABB aabb, ref HitInfo info) { return(false); }
public virtual Vector3 Emmitted(RayComponent rayIn, ref HitInfo result, float u, float v, Vector3 point) { return(Vector3.zero); }
public virtual bool Scatter(RayComponent ray, ref HitInfo result, ref ScatterInfo info) { return(false); }
public abstract bool Hit(RayComponent ray, float min, float max, ref HitInfo info);