Exemple #1
0
 protected VertexArray(int vertexArrayId, VertexBuffer vertexBuffer, ShaderProgram shader, Texture texture, ElementBuffer elementBuffer, params VertexAttribute[] vertexAttributes) : this(vertexArrayId, vertexBuffer)
 {
     Shaders.Add(shader);
     Textures.Add(texture);
     ElementBuffer = elementBuffer;
     _vertexAttributes.AddRange(vertexAttributes);
 }
Exemple #2
0
 public void Save()
 {
     Loader.Save();
     Shaders.Save();
     OpenSauce.Save();
     Chimera.Save();
 }
Exemple #3
0
    private void OnTriggerEnter(Collider other)
    {
        Shaders script = other.GetComponent <Shaders>();

        if (script != null)
        {
            presed = true;
        }
        if (other.CompareTag(tag))
        {
            GameObject.Find("Sucess").GetComponentInChildren <AudioSource> ().Play();
            GameObject.Find("Estructura").GetComponent <Celta> ().points += 1;
            presionado = false;
            ok         = true;
        }
        else
        {
            GameObject.Find("Failure").GetComponentInChildren <AudioSource> ().Play();
            presionado = false;
            StartCoroutine(cambiopos());
        }
        if (script != null)
        {
            other.GetComponent <Shaders>().cambioShader(this.gameObject, ok);
        }
    }
Exemple #4
0
        private IDialog createShadersDialog(IGameFactory factory)
        {
            IDialogOption option1 = factory.Dialog.GetDialogOption("Normal");
            IDialogOption option2 = factory.Dialog.GetDialogOption("Grayscale");
            IDialogOption option3 = factory.Dialog.GetDialogOption("Sepia");
            IDialogOption option4 = factory.Dialog.GetDialogOption("Soft Sepia");
            IDialogOption option5 = factory.Dialog.GetDialogOption("Vignette");
            IDialogOption option6 = factory.Dialog.GetDialogOption("Blur me!");
            IDialogOption option7 = factory.Dialog.GetDialogOption("Shake the screen!");
            IDialogOption option8 = factory.Dialog.GetDialogOption("Actually, I don't want a shader!");

            setShaderOption(option1, () => Shaders.SetStandardShader());
            setShaderOption(option2, () => Shaders.SetGrayscaleShader());
            setShaderOption(option3, () => Shaders.SetSepiaShader());
            setShaderOption(option4, () => Shaders.SetSoftSepiaShader());
            setShaderOption(option5, () => Shaders.SetVignetteShader());
            setShaderOption(option6, () => Shaders.SetBlurShader());
            setShaderOption(option7, () => Shaders.SetShakeShader());
            setShaderOption(option8, () => Shaders.TurnOffShader());

            IDialog dialog = factory.Dialog.GetDialog("Dialog: Beman- Shaders");

            dialog.AddOptions(option1, option2, option3, option4, option5, option6, option7, option8);

            return(dialog);
        }
Exemple #5
0
        // is called on startup
        public override void Init()
        {
            RC.ClearColor = new float4(0.1f, 0.1f, 0.5f, 1);

            // IMPORTANT: You are supposed to use either one SetWindowSize() or VideoWall(). You can't use both.
            // It's possible to resize a window to fit on a video wall or display.
            // Here are some different variants how to use this functionality. Uncomment to test.
            //SetWindowSize(800, 600);
            //SetWindowSize(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height/5 * 2, true, 0, 0);
            //SetWindowSize(Screen.PrimaryScreen.Bounds.Width/9 * 2, Screen.PrimaryScreen.Bounds.Height, true, 0, 0);
            //SetWindowSize(640, 480, false, Screen.PrimaryScreen.Bounds.Width/2 - 640/2, Screen.PrimaryScreen.Bounds.Height/2 - 480/2);
            // IMPORTANT: For video Walls or projector matrices it's possible to let the system do the magic by
            // giving it the number of monitors/projectors per axis and specify some border information.
            // This only works in pseudo-fullscreen mode a.k.a borderless fullscreen-window.
            VideoWall(0, 0, true, true);

            // This is the old method. More than this could not be done directly in a project code(?)
            //Width = 640;
            //Height = 480;

            // Initialize an ui.
            _guiHandler = new GUIHandler();
            _guiHandler.AttachToContext(RC);

            // Create a new element.
            GUIElement element = new GUIImage("Assets/image.png", 0, 0, -10, 320, 130);

            // Add the element to the gui.
            _guiHandler.Add(element);

            // Add something to render.
            _cube       = new Cube();
            _spcolor    = Shaders.GetDiffuseColorShader(RC);
            _colorParam = _spcolor.GetShaderParam("color");
        }
Exemple #6
0
        protected override YAMLMappingNode ExportYAMLRoot(IExportContainer container)
        {
            YAMLMappingNode node = base.ExportYAMLRoot(container);

            node.Add("m_Shaders", Shaders.ExportYAML(container));
            return(node);
        }
Exemple #7
0
        public override void Render(bool shadow)
        {
            if (shadow)
            {
                Graphics.Render(Sprite, Entity.Position + Origin + new Vector2(0, ShadowZ + Sprite.Height), Angle, Origin, Scale, Graphics.ParseEffect(Flipped, ShadowZ > 0 ? FlippedVerticaly : !FlippedVerticaly));
                return;
            }

            var stopShader = false;

            if (Entity.TryGetComponent <HealthComponent>(out var health) && health.RenderInvt)
            {
                var i = health.InvincibilityTimer;

                if (i > health.InvincibilityTimerMax / 2f || i % 0.1f > 0.05f)
                {
                    var shader = Shaders.Entity;
                    Shaders.Begin(shader);

                    shader.Parameters["flash"].SetValue(1f);
                    shader.Parameters["flashReplace"].SetValue(1f);
                    shader.Parameters["flashColor"].SetValue(ColorUtils.White);

                    stopShader = true;
                }
            }

            Graphics.Render(Sprite, Entity.Position + Origin, Angle, Origin, Scale);

            if (stopShader)
            {
                Shaders.End();
            }
        }
Exemple #8
0
        /// <summary>
        /// Function to clean up the categorized interfaces.
        /// </summary>
        private void DestroyInterfaces()
        {
            if (Fonts != null)
            {
                Fonts.CleanUp();
            }

            Fonts = null;

            if (Textures != null)
            {
                Textures.CleanUp();
            }

            Textures = null;

            if (Shaders != null)
            {
                Shaders.CleanUp();
            }

            Shaders = null;

            if (Output != null)
            {
                Output.CleanUp();
            }

            Output = null;

            if (Rasterizer != null)
            {
                Rasterizer.CleanUp();
            }
        }
Exemple #9
0
        public override void Render(bool shadow)
        {
            var timer      = Entity.GetComponent <ExplodeComponent>();
            var origin     = new Vector2(Sprite.Center.X, shadow ? 0 : Sprite.Source.Height);
            var stopShader = false;
            var bomb       = (Bomb)Entity;

            if (!shadow && (timer.Timer <1f ? timer.Timer % 0.3f> 0.1f : timer.Timer % 0.5f > 0.4f))
            {
                var shader = Shaders.Entity;
                Shaders.Begin(shader);

                shader.Parameters["flash"].SetValue(1f);
                shader.Parameters["flashReplace"].SetValue(1f);
                shader.Parameters["flashColor"].SetValue(ColorUtils.White);

                stopShader = true;
            }

            Graphics.Render(Sprite, Entity.Position + new Vector2(origin.X, origin.Y + (shadow ? Sprite.Height : 0)),
                            0, origin, new Vector2(
                                (float)((Math.Cos(timer.Timer * 16) / 2f) + 1) * bomb.Scale * Math.Min(bomb.T * 4f, 1),
                                (float)((Math.Cos(timer.Timer * 16 + Math.PI) / 3f) + 1) * bomb.Scale
                                ),
                            Graphics.ParseEffect(false, shadow));

            if (stopShader)
            {
                Shaders.End();
            }
        }
        public void LoadShaders()
        {
            BasicEffect BasicEffect = new BasicEffect(Graphics);

            Shaders.Add("Default", BasicEffect);

            DirectoryInfo Folder = new DirectoryInfo(ShaderLocation);

            if (Folder.Exists)
            {
                FileInfo[] ConfigFiles = Folder.GetFiles();

                foreach (FileInfo CurrentFile in ConfigFiles)
                {
                    if (CurrentFile.Extension.Equals(".mgfxo"))
                    {
                        string Name = CurrentFile.Name.Remove(CurrentFile.Name.Length - 6, 6);

                        Effect Test = new Effect(Graphics, File.ReadAllBytes(CurrentFile.FullName.ToString()));
                        Test.Name = Name;

                        Shaders.Add(Name, Test);
                    }
                }
            }
        }
Exemple #11
0
        public void ExecuteRow(
            Vector2 screenUV, Vector2 objUV,
            int cols, float screenUVdx, float objUVdx,
            Color[] backbuffer, int backbufferOffset,
            ref Texture texture, ref ShaderGlobals globals)
        {
            int   texY     = Shaders.SampleTextureY(texture, objUV);
            float darkXfac = -0.5f + globals.CosTime1000 * 0.1f;

            screenUV.x += darkXfac;
            float darkY        = screenUV.y - 0.5f + globals.CosTime600 * 0.1f;
            float darkY2       = darkY * darkY;
            float darkFac      = 1.0f - 4.0f * darkY2;
            uint  ditherOffset = (uint)(backbufferOffset + (int)globals.Time);

            for (int x = 0; x < cols; ++x, screenUV.x += screenUVdx, objUV.x += objUVdx, backbufferOffset++, ++ditherOffset)
            {
                Color result = new Color(0xFF000000);

                float darkX = screenUV.x;
                float dark  = darkFac - 4f * darkX * darkX;
                if (dark > 0.0f)
                {
                    result = Shaders.SampleTextureX(texture, texY, objUV);

                    uint darkI = (uint)(dark * 255.0f);
                    result.Scale(darkI);

                    result = Shaders.Dither(result, ditherOffset);
                }
                backbuffer[backbufferOffset] = result;
            }
        }
Exemple #12
0
        public override void Init()
        {
            RC.ClearColor = new float4(0, 0, 0, 1);

            Mesh = new Cube();

            var sp = Shaders.GetDiffuseColorShader(RC);

            RC.SetShader(sp);

            _vColor = RC.GetShaderParam(sp, "color");
            RC.SetShaderParam(_vColor, new float4(0.8f, 0.1f, 0.1f, 1));

            // sound by http://www.soundjay.com
            _audio1 = Audio.Instance.LoadFile("Assets/beep.ogg");

            // excerpt from "the final rewind" by tryad (http://www.tryad.org) - cc-by-sa
            _audio2 = Audio.Instance.LoadFile("Assets/music.ogg");

            _state  = 0;
            _testID = 1;

            _timeStep = 1.0f;
            _curTime  = 2.0f;

            _tests = new Tests();
        }
Exemple #13
0
        public RenderSystem(PresentationParameters parameters)
        {
            Adapters = GraphicsAdapter.EnumerateGraphicsAdapter();

            Device = new GraphicsDevice(Adapters[0]);

            SwapChain = new GraphicsSwapChain(parameters, Device);

            CommandList = new CommandList(Device);

            Texture = new Texture(Device, SwapChain);

            Shaders = new Shaders(Device, "Shaders/VertexShader.hlsl", "Shaders/PixelShader.hlsl");

            StateWireframe = new PipelineState(Device, FillMode.Wireframe, CullMode.None);

            StateSolid = new PipelineState(Device, FillMode.Solid, CullMode.None);

            Grid = new Grid(1, 1, 8, 8);

            VertexBuffer = new Buffer(Grid.SizeInBytes, Grid.Size, Device, ResourceInfo.VertexBuffer);

            IndexBuffer = new Buffer(Grid.IndexSizeInBytes, Grid.IndexSize, Device, ResourceInfo.IndexBuffer);

            ConstantBuffer = new Buffer(Utilities.SizeOf <Transform>(), Utilities.SizeOf <Transform>(), Device, ResourceInfo.ConstantBuffer);

            Camera = new Camera(CameraType.Static);

            Camera.Position = new Vector3(0.0f, 0.0f, -2.5f);

            Camera.SetLens((float)Math.PI / 4, 1.2f, 1.0f, 1000.0f);

            World = new Matrix[2];
        }
Exemple #14
0
        public static void OnWindowLoad()
        {
            if (WindowLoadedContextVersion != WindowContextVersion)
            {
                Window.VSync = VSyncMode.Off;
                GL.EnableClientState(ArrayCap.VertexArray);
                GL.EnableClientState(ArrayCap.ColorArray);
                GL.EnableClientState(ArrayCap.TextureCoordArray);
                GL.Enable(EnableCap.TextureRectangle);
                GL.Enable(EnableCap.Blend);
                GL.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha);
                WindowLoadedContextVersion = WindowContextVersion;
            }

            // set necessary uniforms
            Shader s_rgb      = Shaders.Get("rgb");
            Shader s_stencil  = Shaders.Get("stencil");
            Shader s_paletted = Shaders.Get("paletted");

            s_rgb.SetUniform("texture1", 0);
            s_stencil.SetUniform("texture1", 0);
            s_paletted.SetUniform("texture1", 0);
            s_paletted.SetUniform("texture2", 1);

            SetViewport(0, 0, Width, Height);
            SetTranslation(0f, 0f, 0f);
        }
Exemple #15
0
        public void StartGame(IGame game)
        {
            //Rendering the text at a 4 time higher resolution than the actual game, so it will still look sharp when maximizing the window.
            GLText.TextResolutionFactorX = 4;
            GLText.TextResolutionFactorY = 4;

            game.Events.OnLoad.Subscribe(async() =>
            {
                game.Factory.Resources.ResourcePacks.Add(new ResourcePack(new FileSystemResourcePack(AGSGame.Device.FileSystem), 0));
                game.Factory.Resources.ResourcePacks.Add(new ResourcePack(new EmbeddedResourcesPack(AGSGame.Device.Assemblies.EntryAssembly), 1));
                game.Factory.Fonts.InstallFonts("../../Assets/Fonts/pf_ronda_seven.ttf", "../../Assets/Fonts/Pixel_Berry_08_84_Ltd.Edition.TTF");
                AGSGameSettings.DefaultSpeechFont     = game.Factory.Fonts.LoadFontFromPath("../../Assets/Fonts/pf_ronda_seven.ttf", 14f, FontStyle.Regular);
                AGSGameSettings.DefaultTextFont       = game.Factory.Fonts.LoadFontFromPath("../../Assets/Fonts/Pixel_Berry_08_84_Ltd.Edition.TTF", 14f, FontStyle.Regular);
                AGSGameSettings.CurrentSkin           = null;
                game.State.RoomTransitions.Transition = AGSRoomTransitions.Fade();
                setKeyboardEvents(game);
                Shaders.SetStandardShader();

                addDebugLabels(game);
                Debug.WriteLine("Startup: Loading Assets");
                await loadPlayerCharacter(game);
                Debug.WriteLine("Startup: Loaded Player Character");
                await loadSplashScreen(game);
            });
        }
Exemple #16
0
        /// <summary>
        /// GetShader loads a shader resource from disk
        /// </summary>
        private RhGLShaderProgram GetShader(string baseName)
        {
            for (int i = 0; i < Shaders.Count; i++)
            {
                var shader = Shaders [i];
                if (shader.Name.Equals(baseName, StringComparison.InvariantCultureIgnoreCase))
                {
                    SetupShader(shader, Model, Viewport);
                    return(shader);
                }
            }

            String vertex_shader   = GetResourceAsString(baseName, "vsh");
            String fragment_shader = GetResourceAsString(baseName, "fsh");

            var new_shader = RhGLShaderProgram.BuildProgram(baseName, vertex_shader, fragment_shader);

            if (new_shader != null)
            {
                Shaders.Add(new_shader);
            }

            SetupShader(new_shader, Model, Viewport);
            return(new_shader);
        }
Exemple #17
0
        public static void Run()
        {
            IGame game = AGSGame.CreateEmpty();

            _gameDebugView = new Lazy <GameDebugView>(() =>
            {
                var gameDebugView = new GameDebugView(game);
                gameDebugView.Load();
                return(gameDebugView);
            });

            //Rendering the text at a 4 time higher resolution than the actual game, so it will still look sharp when maximizing the window.
            GLText.TextResolutionFactorX = 4;
            GLText.TextResolutionFactorY = 4;

            game.Events.OnLoad.Subscribe(async() =>
            {
                game.Factory.Fonts.InstallFonts("../../Assets/Fonts/pf_ronda_seven.ttf", "../../Assets/Fonts/Pixel_Berry_08_84_Ltd.Edition.TTF");
                AGSGameSettings.DefaultSpeechFont     = game.Factory.Fonts.LoadFontFromPath("../../Assets/Fonts/pf_ronda_seven.ttf", 14f, FontStyle.Regular);
                AGSGameSettings.DefaultTextFont       = game.Factory.Fonts.LoadFontFromPath("../../Assets/Fonts/Pixel_Berry_08_84_Ltd.Edition.TTF", 14f, FontStyle.Regular);
                AGSGameSettings.CurrentSkin           = null;
                game.State.RoomTransitions.Transition = AGSRoomTransitions.Fade();
                setKeyboardEvents(game);
                Shaders.SetStandardShader();

                addDebugLabels(game);
                Debug.WriteLine("Startup: Loading Assets");
                await loadPlayerCharacter(game);
                Debug.WriteLine("Startup: Loaded Player Character");
                await loadSplashScreen(game);
            });

            game.Start(new AGSGameSettings("Demo Game", new AGS.API.Size(320, 200),
                                           windowSize: new AGS.API.Size(640, 400), windowState: WindowState.Normal));
        }
Exemple #18
0
        public RenderSystem(PresentationParameters parameters)
        {
            Adapters = GraphicsAdapter.EnumerateGraphicsAdapter();

            Device = new GraphicsDevice(Adapters[0]);

            SwapChain = new GraphicsSwapChain(parameters, Device);

            CommandList = new CommandList(Device);

            Texture = new Texture(Device, SwapChain);

            Shaders = new Shaders(Device, "Shaders/VertexShader.hlsl", "Shaders/PixelShader.hlsl");

            Mesh = new Mesh();

            VertexBuffer = new Buffer(Mesh.SizeInBytes, Mesh.Size, Device, ResourceInfo.VertexBuffer);

            IndexBuffer = new Buffer(Mesh.IndexSizeInBytes, Mesh.IndexSize, Device, ResourceInfo.IndexBuffer);

            ConstantBuffer = new Buffer(Utilities.SizeOf <Transform>(), Utilities.SizeOf <Transform>(), Device, ResourceInfo.ConstantBuffer);

            Camera = new Camera(CameraType.Static);

            Camera.SetLens((float)Math.PI / 4, 1.2f, 1.0f, 1000.0f);
        }
Exemple #19
0
 public void SetMaterialUniforms(Shaders.ShaderProgram prog)
 {
     prog.SetUniform("material.specCoef",SpecCoef);
     prog.SetUniform("material.diffCoef", diffCoef);
     prog.SetUniform("material.ambCoef", ambCoef);
     prog.SetUniform("material.shininess", shininess);
 }
 /// <summary>
 /// 在使用<see cref="VertexArrayObject"/>后,此方法只会执行一次。
 /// </summary>
 /// <param name="e"></param>
 /// <param name="shaderProgram"></param>
 public override void Render(RenderEventArgs e, Shaders.ShaderProgram shaderProgram)
 {
     uint location = shaderProgram.GetAttributeLocation(this.VarNameInVertexShader);
     GL.BindBuffer(BufferTarget.ArrayBuffer, this.BufferID);
     GL.VertexAttribPointer(location, this.DataSize, this.DataType, false, 0, IntPtr.Zero);
     GL.EnableVertexAttribArray(location);
 }
        public scenario_structure_bsp(CacheBase Cache, CacheBase.IndexItem Tag)
        {
            cache = Cache;
            int          Address = Tag.Offset;
            EndianReader Reader  = Cache.Reader;

            Reader.SeekTo(Address);

            Reader.SeekTo(Address + 68);
            XBounds = new Range <float>(Reader.ReadSingle(), Reader.ReadSingle());
            YBounds = new Range <float>(Reader.ReadSingle(), Reader.ReadSingle());
            ZBounds = new Range <float>(Reader.ReadSingle(), Reader.ReadSingle());

            #region Clusters Block
            Reader.SeekTo(Address + 172);
            int iCount  = Reader.ReadInt32();
            int iOffset = Reader.ReadInt32() - Tag.Magic;
            for (int i = 0; i < iCount; i++)
            {
                ModelSections.Add(new ModelSection(Cache, Tag, iOffset + 176 * i, null)
                {
                    FacesIndex = i, VertsIndex = i, NodeIndex = 255
                });
                Clusters.Add(new Cluster(i));
            }
            #endregion

            #region Shaders Block
            Reader.SeekTo(Address + 180);
            iCount  = Reader.ReadInt32();
            iOffset = Reader.ReadInt32() - Tag.Magic;
            for (int i = 0; i < iCount; i++)
            {
                Shaders.Add(new Halo2Xbox.render_model.Shader(Cache, iOffset + 32 * i));
            }
            #endregion

            #region ModelParts Block
            Reader.SeekTo(Address + 328);
            iCount  = Reader.ReadInt32();
            iOffset = Reader.ReadInt32() - Tag.Magic;
            for (int i = 0; i < iCount; i++)
            {
                ModelSections.Add(new ModelSection(Cache, Tag, iOffset + 200 * i, BoundingBoxes)
                {
                    FacesIndex = i + Clusters.Count, VertsIndex = i + Clusters.Count, NodeIndex = 255
                });
            }
            #endregion

            #region GeometryInstances Block
            Reader.SeekTo(Address + 336);
            iCount  = Reader.ReadInt32();
            iOffset = Reader.ReadInt32() - Tag.Magic;
            for (int i = 0; i < iCount; i++)
            {
                GeomInstances.Add(new InstancedGeometry(Cache, iOffset + 88 * i, Clusters.Count));
            }
            #endregion
        }
Exemple #22
0
        public override void Render(bool shadow)
        {
            if (!shadow)
            {
                var m = (Mob)Entity;

                if (m.HasPrefix)
                {
                    var p      = m.Prefix;
                    var pos    = Entity.Position + Offset;
                    var shader = Shaders.Entity;
                    Shaders.Begin(shader);

                    shader.Parameters["flash"].SetValue(1f);
                    shader.Parameters["flashReplace"].SetValue(1f);
                    shader.Parameters["flashColor"].SetValue(p.GetColor());

                    foreach (var d in MathUtils.Directions)
                    {
                        CallRender(pos + d, false);
                    }

                    Shaders.End();
                }
            }

            base.Render(shadow);
        }
Exemple #23
0
        public override void Render(bool shadow)
        {
            var p     = (Projectile)Entity;
            var scale = new Vector2(p.Scale);
            var a     = Rotation;
            var b     = p.FlashTimer > 0;
            var spr   = b ? Flash : Sprite;
            var or    = spr.Center;

            if (shadow)
            {
                Graphics.Render(spr, Entity.Center + new Vector2(0, 6),
                                a, or, scale);

                return;
            }

            var d       = p.Dying || (p.IndicateDeath && p.NearingDeath);
            var started = false;

            if (!d)
            {
                // fixme: p.Effect.GetColor()
                Graphics.Color = p.Color;
            }
            else if (Light == null)
            {
                var shader = Shaders.Entity;
                Shaders.Begin(shader);

                shader.Parameters["flash"].SetValue(1f);
                shader.Parameters["flashReplace"].SetValue(1f);
                shader.Parameters["flashColor"].SetValue(ColorUtils.White);

                started = true;
            }

            Graphics.Render(spr, Entity.Center, a, or, scale);
            Graphics.Color = ColorUtils.WhiteColor;

            if (started)
            {
                Shaders.End();
            }

            if (!b && Light != null)
            {
                if (p.Scourged)
                {
                    Graphics.Color = ProjectileColor.Red;
                }

                Graphics.Render(Light, Entity.Center, a, or, scale);

                if (p.Scourged)
                {
                    Graphics.Color = ColorUtils.WhiteColor;
                }
            }
        }
Exemple #24
0
 /// <summary />
 public ShaderLibrary(RenderHost renderHost)
 {
     Shaders.Add(ShaderDefault         = new Default.Shader(renderHost));
     Shaders.Add(ShaderPosition        = new Position.Shader(renderHost));
     Shaders.Add(ShaderPositionColor   = new PositionColor.Shader(renderHost));
     Shaders.Add(ShaderPositionTexture = new PositionTexture.Shader(renderHost));
 }
Exemple #25
0
 public void Load()
 {
     Loader.Load();
     Shaders.Load();
     OpenSauce.Load();
     Chimera.Load();
 }
Exemple #26
0
        public void LoadFormatsFile(string filePath)
        {
            FormatsFile file = new FormatsFile(filePath);

            var versionNode = file.Root.Properties.FirstOrDefault(n => n.Name == "Version");

            if (!Formats.CheckVersion(versionNode, Type, Version))
            {
                return;
            }

            var shadersNode = versionNode.Properties.FirstOrDefault(n => n.Name == "Shaders");

            if (shadersNode != null)
            {
                foreach (var shaderNode in shadersNode.Properties)
                {
                    Shader shader = new Shader();
                    shader.LoadFormatsNode(shaderNode);
                    Shaders.Add(shader);
                }
            }

            var skeletonNode = versionNode.Properties.FirstOrDefault(n => n.Name == "Skeleton");

            if (skeletonNode != null && skeletonNode.Value != "null")
            {
                /*
                 * Skeleton = new Skeleton();
                 * Skeleton.LoadFormatsFile(Path.Combine(Path.GetDirectoryName(file.FileName), skeletonNode.Value));
                 */
            }

            var lodGroupNode = versionNode.Properties.FirstOrDefault(n => n.Name == "LodGroup");

            if (lodGroupNode != null)
            {
                LodGroup = new LodGroup();
                LodGroup.LoadFormatsNode(lodGroupNode);
            }

            var jointsNode = versionNode.Properties.FirstOrDefault(n => n.Name == "Joints");

            if (jointsNode != null && jointsNode.Value != "null")
            {
            }

            var lightNode = versionNode.Properties.FirstOrDefault(n => n.Name == "Light");

            if (lightNode != null && lightNode.Value != "null")
            {
            }

            var boundNode = versionNode.Properties.FirstOrDefault(n => n.Name == "Bound");

            if (boundNode != null && boundNode.Value != "null")
            {
            }
        }
        public override void Render(bool shadow)
        {
            var origin = new Vector2(Sprite.Width / 2, Sprite.Height);
            var pos    = Entity.Position + origin + Offset;

            if (shadow)
            {
                Graphics.Render(Sprite, pos, 0, new Vector2(origin.X, 0), Scale, Graphics.ParseEffect(Flipped, !FlippedVerticaly));
                return;
            }

            if (Entity.TryGetComponent <ZComponent>(out var z))
            {
                pos -= new Vector2(0, z.Z);
            }

            if (Entity.TryGetComponent <InteractableComponent>(out var component) && component.OutlineAlpha > 0.05f)
            {
                var shader = Shaders.Entity;
                Shaders.Begin(shader);

                shader.Parameters["flash"].SetValue(component.OutlineAlpha);
                shader.Parameters["flashReplace"].SetValue(1f);
                shader.Parameters["flashColor"].SetValue(ColorUtils.White);

                foreach (var d in MathUtils.Directions)
                {
                    Graphics.Render(Sprite, pos + d, 0, origin, Scale);
                }

                Shaders.End();
            }

            var stopShader = false;

            if (Entity.TryGetComponent <HealthComponent>(out var health) && health.RenderInvt)
            {
                var i = health.InvincibilityTimer;

                if (i > health.InvincibilityTimerMax / 2f || i % 0.1f > 0.05f)
                {
                    var shader = Shaders.Entity;
                    Shaders.Begin(shader);

                    shader.Parameters["flash"].SetValue(1f);
                    shader.Parameters["flashReplace"].SetValue(1f);
                    shader.Parameters["flashColor"].SetValue(ColorUtils.White);

                    stopShader = true;
                }
            }

            Graphics.Render(Sprite, pos, 0, origin, Scale);

            if (stopShader)
            {
                Shaders.End();
            }
        }
Exemple #28
0
 public void Load()
 {
     Kernel.Load();    // kernel/loader bin
     Loader = spv3;    // loader bin. Copy static instance to local instance. Deprecate local instance?
     Shaders.Load();   // kernel bin, load from Kernel.hxe
     OpenSauce.Load(); // OS_Settings.user.xml
     Chimera.Load();   // chimera bin
 }
Exemple #29
0
 public void Save()
 {
     spv3 = Loader;    // loader bin. Copy local instance to static instance
     Shaders.Save();   // kernel bin, load from Kernel.hxe
     Kernel.Save();    // kernel/loader bin.
     OpenSauce.Save(); // OS_Settings.user.xml
     Chimera.Save();   // chimera bin
 }
Exemple #30
0
        public BasicProgram()
        {
            vertexShader   = shaderBuilder.VertexShader("Common", "Uniforms", "Vertex");
            fragmentShader = shaderBuilder.FragmentShader("Common", "Uniforms", "Fragment");

            Shaders.AddRange(vertexShader, fragmentShader);
            MustLink();
        }
Exemple #31
0
 public static Shader LoadShader(string vShaderPath, string fShaderPath, string name)
 {
     if (!Shaders.ContainsKey(name))
     {
         Shaders[name] = LoadShaderFromFile(vShaderPath, fShaderPath);
     }
     return(Shaders[name]);
 }
Exemple #32
0
        /// <summary>
        ///     Gets the shader specified by name. Returns null if it doesn't exist
        /// </summary>
        /// <param name="name">Name of the shader (with .*)</param>
        /// <returns></returns>
        public static ShaderProgram GetShader(string name)
        {
            ShaderProgram sp = null;

            Shaders.TryGetValue(name, out sp);

            return(sp);
        }
        /// <summary>
        /// 在OpenGL中创建VAO。
        /// 创建的过程就是执行一次渲染的过程。
        /// </summary>
        /// <param name="e"></param>
        /// <param name="shaderProgram"></param>
        public void Create(RenderEventArgs e, Shaders.ShaderProgram shaderProgram)
        {
            if (this.ID != 0)
            { throw new Exception(string.Format("ID[{0}] is already generated!", this.ID)); }

            uint[] buffers = new uint[1];
            GL.GenVertexArrays(1, buffers);

            this.ID = buffers[0];

            this.Bind();
            foreach (var item in this.bufferRenderers)
            {
                item.Render(e, shaderProgram);
            }
            this.Unbind();
        }
Exemple #34
0
        public void Initialize()
        {
            timah = 0;
            shader = new Shaders();
            currentSceneId = 0;

            ErrorCode ErrorCheckValue = GL.GetError();
            GL.ClearColor(0.0f, 0.0f, 0.0f, 0.0f);
            GL.Enable(EnableCap.DepthTest);
            ModelMatrix = Matrix4.Identity;
            ViewMatrix = Matrix4.Identity;
            ProjectionMatrix = Matrix4.Identity;
            GL.Enable(EnableCap.DepthTest);
            GL.DepthFunc(DepthFunction.Less);
            GL.Enable(EnableCap.CullFace);
            GL.CullFace(CullFaceMode.Back);
            GL.FrontFace(FrontFaceDirection.Ccw);

            shader.Initialize();

            ErrorCheckValue = GL.GetError();
            if (ErrorCheckValue != ErrorCode.NoError)
                Trace.WriteLine("Error at Creating Shaders: " + ErrorCheckValue);

            //Binding UniformLocations to variables found in shader files
            modelLocation = GL.GetUniformLocation(shader.ProgramIds[0], "ModelMatrix");
            viewLocation = GL.GetUniformLocation(shader.ProgramIds[0], "ViewMatrix");
            projectionLocation = GL.GetUniformLocation(shader.ProgramIds[0], "ProjectionMatrix");
            timeLocation = GL.GetUniformLocation(shader.ProgramIds[0], "time");
            resoLocation = GL.GetUniformLocation(shader.ProgramIds[0], "resolution");

            resolution = new Vector2(1280, 720);

            scenes = new Scene[10];
            scenes[0] = new Scene(1000);

            // Creating a VBO object now, and after it Indexed vb. In otherwords ElementBuffer
            scenes[0].setBackground(new VBOCube(0, 0, 0, 10.0f, 0, true));
            //scenes[0].addNewVBOCube(new VBOCube(0, 0, 0, 10.0f, 0, true));
            //scenes[0].addNewVBOCube(new VBOCube(0, 0, 0, 0.5f, 0));
            //scenes[0].addNewVBOCube(new VBOCube(0.5f,  0.5f, 0, 0.5f, 0));
            //scenes[0].addNewVBOCube(new VBOCube(0, -0.5f, 0, 0.5f, 0));
            initializeScene(0);

            scenes[1] = new Scene(10);
            scenes[1].setBackground(new VBOCube(0, 0, 0, 10.0f, 1, true));
            initializeScene(1);

            //scenes[5] = new Scene(10000);
            //scenes[5].setBackground(new VBOCube(0, 0, 0, 10.0f, 2, true));

            scenes[2] = new Scene(15);
            scenes[2].setBackground(new VBOCube(0, 0, 0, 10.0f, 3, true));
            scenes[2].addNewVBOCube(new VBOCube(0.7f, 0, 0, 2.0f, 2));
            scenes[2].addNewVBOCube(new VBOCube(-0.7f, 0, 0, 2.0f, 2));

            initializeScene(2);

            //JEEB!
            scenes[3] = new Scene(10); //monta cubea sul on maksimissaan, ei kasva automaattisesti ku lisäät
            scenes[3].setBackground(new VBOCube(0, 0, 0, ((float)Math.PI * 5), 5, true)); //"5" on sinun shader program
            //scenes[3].addNewVBOCube(new VBOCube(0.7f, 0, 0.4f, ((float)Math.PI / 3), 2)); // Dunno, liikkuva boksi vai ei
            initializeScene(3);
            scenes[4] = new Scene(10);
            scenes[4].setBackground(new VBOCube(0, 0, 0, 10.0f, 3, true));
            scenes[4].addNewVBOCube(new VBOCube(2, 0, 0, 0.5f, 0));

            initializeScene(4);

            scenes[7] = new Scene(10);
            scenes[7].setBackground(new VBOCube(0, 0, 0, 10.0f, 3, true));
            scenes[7].addNewVBOCube(new VBOCube(0.5f, 0, 0, 0.5f, 0));

            initializeScene(7);

            scenes[8] = new Scene(10);
            scenes[8].setBackground(new VBOCube(0, 0, 0, 10.0f, 3, true));
            scenes[8].addNewVBOCube(new VBOCube(-1.0f, -0.2f, -2.0f, 0.5f, 0));

            initializeScene(8);

            scenes[9] = new Scene(10);
            scenes[9].setBackground(new VBOCube(0, 0, 0, 10.0f, 3, true));
            scenes[9].addNewVBOCube(new VBOCube(1.0f, 0.3f, -1.0f, 0.5f, 0));

            initializeScene(9);
            UuNyaaBuilder builder2 = new UuNyaaBuilder(4);
            scenes[5] = builder2.sceneBuilder();
            initializeScene(5);

            UuNyaaBuilder builder = new UuNyaaBuilder(6);
            scenes[6] = builder.sceneBuilder();
            initializeScene(6);

            ErrorCheckValue = GL.GetError();
            if (ErrorCheckValue != ErrorCode.NoError)
                Trace.WriteLine("Error at Creating VBO: " + ErrorCheckValue);

            Matrix4 modelview = Matrix4.CreateTranslation(new Vector3(0, 0, -2));
            ViewMatrix = modelview;
        }
 /// <summary>
 /// 执行一次渲染的过程。
 /// </summary>
 /// <param name="e"></param>
 /// <param name="shaderProgram"></param>
 public void Render(RenderEventArgs e, Shaders.ShaderProgram shaderProgram)
 {
     this.Bind();
     this.indexBufferRenderer.Render(e, shaderProgram);
     this.Unbind();
 }
 public override void Render(RenderEventArgs e, Shaders.ShaderProgram shaderProgram)
 {
     GL.DrawArrays(this.Mode, this.FirstVertex, this.VertexCount);
 }
Exemple #37
0
 /// <summary>
 /// 执行此VBO的渲染操作。
 /// </summary>
 /// <param name="e"></param>
 /// <param name="shaderProgram">此VBO使用的shader program。</param>
 public abstract void Render(RenderEventArgs e, Shaders.ShaderProgram shaderProgram);
 public override void Render(RenderEventArgs e, Shaders.ShaderProgram shaderProgram)
 {
     GL.BindBuffer(GL.GL_ELEMENT_ARRAY_BUFFER, this.BufferID);
     GL.DrawElements(this.Mode, this.ElementCount, (uint)this.Type, IntPtr.Zero);
 }
Exemple #39
0
 public ByteCodeBind(Shaders _shaderType, ShaderBytecode _byteCode)
 {
     shaderType = _shaderType;
     byteCode = _byteCode;
 }
        //constructor, including shaders
        //This constructor is called from the LoadContent method, the ContentManager is passed in.
        public SimpleTerrainShaderProvider(Shaders.SimpleTerrain shader, Xen.Ex.Graphics.Content.ModelData model, ContentManager manager, string assetLocation)
        {
            //Generate a list of SOF textures for this model
            List<Texture2D> textures = new List<Texture2D>();

            assetLocation = assetLocation ?? "";
            if (assetLocation.Length > 0)
                assetLocation += "/";

            //loop through all the geometries in the model
            foreach (Xen.Ex.Graphics.Content.MeshData mesh in model.Meshes)
            {
                foreach (Xen.Ex.Graphics.Content.GeometryData geom in mesh.Geometry)
                {
                    //take the existing texture file name and add 'SOF' on the end, to find the skin/occlusion/face+skin texture

                    //Normally, XNA would add '_0' to the end of every texture asset, so each model has a unique copy of the
                    //asset (incase a model sets up different processing options for the asset).

                    //Xen supports the ability to set 'Manual Texture Import' property to true.
                    //When this is set to true, the model will not directly process the textures, it
                    //will simply assume they are processed. This requires each texture is manually added to the project.
                    //When this is true, the textures are not renamed.

                    //Try and load a texture with 'SOF' on the end.
                    Texture2D texture = manager.Load<Texture2D>(assetLocation + geom.MaterialData.TextureFileName + "SOF");
                    textures.Add(texture);
                }
            }

            //store the textures
            this.SofTextures = textures.ToArray();

            this.shader = shader;
        }