Exemple #1
0
        private void ColorPass(float[] eniromentLight, float[] color, float[] normal, float[] p3D, float[] tex,
                               bool specular, int from)
        {
            ArrayMath.Sub(_lightPosArray, p3D, _l, 0, from, from, 3);
            ArrayMath.Normalize(_l, from, 3);

            var dotNl = ArrayMath.Dot(normal, _l, from, from, 3);

            ArrayMath.Mul(color, Math.Max(0f, dotNl), _Id, from, from, 3);

            ArrayMath.Mul(normal, dotNl * 2, _r, from, from, 3);
            ArrayMath.Sub(_r, _l, _r, from, from, from, 3);
            ArrayMath.Normalize(_r, from, 3);
            ArrayMath.Normalize(p3D, from, 3);

            var rDotP3D = -ArrayMath.Dot(_r, p3D, from, from, 3);

            var Is = 0f;

            if (specular)
            {
                var max = Math.Max(0, rDotP3D);
                Is = DeviceFunction.Pow(max, 50);
            }

            ArrayMath.Mul(eniromentLight, color, color, 0, from, from, 3);
            ArrayMath.Mul(tex, _Id, tex, from, from, from, 3);

            ArrayMath.Add(color, tex, color, from, from, from, 3);

            ArrayMath.Add(color, Is, color, from, 3);
            ArrayMath.Mul(color, 255, color, from, from, 3);
        }