• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C# Graphics.Shader类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中SFML.Graphics.Shader的典型用法代码示例。如果您正苦于以下问题:C# Shader类的具体用法?C# Shader怎么用?C# Shader使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



Shader类属于SFML.Graphics命名空间,在下文中一共展示了Shader类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: RenderStates

 ////////////////////////////////////////////////////////////
 /// <summary>
 /// Construct a set of render states with all its attributes
 /// </summary>
 /// <param name="blendMode">Blend mode to use</param>
 /// <param name="transform">Transform to use</param>
 /// <param name="texture">Texture to use</param>
 /// <param name="shader">Shader to use</param>
 ////////////////////////////////////////////////////////////
 public RenderStates(BlendMode blendMode, Transform transform, Texture texture, Shader shader)
 {
     BlendMode = blendMode;
     Transform = transform;
     Texture = texture;
     Shader = shader;
 }
开发者ID:mateuscezar,项目名称:netgore,代码行数:16,代码来源:RenderStates.cs


示例2: Initialize

        public void Initialize()
        {
            SelectedShader = new Shader(null, "Shader/SelectedShader.frag");
            SelectedState = new RenderStates(SelectedShader);

            AddControls();
        }
开发者ID:Kedreals,项目名称:MicrosoftGameJam2015AwesomeHurray,代码行数:7,代码来源:MainMenu.cs


示例3: BloomTest

        public BloomTest(RenderTexture target_tex, RenderTarget target)
        {
            _target = target;

            _bloom = new Shader(null, "bloom.glsl");
            _texture = new RenderTexture((uint)GlobalProps.Width, (uint)GlobalProps.Height);
            _states.BlendMode = BlendMode.Alpha;
            _states.Shader = _bloom;
            _states.Transform = Transform.Identity;
            _states.Texture = target_tex.Texture;
            _bloom.SetParameter("referenceTex", Shader.CurrentTexture);
            _bloom.SetParameter("pixelWidth", 4);
            _bloom.SetParameter("pixelHeight", 4);

            int w = GlobalProps.Width, h = GlobalProps.Height;
            Vector2f v0 = new Vector2f(0, 0);
            Vector2f v1 = new Vector2f(w, 0);
            Vector2f v2 = new Vector2f(w, h);
            Vector2f v3 = new Vector2f(0, h);

            _verts = new Vertex[4];
            _verts[0] = new Vertex(v0, Color.White, v0);
            _verts[1] = new Vertex(v1, Color.White, v1);
            _verts[2] = new Vertex(v2, Color.White, v2);
            _verts[3] = new Vertex(v3, Color.White, v3);
        }
开发者ID:Radnen,项目名称:sphere-sfml,代码行数:26,代码来源:BloomTest.cs


示例4: WaterRefractionEffect

        /// <summary>
        /// Initializes the <see cref="WaterRefractionEffect"/> class.
        /// </summary>
        static WaterRefractionEffect()
        {
            // Set the default values
            DefaultWaterAlpha = _defaultWaterAlpha;
            DefaultWaveSpeed = _defaultWaveSpeed;
            DefaultWaveIntensity = _defaultWaveIntensity;
            DefaultMagnification = _defaultMagnification;

            // Check if shaders are supported
            if (!Shader.IsAvailable)
            {
                const string msg =
                    "Unable to construct shader for `WaterRefractionEffect` - shaders are not supported on this system.";
                if (log.IsInfoEnabled)
                    log.InfoFormat(msg);
                return;
            }

            // Try to create the default shader
            try
            {
                var code = Resources.WaterRefractionEffectShader;
                _defaultShader = ShaderExtensions.LoadFromMemory(code);
            }
            catch (LoadingFailedException ex)
            {
                const string errmsg = "Failed to load the default Shader for WaterRefractionEffect. Exception: {0}";
                if (log.IsErrorEnabled)
                    log.ErrorFormat(errmsg, ex);
                Debug.Fail(string.Format(errmsg, ex));
            }
        }
开发者ID:Vizzini,项目名称:netgore,代码行数:35,代码来源:WaterRefractionEffect.cs


示例5: ExplosionRefractionEffect

        /// <summary>
        /// Initializes the <see cref="ExplosionRefractionEffect"/> class.
        /// </summary>
        static ExplosionRefractionEffect()
        {
            // Set the default values
            DefaultLifeSpan = _defaultLifeSpan;
            DefaultExpansionRate = new Vector2(1.5f, 1.5f);
            DefaultIntensity = _defaultIntensity;

            // Check if shaders are supported
            if (!Shader.IsAvailable)
            {
                const string msg =
                    "Unable to construct shader for `ExplosionRefractionEffect` - shaders are not supported on this system.";
                if (log.IsInfoEnabled)
                    log.InfoFormat(msg);
                return;
            }

            // Try to create the default shader
            try
            {
                var code = Resources.ExplosionRefractionEffectShader;
                _defaultShader = ShaderExtensions.LoadFromMemory(code);
            }
            catch (LoadingFailedException ex)
            {
                const string errmsg = "Failed to load the default Shader for ExplosionRefractionEffect. Exception: {0}";
                if (log.IsErrorEnabled)
                    log.ErrorFormat(errmsg, ex);
                Debug.Fail(string.Format(errmsg, ex));
            }
        }
开发者ID:mateuscezar,项目名称:netgore,代码行数:34,代码来源:ExplosionRefractionEffect.cs


示例6: Edge

        public Edge()
            : base("edge post-effect")
        {
            // Create the off-screen surface
            mySurface = new RenderTexture(800, 600);
            mySurface.Smooth = true;

            // Load the textures
            myBackgroundTexture = new Texture("resources/sfml.png");
            myBackgroundTexture.Smooth = true;
            myEntityTexture = new Texture("resources/devices.png");
            myEntityTexture.Smooth = true;

            // Initialize the background sprite
            myBackgroundSprite = new Sprite(myBackgroundTexture);
            myBackgroundSprite.Position = new Vector2f(135, 100);

            // Load the moving entities
            myEntities = new Sprite[6];
            for (int i = 0; i < myEntities.Length; ++i)
            {
                myEntities[i] = new Sprite(myEntityTexture, new IntRect(96 * i, 0, 96, 96));
            }

            // Load the shader
            myShader = new Shader(null, "resources/edge.frag");
            myShader.SetParameter("texture", Shader.CurrentTexture);
        }
开发者ID:kaldhu,项目名称:MyGameEngine,代码行数:28,代码来源:Shader.cs


示例7: Pixelate

        public Pixelate() : base("pixelate")
        {
            // Load the texture and initialize the sprite
            myTexture = new Texture("resources/background.jpg");
            mySprite = new Sprite(myTexture);

            // Load the shader
            myShader = new Shader(null, null, "resources/pixelate.frag");
            myShader.SetUniform("texture", Shader.CurrentTexture);
        }
开发者ID:SFML,项目名称:SFML.Net,代码行数:10,代码来源:Shader.cs


示例8: PointLight

        public PointLight(Color color, float power, float radius, Vector2f position)
        {
            Position = position;
            Color = color;
            Power = power;
            Radius = radius;

            VisMap = new VisbilityMap(Position, Radius);

            _shader = new Shader("shaders/lightShader.vert", "shaders/lightShader.frag");
        }
开发者ID:Tetramputechture,项目名称:Ending_0.1b,代码行数:11,代码来源:PointLight.cs


示例9: GraphicsDisplay

        public GraphicsDisplay(uint width, uint height)
        {
            Width = width;
            Height = height;

            _data = new Image(width, height, Color.Black);
            _dataTexture = new Texture(_data);
            _palette = new Image("Data/palette.png");
            _paletteTexture = new Texture(_palette);

            _display = new Sprite(_dataTexture);

            _renderer = new Shader("Data/display.vert", "Data/display.frag");
            _renderer.SetParameter("data", _dataTexture);
            _renderer.SetParameter("dataSize", width, height);
            _renderer.SetParameter("palette", _paletteTexture);
        }
开发者ID:Rohansi,项目名称:LoonyVM,代码行数:17,代码来源:GraphicsDisplay.cs


示例10: LightLayer

        public LightLayer(Vector2u gameRez, Vector2u windowRez)
        {
            Lights = new List<Light>();
            Polygons = new List<Polygon>();

            renText = new RenderTexture(gameRez.X, gameRez.Y);
            lightMap = new RenderTexture(gameRez.X, gameRez.Y);
            lightMap.Smooth = true;
            scene = new Texture(windowRez.X, windowRez.Y);

            lightShader = new Shader(null, "Content/shaders/light.frag");
            lightShader.SetParameter("screenHeight", gameRez.Y);
            lightState = new RenderStates(BlendMode.Add, Transform.Identity, renText.Texture, lightShader);

            shadowShader = new Shader(null, "Content/shaders/shadows.frag");
            //shadowState = new RenderStates(shadowShader);
            shadowState = new RenderStates(BlendMode.Multiply);
        }
开发者ID:Raptor2277,项目名称:CubePlatformer,代码行数:18,代码来源:LightLayer.cs


示例11: Game

        public Game()
        {
            win = win = new RenderWindow(new SFML.Window.VideoMode(800, 670), "Shader^^");
            win.Closed += (sender, e) => { ((RenderWindow)sender).Close(); };

            BackgroundGrayScale = new Sprite(new Texture("bg.png"));

            BackgroundMult = new Sprite(new Texture("wall.png"));
            Overlay = new Sprite(new Texture("lightMask.png"));
            t = new GameTime();

            GrayScaleShader = new Shader(null, "GrayScale.frag");
            GrayScaleState = new RenderStates(GrayScaleShader);

            MultTexture = new RenderTexture(800, 670);
            MultShader = new Shader(null, "Mult.frag");
            MultState = new RenderStates(MultShader);
            Add = new RenderStates(BlendMode.Add);
        }
开发者ID:endert,项目名称:Intro2D,代码行数:19,代码来源:Game.cs


示例12: LightEffectManager

        public LightEffectManager(Map parent)
        {
            Parent = parent;

            DynamicEffects = new List<LightEffect>();
            StaticEffects = new List<LightEffect>();

            GlobalColor = DEFAUT_GLOBAL_COLOR;

            IsRefreshed = false;

            RenderTexture = new RenderTexture(GameData.WINDOW_WIDTH, GameData.WINDOW_HEIGHT);
            BlurEffect = new Shader(GameData.DATAS_DEFAULT_PATH + "gfx/blur.sfx");
            BlurEffect.SetCurrentTexture("texture");
            BlurEffect.SetParameter("offset", 0.005F * SMOOTHNESS);

            Walls = null;
            OpacityBoxes = null;
        }
开发者ID:jpx,项目名称:blazera,代码行数:19,代码来源:LightEffectManager.cs


示例13: load_batch_shaders

        public static void load_batch_shaders(string folder)
        {
            //Debug.Log("Loading shaders from folder " + folder);
            Debug.StartLogGroup();
                DirectoryInfo dir = new DirectoryInfo(folder);

                if (dir.Exists)
                {
                    FileInfo[] files = dir.GetFiles("*.sfx", System.IO.SearchOption.AllDirectories);

                    for (int f = 0; f < files.Length; f++)
                    {
                        Debug.Log("Loading " + files[f].FullName);
                        bool succeeded = true;
                        Shader shader = null;
                        try
                        {
                            shader = new Shader(files[f].FullName);
                        }
                        catch (SFML.LoadingFailedException e)
                        {
                            succeeded = false;
                            throw;
                        }

                        if (succeeded)
                        {
                            Debug.Log("Success!");
                            var temp = files[f].Name;
                            var identifier = files[f].Name.Remove(files[f].Name.LastIndexOf('.'));
                            shaders.Add(identifier, shader);
                        }
                        else
                        {
                            Debug.Log("Shader loading failed");
                        }

                    }
                }
            Debug.EndLogGroup();
        }
开发者ID:AllMyKilobits,项目名称:XFramework,代码行数:41,代码来源:Loader.cs


示例14: Draw

        /// <summary>
        /// Draws a raw <see cref="SFML.Graphics.Sprite"/>. Recommended to avoid using when possible, but when needed,
        /// can provide a slight performance boost when drawing a large number of sprites with identical state.
        /// </summary>
        /// <param name="sprite">The <see cref="SFML.Graphics.Sprite"/> to draw.</param>
        /// <param name="shader">The <see cref="Shader"/> to use while drawing.</param>
        public virtual void Draw(SFML.Graphics.Sprite sprite, Shader shader = null)
        {
            if (sprite == null || !IsAssetValid(sprite.Image))
                return;

            _rt.Draw(sprite, shader);
        }
开发者ID:mateuscezar,项目名称:netgore,代码行数:13,代码来源:SpriteBatch.cs


示例15: Main

        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        static void Main()
        {
            // Create the main window
            RenderWindow window = new RenderWindow(new VideoMode(800, 600), "SFML.Net Shader");

            // Setup event handlers
            window.Closed     += new EventHandler(OnClosed);
            window.KeyPressed += new EventHandler<KeyEventArgs>(OnKeyPressed);

            // Check that the system can use shaders
            if (Shader.IsAvailable == false)
            {
                DisplayError(window);
                return;
            }

            // Create the render image
            RenderImage image = new RenderImage(window.Width, window.Height);

            // Load a background image to display
            Sprite background = new Sprite(new Image("resources/background.jpg"));
            background.Image.Smooth = false;

            // Load a sprite which we'll move into the scene
            Sprite entity = new Sprite(new Image("resources/sprite.png"));

            // Load the text font
            Font font = new Font("resources/arial.ttf");

            // Load the image needed for the wave effect
            Image waveImage = new Image("resources/wave.jpg");

            // Load all effects
            shaders = new Dictionary<string, Shader>();
            shaders["nothing"]  = new Shader("resources/nothing.sfx");
            shaders["blur"]     = new Shader("resources/blur.sfx");
            shaders["colorize"] = new Shader("resources/colorize.sfx");
            shaders["fisheye"]  = new Shader("resources/fisheye.sfx");
            shaders["wave"]     = new Shader("resources/wave.sfx");
            shaders["pixelate"] = new Shader("resources/pixelate.sfx");
            backgroundShader = new ShaderSelector(shaders);
            entityShader     = new ShaderSelector(shaders);
            globalShader     = new ShaderSelector(shaders);

            // Do specific initializations
            shaders["nothing"].SetTexture("texture", Shader.CurrentTexture);
            shaders["blur"].SetTexture("texture", Shader.CurrentTexture);
            shaders["blur"].SetParameter("offset", 0.0F);
            shaders["colorize"].SetTexture("texture", Shader.CurrentTexture);
            shaders["colorize"].SetParameter("color", 1.0F, 1.0F, 1.0F);
            shaders["fisheye"].SetTexture("texture", Shader.CurrentTexture);
            shaders["wave"].SetTexture("texture", Shader.CurrentTexture);
            shaders["wave"].SetTexture("wave", waveImage);
            shaders["pixelate"].SetTexture("texture", Shader.CurrentTexture);

            // Define a string for displaying current effect description
            shaderText = new Text();
            shaderText.Font = font;
            shaderText.Size = 20;
            shaderText.Position = new Vector2(5.0F, 0.0F);
            shaderText.Color = new Color(250, 100, 30);
            shaderText.DisplayedString = "Background shader: \"" + backgroundShader.Name + "\"\n" +
                                         "Flower shader: \"" + entityShader.Name + "\"\n" +
                                         "Global shader: \"" + globalShader.Name + "\"\n";

            // Define a string for displaying help
            Text infoText = new Text();
            infoText.Font = font;
            infoText.Size = 20;
            infoText.Position = new Vector2(5.0F, 500.0F);
            infoText.Color = new Color(250, 100, 30);
            infoText.DisplayedString = "Move your mouse to change the shaders' parameters\n" +
                                       "Press numpad 1 to change the background shader\n" +
                                       "Press numpad 2 to change the flower shader\n" +
                                       "Press numpad 3 to change the global shader";

            // Start the game loop
            float time = 0.0F;
            while (window.IsOpened())
            {
                // Process events
                window.DispatchEvents();

                // TOFIX -- using window.Input together with image.Draw apparently causes a memory corruption
                // Get the mouse position in the range [0, 1]
                //float x = window.Input.GetMouseX() / (float)window.Width;
                //float y = window.Input.GetMouseY() / (float)window.Height;
                float x = (float)(Math.Cos(time * 1.3) + 1) * 0.5F;
                float y = (float)(Math.Sin(time * 0.8) + 1) * 0.5F;

                // Update the shaders
                backgroundShader.Update(x, y);
                entityShader.Update(x, y);
                globalShader.Update(x, y);

                // Animate the sprite
                time += window.GetFrameTime();
//.........这里部分代码省略.........
开发者ID:vidjogamer,项目名称:ProjectTemplate,代码行数:101,代码来源:Shader.cs


示例16: Draw

 ////////////////////////////////////////////////////////////
 /// <summary>
 /// Draw something into the window with a shader
 /// </summary>
 /// <param name="objectToDraw">Object to draw</param>
 /// <param name="shader">Shader to apply</param>
 ////////////////////////////////////////////////////////////
 public void Draw(Drawable objectToDraw, Shader shader)
 {
     objectToDraw.Render(this, shader);
 }
开发者ID:Vizzini,项目名称:netgore,代码行数:11,代码来源:RenderWindow.cs


示例17: WaveBlur

        public WaveBlur()
            : base("wave + blur")
        {
            // Create the text
            myText = new Text();
            myText.DisplayedString = "Praesent suscipit augue in velit pulvinar hendrerit varius purus aliquam.\n" +
                                     "Mauris mi odio, bibendum quis fringilla a, laoreet vel orci. Proin vitae vulputate tortor.\n" +
                                     "Praesent cursus ultrices justo, ut feugiat ante vehicula quis.\n" +
                                     "Donec fringilla scelerisque mauris et viverra.\n" +
                                     "Maecenas adipiscing ornare scelerisque. Nullam at libero elit.\n" +
                                     "Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas.\n" +
                                     "Nullam leo urna, tincidunt id semper eget, ultricies sed mi.\n" +
                                     "Morbi mauris massa, commodo id dignissim vel, lobortis et elit.\n" +
                                     "Fusce vel libero sed neque scelerisque venenatis.\n" +
                                     "Integer mattis tincidunt quam vitae iaculis.\n" +
                                     "Vivamus fringilla sem non velit venenatis fermentum.\n" +
                                     "Vivamus varius tincidunt nisi id vehicula.\n" +
                                     "Integer ullamcorper, enim vitae euismod rutrum, massa nisl semper ipsum,\n" +
                                     "vestibulum sodales sem ante in massa.\n" +
                                     "Vestibulum in augue non felis convallis viverra.\n" +
                                     "Mauris ultricies dolor sed massa convallis sed aliquet augue fringilla.\n" +
                                     "Duis erat eros, porta in accumsan in, blandit quis sem.\n" +
                                     "In hac habitasse platea dictumst. Etiam fringilla est id odio dapibus sit amet semper dui laoreet.\n";
            myText.Font = GetFont();
            myText.CharacterSize = 22;
            myText.Position = new Vector2f(30, 20);

            // Load the shader
            myShader = new Shader("resources/wave.vert", "resources/blur.frag");
        }
开发者ID:kaldhu,项目名称:MyGameEngine,代码行数:30,代码来源:Shader.cs


示例18: StormBlink

        public StormBlink()
            : base("storm + blink")
        {
            Random random = new Random();

            // Create the points
            myPoints = new VertexArray(PrimitiveType.Points);
            for (int i = 0; i < 40000; ++i)
            {
                float x = (float)random.Next(0, 800);
                float y = (float)random.Next(0, 600);
                byte r = (byte)random.Next(0, 255);
                byte g = (byte)random.Next(0, 255);
                byte b = (byte)random.Next(0, 255);
                myPoints.Append(new Vertex(new Vector2f(x, y), new Color(r, g, b)));
            }

            // Load the shader
            myShader = new Shader("resources/storm.vert", "resources/blink.frag");
        }
开发者ID:kaldhu,项目名称:MyGameEngine,代码行数:20,代码来源:Shader.cs


示例19: Shader

 ////////////////////////////////////////////////////////////
 /// <summary>
 /// Construct the shader from another shader
 /// </summary>
 /// <param name="copy">Shader to copy</param>
 ////////////////////////////////////////////////////////////
 public Shader(Shader copy) :
     base(sfShader_Copy(copy.This))
 {
     foreach (KeyValuePair<string, Image> pair in copy.myTextures)
         myTextures[pair.Key] = copy.myTextures[pair.Key];
 }
开发者ID:wtfcolt,项目名称:game,代码行数:12,代码来源:Shader.cs


示例20: DrawString

        /// <summary>
        /// Adds a mutable sprite string to the batch of sprites to be rendered, specifying the font, output text,
        /// screen position, color tint, rotation, origin, scale, effects, and depth.
        /// </summary>
        /// <param name="font">The <see cref="Font"/> to use to draw.</param>
        /// <param name="text">The string to draw.</param>
        /// <param name="position">The location, in screen coordinates, where the text will be drawn.</param>
        /// <param name="color">The desired color of the text.</param>
        /// <param name="rotation">The angle, in radians, to rotate the text around the origin.</param>
        /// <param name="origin">The origin of the string. Specify (0,0) for the upper-left corner.</param>
        /// <param name="scale">Vector containing separate scalar multiples for the x- and y-axes of the sprite.</param>
        /// <param name="style">How to style the drawn string.</param>
        /// <param name="shader">The shader to use on the text being drawn.</param>
        public virtual void DrawString(Font font, string text, Vector2 position, Color color, float rotation, Vector2 origin,
                                       float scale, Text.Styles style = Text.Styles.Regular, Shader shader = null)
        {
            if (!IsAssetValid(font))
                return;

            DrawString(font, text, position, color, rotation, origin, new Vector2(scale), style, shader);
        }
开发者ID:mateuscezar,项目名称:netgore,代码行数:21,代码来源:SpriteBatch.cs



注:本文中的SFML.Graphics.Shader类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# Graphics.Sprite类代码示例发布时间:2022-05-26
下一篇:
C# Graphics.RenderWindow类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap