Exemplo n.º 1
0
        public bool Scatter(Ray ray, HitRecord hitRecord, out ScatterRecord sRecord)
        {
            sRecord = new ScatterRecord();
            var normal = hitRecord.normal;
            var point = hitRecord.point;
            var reflected = Exten.reflect(ray.direction, normal);
            if (fuzz > 0)
            {
                ONB o = new ONB(reflected);
                var next = RandomCosineDir();

                reflected = o.Local(next);
            }
            sRecord.attenuation = color;
            sRecord.pdf = new ConstPDF(reflected);
            return glm.dot(ray.direction, normal) < 0;
        }
Exemplo n.º 2
0
        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;

        }