コード例 #1
0
        public PostEffectLightBloom()
        {
            var g        = Engine.Graphics;
            var baseCode = SwigObject.GetLightBloomShader((swig.GraphicsDeviceType)g.GraphicsDeviceType);

            var codeX     = "#define BLUR_X 1\n" + baseCode;
            var codeX_Lum = "#define BLUR_X 1\n#define LUM 1\n" + baseCode;
            var codeY     = "#define BLUR_Y 1\n" + baseCode;
            var codeSum   = "#define SUM 1\n" + baseCode;

            var shaderX = g.CreateShader2D(codeX);

            material2dX = g.CreateMaterial2D(shaderX);

            var shaderX_Lum = g.CreateShader2D(codeX_Lum);

            material2dX_Lum = g.CreateMaterial2D(shaderX_Lum);

            var shaderY = g.CreateShader2D(codeY);

            material2dY = g.CreateMaterial2D(shaderY);

            var shaderSum = g.CreateShader2D(codeSum);

            materialSum = g.CreateMaterial2D(shaderSum);

            string downsampleCode   = SwigObject.GetDownsampleShader((swig.GraphicsDeviceType)g.GraphicsDeviceType);
            var    downsampleShader = g.CreateShader2D(downsampleCode);

            downsample = g.CreateMaterial2D(downsampleShader);
        }
コード例 #2
0
        public PostEffectSepia()
        {
            var g      = Engine.Graphics;
            var shader = g.CreateShader2D(SwigObject.GetSepiaShader((swig.GraphicsDeviceType)g.GraphicsDeviceType));

            material2d = g.CreateMaterial2D(shader);
        }
コード例 #3
0
ファイル: Layer2D.cs プロジェクト: cannorin/Altseed
 /// <summary>
 /// 通常の描画に加えて専用のシェーダーを用いて2Dスプライトを描画する。
 /// </summary>
 /// <param name="upperLeftPos">テクスチャの左上の描画位置</param>
 /// <param name="upperRightPos">テクスチャの右上の描画位置</param>
 /// <param name="lowerRightPos">テクスチャの右下の描画位置</param>
 /// <param name="lowerLeftPos">テクスチャの左下の描画位置</param>
 /// <param name="upperLeftCol">テクスチャの左上の頂点色</param>
 /// <param name="upperRightCol">テクスチャの右上の頂点色</param>
 /// <param name="lowerRightCol">テクスチャの右下の頂点色</param>
 /// <param name="lowerLeftCol">テクスチャの左下の頂点色</param>
 /// <param name="upperLeftUV">テクスチャの左上のUV値</param>
 /// <param name="upperRightUV">テクスチャの右上のUV値</param>
 /// <param name="lowerRightUV">テクスチャの右下のUV値</param>
 /// <param name="lowerLeftUV">テクスチャの左下のUV値</param>
 /// <param name="material">表示に使用するマテリアル</param>
 /// <param name="alphaBlend">アルファブレンドの種類</param>
 /// <param name="priority">描画の優先順位(大きいほど前面に描画される)</param>
 /// <remarks>
 /// 専用のシェーダーを用いてスプライトを描画する。
 /// OnDrawAdditionallyの中以外では実行してはいけない。
 /// </remarks>
 public void DrawSpriteWithMaterialAdditionally(Vector2DF upperLeftPos, Vector2DF upperRightPos, Vector2DF lowerRightPos, Vector2DF lowerLeftPos,
                                                Color upperLeftCol, Color upperRightCol, Color lowerRightCol, Color lowerLeftCol,
                                                Vector2DF upperLeftUV, Vector2DF upperRightUV, Vector2DF lowerRightUV, Vector2DF lowerLeftUV,
                                                Material2D material, AlphaBlendMode alphaBlend, int priority)
 {
     coreLayer2D.DrawSpriteWithMaterialAdditionally(upperLeftPos, upperRightPos, lowerRightPos, lowerLeftPos, upperLeftCol, upperRightCol, lowerRightCol, lowerLeftCol, upperLeftUV, upperRightUV, lowerRightUV, lowerLeftUV, IG.GetMaterial2D(material), (swig.AlphaBlendMode)alphaBlend, priority);
 }
コード例 #4
0
 /// <summary>
 /// 通常の描画に加えて専用のシェーダーを用いて2Dスプライトを描画する。
 /// </summary>
 /// <param name="upperLeftPos">テクスチャの左上の描画位置</param>
 /// <param name="upperRightPos">テクスチャの右上の描画位置</param>
 /// <param name="lowerRightPos">テクスチャの右下の描画位置</param>
 /// <param name="lowerLeftPos">テクスチャの左下の描画位置</param>
 /// <param name="upperLeftCol">テクスチャの左上の頂点色</param>
 /// <param name="upperRightCol">テクスチャの右上の頂点色</param>
 /// <param name="lowerRightCol">テクスチャの右下の頂点色</param>
 /// <param name="lowerLeftCol">テクスチャの左下の頂点色</param>
 /// <param name="upperLeftUV">テクスチャの左上のUV値</param>
 /// <param name="upperRightUV">テクスチャの右上のUV値</param>
 /// <param name="lowerRightUV">テクスチャの右下のUV値</param>
 /// <param name="lowerLeftUV">テクスチャの左下のUV値</param>
 /// <param name="material">表示に使用するマテリアル</param>
 /// <param name="alphaBlend">アルファブレンドの種類</param>
 /// <param name="priority">描画の優先順位(大きいほど前面に描画される)</param>
 /// <remarks>
 /// 専用のシェーダーを用いてスプライトを描画する。
 /// OnDrawAdditionallyの中以外では実行してはいけない。
 /// </remarks>
 public void DrawSpriteWithMaterialAdditionally(Vector2DF upperLeftPos, Vector2DF upperRightPos, Vector2DF lowerRightPos, Vector2DF lowerLeftPos,
                                                Color upperLeftCol, Color upperRightCol, Color lowerRightCol, Color lowerLeftCol,
                                                Vector2DF upperLeftUV, Vector2DF upperRightUV, Vector2DF lowerRightUV, Vector2DF lowerLeftUV,
                                                Material2D material, AlphaBlendMode alphaBlend, int priority)
 {
     Layer.DrawSpriteWithMaterialAdditionally(upperLeftPos, upperRightPos, lowerRightPos, lowerLeftPos, upperLeftCol, upperRightCol, lowerRightCol, lowerLeftCol, upperLeftUV, upperRightUV, lowerRightUV, lowerLeftUV, material, alphaBlend, priority);
 }
コード例 #5
0
        public PostEffectLightBloom()
        {
            var g = Engine.Graphics;
            var baseCode = SwigObject.GetLightBloomShader((swig.GraphicsDeviceType)g.GraphicsDeviceType);

            var codeX = "#define BLUR_X 1\n" + baseCode;
            var codeX_Lum = "#define BLUR_X 1\n#define LUM 1\n" + baseCode;
            var codeY = "#define BLUR_Y 1\n" + baseCode;
            var codeSum = "#define SUM 1\n" + baseCode;

            var shaderX = g.CreateShader2D(codeX);
            material2dX = g.CreateMaterial2D(shaderX);

            var shaderX_Lum = g.CreateShader2D(codeX_Lum);
            material2dX_Lum = g.CreateMaterial2D(shaderX_Lum);

            var shaderY = g.CreateShader2D(codeY);
            material2dY = g.CreateMaterial2D(shaderY);

            var shaderSum = g.CreateShader2D(codeSum);
            materialSum = g.CreateMaterial2D(shaderSum);

            string downsampleCode = SwigObject.GetDownsampleShader((swig.GraphicsDeviceType)g.GraphicsDeviceType);
            var downsampleShader = g.CreateShader2D(downsampleCode);
            downsample = g.CreateMaterial2D(downsampleShader);
        }
コード例 #6
0
        public PostEffectGrayScale()
        {
            var g      = Engine.Graphics;
            var shader = g.CreateShader2D(CoreInstance.GetGrayScaleShader((swig.GraphicsDeviceType)g.GraphicsDeviceType));

            material2d = g.CreateMaterial2D(shader);
        }
コード例 #7
0
ファイル: InternalGetter.cs プロジェクト: wraikny/Altseed
 static public swig.Material2D GetMaterial2D(Material2D o)
 {
     if (o == null)
     {
         return(null);
     }
     return(o.CoreInstance);
 }
コード例 #8
0
        /// <summary>
        /// マテリアルを用いてテクスチャに画像を描画する。
        /// </summary>
        /// <param name="target">描画先</param>
        /// <param name="material">マテリアル</param>
        protected void DrawOnTexture2DWithMaterial(RenderTexture2D target, Material2D material)
        {
            if (disposed)
            {
                throw new ObjectDisposedException(GetType().FullName);
            }

            coreInstance.DrawOnTexture2DWithMaterial(IG.GetRenderTexture2D(target), IG.GetMaterial2D(material));
        }
コード例 #9
0
        public PostEffectGaussianBlur()
        {
            var g = Engine.Graphics;
            var baseShader = SwigObject.GetGaussianBlurShader((swig.GraphicsDeviceType)g.GraphicsDeviceType);
            var codeX = "#define BLUR_X 1\n" + baseShader;
            var codeY = "#define BLUR_Y 1\n" + baseShader;

            var shaderX = g.CreateShader2D(codeX);
            material2dX = g.CreateMaterial2D(shaderX);

            var shaderY = g.CreateShader2D(codeY);
            material2dY = g.CreateMaterial2D(shaderY);
        }
コード例 #10
0
        public PostEffectGaussianBlur()
        {
            var g          = Engine.Graphics;
            var baseShader = CoreInstance.GetGaussianBlurShader((swig.GraphicsDeviceType)g.GraphicsDeviceType);
            var codeX      = "#define BLUR_X 1\n" + baseShader;
            var codeY      = "#define BLUR_Y 1\n" + baseShader;

            var shaderX = g.CreateShader2D(codeX);

            material2dX = g.CreateMaterial2D(shaderX);

            var shaderY = g.CreateShader2D(codeY);

            material2dY = g.CreateMaterial2D(shaderY);
        }
コード例 #11
0
        /// <summary>
        /// マテリアル(2D)を生成する。
        /// </summary>
        /// <param name="shader">シェーダー</param>
        /// <returns>マテリアル(2D)</returns>
        public Material2D CreateMaterial2D(Shader2D shader)
        {
            var material = CoreInstance.CreateMaterial2D_(shader.CoreInstance);
            var p        = material.GetPtr();

            var existing = GC.Material2Ds.GetObject(p);

            if (existing != null)
            {
                return(existing);
            }

            var ret = new Material2D(material);

            GC.Material2Ds.AddObject(p, ret);
            return(ret);
        }
コード例 #12
0
ファイル: GC.cs プロジェクト: wraikny/Altseed
        internal static Material2D GenerateMaterial2D(swig.Material2D o, GenerationType type)
        {
            if (o == null)
            {
                return(null);
            }
            var p = o.GetPtr();

            var existing = GC.Material2Ds.GetObject(p);

            existing = GenerateInternal(existing, o, type);
            if (existing != null)
            {
                return(existing);
            }

            var ret = new Material2D(o);

            GC.Material2Ds.AddObject(p, ret);
            return(ret);
        }
コード例 #13
0
ファイル: Graphics.cs プロジェクト: Pctg-x8/Altseed
        /// <summary>
        /// マテリアル(2D)を生成する。
        /// </summary>
        /// <param name="shader">シェーダー</param>
        /// <returns>マテリアル(2D)</returns>
        public Material2D CreateMaterial2D(Shader2D shader)
        {
            var material = graphics.CreateMaterial2D_(shader.CoreInstance);
            var p = material.GetPtr();

            var existing = GC.Material2Ds.GetObject(p);
            if (existing != null)
            {
                return existing;
            }

            var ret = new Material2D(material);
            GC.Material2Ds.AddObject(p, ret);
            return ret;
        }
コード例 #14
0
        public override void OnDraw(RenderTexture2D dst, RenderTexture2D src)
        {
            Vector4DF weights1 = new Vector4DF();
            Vector4DF weights2 = new Vector4DF();

            float[] ws         = new float[8];
            float   total      = 0.0f;
            float   dispersion = intensity * intensity;

            for (int i = 0; i < 8; i++)
            {
                float pos = 1.0f + 2.0f * i;
                ws[i]  = (float)Math.Exp(-0.5f * pos * pos / dispersion);
                total += ws[i] * 2.0f;
            }
            weights1.X = ws[0] / total;
            weights1.Y = ws[1] / total;
            weights1.Z = ws[2] / total;
            weights1.W = ws[3] / total;
            weights2.X = ws[4] / total;
            weights2.Y = ws[5] / total;
            weights2.Z = ws[6] / total;
            weights2.W = ws[7] / total;

            var size   = src.Size;
            var format = src.Format;

            if (tempTexture0 == null ||
                (tempTexture0.Size != size / 2 || tempTexture0.Format != format))
            {
                if (format == TextureFormat.R32G32B32A32_FLOAT)
                {
                    tempTexture0 = Engine.Graphics.CreateRenderTexture2D(size.X / 2, size.Y / 2, TextureFormat.R32G32B32A32_FLOAT);
                    tempTexture1 = Engine.Graphics.CreateRenderTexture2D(size.X / 4, size.Y / 4, TextureFormat.R32G32B32A32_FLOAT);
                    tempTexture2 = Engine.Graphics.CreateRenderTexture2D(size.X / 8, size.Y / 8, TextureFormat.R32G32B32A32_FLOAT);
                    tempTexture3 = Engine.Graphics.CreateRenderTexture2D(size.X / 16, size.Y / 16, TextureFormat.R32G32B32A32_FLOAT);

                    downsampledTexture0 = Engine.Graphics.CreateRenderTexture2D(size.X / 2, size.Y / 2, TextureFormat.R32G32B32A32_FLOAT);
                    downsampledTexture1 = Engine.Graphics.CreateRenderTexture2D(size.X / 4, size.Y / 4, TextureFormat.R32G32B32A32_FLOAT);
                    downsampledTexture2 = Engine.Graphics.CreateRenderTexture2D(size.X / 8, size.Y / 8, TextureFormat.R32G32B32A32_FLOAT);
                    downsampledTexture3 = Engine.Graphics.CreateRenderTexture2D(size.X / 16, size.Y / 16, TextureFormat.R32G32B32A32_FLOAT);
                }
                else
                {
                    tempTexture0 = Engine.Graphics.CreateRenderTexture2D(size.X / 2, size.Y / 2, TextureFormat.R8G8B8A8_UNORM);
                    tempTexture1 = Engine.Graphics.CreateRenderTexture2D(size.X / 4, size.Y / 4, TextureFormat.R8G8B8A8_UNORM);
                    tempTexture2 = Engine.Graphics.CreateRenderTexture2D(size.X / 8, size.Y / 8, TextureFormat.R8G8B8A8_UNORM);
                    tempTexture3 = Engine.Graphics.CreateRenderTexture2D(size.X / 16, size.Y / 16, TextureFormat.R8G8B8A8_UNORM);

                    downsampledTexture0 = Engine.Graphics.CreateRenderTexture2D(size.X / 2, size.Y / 2, TextureFormat.R8G8B8A8_UNORM);
                    downsampledTexture1 = Engine.Graphics.CreateRenderTexture2D(size.X / 4, size.Y / 4, TextureFormat.R8G8B8A8_UNORM);
                    downsampledTexture2 = Engine.Graphics.CreateRenderTexture2D(size.X / 8, size.Y / 8, TextureFormat.R8G8B8A8_UNORM);
                    downsampledTexture3 = Engine.Graphics.CreateRenderTexture2D(size.X / 16, size.Y / 16, TextureFormat.R8G8B8A8_UNORM);
                }
            }

            downsample.SetTexture2D("g_texture", src);
            downsample.SetTextureFilterType("g_texture", TextureFilterType.Linear);
            downsample.SetVector2DF("g_offset", new Vector2DF(1.0f / (float)size.X, 1.0f / (float)size.Y));
            DrawOnTexture2DWithMaterial(downsampledTexture0, downsample);

            downsample.SetTexture2D("g_texture", downsampledTexture0);
            downsample.SetTextureFilterType("g_texture", TextureFilterType.Linear);
            downsample.SetVector2DF("g_offset", new Vector2DF(2.0f / (float)size.X, 2.0f / (float)size.Y));
            DrawOnTexture2DWithMaterial(downsampledTexture1, downsample);

            downsample.SetTexture2D("g_texture", downsampledTexture1);
            downsample.SetTextureFilterType("g_texture", TextureFilterType.Linear);
            downsample.SetVector2DF("g_offset", new Vector2DF(4.0f / (float)size.X, 4.0f / (float)size.Y));
            DrawOnTexture2DWithMaterial(downsampledTexture2, downsample);

            downsample.SetTexture2D("g_texture", downsampledTexture2);
            downsample.SetTextureFilterType("g_texture", TextureFilterType.Linear);
            downsample.SetVector2DF("g_offset", new Vector2DF(8.0f / (float)size.X, 8.0f / (float)size.Y));
            DrawOnTexture2DWithMaterial(downsampledTexture3, downsample);

            Material2D blurX = null;

            if (isLuminanceMode)
            {
                blurX = material2dX_Lum;
            }
            else
            {
                blurX = material2dX;
            }

            // ブラー1
            blurX.SetTexture2D("g_blurredTexture", downsampledTexture1);
            blurX.SetVector4DF("g_weight1", weights1);
            blurX.SetVector4DF("g_weight2", weights2);
            blurX.SetFloat("g_threshold", threshold);
            blurX.SetFloat("g_exposure", exposure);
            blurX.SetTextureFilterType("g_blurredTexture", TextureFilterType.Linear);
            DrawOnTexture2DWithMaterial(tempTexture1, blurX);

            material2dY.SetTexture2D("g_blurredTexture", tempTexture1);
            material2dY.SetVector4DF("g_weight1", weights1);
            material2dY.SetVector4DF("g_weight2", weights2);
            material2dY.SetTextureFilterType("g_blurredTexture", TextureFilterType.Linear);
            DrawOnTexture2DWithMaterial(downsampledTexture1, material2dY);

            // ブラー2
            blurX.SetTexture2D("g_blurredTexture", downsampledTexture2);
            blurX.SetVector4DF("g_weight1", weights1);
            blurX.SetVector4DF("g_weight2", weights2);
            blurX.SetFloat("g_threshold", threshold);
            blurX.SetFloat("g_exposure", exposure);
            blurX.SetTextureFilterType("g_blurredTexture", TextureFilterType.Linear);
            DrawOnTexture2DWithMaterial(tempTexture2, blurX);

            material2dY.SetTexture2D("g_blurredTexture", tempTexture2);
            material2dY.SetVector4DF("g_weight1", weights1);
            material2dY.SetVector4DF("g_weight2", weights2);
            material2dY.SetTextureFilterType("g_blurredTexture", TextureFilterType.Linear);
            DrawOnTexture2DWithMaterial(downsampledTexture2, material2dY);

            // ブラー3
            blurX.SetTexture2D("g_blurredTexture", downsampledTexture3);
            blurX.SetVector4DF("g_weight1", weights1);
            blurX.SetVector4DF("g_weight2", weights2);
            blurX.SetFloat("g_threshold", threshold);
            blurX.SetFloat("g_exposure", exposure);
            blurX.SetTextureFilterType("g_blurredTexture", TextureFilterType.Linear);
            DrawOnTexture2DWithMaterial(tempTexture3, blurX);

            material2dY.SetTexture2D("g_blurredTexture", tempTexture3);
            material2dY.SetVector4DF("g_weight1", weights1);
            material2dY.SetVector4DF("g_weight2", weights2);
            material2dY.SetTextureFilterType("g_blurredTexture", TextureFilterType.Linear);
            DrawOnTexture2DWithMaterial(downsampledTexture3, material2dY);

            // 合計
            materialSum.SetTexture2D("g_blurred0Texture", downsampledTexture1);
            materialSum.SetTexture2D("g_blurred1Texture", downsampledTexture2);
            materialSum.SetTexture2D("g_blurred2Texture", downsampledTexture3);
            materialSum.SetTexture2D("g_originalTexture", src);
            materialSum.SetTextureFilterType("g_blurred0Texture", TextureFilterType.Linear);
            materialSum.SetTextureFilterType("g_blurred1Texture", TextureFilterType.Linear);
            materialSum.SetTextureFilterType("g_blurred2Texture", TextureFilterType.Linear);
            materialSum.SetTextureFilterType("g_originalTexture", TextureFilterType.Linear);

            DrawOnTexture2DWithMaterial(dst, materialSum);
        }
コード例 #15
0
ファイル: PostEffect.cs プロジェクト: Pctg-x8/Altseed
 /// <summary>
 /// マテリアルを用いてテクスチャに画像を描画する。
 /// </summary>
 /// <param name="target">描画先</param>
 /// <param name="material">マテリアル</param>
 public void DrawOnTexture2DWithMaterial(RenderTexture2D target, Material2D material)
 {
     SwigObject.DrawOnTexture2DWithMaterial(IG.GetRenderTexture2D(target), IG.GetMaterial2D(material));
 }
コード例 #16
0
 /// <summary>
 /// マテリアルを用いてテクスチャに画像を描画する。
 /// </summary>
 /// <param name="target">描画先</param>
 /// <param name="material">マテリアル</param>
 public void DrawOnTexture2DWithMaterial(RenderTexture2D target, Material2D material)
 {
     SwigObject.DrawOnTexture2DWithMaterial(IG.GetRenderTexture2D(target), IG.GetMaterial2D(material));
 }
コード例 #17
0
ファイル: CustomPostEffect.cs プロジェクト: Pctg-x8/Altseed
            public PostEffect(asd.Graphics g)
            {
                if (g.GraphicsDeviceType == GraphicsDeviceType.DirectX11)
                {
                    m_shader = g.CreateShader2D(
                        shader2d_dx_ps
                        );
                }
                else if (g.GraphicsDeviceType == GraphicsDeviceType.OpenGL)
                {
                    m_shader = g.CreateShader2D(
                        shader2d_gl_ps
                        );
                }
                else
                {
                    throw new Exception();
                }

                m_material2d = g.CreateMaterial2D(m_shader);
            }
コード例 #18
0
ファイル: PostEffectSepia.cs プロジェクト: Pctg-x8/Altseed
 public PostEffectSepia()
 {
     var g = Engine.Graphics;
     var shader = g.CreateShader2D(SwigObject.GetSepiaShader((swig.GraphicsDeviceType)g.GraphicsDeviceType));
     material2d = g.CreateMaterial2D(shader);
 }
コード例 #19
0
ファイル: InternalGetter.cs プロジェクト: Pctg-x8/Altseed
 public static swig.Material2D GetMaterial2D(Material2D o)
 {
     if (o == null) return null;
     return o.CoreInstance;
 }