예제 #1
0
        public WaterSceneNode(SceneNode parent, SceneManager mgr, Dimension2Df tileSize,
                              Dimension2D tileCount, Dimension2D precision, int id) :
            base(parent, mgr, id)
        {
            _scene = mgr;
            _driver = mgr.VideoDriver;

            AnimatedMesh wmesh = _scene.AddHillPlaneMesh("watermesh" + _current,
                tileSize,
                tileCount, 0,
                new Dimension2Df(0, 0),
                new Dimension2Df(1, 1));
            _current++;

            int dmat;
            if (_driver.DriverType == DriverType.OpenGL)
                dmat = _driver.GPUProgrammingServices.AddHighLevelShaderMaterial(
                 WATER_VERTEX_GLSL, "main", VertexShaderType._1_1, WATER_FRAGMENT_GLSL,
                 "main", PixelShaderType._1_1, OnShaderSet, MaterialType.TransparentAlphaChannel, 0);
            else
                dmat = _driver.GPUProgrammingServices.AddHighLevelShaderMaterial(
                 WATER_HLSL, "vertexMain", VertexShaderType._2_0, WATER_HLSL,
                 "pixelMain", PixelShaderType._2_0, OnShaderSet, MaterialType.TransparentAlphaChannel, 2);

            if (_driver.DriverType == DriverType.OpenGL)
                ClampShader = _driver.GPUProgrammingServices.AddHighLevelShaderMaterial(
                 CLAMP_VERTEX_GLSL, "main", VertexShaderType._1_1, CLAMP_FRAGMENT_GLSL,
                 "main", PixelShaderType._1_1, OnShaderSet, MaterialType.TransparentAlphaChannel, 1);
            else
                ClampShader = _driver.GPUProgrammingServices.AddHighLevelShaderMaterial(
                 CLAMP_HLSL, "vertexMain", VertexShaderType._2_0, CLAMP_HLSL,
                 "pixelMain", PixelShaderType._2_0, OnShaderSet, MaterialType.TransparentAlphaChannel, 3);

            _waternode = _scene.AddMeshSceneNode(wmesh.GetMesh(0), this, -1);
            _waternode.SetMaterialType(dmat);
            _waternode.SetMaterialFlag(MaterialFlag.BackFaceCulling, false);
            _waternode.SetMaterialFlag(MaterialFlag.Lighting, false);
            _waternode.SetMaterialFlag(MaterialFlag.FogEnable, false);

            _rt = _driver.CreateRenderTargetTexture(precision);
            _waternode.SetMaterialTexture(0, _rt);

            CameraSceneNode oldcam = _scene.ActiveCamera;
            _fixedcam = _scene.AddCameraSceneNode(null);
            if (oldcam != null)
                _scene.ActiveCamera = oldcam;
        }
예제 #2
0
 public WaterSceneNode(SceneNode parent, SceneManager mgr, Dimension2Df tileSize, Dimension2D tileCount) :
     this(parent, mgr, tileSize, tileCount, new Dimension2D(256, 256), -1)
 { }
예제 #3
0
 public WaterSceneNode(SceneNode parent, SceneManager mgr, Dimension2Df tileSize, Dimension2D tileCount, Dimension2D precision) :
     this(parent, mgr, tileSize, tileCount, precision, -1)
 { }
예제 #4
0
        bool Create(bool save)
        {
            Random rand = new Random((int)((100 * gridpos.X) + gridpos.Z));
            int count = rand.Next(3000, 3200);

            _bbox = new Box3D();

            Particles = new GrassParticle[count];

            /*Matrix4 m = new Matrix4();
            m.RotationDegrees = Terrain.Rotation;
            m.Translation = Terrain.AbsolutePosition;
            m.MakeInverse();*/

            Color[,] TGMRetrieve = TerrainGrassMap.Retrieve();
            Color[,] TCMRetrieve = TerrainColourMap.Retrieve();
            Color[,] THMRetrieve = TerrainHeightMap.Retrieve();
            System.Collections.ArrayList tosave = new System.Collections.ArrayList();

            for (int i = 0; i < count; i++)
            {
                Particles[i].points = new Vector3D[4];

                float x = rand.Next(0, GRASS_PATCH_SIZE * 10) / 10f;
                float z = rand.Next(0, GRASS_PATCH_SIZE * 10) / 10f;

                x -= GRASS_PATCH_SIZE / 2f;
                z -= GRASS_PATCH_SIZE / 2f;

                Particles[i].pos.X = x;
                Particles[i].pos.Z = z;

                Particles[i].flex = rand.Next(0, 100) / 100f;
                Particles[i].sprite.Width = rand.Next(0, _imagecount.Width);

                if (i < 30)
                    Particles[i].sprite.Height = rand.Next(0, _imagecount.Height);
                else
                    Particles[i].sprite.Height = 0;

                Vector3D p = Position + Particles[i].pos;

                Vector3D xz = new Vector3D(p.X / Terrain.Scale.X, 0f, p.Z / Terrain.Scale.Z);

                int x1 = (int)Math.Floor(xz.X);
                int z1 = (int)Math.Floor(xz.Z);

                if (x1 < 1 ||
                   z1 < 1 ||
                   x1 > TerrainHeightMap.OriginalSize.Width - 1 ||
                   z1 > TerrainHeightMap.OriginalSize.Height - 1)
                    continue;

                Color cDensity = TGMRetrieve[x1, z1];
                if (rand.Next(0, 255) > cDensity.A || cDensity.A < 1)
                    continue;

                float ay = THMRetrieve[x1, z1].B * Terrain.Scale.Y;
                float by = THMRetrieve[x1 + 1, z1].B * Terrain.Scale.Y;
                float cy = THMRetrieve[x1, z1 + 1].B * Terrain.Scale.Y;
                float dy = THMRetrieve[x1 + 1, z1 + 1].B * Terrain.Scale.Y;
                float u1 = xz.X - x1;
                float v1 = xz.Z - z1;
                float height = ay * (1.0f - u1) * (1.0f - v1) + by * u1 * (1.0f - v1) + cy * (1.0f - u1) * v1 + dy * u1 * v1;

                Dimension2Df size = new Dimension2Df(rand.Next(40, 70), 100);
                size.Height *= cDensity.B / 200f;

                Particles[i].pos.Y = height + (size.Height * 0.5f);

                Particles[i].color = TCMRetrieve[x1, z1];
                Particles[i].startColor = TCMRetrieve[x1, z1];

                _bbox.AddInternalPoint(Particles[i].pos);

                Vector3D dimensions = new Vector3D(0.5f * size.Width,
                                                   -0.5f * size.Height,
                                                   0);

                /*float rotation = rand.Next(0, 3600) / 10f;
                Matrix4 m2 = new Matrix4();
                m2.RotationDegrees = new Vector3D(0, rotation, 0);
                m2.RotateVect(dimensions);*/

                //Vector3D h = new Vector3D(dimensions.X,0.0f,dimensions.Z);
                //Vector3D v = new Vector3D(0.0f,dimensions.Y,0.0f);
                Particles[i].points[0] = Particles[i].pos + new Vector3D(dimensions.X, dimensions.Y, dimensions.Z);
                Particles[i].points[1] = Particles[i].pos + new Vector3D(dimensions.X, -dimensions.Y, dimensions.Z);
                Particles[i].points[2] = Particles[i].pos - new Vector3D(dimensions.X, dimensions.Y, dimensions.Z);
                Particles[i].points[3] = Particles[i].pos - new Vector3D(dimensions.X, -dimensions.Y, dimensions.Z);
                tosave.Add(Particles[i]);
            }

            Particles = (GrassParticle[])tosave.ToArray(typeof(GrassParticle));
            tosave.Clear();
            if (save)
                return Save();

            return true;
        }