示例#1
0
        // Unit conversion helpers
        static float3 XYZ2rgb(float3 xyz)
        {
            float R = float3.Dot(ref xyz, ref X_F);
            float G = float3.Dot(ref xyz, ref Y_F);
            float B = float3.Dot(ref xyz, ref Z_F);
            return new Vector3(R, G, B);

        }
示例#2
0
        public void preprocess()
        {
            if (!_dirty) return;

            _dirty = false;


            _c0 = new Vector3(0.1787f * _turbidity - 1.4630f,
                                -0.0193f * _turbidity - 0.2592f,
                                -0.0167f * _turbidity - 0.2608f);

            _c1 = new Vector3(-0.3554f * _turbidity + 0.4275f,
                                -0.0665f * _turbidity + 0.0008f,
                                -0.0950f * _turbidity + 0.0092f);

            _c2 = new Vector3(-0.0227f * _turbidity + 5.3251f,
                                -0.0004f * _turbidity + 0.2125f,
                                -0.0079f * _turbidity + 0.2102f);

            _c3 = new Vector3(0.1206f * _turbidity - 2.5771f,
                                -0.0641f * _turbidity - 0.8989f,
                                -0.0441f * _turbidity - 1.6537f);

            _c4 = new Vector3(-0.0670f * _turbidity + 0.3703f,
                                -0.0033f * _turbidity + 0.0452f,
                                -0.0109f * _turbidity + 0.0529f);

            float sun_theta_2 = _sun_theta * _sun_theta;
            float sun_theta_3 = sun_theta_2 * _sun_theta;

            float xi = (4.0f / 9.0f - _turbidity / 120.0f) *
                             ((float)(Math.PI) - 2.0f * _sun_theta);

            float3 zenith = new Vector3();
            // Preetham paper is in kilocandellas -- we want candellas
            zenith.X = ((4.0453f * _turbidity - 4.9710f) * (float)Math.Tan(xi) - 0.2155f * _turbidity + 2.4192f) * 1000.0f;
            zenith.Y = _turbidity * _turbidity * (0.00166f * sun_theta_3 - 0.00375f * sun_theta_2 + 0.00209f * _sun_theta) +
                                    _turbidity * (-0.02903f * sun_theta_3 + 0.06377f * sun_theta_2 - 0.03202f * _sun_theta + 0.00394f) +
                                                 (0.11693f * sun_theta_3 - 0.21196f * sun_theta_2 + 0.06052f * _sun_theta + 0.25886f);
            zenith.Z = _turbidity * _turbidity * (0.00275f * sun_theta_3 - 0.00610f * sun_theta_2 + 0.00317f * _sun_theta) +
                                    _turbidity * (-0.04214f * sun_theta_3 + 0.08970f * sun_theta_2 - 0.04153f * _sun_theta + 0.00516f) +
                                                 (0.15346f * sun_theta_3 - 0.26756f * sun_theta_2 + 0.06670f * _sun_theta + 0.26688f);


            float cos_sun_theta = (float)Math.Cos(_sun_theta);

            float3 divisor_Yxy = (_c0 * expf(_c1)).Add(1.0f) * (_c2 * expf(_c3 * _sun_theta).Add(1.0f) + _c4 * cos_sun_theta * cos_sun_theta);

            _inv_divisor_Yxy = zenith.Div(ref divisor_Yxy);

            // 
            // Direct sunlight
            //
            _sun_color = sunColor();

            float sin_sun_theta = (float)Math.Sin(_sun_theta);
            _sun_dir = new Vector3((float)Math.Cos(_sun_phi) * sin_sun_theta,
                                   (float)Math.Sin(_sun_phi) * sin_sun_theta,
                                   (float)Math.Cos(_sun_theta));
            //  optix::Onb onb( _up );
            //onb.inverse_transform( _sun_dir );

        }
示例#3
0
 private Vector3 expf(Vector3 v)
 {
     return new Vector3((float)Math.Exp(v.X), (float)Math.Exp(v.Y), (float)Math.Exp(v.Z));
 }
示例#4
0
                };                  // Table2

        public PreethamSkyModel()
        {
            _turbidity = 2.85f;
            _sun_phi = 2.85f;
            _overcast = 0.95f;
            _dirty = true;
            _sun_theta = (float)Math.PI;
            _up = new Vector3(0f, 0f, -1f);
        }