/// <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); } } }
public Circle(PPDDevice device, PPDFramework.Resource.ResourceManager resourceManager) : base(device) { loadCircleImageResource = resourceManager.GetResource <ImageResourceBase>(Utility.Path.Combine("logo", "circle.png")); loadCircleImageVertex = device.GetModule <ShaderCommon>().CreateVertex(362); invLoadCircleImageVertex = device.GetModule <ShaderCommon>().CreateVertex(362); var tempLoadCircleVertices = new ColoredTexturedVertex[362]; var tempInvLoadCircleVertices = new ColoredTexturedVertex[362]; for (var i = 0; i < tempLoadCircleVertices.Length; i++) { tempLoadCircleVertices[i] = new ColoredTexturedVertex(Vector3.Zero); tempInvLoadCircleVertices[i] = new ColoredTexturedVertex(Vector3.Zero); } tempLoadCircleVertices[0].Position = new Vector3(400, 225, 0.5f); tempLoadCircleVertices[0].TextureCoordinates = loadCircleImageResource.GetActualUV(new Vector2(0.5f)); for (int i = 1; i < tempLoadCircleVertices.Length; i++) { var rad = (float)((i - 1) * Math.PI / 180); var uv = new Vector2((float)Math.Sin(rad), -(float)Math.Cos(rad)); tempLoadCircleVertices[i].Position = new Vector3( 400 + loadCircleImageResource.Width / 2 * uv.X, 225 + loadCircleImageResource.Height / 2 * uv.Y, 0.5f); tempLoadCircleVertices[i].TextureCoordinates = loadCircleImageResource.GetActualUV((uv / 2 + new Vector2(0.5f))); } Array.Copy(tempLoadCircleVertices, 1, tempInvLoadCircleVertices, 0, 361); Array.Reverse(tempInvLoadCircleVertices, 0, tempInvLoadCircleVertices.Length); tempInvLoadCircleVertices[0] = tempLoadCircleVertices[0]; loadCircleImageVertex.Write(tempLoadCircleVertices); invLoadCircleImageVertex.Write(tempInvLoadCircleVertices); }
public AlphaBlendLegacy(PPDDevice device) { effect = EffectFactoryManager.Factory.FromMemory(device, device.GetShaderBytecode("AlphaBlend")); alphas = new SharpDX.Direct3D9.Texture[256]; paAlphas = new SharpDX.Direct3D9.Texture[256]; for (var i = 0; i < alphas.Length; i++) { alphas[i] = ((Texture.DX9.Texture)device.GetModule <ColorTextureAllcator>().CreateTexture(new Color4(1, 1, 1, i / 255f)))._Texture; paAlphas[i] = ((Texture.DX9.Texture)device.GetModule <ColorTextureAllcator>().CreateTexture(new Color4(i / 255f)))._Texture; } }
public ColorMarkInfo(PPDDevice device, GameComponent colorMark, Vector2 basePosition, PictureObject trace) : base(device) { ColorMark = colorMark; BasePosition = basePosition; if (trace == null) { } this.trace = trace; Pos1 = new Vector2[40]; Pos2 = new Vector2[40]; vertices1 = device.GetModule <ShaderCommon>().CreateVertex(80); vertices2 = device.GetModule <ShaderCommon>().CreateVertex(80); }
public LineRectangleComponent(PPDDevice device, PPDFramework.Resource.ResourceManager resourceManager, Color4 color) : base(device) { this.resourceManager = resourceManager; UpdateResource(color); borderThickness = 1; vertices = device.GetModule <ShaderCommon>().CreateVertex(10); }
/// <summary> /// 描画します。 /// </summary> /// <param name="device"></param> /// <param name="context"></param> /// <param name="primitiveType"></param> /// <param name="primitiveCount"></param> /// <param name="startIndex"></param> /// <param name="vertexCount"></param> public void Draw(PPDDevice device, AlphaBlendContext context, PrimitiveType primitiveType = PrimitiveType.TriangleStrip, int primitiveCount = 2, int startIndex = 0, int vertexCount = 4) { var cloneContext = device.GetModule <AlphaBlendContextCache>().Clone(context); DrawInternal(device, cloneContext, primitiveType, primitiveCount, startIndex, vertexCount); }
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(); } }
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); } } }
private void DrawQuad(PPDDevice device) { effect.CommitChanges(); device.VertexDeclaration = effect.VertexDeclaration; var screenVertex = device.GetModule <ShaderCommon>().ScreenVertex; device.SetStreamSource(screenVertex.VertexBucket.VertexBuffer); device.DrawPrimitives(PrimitiveType.TriangleStrip, screenVertex.Offset, 2); }
/// <summary> /// フィルタ処理です /// </summary> public override void Filter(PPDDevice device) { if (Filters.Count == 0) { return; } device.GetModule <Impl.ColorScreenFilter>().Draw(device, Filters); }
public override void Draw(PPDDevice device, AlphaBlendContext context, PrimitiveType primitiveType, int primitiveCount, int startIndex, int vertexCount) { if (context.Texture == null) { return; } #if BENCHMARK using (var handler = Benchmark.Instance.Start("Draw")) { #endif Matrix m = context.SRTS[0]; if (!context.WorldDisabled) { m *= device.World; } for (var i = 1; i <= context.SRTDepth; i++) { m = context.SRTS[i] * m; } var _device = (device.Device as SharpDX.Direct3D9.Device); _device.SetRenderState(SharpDX.Direct3D9.RenderState.SourceBlend, context.Texture.PA ? SharpDX.Direct3D9.Blend.One : SharpDX.Direct3D9.Blend.SourceAlpha); _device.SetTransform(SharpDX.Direct3D9.TransformState.World, m); _device.SetTexture(0, ((Texture.DX9.Texture)context.Texture)._Texture); var alpha = Math.Max(0, Math.Min(255, (int)(context.Alpha * 255))); _device.SetTexture(1, context.Texture.PA ? paAlphas[alpha] : alphas[alpha]); _device.SetTextureStageState(1, SharpDX.Direct3D9.TextureStage.ColorOperation, SharpDX.Direct3D9.TextureOperation.Modulate); _device.SetTextureStageState(1, SharpDX.Direct3D9.TextureStage.ColorArg1, SharpDX.Direct3D9.TextureArgument.Texture); _device.SetTextureStageState(1, SharpDX.Direct3D9.TextureStage.ColorArg2, SharpDX.Direct3D9.TextureArgument.Current); _device.SetTextureStageState(1, SharpDX.Direct3D9.TextureStage.AlphaOperation, SharpDX.Direct3D9.TextureOperation.Modulate); _device.SetTextureStageState(1, SharpDX.Direct3D9.TextureStage.AlphaArg1, SharpDX.Direct3D9.TextureArgument.Texture); _device.SetTextureStageState(1, SharpDX.Direct3D9.TextureStage.AlphaArg2, SharpDX.Direct3D9.TextureArgument.Current); if (context.Overlay.Alpha > 0) { var colorTexture = ((Texture.DX9.Texture)device.GetModule <ColorTextureAllcator>().CreateTexture(context.Overlay))._Texture; _device.SetTexture(2, colorTexture); _device.SetTextureStageState(2, SharpDX.Direct3D9.TextureStage.ColorOperation, SharpDX.Direct3D9.TextureOperation.Modulate); _device.SetTextureStageState(2, SharpDX.Direct3D9.TextureStage.ColorArg1, SharpDX.Direct3D9.TextureArgument.Texture); _device.SetTextureStageState(2, SharpDX.Direct3D9.TextureStage.ColorArg2, SharpDX.Direct3D9.TextureArgument.Current); _device.SetTextureStageState(2, SharpDX.Direct3D9.TextureStage.AlphaOperation, SharpDX.Direct3D9.TextureOperation.Modulate); _device.SetTextureStageState(2, SharpDX.Direct3D9.TextureStage.AlphaArg1, SharpDX.Direct3D9.TextureArgument.Texture); _device.SetTextureStageState(2, SharpDX.Direct3D9.TextureStage.AlphaArg2, SharpDX.Direct3D9.TextureArgument.Current); } else { _device.SetTexture(2, null); _device.SetTextureStageState(2, SharpDX.Direct3D9.TextureStage.ColorOperation, SharpDX.Direct3D9.TextureOperation.Disable); _device.SetTextureStageState(2, SharpDX.Direct3D9.TextureStage.AlphaOperation, SharpDX.Direct3D9.TextureOperation.Disable); } if (context?.Vertex?.VertexBucket?.VertexBuffer is VertexBuffer vertexBuffer) { device.DrawUserPrimitives(primitiveType, context.Vertex.Offset + startIndex, primitiveCount, vertexBuffer.Vertices); } #if BENCHMARK } #endif }
public MarkConnectionLine(PPDDevice device, Mark mk1, Mark mk2, MarkConnectionCommon markConnectionCommon) : base(device) { this.markConnectionCommon = markConnectionCommon; this.mk1 = mk1; this.mk2 = mk2; vertices = new VertexInfo[MarkConnectionCommon.ConnectionCount]; for (int i = 0; i < MarkConnectionCommon.ConnectionCount; i++) { vertices[i] = device.GetModule <ShaderCommon>().CreateVertex(MarkConnectionCommon.SplitCount); } }
private void CreateVertexBuffer(PPDDevice device) { vertices = device.GetModule <ShaderCommon>().CreateVertex(4); var rect = GetActualUVRectangle(0, 0, 1, 1); vertices.Write(new[] { new ColoredTexturedVertex(new Vector3(0, 0, 0.5f), rect.TopLeft), new ColoredTexturedVertex(new Vector3(Width, 0, 0.5f), rect.TopRight), new ColoredTexturedVertex(new Vector3(0, Height, 0.5f), rect.BottomLeft), new ColoredTexturedVertex(new Vector3(Width, Height, 0.5f), rect.BottomRight) }); }
public NormalExMarkGage(PPDDevice device, PictureObject trace, Vector2[] circlePoints) : base(device) { this.trace = trace; vertices = device.GetModule <ShaderCommon>().CreateVertex(circlePoints.Length); ColoredTexturedVertex[] dataVertices = new ColoredTexturedVertex[circlePoints.Length]; var uv = trace.ImageResource.GetActualUV(new Vector2(alpha, 0.5f)) + trace.ImageResource.HalfPixel; var color = PPDColors.White.ToBgra(); for (int i = 0; i < dataVertices.Length; i++) { dataVertices[i].Position = new Vector3(circlePoints[i].X, circlePoints[i].Y, 0.5f); dataVertices[i].TextureCoordinates = uv; dataVertices[i].Color = color; } vertices.Write(dataVertices); }
/// <summary> /// コピーします。 /// </summary> /// <param name="device"></param> /// <param name="filterTexture"></param> /// <param name="lastRenderTargetTexture"></param> public void Draw(PPDDevice device, TextureBase filterTexture, TextureBase lastRenderTargetTexture) { effect.SetTexture(filterTextureHandle, filterTexture); effect.SetTexture(lastRenderTargetFilterTextureHandle, lastRenderTargetTexture); 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(); }
/// <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(); } }
/// <summary> /// コンストラクタです /// </summary> /// <param name="device"></param> /// <param name="color"></param> public ColorTextureResource(PPDDevice device, Color4 color) { this.color = color; texture = device.GetModule <ColorTextureAllcator>().CreateTexture(color); }
/// <summary> /// フィルター処理です /// </summary> /// <param name="device"></param> public override void Filter(PPDDevice device) { device.GetModule <Impl.GaussianFilter>().Draw(device, weights); }
public override void Draw(PPDDevice device, WorkspaceTexture maskTexture) { device.GetModule <BorderFilter>().Draw(device, maskTexture, border); }
public object GetResource(string resourceName, ResourceKind resourceKind, Dictionary <string, object> param) { if (initialized) { Vector2 position = param != null && param.ContainsKey("Position") ? (Vector2)param["Position"] : Vector2.Zero; switch (resourceKind) { case ResourceKind.Effect: var path = String.Format("Effect\\{0}", resourceName); if (EffectLoader.IsCached(path)) { return(new EffectObject(device, resourceManager, EffectLoader.Load(null, path, f => { return; }, f => null)) { Position = position }); } return(null); case ResourceKind.Image: var isCenter = (bool)param["IsCenter"]; return(new PictureObject(device, resourceManager, pathManager.Combine("Image", resourceName), isCenter) { Position = position }); case ResourceKind.Sound: soundID++; var name = String.Format("Sound\\{0}_{1}", resourceName, soundID); var soundResource = new SoundResource(sound, name, soundDict[String.Format("Sound\\{0}", resourceName)]); resourceManager.Add(name, soundResource); return(soundResource); case ResourceKind.Number: var alignment = (Alignment)param["Alignment"]; var maxDigit = (int)param["MaxDigit"]; return(new NumberPictureObject(device, resourceManager, pathManager.Combine("Image", resourceName)) { Position = position, Alignment = alignment, MaxDigit = maxDigit }); case ResourceKind.Others: return(new MemoryStream(othersDict[String.Format("Others\\{0}", resourceName)])); case ResourceKind.Rectangle: return(new RectangleComponent(device, resourceManager, (Color4)param["Color"])); case ResourceKind.VertexBuffer: var vertexInfo = device.GetModule <ShaderCommon>().CreateVertex((int)param["VertexCount"]); createdVertices.Add(vertexInfo); return(vertexInfo); case ResourceKind.Polygon: var filename = pathManager.Combine("Image", resourceName); var imageResource = resourceManager.GetResource <ImageResourceBase>(filename); if (imageResource == null) { imageResource = (ImageResourceBase)resourceManager.Add(filename, ImageResourceFactoryManager.Factory.Create(device, filename, false)); } var primitiveType = (PrimitiveType)param["PrimitiveType"]; var primitiveCount = (int)param["PrimitiveCount"]; var startIndex = (int)param["StartIndex"]; var vertexCount = (int)param["VertexCount"]; return(new PolygonObject(device, imageResource, (VertexInfo)param["Vertex"]) { PrimitiveType = primitiveType, PrimitiveCount = primitiveCount, StartIndex = startIndex, VertexCount = vertexCount, }); } } return(null); }
/// <summary> /// 描画します。 /// </summary> /// <param name="device"></param> /// <param name="maskTexture"></param> public override void Draw(PPDDevice device, WorkspaceTexture maskTexture) { device.GetModule <MosaicFilter>().Draw(device, maskTexture, Size); }