Пример #1
0
 public GUIElement(Vector2 min, Vector2 max, TextureResource image, Vector4 color)
 {
     Color = color;
     ScaleOffset = Vector4.Zero;
     Image = image;
     SetDimensions(min, max);
 }
Пример #2
0
        public SkyElementManager(RenderView renderView)
            : base(renderView)
        {
            skyShaderPrepass = ResourceManager.Inst.GetShader("SkyShaderPrepass");
            skyShader = ResourceManager.Inst.GetShader("SkyShader");

            nightTexture = ResourceManager.Inst.GetTexture("Textures/Sky/StarrySky.dds");

            skyTexture = new RenderTarget2D(GFX.Device, 64, 64, 1, SurfaceFormat.Color);
        }
        public SkyElementManager(RenderView renderView)
            : base(renderView)
        {
            skyShaderPrepass = ResourceManager.Inst.GetShader("SkyShaderPrepass");
            skyShader = ResourceManager.Inst.GetShader("SkyShader");
            cloudShader = ResourceManager.Inst.GetShader("CloudShader");

            nightTexture = ResourceManager.Inst.GetTexture("Textures/Sky/StarrySky.dds");

            skyTexture = new RenderTarget2D(GFX.Device, 16, 16, 1, SurfaceFormat.Color);

            cloudMatrix = Matrix.CreateRotationX(MathHelper.PiOver2);
            cloudMatrix.Translation = Vector3.Up * 0.09f;
        }
        public PostProcessElementManager(MainRenderView renderView)
            : base(renderView)
        {
            mainRenderView = renderView;
            waterShader = ResourceManager.Inst.GetShader("WaterShader");
            basicImageShader = ResourceManager.Inst.GetShader("Generic2D");
            debugNormalsShader = ResourceManager.Inst.GetShader("DebugNormals");
            motionBlurShader = ResourceManager.Inst.GetShader("MotionBlur");
            compositeShader = ResourceManager.Inst.GetShader("Composite");
            fogShader = ResourceManager.Inst.GetShader("Fog");
            colorCorrectShader = ResourceManager.Inst.GetShader("ColorCorrect");
            colorCorrectTexture = ResourceManager.Inst.GetTexture("Textures/Color Correction/colorRamp0.dds");
            godRayShader = ResourceManager.Inst.GetShader("GodRay");
            bloomShader = ResourceManager.Inst.GetShader("Bloom");
            gaussBlurHShader = ResourceManager.Inst.GetShader("GaussH");
            gaussBlurVShader = ResourceManager.Inst.GetShader("GaussV");
            boxBlurHShader = ResourceManager.Inst.GetShader("BoxH");
            boxBlurVShader = ResourceManager.Inst.GetShader("BoxV");

            underwaterRamp = ResourceManager.Inst.GetTexture("Textures/Water/underwater_color.dds");
            underwaterShader = ResourceManager.Inst.GetShader("UnderwaterShader");

            oceanShader = ResourceManager.Inst.GetShader("Ocean");
            oceanScreenSpaceShader = ResourceManager.Inst.GetShader("OceanPP");
            oceanTexture = ResourceManager.Inst.GetTexture("Textures/Water/noise02.dds");
            oceanGeometry = new ProjectiveOcean(64);
            bumpCoords = new Vector4[]
            {
                new Vector4(0.264000f,0.178000f, 0.2f, 0.1f),
                new Vector4(-2.06840f, -1.52640f, -1.0f, 0.23f),
                new Vector4(1.87920f, 1.9232f, 0.2f, 0.15f),
                new Vector4(0.096000f, 0.04f, -0.3f, 0.1f),
            };
            waveDirs = new Vector4[]
            {
                new Vector4(-0.66f, -0.208f, 0.2f, MathHelper.TwoPi/0.4f),
                new Vector4(-1.62f, 0.1708f, 0.38f, MathHelper.TwoPi/2.2f),
                new Vector4(-2.16f, 1.338f, 0.28f, MathHelper.TwoPi/1.0f),
                new Vector4(-2.72f, 8.6108f, 0.15f, MathHelper.TwoPi/4.8f),
            };
            float ratio = waveScale / waterScale;
            waveAmplitudes = new Vector4[]
            {
                ratio*Vector4.One*0.8f,
                ratio*Vector4.One*0.4f,
                ratio*Vector4.One*0.4f,
                ratio*Vector4.One*0.8f,
            };
        }
Пример #5
0
 public WaterElementManager(RenderView view)
     : base(view)
 {
     waterShader = ResourceManager.Inst.GetShader("WaterShader");
     generic2DShader = ResourceManager.Inst.GetShader("Generic2D");
     noiseTexture = ResourceManager.Inst.GetTexture("Textures/Water/noise02.dds");
     bumpCoords = new Vector4[]
     {
         new Vector4(0.264000f,0.178000f, 0.2f, 0.1f),
         new Vector4(-2.06840f, -1.52640f, -1.0f, 0.23f),
         new Vector4(1.87920f, 1.9232f, 0.2f, 0.15f),
         new Vector4(0.096000f, 0.04f, -0.3f, 0.1f),
     };
     waterMatrix = Matrix.CreateScale(Vector3.One * 4096)*Matrix.CreateRotationX(MathHelper.Pi);
 }
        void IResource.LoadFromXML(XmlNode node)
        {
            TextureResource[] baseTextures = new TextureResource[TerrainClimateVoxels.MAX_BLEND_ZONES];
            TextureResource[] normalTextures = new TextureResource[TerrainClimateVoxels.MAX_BLEND_ZONES];
            foreach (XmlAttribute attrib in node.Attributes)
            {
                string[] attribs = attrib.Name.ToLower().Split('_');
                int index = -1;
                if(attribs.Length > 1)
                    index = int.Parse(attribs[1]);
                if (index >= 0 && index < TerrainClimateVoxels.MAX_BLEND_ZONES)
                {
                    switch (attribs[0])
                    {
                        case "basemap":
                                baseTextures[index] = ResourceManager.Inst.GetTexture(attrib.Value);
                            break;
                        case "normalmap":
                            normalTextures[index] = ResourceManager.Inst.GetTexture(attrib.Value);
                            break;
                        case "blendzone":
                            blendZones[index] = float.Parse(attrib.Value);
                            break;
                        case "gradient":
                            gradientCoeffs[index] = float.Parse(attrib.Value);
                            break;
                        case "curvature":
                            curvatureCoeffs[index] = float.Parse(attrib.Value);
                            break;
                        case "score":
                            baseScores[index] = float.Parse(attrib.Value);
                            break;
                        case "height":
                            heightCoeffs[index] = float.Parse(attrib.Value);
                            break;
                    }
                }

                if(attrib.Name.ToLower() == "name")
                    name = attrib.Value;
            }

            Create3DTextures(baseTextures, normalTextures);
        }
Пример #7
0
 void IResource.LoadFromXML(XmlNode node)
 {
     foreach (XmlAttribute attrib in node.Attributes)
     {
         string[] attribs = attrib.Name.ToLower().Split('_');
         switch (attribs[0])
         {
             case "name":
                 name = attrib.Value;
                 break;
             case "health":
                 Health = float.Parse(attrib.Value);
                 break;
             case "damage":
                 Damage = float.Parse(attrib.Value);
                 break;
             case "aggressive":
                 Aggressiveness = float.Parse(attrib.Value);
                 break;
             case "fear":
                 Fear = float.Parse(attrib.Value);
                 break;
             case "hearing":
                 Hearing = float.Parse(attrib.Value);
                 break;
             case "sight":
                 Sight = float.Parse(attrib.Value);
                 break;
             case "huntimage":
                 HuntImage = ResourceManager.Inst.GetTexture(attrib.Value);
                 break;
             case "mesh":
                 MeshName = attrib.Value;
                 break;
             case "team":
                 Team = int.Parse(attrib.Value);
                 break;
             case "herdbonus":
                 HerdBonus = float.Parse(attrib.Value);
                 break;
             case "herdsize":
                 HerdSize = int.Parse(attrib.Value);
                 break;
             case "animationtype":
                 switch (attrib.Value.ToLower())
                 {
                     case "simple":
                         Style = DinosaurAnimationStyle.Simple;
                         break;
                     case "complex":
                         Style = DinosaurAnimationStyle.Complex;
                         break;
                     case "raptor":
                         Style = DinosaurAnimationStyle.Raptor;
                         break;
                 }
                 break;
             case "animation":
                 int index = int.Parse(attribs[1]);
                 if (Animations[index] == null)
                     Animations[index] = new List<string>();
                 Animations[index].Add(attrib.Value);
                 break;
             case "scale":
                 Scale = ParseUtils.ParseVector3(attrib.Value);
                 break;
             case "rotation":
                 Rotation = ParseUtils.ParseVector3(attrib.Value);
                 break;
             case "position":
                 Position = ParseUtils.ParseVector3(attrib.Value);
                 break;
             case "deathrot":
                 DeathRotation = ParseUtils.ParseVector3(attrib.Value);
                 break;
             case "deathpos":
                 DeathPosition = ParseUtils.ParseVector3(attrib.Value);
                 break;
             case "roar":
                 RoarSoundEffect = attrib.Value;
                 break;
             case "death":
                 DeathSoundEffect = attrib.Value;
                 break;
             case "idle":
                 IdleSoundEffect = attrib.Value;
                 break;
             case "bark":
                 BarkSoundEffect = attrib.Value;
                 break;
             case "attack":
                 AttackSoundEffect = attrib.Value;
                 break;
             case "maul":
                 MaulSoundEffect = attrib.Value;
                 break;
             case "canbackoff":
                 CanBackoff = bool.Parse(attrib.Value);
                 break;
         }
     }
 }
        void Create3DTextures(TextureResource[] baseMaps, TextureResource[] normalMaps)
        {
            Texture2D simpleWhite = new Texture2D(GFX.Device, 1, 1, 1, TextureUsage.None, SurfaceFormat.Color);
            Texture2D simpleNormal = new Texture2D(GFX.Device, 1, 1, 1, TextureUsage.None, SurfaceFormat.Color);
            Color[] whiteColor = new Color[1] { Color.White };
            Color[] normalColor = new Color[1] { Color.Blue };
            simpleWhite.SetData<Color>(whiteColor);
            simpleNormal.SetData<Color>(normalColor);

            List<Texture2D> baseTextures = new List<Texture2D>(TerrainClimateVoxels.MAX_BLEND_ZONES);
            List<Texture2D> normalTextures = new List<Texture2D>(TerrainClimateVoxels.MAX_BLEND_ZONES);
            int maxBaseSize = 256;
            int maxNormalSize = 256;

            for (int i = 0; i < TerrainClimate.MAX_BLEND_ZONES; i++)
            {
                if(baseMaps[i] != null)
                {
                    Texture2D baseMap = (Texture2D)baseMaps[i].GetTexture();
                    maxBaseSize = Math.Max(maxBaseSize, baseMap.Width);
                    baseTextures.Add(baseMap);
                }
                else
                    baseTextures.Add(simpleWhite);
                if(normalMaps[i] != null)
                {
                    Texture2D normalMap = (Texture2D)normalMaps[i].GetTexture();
                    maxNormalSize = Math.Max(maxNormalSize, normalMap.Width);
                    normalTextures.Add(normalMap);
                }
                else
                    normalTextures.Add(simpleNormal);
            }

            Texture3D baseAtlas = new Texture3D(GFX.Device, maxBaseSize, maxBaseSize, TerrainClimateVoxels.MAX_BLEND_ZONES, 1, TextureUsage.None, SurfaceFormat.Color);
            Texture3D normalAtlas = new Texture3D(GFX.Device, maxNormalSize, maxNormalSize, TerrainClimateVoxels.MAX_BLEND_ZONES, 1, TextureUsage.None, SurfaceFormat.Color);

            width = maxBaseSize;
            height = maxBaseSize;
            depth = TerrainClimate.MAX_BLEND_ZONES;

            PopulateAtlas(baseTextures.ToArray(), baseAtlas);

            PopulateAtlas(normalTextures.ToArray(), normalAtlas);

            BaseMapAtlas = new TextureResource();
            BaseMapAtlas.SetTexture(TextureResourceType.Texture3D, baseAtlas);

            NormalMapAtlas = new TextureResource();
            NormalMapAtlas.SetTexture(TextureResourceType.Texture3D, normalAtlas);

            baseAtlas.Save("BaseMapAtlas.dds", ImageFileFormat.Dds);

            normalAtlas.Save("NormalMapAtlas.dds", ImageFileFormat.Dds);
        }
Пример #9
0
 public void SetTexture(int index, TextureResource texture)
 {
     if (index >= 0 && index < textures.Length)
         textures[index] = texture;
 }
Пример #10
0
 public void SetButtonImage(TextureResource image)
 {
     buttonImage = image;
 }
Пример #11
0
 public UIButton(TextureResource image, Vector4 color, string text)
 {
     buttonImage = image;
     buttonColor = color;
     buttonText = text;
 }
Пример #12
0
 public void AddCustomMarker(Transform transform, TextureResource texture)
 {
     customMarkers.Add(new CustomMarker(transform, texture.GetTexture() as Texture2D));
 }
Пример #13
0
 public void SetScrollBarImage(TextureResource image)
 {
     scrollBarImage = image;
 }
Пример #14
0
 public void SetSliderImage(TextureResource image)
 {
     sliderButton.SetButtonImage(image);
 }
Пример #15
0
        void CreateImposter()
        {
            const int textureSize = 128;
            const int numViews = 4;

            int textureWidth = textureSize * numViews;
            int textureHeight = textureSize;

            imposterGeometry = new Imposter(this);
            imposterGeometry.BaseMap = new RenderTarget2D(GFX.Device, textureWidth, textureHeight, 1, SurfaceFormat.Color);
            imposterGeometry.NormalMap = new RenderTarget2D(GFX.Device, textureWidth, textureHeight, 1, SurfaceFormat.Vector2);

            ImposterRenderView renderViewImposter = new ImposterRenderView(Matrix.Identity, Matrix.Identity, Vector3.Zero, 1.0f, 1000.0f);

            Vector3 centerPos = (this.meshBounds.Min + this.meshBounds.Max)*0.5f;
            float rad = Math.Max(this.meshBounds.Min.Length(), this.meshBounds.Max.Length());

            renderViewImposter.SetNearPlane(1.0f);
            renderViewImposter.SetFarPlane(rad * rad);
            renderViewImposter.SetProjection(Matrix.CreateOrthographicOffCenter(-rad * 0.5f, rad * 0.5f, -rad*0.5f, rad*0.5f, 1.0f, rad * rad));

            Viewport oldViewport = GFX.Device.Viewport;
            DepthStencilBuffer oldDSBuffer = GFX.Device.DepthStencilBuffer;
            DepthStencilBuffer dsBufferImposter = new DepthStencilBuffer(GFX.Device, textureWidth, textureHeight, oldDSBuffer.Format);
            GFX.Device.DepthStencilBuffer = dsBufferImposter;

            float deltaTheta = MathHelper.TwoPi / (float)numViews;

            GFX.Device.SetRenderTarget(0, imposterGeometry.BaseMap);
            GFX.Device.SetRenderTarget(1, imposterGeometry.NormalMap);
            GFX.Device.Clear(Color.TransparentBlack);

            for (int i = 0; i < numViews; i++)
            {
                float theta = deltaTheta * i;
                Vector3 offset = new Vector3((float)Math.Sin(theta), 0, (float)Math.Cos(theta)) * rad;
                Vector3 camPos = centerPos + offset;

                renderViewImposter.SetPosition(camPos);
                renderViewImposter.SetView(Matrix.CreateLookAt(camPos, centerPos, Vector3.Up));

                Viewport newViewport = new Viewport();
                newViewport.X = i * textureSize;
                newViewport.Y = 0;
                newViewport.Width = textureSize;
                newViewport.Height = textureHeight;

                GFX.Device.Viewport = newViewport;
                this.RenderNoLOD(Matrix.Identity, renderViewImposter);
                renderViewImposter.Render();
            }

            GFX.Device.SetRenderTarget(1, null);

            for (int i = 0; i < numViews; i++)
            {
                float theta = deltaTheta * i;
                Vector3 offset = new Vector3((float)Math.Cos(theta), 0, (float)Math.Sin(theta)) * rad;
                Vector3 camPos = centerPos + offset;

                renderViewImposter.SetPosition(camPos);
                renderViewImposter.SetView(Matrix.CreateLookAt(camPos, centerPos, Vector3.Up));

                Viewport newViewport = new Viewport();
                newViewport.X = i * textureSize;
                newViewport.Y = 0;
                newViewport.Width = textureSize;
                newViewport.Height = textureHeight;

                GFX.Device.Viewport = newViewport;
                this.RenderNoLOD(Matrix.Identity, renderViewImposter);
                renderViewImposter.RenderBlended();
            }

            GFX.Device.SetRenderTarget(0, null);

            GFX.Device.Viewport = oldViewport;
            GFX.Device.DepthStencilBuffer = oldDSBuffer;
            dsBufferImposter.Dispose();
            imposterGeometry.BaseMap.GetTexture().Save("BaseMapImposter.dds", ImageFileFormat.Dds);

            imposterGeometry.ImposterMaterial.SetShader(ResourceManager.Inst.GetShader("ImposterShader"));
            TextureResource baseMap = new TextureResource();
            baseMap.SetTexture(TextureResourceType.Texture2D, imposterGeometry.BaseMap.GetTexture());
            imposterGeometry.BaseMap.GetTexture().GenerateMipMaps(TextureFilter.GaussianQuad);
            TextureResource normalMap = new TextureResource();
            normalMap.SetTexture(TextureResourceType.Texture2D, imposterGeometry.NormalMap.GetTexture());
            imposterGeometry.ImposterMaterial.SetTexture(0, baseMap);
            imposterGeometry.ImposterMaterial.SetTexture(1, normalMap);
            imposterGeometry.ImposterMaterial.SetName(name + "_IMPOSTER_MATERIAL");
            imposterGeometry.ImposterMaterial.IsFoliage = true;
        }