Exemple #1
0
        /// <summary>
        ///  <para>Loads Shader from given Zip-File and Entry.</para>
        /// </summary>
        private FXShader LoadShaderFrom(ZipFile zipFile, ZipEntry shaderEntry)
        {
            string ResourceName = Path.GetFileNameWithoutExtension(shaderEntry.Name).ToLowerInvariant();



            var byteBuffer = new byte[zipBufferSize];

            Stream zipStream = zipFile.GetInputStream(shaderEntry);
            //Will throw exception is missing or wrong password. Handle this.

            var memStream = new MemoryStream();

            StreamUtils.Copy(zipStream, memStream, byteBuffer);
            memStream.Position = 0;

            FXShader loadedShader = new FXShader(ResourceName, ResourceName);

            loadedShader.memStream = memStream;

            memStream.Close();
            zipStream.Close();
            memStream.Dispose();
            zipStream.Dispose();

            return(loadedShader);
        }
        /// <summary>
        ///  <para>Loads Shader from given Zip-File and Entry.</para>
        /// </summary>
        private FXShader LoadShaderFrom(ZipFile zipFile, ZipEntry shaderEntry)
        {
            string ResourceName = Path.GetFileNameWithoutExtension(shaderEntry.Name).ToLowerInvariant();

            if (ShaderCache.Shaders.Contains(ResourceName))
            {
                return(null);
            }

            var byteBuffer = new byte[zipBufferSize];

            Stream zipStream = zipFile.GetInputStream(shaderEntry);
            //Will throw exception is missing or wrong password. Handle this.

            var memStream = new MemoryStream();

            StreamUtils.Copy(zipStream, memStream, byteBuffer);
            memStream.Position = 0;

            FXShader loadedShader = FXShader.FromStream(ResourceName, memStream, ShaderCompileOptions.Debug,
                                                        (int)memStream.Length, false);

            memStream.Close();
            zipStream.Close();
            memStream.Dispose();
            zipStream.Dispose();

            return(loadedShader);
        }
Exemple #3
0
        private void SetupGorgon()
        {
            Gorgon.Initialize(true, false);
            Gorgon.SetMode(this);
            //Gorgon.AllowBackgroundRendering = true;
            //Gorgon.Screen.BackgroundColor = Color.FromArgb(50, 50, 50);

            //Gorgon.CurrentClippingViewport = new Viewport(0, 20, Gorgon.Screen.Width, Gorgon.Screen.Height - 20);
            //PreciseTimer preciseTimer = new PreciseTimer();
            //Gorgon.MinimumFrameTime = PreciseTimer.FpsToMilliseconds(66);
            Gorgon.Idle += new FrameEventHandler(Gorgon_Idle);
            Gorgon.FrameStatsVisible = true;

            bouncesprite = new Sprite("bouncey", GorgonLibrary.Graphics.Image.FromFile(mediadir + @"\textures\0_Items.png"), new Vector2D(0, 0), new Vector2D(22, 20));
            bouncesprite.SetScale(3, 3);
            decalsprite = new Sprite("decal", GorgonLibrary.Graphics.Image.FromFile(mediadir + @"\textures\0_Decals.png"), new Vector2D(56, 0), new Vector2D(103, 29));
            decalsprite.SetScale(1, 1);
            decalShader = FXShader.FromFile(mediadir + @"\shaders\decalshader.fx", ShaderCompileOptions.Debug);
            decalShader.Parameters["tex1"].SetValue(decalsprite.Image);

            baseTarget       = new RenderImage("baseTarget", 32, 32, ImageBufferFormats.BufferRGB888A8);
            baseTargetSprite = new Sprite("baseTargetSprite", baseTarget);

            bounceysprites = new BounceySprite[10];
            for (int i = 0; i < 10; i++)
            {
                bounceysprites[i] = new BounceySprite(bouncesprite, new Vector2D(random.Next(0, Gorgon.Screen.Width), random.Next(0, Gorgon.Screen.Height)),
                                                      new Vector2D((float)random.Next(-100000, 100000) / 100000, (float)random.Next(-100000, 100000) / 100000),
                                                      decalsprite, new Vector2D(random.Next(-10, 15), random.Next(-10, 15)), decalShader, this);
            }


            //Calculate decal texcoord offsets

            /*Vector2D decalBToffset = new Vector2D(10,5);
             * float BTXDTL_x = decalBToffset.X / bouncesprite.Image.Width;
             * float BTXDTL_y = decalBToffset.Y / bouncesprite.Image.Height;
             * float BTXDBR_x = (decalBToffset.X + decalsprite.Width)/bouncesprite.Image.Width;
             * float BTXDBR_y = (decalBToffset.Y + decalsprite.Height)/bouncesprite.Image.Height;
             * float CFx = (float)decalsprite.Image.Width/(float)bouncesprite.Image.Width;
             * float CFy = (float)decalsprite.Image.Height / (float)bouncesprite.Image.Height;
             * float DOtc_xtl = (float)decalsprite.ImageOffset.X / (float)decalsprite.Image.Width;
             * float DOtc_ytl = (float)decalsprite.ImageOffset.Y / (float)decalsprite.Image.Height;
             *
             * Vector4D decalParms1 = new Vector4D(BTXDTL_x, BTXDTL_y, BTXDBR_x, BTXDBR_y);
             * Vector4D decalParms2 = new Vector4D(CFx, CFy, DOtc_xtl, DOtc_ytl);*/
        }
Exemple #4
0
        private void SetupGorgon()
        {
            Gorgon.Initialize(true, false);
            Gorgon.SetMode(this);
            //Gorgon.AllowBackgroundRendering = true;
            //Gorgon.Screen.BackgroundColor = Color.FromArgb(50, 50, 50);

            //Gorgon.CurrentClippingViewport = new Viewport(0, 20, Gorgon.Screen.Width, Gorgon.Screen.Height - 20);
            //PreciseTimer preciseTimer = new PreciseTimer();
            //Gorgon.MinimumFrameTime = PreciseTimer.FpsToMilliseconds(66);
            Gorgon.Idle += new FrameEventHandler(Gorgon_Idle);
            Gorgon.FrameStatsVisible = true;

            bouncesprite = new Sprite("bouncey", GorgonLibrary.Graphics.Image.FromFile(mediadir + @"\textures\0_Items.png"), new Vector2D(0,0), new Vector2D(22,20));
            bouncesprite.SetScale(3, 3);
            decalsprite = new Sprite("decal", GorgonLibrary.Graphics.Image.FromFile(mediadir + @"\textures\0_Decals.png"), new Vector2D(56,0), new Vector2D(103,29));
            decalsprite.SetScale(1, 1);
            decalShader = FXShader.FromFile(mediadir + @"\shaders\decalshader.fx", ShaderCompileOptions.Debug);
            decalShader.Parameters["tex1"].SetValue(decalsprite.Image);

            baseTarget = new RenderImage("baseTarget", 32, 32, ImageBufferFormats.BufferRGB888A8);
            baseTargetSprite = new Sprite("baseTargetSprite", baseTarget);

            bounceysprites = new BounceySprite[10];
            for (int i = 0; i < 10; i++)
            {
                bounceysprites[i] = new BounceySprite(bouncesprite, new Vector2D(random.Next(0, Gorgon.Screen.Width), random.Next(0, Gorgon.Screen.Height)), 
                                        new Vector2D((float)random.Next(-100000,100000) / 100000, (float)random.Next(-100000,100000) / 100000),
                                        decalsprite, new Vector2D(random.Next(-10,15), random.Next(-10,15)), decalShader, this);
            }


            //Calculate decal texcoord offsets
            /*Vector2D decalBToffset = new Vector2D(10,5);
            float BTXDTL_x = decalBToffset.X / bouncesprite.Image.Width;
            float BTXDTL_y = decalBToffset.Y / bouncesprite.Image.Height;
            float BTXDBR_x = (decalBToffset.X + decalsprite.Width)/bouncesprite.Image.Width;
            float BTXDBR_y = (decalBToffset.Y + decalsprite.Height)/bouncesprite.Image.Height;
            float CFx = (float)decalsprite.Image.Width/(float)bouncesprite.Image.Width;
            float CFy = (float)decalsprite.Image.Height / (float)bouncesprite.Image.Height;
            float DOtc_xtl = (float)decalsprite.ImageOffset.X / (float)decalsprite.Image.Width;
            float DOtc_ytl = (float)decalsprite.ImageOffset.Y / (float)decalsprite.Image.Height;

            Vector4D decalParms1 = new Vector4D(BTXDTL_x, BTXDTL_y, BTXDBR_x, BTXDBR_y);
            Vector4D decalParms2 = new Vector4D(CFx, CFy, DOtc_xtl, DOtc_ytl);*/
        }
        public void LoadContent()
        {
            reductionEffect = _resourceManager.GetShader("reductionEffect");
            resolveShadowsEffect = _resourceManager.GetShader("resolveShadowsEffect");

            // BUFFER TYPES ARE VERY IMPORTANT HERE AND IT WILL BREAK IF YOU CHANGE THEM!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
            distortRT = new RenderImage("distortRT" + baseSize, baseSize, baseSize, ImageBufferFormats.BufferGR1616F);
            distancesRT = new RenderImage("distancesRT" + baseSize, baseSize, baseSize, ImageBufferFormats.BufferGR1616F);
            shadowMap = new RenderImage("shadowMap" + baseSize, 2, baseSize, ImageBufferFormats.BufferGR1616F);
            reductionRT = new RenderImage[reductionChainCount];
            for (int i = 0; i < reductionChainCount; i++)
            {
                reductionRT[i] = new RenderImage("reductionRT" + i + baseSize, 2 << i, baseSize,
                                                 ImageBufferFormats.BufferGR1616F);
            }
            shadowsRT = new RenderImage("shadowsRT" + baseSize, baseSize, baseSize, ImageBufferFormats.BufferRGB888A8);
            processedShadowsRT = new RenderImage("processedShadowsRT" + baseSize, baseSize, baseSize,
                                                 ImageBufferFormats.BufferRGB888A8);
        }
        public void LoadContent()
        {
            reductionEffect      = _resourceManager.GetShader("reductionEffect");
            resolveShadowsEffect = _resourceManager.GetShader("resolveShadowsEffect");

            //// BUFFER TYPES ARE VERY IMPORTANT HERE AND IT WILL BREAK IF YOU CHANGE THEM!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
            //distortRT = new RenderImage("distortRT" + baseSize, baseSize, baseSize, ImageBufferFormats.BufferGR1616F);
            //distancesRT = new RenderImage("distancesRT" + baseSize, baseSize, baseSize, ImageBufferFormats.BufferGR1616F);
            //shadowMap = new RenderImage("shadowMap" + baseSize, 2, baseSize, ImageBufferFormats.BufferGR1616F);
            reductionRT = new RenderImage[reductionChainCount];
            for (int i = 0; i < reductionChainCount; i++)
            {
                reductionRT[i] = new RenderImage("reductionRT" + i + baseSize, 2 << i, baseSize,
                                                 ImageBufferFormats.BufferGR1616F);
            }
            shadowsRT          = new RenderImage("shadowsRT" + baseSize, baseSize, baseSize, ImageBufferFormats.BufferRGB888A8);
            processedShadowsRT = new RenderImage("processedShadowsRT" + baseSize, baseSize, baseSize,
                                                 ImageBufferFormats.BufferRGB888A8);
        }
Exemple #7
0
 public BounceySprite(Sprite _sprite, Vector2D _position, Vector2D _direction, Sprite _decal, Vector2D _decalpos, FXShader _decalShader, Form1 _form1)
 {
     position = _position;
     direction = _direction;
     decalsprite = _decal;
     decalspritepos = _decalpos;
     //decalShader = _decalShader;
     form1 = _form1;
     Vector4D decpar1 = decalParms1(decalspritepos, new Vector2D(form1.bouncesprite.Image.Width, form1.bouncesprite.Image.Height), decalsprite.Size);
     Vector4D decpar2 = decalParms2(new Vector2D(decalsprite.Image.Width, decalsprite.Image.Height), new Vector2D(form1.bouncesprite.Image.Width, form1.bouncesprite.Image.Height), decalsprite.ImageOffset);
     decalParams1 = new Vector4D[] { decpar1, decpar1, decpar1, decpar1, decpar1 };
     decalParams2 = new Vector4D[] { decpar2, decpar2, decpar2, decpar2, decpar2 };
     
 }
 private void SetShader()
 {
     _shader = _resourceManager.GetShader("GaussianBlur" + Radius);
 }
Exemple #9
0
 private void SetShader()
 {
     _shader = _resourceManager.GetShader("GaussianBlur" + Radius);
 }
        /// <summary>
        ///  <para>Loads all Resources from given Zip into the respective Resource Lists and Caches</para>
        /// </summary>
        public void LoadResourceZip(string path = null, string pw = null)
        {
            string zipPath  = path ?? _configurationManager.GetResourcePath();
            string password = pw ?? _configurationManager.GetResourcePassword();


            if (!File.Exists(zipPath))
            {
                throw new FileNotFoundException("Specified Zip does not exist: " + zipPath);
            }

            FileStream zipFileStream = File.OpenRead(zipPath);
            var        zipFile       = new ZipFile(zipFileStream);

            if (!string.IsNullOrWhiteSpace(password))
            {
                zipFile.Password = password;
            }

            var directories = from ZipEntry a in zipFile
                              where a.IsDirectory
                              orderby a.Name.ToLowerInvariant() == "textures" descending
                              select a;

            Dictionary <string, List <ZipEntry> > sorted = new Dictionary <string, List <ZipEntry> >();

            foreach (ZipEntry dir in directories)
            {
                if (sorted.ContainsKey(dir.Name.ToLowerInvariant()))
                {
                    continue;                                                  //Duplicate folder? shouldnt happen.
                }
                List <ZipEntry> folderContents = (from ZipEntry entry in zipFile
                                                  where entry.Name.ToLowerInvariant().Contains(dir.Name.ToLowerInvariant())
                                                  where entry.IsFile
                                                  select entry).ToList();

                sorted.Add(dir.Name.ToLowerInvariant(), folderContents);
            }

            sorted = sorted.OrderByDescending(x => x.Key == "textures/").ToDictionary(x => x.Key, x => x.Value); //Textures first.

            foreach (KeyValuePair <string, List <ZipEntry> > current in sorted)
            {
                switch (current.Key)
                {
                case ("textures/"):
                    foreach (ZipEntry texture in current.Value)
                    {
                        if (supportedImageExtensions.Contains(Path.GetExtension(texture.Name).ToLowerInvariant()))
                        {
                            Image loadedImg = LoadImageFrom(zipFile, texture);
                            if (loadedImg == null)
                            {
                                continue;
                            }
                            else
                            {
                                _images.Add(loadedImg.Name, loadedImg);
                            }
                        }
                    }
                    break;

                case ("tai/"):
                    foreach (ZipEntry tai in current.Value)
                    {
                        if (Path.GetExtension(tai.Name).ToLowerInvariant() == ".tai")
                        {
                            IEnumerable <Sprite> loadedSprites = LoadSpritesFrom(zipFile, tai);
                            foreach (Sprite currentSprite in loadedSprites.Where(currentSprite => !_sprites.ContainsKey(currentSprite.Name)))
                            {
                                _sprites.Add(currentSprite.Name, currentSprite);
                            }
                        }
                    }
                    break;

                case ("fonts/"):
                    foreach (ZipEntry font in current.Value)
                    {
                        if (Path.GetExtension(font.Name).ToLowerInvariant() == ".ttf")
                        {
                            Font loadedFont = LoadFontFrom(zipFile, font);
                            if (loadedFont == null)
                            {
                                continue;
                            }
                            else
                            {
                                _fonts.Add(loadedFont.Name, loadedFont);
                            }
                        }
                    }
                    break;

                case ("particlesystems/"):
                    foreach (ZipEntry particles in current.Value)
                    {
                        if (Path.GetExtension(particles.Name).ToLowerInvariant() == ".xml")
                        {
                            ParticleSettings particleSettings = LoadParticlesFrom(zipFile, particles);
                            if (particleSettings == null)
                            {
                                continue;
                            }
                            else
                            {
                                _particles.Add(Path.GetFileNameWithoutExtension(particles.Name), particleSettings);
                            }
                        }
                    }
                    break;

                case ("shaders/"):
                    foreach (ZipEntry shader in current.Value)
                    {
                        if (Path.GetExtension(shader.Name).ToLowerInvariant() == ".fx")
                        {
                            FXShader loadedShader = LoadShaderFrom(zipFile, shader);
                            if (loadedShader == null)
                            {
                                continue;
                            }
                            else
                            {
                                _shaders.Add(loadedShader.Name, loadedShader);
                            }
                        }
                    }
                    break;

                case ("animations/"):
                    foreach (ZipEntry animation in current.Value)
                    {
                        if (Path.GetExtension(animation.Name).ToLowerInvariant() == ".xml")
                        {
                            AnimationCollection animationCollection = LoadAnimationCollectionFrom(zipFile, animation);
                            if (animationCollection == null)
                            {
                                continue;
                            }
                            else
                            {
                                _animationCollections.Add(animationCollection.Name, animationCollection);
                            }
                        }
                    }
                    break;
                }
            }

            sorted = null;

            zipFile.Close();
            zipFileStream.Close();
            zipFileStream.Dispose();

            GC.Collect();
        }
Exemple #11
0
 public DeathPostProcessingEffect(float duration)
     : base(duration)
 {
     _shader = IoCManager.Resolve <IResourceManager>().GetShader("deathshader");
 }
Exemple #12
0
        public BounceySprite(Sprite _sprite, Vector2D _position, Vector2D _direction, Sprite _decal, Vector2D _decalpos, FXShader _decalShader, Form1 _form1)
        {
            position       = _position;
            direction      = _direction;
            decalsprite    = _decal;
            decalspritepos = _decalpos;
            //decalShader = _decalShader;
            form1 = _form1;
            Vector4D decpar1 = decalParms1(decalspritepos, new Vector2D(form1.bouncesprite.Image.Width, form1.bouncesprite.Image.Height), decalsprite.Size);
            Vector4D decpar2 = decalParms2(new Vector2D(decalsprite.Image.Width, decalsprite.Image.Height), new Vector2D(form1.bouncesprite.Image.Width, form1.bouncesprite.Image.Height), decalsprite.ImageOffset);

            decalParams1 = new Vector4D[] { decpar1, decpar1, decpar1, decpar1, decpar1 };
            decalParams2 = new Vector4D[] { decpar2, decpar2, decpar2, decpar2, decpar2 };
        }
 public DeathPostProcessingEffect(float duration)
     : base(duration)
 {
     _shader = IoCManager.Resolve<IResourceManager>().GetShader("deathshader");
 }