public bool Hit(Ray ray, float min, float max, out HitRecord record) { HitRecord nearestRecord = null; foreach (var h in _hitables) { HitRecord tempr; if (h.Hit(ray, min, max, out tempr)) { if (nearestRecord == null || nearestRecord.t > tempr.t) { nearestRecord = tempr; } } } record = nearestRecord; return(nearestRecord != null); }
public bool Scatter(Ray ray, HitRecord hitRecord, out ScatterRecord sRecord) { sRecord = new ScatterRecord(); var normal = hitRecord.normal; var point = hitRecord.point; sRecord.attenuation = new vec3(1.0f, 1.0f, 1.0f); float eta = ref_idx; var n = normal; if (glm.dot(ray.direction, normal) > 0)//从内到外 { n = new vec3(-normal.x, -normal.y, -normal.z); } else { eta = 1.0f / eta; } vec3 r; float prob = 1.0f; if (Exten.refract(ray.direction, n, eta, out r)) { float cosi = -glm.dot(ray.direction, n); float cost = -glm.dot(r, n); prob = fresnel(cosi, cost, eta); } if (Exten.rand01() < prob) { vec3 reflected = Exten.reflect(ray.direction, normal); sRecord.pdf = new ConstPDF(reflected); } else { sRecord.pdf = new ConstPDF(r); } return true; }
public bool Hit(Ray ray, float min, float max, out HitRecord r) { return(_sideList.Hit(ray, min, max, out r)); }
public vec3 Emitted(Ray ray, HitRecord hitRecord, float u, float v, vec3 pos) { return new vec3(0, 0, 0); }
public float Scatter_PDf(Ray ray, HitRecord hitRecord, Ray scattered) { return 1; }
public bool Scatter(Ray ray, HitRecord hitRecord, out ScatterRecord sRecord) { sRecord = null; return false; }
public float Scatter_PDf(Ray ray, HitRecord hitRecord, Ray scattered) { return glm.dot(hitRecord.normal, scattered.direction) /MathF.PI; }