Exemplo n.º 1
0
 /// <summary>
 /// 描画します
 /// </summary>
 /// <param name="device"></param>
 /// <param name="weights"></param>
 public void Draw(PPDDevice device, float[] weights)
 {
     if (PPDSetting.Setting.ShaderDisabled)
     {
         return;
     }
     using (var tempWorkSpace = device.Workspace.Get())
     {
         effect.SetValue(weightsHandle, weights);
         effect.SetTexture(textureHandle, device.GetRenderTarget().Texture);
         var renderTarget = device.GetRenderTarget();
         device.SetRenderTarget(tempWorkSpace);
         device.Clear();
         var passCount = effect.Begin();
         effect.BeginPass(0);
         DrawQuad(device);
         effect.EndPass();
         device.SetRenderTarget(renderTarget);
         device.Clear();
         effect.SetTexture(textureHandle, tempWorkSpace.Texture);
         effect.BeginPass(1);
         DrawQuad(device);
         effect.EndPass();
         effect.End();
     }
 }
Exemplo n.º 2
0
            private void DrawGlass(PPDDevice device, AlphaBlendContext context, Matrix m,
                                   PrimitiveType primitiveType, int primitiveCount, int startIndex, int vertexCount)
            {
                using (var workspaceTexture = device.Workspace.Get())
                {
                    Flush();
#if BENCHMARK
                    using (var handler = Benchmark.Instance.Start("Copy"))
                    {
#endif
                    device.StretchRectangle(device.GetRenderTarget(), workspaceTexture);
#if BENCHMARK
                }
#endif
                    using (var tempWorkspaceTexture = device.Workspace.Get())
                        using (var tempWorkspaceTexture2 = device.Workspace.Get())
                        {
                            context.BlendMode = BlendMode.Normal;
                            var renderTarget = device.GetRenderTarget();
                            device.SetRenderTarget(tempWorkspaceTexture);
                            device.Clear();
                            device.SetRenderTarget(tempWorkspaceTexture2);
                            device.Clear();
                            device.SetRenderTarget(tempWorkspaceTexture);
                            DrawNotNormalBlend(device, context, m, tempWorkspaceTexture2, primitiveType, primitiveCount, startIndex, vertexCount);
                            device.SetRenderTarget(renderTarget);
                            device.GetModule <GlassFilter>().Draw(device, tempWorkspaceTexture.Texture, workspaceTexture.Texture);
                        }
                }
            }
Exemplo n.º 3
0
 /// <summary>
 /// 描画します
 /// </summary>
 /// <param name="device"></param>
 /// <param name="filters"></param>
 public void Draw(PPDDevice device, IEnumerable <ColorFilterBase> filters)
 {
     if (PPDSetting.Setting.ShaderDisabled)
     {
         return;
     }
     using (var temp = device.Workspace.Get())
     {
         var context = device.GetModule <AlphaBlendContextCache>().Get();
         context.Alpha     = 1;
         context.BlendMode = BlendMode.Normal;
         context.Vertex    = device.GetModule <ShaderCommon>().ScreenVertex;
         context.Texture   = temp.Texture;
         context.SetSRT(Matrix.Identity, 0);
         context.FilterCount   = 1;
         context.Transparent   = true;
         context.WorldDisabled = true;
         foreach (var filter in filters.Reverse())
         {
             device.StretchRectangle(device.GetRenderTarget(), temp);
             context.SetFilter(filter, 0);
             device.GetModule <AlphaBlend>().Draw(device, context);
         }
     }
 }
Exemplo n.º 4
0
        private void Draw(PPDDevice device, WorkspaceTexture filterTexture, Border border, BorderType type, float thickness)
        {
            using (var workspaceTexture = device.Workspace.Get())
            {
#if BENCHMARK
                using (var handler = Benchmark.Instance.Start("Copy"))
                {
#endif
                device.StretchRectangle(device.GetRenderTarget(), workspaceTexture);
#if BENCHMARK
            }
#endif
                effect.Technique = String.Format("{0}{1}Border", type, border.Blend);
                effect.SetTexture(filterTextureHandle, filterTexture.Texture);
                effect.SetTexture(lastRenderTargetTextureHandle, workspaceTexture.Texture);
                effect.SetValue(colorHandle, border.Color);
                var intThickness = (int)Math.Ceiling(thickness * 2 + 1);
                effect.SetValue(thicknessHandle, (float)intThickness);
                effect.SetValue(thickness2Handle, (int)Math.Pow(intThickness, 2));
                effect.SetValue(actualThicknessHandle, thickness);
                var passCount = effect.Begin();
                effect.BeginPass(0);
                effect.CommitChanges();
                device.VertexDeclaration = effect.VertexDeclaration;
                var screenVertex = device.GetModule <ShaderCommon>().ScreenVertex;
                device.SetStreamSource(screenVertex.VertexBucket.VertexBuffer);
                device.DrawPrimitives(PrimitiveType.TriangleStrip, screenVertex.Offset, 2);
                effect.EndPass();
                effect.End();
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// コピーします。
        /// </summary>
        /// <param name="device"></param>
        /// <param name="filterTexture"></param>
        /// <param name="size"></param>
        public void Draw(PPDDevice device, WorkspaceTexture filterTexture, int size)
        {
            using (var workspaceTexture = device.Workspace.Get())
                using (var xTexture = device.Workspace.Get())
                {
#if BENCHMARK
                    using (var handler = Benchmark.Instance.Start("Copy"))
                    {
#endif
                    device.StretchRectangle(device.GetRenderTarget(), workspaceTexture);
#if BENCHMARK
                }
#endif
                    var renderTarget = device.GetRenderTarget();
                    device.SetRenderTarget(xTexture);
                    device.Clear();
                    effect.Technique = "Mosaic";
                    effect.SetTexture(filterTextureHandle, filterTexture.Texture);
                    effect.SetTexture(lastRenderTargetTextureHandle, workspaceTexture.Texture);
                    effect.SetValue(sizeHandle, size);
                    var passCount = effect.Begin();
                    effect.BeginPass(0);
                    effect.CommitChanges();
                    device.VertexDeclaration = effect.VertexDeclaration;
                    var screenVertex = device.GetModule <ShaderCommon>().ScreenVertex;
                    device.SetStreamSource(screenVertex.VertexBucket.VertexBuffer);
                    device.DrawPrimitives(PrimitiveType.TriangleStrip, screenVertex.Offset, 2);
                    effect.EndPass();
                    device.SetRenderTarget(renderTarget);
                    effect.SetTexture(xTextureHandle, xTexture.Texture);
                    effect.BeginPass(1);
                    effect.CommitChanges();
                    device.DrawPrimitives(PrimitiveType.TriangleStrip, screenVertex.Offset, 2);
                    effect.EndPass();
                    effect.End();
                }
        }
Exemplo n.º 6
0
            private void DrawMask(PPDDevice device, AlphaBlendContext context, Matrix m, PrimitiveType primitiveType, int primitiveCount, int startIndex, int vertexCount)
            {
                using (var workspaceTexture = device.Workspace.Get())
                {
#if BENCHMARK
                    using (var handler = Benchmark.Instance.Start("Copy"))
                    {
#endif
                    device.StretchRectangle(device.GetRenderTarget(), workspaceTexture);
#if BENCHMARK
                }
#endif
#if BENCHMARK
                    using (var handler = Benchmark.Instance.Start("Effect Prepare"))
                    {
#endif
                    effect.Technique = maskTechniqueNames[new Tuple <MaskType, bool>(MaskType, context.MaskTexture != null)];
                    effect.SetTexture(textureHandle, context.Texture);
                    effect.SetTexture(lastRenderTargetTextureHandle, workspaceTexture.Texture);
                    effect.SetTexture(maskTextureHandle, context.MaskTexture);
                    effect.SetValue(drawInfoHandle, new DrawInfo
                    {
                        Matrix       = m,
                        Alpha        = context.Alpha,
                        OverlayColor = context.Overlay
                    });
#if BENCHMARK
                }
#endif

#if BENCHMARK
                    using (var handler = Benchmark.Instance.Start("Mask Draw"))
                    {
#endif
                    var passCount = effect.Begin();
                    effect.BeginPass(0);
                    effect.CommitChanges();
                    device.VertexDeclaration = effect.VertexDeclaration;
                    device.SetStreamSource(context.Vertex.VertexBucket.VertexBuffer);
                    device.DrawPrimitives(primitiveType, context.Vertex.Offset + startIndex, primitiveCount);
                    effect.EndPass();
                    effect.End();
                    effect.SetTexture(textureHandle, null);
#if BENCHMARK
                }
#endif
                }
            }
Exemplo n.º 7
0
            public override void Draw(PPDDevice device, AlphaBlendContext context, PrimitiveType primitiveType, int primitiveCount, int startIndex, int vertexCount)
            {
                Matrix m = context.SRTS[0];

                if (!context.WorldDisabled)
                {
                    m *= device.World;
                }
                for (var i = 1; i <= context.SRTDepth; i++)
                {
                    m = context.SRTS[i] * m;
                }
                if (IsMasking)
                {
                    DrawMask(device, context, m, primitiveType, primitiveCount, startIndex, vertexCount);
                }
                else
                {
                    if (context.BlendMode == BlendMode.Glass)
                    {
                        DrawGlass(device, context, m, primitiveType, primitiveCount, startIndex, vertexCount);
                    }
                    else
                    {
                        if (context.BlendMode == BlendMode.Normal && !context.Transparent && context.FilterCount == 0 && context.MaskTexture == null)
                        {
                            DrawNormalBlend(device, context, m, primitiveType, primitiveCount, startIndex, vertexCount);
                        }
                        else
                        {
                            using (var workspaceTexture = device.Workspace.Get())
                            {
                                Flush();
#if BENCHMARK
                                using (var handler = Benchmark.Instance.Start("Copy"))
                                {
#endif
                                device.StretchRectangle(device.GetRenderTarget(), workspaceTexture);
#if BENCHMARK
                            }
#endif
                                DrawNotNormalBlend(device, context, m, workspaceTexture, primitiveType, primitiveCount, startIndex, vertexCount);
                            }
                        }
                    }
                }
            }