示例#1
0
        private void UpdateColor(DrawArgs drawArgs, MeshSubset meshSubset, bool doHighResolution)
        {
            int blank = System.Drawing.Color.FromArgb(255, 0, 0, 0).ToArgb();

            if (doHighResolution)
            {
                for (int i = 0; i < meshSubset.HigherResolutionVertices.Length; i++)
                {
                    if (Vector3.Dot(drawArgs.WorldCamera.Position, new Vector3(meshSubset.HigherResolutionVertices[i].X, meshSubset.HigherResolutionVertices[i].Y, meshSubset.HigherResolutionVertices[i].Z)) > 0)
                        SetColor(ref meshSubset.HigherResolutionVertices[i], drawArgs);
                    else
                        meshSubset.HigherResolutionVertices[i].Color = blank;
                }
            }
            else
            {
                for (int i = 0; i < meshSubset.Vertices.Length; i++)
                {
                    if (Vector3.Dot(drawArgs.WorldCamera.Position, new Vector3(meshSubset.Vertices[i].X, meshSubset.Vertices[i].Y, meshSubset.Vertices[i].Z)) > 0)
                        SetColor(ref meshSubset.Vertices[i], drawArgs);
                    else
                        meshSubset.Vertices[i].Color = blank;
                }
            }
        }
示例#2
0
        public void Init(float radius, int slices, int sections)
        {
            try
            {
                m_radius = radius;
                m_numberSlices = slices;
                m_numberSections = sections;

                Point3d sunPosition = SunCalculator.GetGeocentricPosition(TimeKeeper.CurrentTimeUtc);
                Vector3 sunVector = new Vector3(
                    (float)-sunPosition.X,
                    (float)-sunPosition.Y,
                    (float)-sunPosition.Z);

                m_vLight = sunVector * 100000000f;
                m_vLightDirection = new Vector3(
                    m_vLight.X / m_vLight.Length(),
                    m_vLight.Y / m_vLight.Length(),
                    m_vLight.Z / m_vLight.Length()
                    );

                m_fScale = 1 / (m_fOuterRadius - m_fInnerRadius);

                m_meshList.Clear();

                double latRange = 180.0 / (double)TilesHigh;
                double lonRange = 360.0 / (double)TilesWide;

                int meshDensity = m_numberSlices / TilesHigh;

                for (int y = 0; y < TilesHigh; y++)
                {
                    for (int x = 0; x < TilesWide; x++)
                    {
                        MeshSubset mesh = new MeshSubset();
                        double north = y * latRange + latRange - 90;
                        double south = y * latRange - 90;

                        double west = x * lonRange - 180;
                        double east = x * lonRange + lonRange - 180;

                        mesh.Vertices = CreateMesh(south, north, west, east, meshDensity);
                        mesh.HigherResolutionVertices = CreateMesh(south, north, west, east, 2 * meshDensity);
                        mesh.BoundingBox = new BoundingBox((float)south, (float)north, (float)west, (float)east, (float)radius, (float)radius);
                        m_meshList.Add(mesh);
                    }
                }

                m_indices = computeIndices(meshDensity);
                m_indicesHighResolution = computeIndices(2 * meshDensity);

                m_nSamples = 4;		// Number of sample rays to use in integral equation
                m_Kr = 0.0025f;		// Rayleigh scattering constant
                m_Kr4PI = m_Kr * 4.0f * (float)Math.PI;
                m_Km = 0.0015f;		// Mie scattering constant
                m_Km4PI = m_Km * 4.0f * (float)Math.PI;
                m_ESun = 15.0f;		// Sun brightness constant
                m_g = -0.85f;		// The Mie phase asymmetry factor

                m_fWavelength[0] = 0.650f;		// 650 nm for red
                m_fWavelength[1] = 0.570f;		// 570 nm for green
                m_fWavelength[2] = 0.475f;		// 475 nm for blue
                m_fWavelength4[0] = (float)Math.Pow(m_fWavelength[0], 4.0f);
                m_fWavelength4[1] = (float)Math.Pow(m_fWavelength[1], 4.0f);
                m_fWavelength4[2] = (float)Math.Pow(m_fWavelength[2], 4.0f);

                m_fRayleighScaleDepth = 0.25f;
                m_fMieScaleDepth = 0.1f;

            }
            catch (Exception ex)
            {
                Log.Write(ex);
            }
        }
示例#3
0
			public ShadingGroup( MeshSubset subset, MaterialInstance material )
			{
				StartIndex	=	subset.StartPrimitive * 3;
				IndicesCount=	subset.PrimitiveCount * 3;
				Material	=	material;
			}