static Vector3 CalculateProjectedPosition() { Vector3 directionFromSunNormalized = -MyGuiScreenGamePlay.Static.GetDirectionToSunNormalized(); // Tell the lensflare component where our camera is positioned. m_view = MyCamera.ViewMatrix; m_projection = MyCamera.ProjectionMatrix; // The sun is infinitely distant, so it should not be affected by the // position of the camera. Floating point math doesn't support infinitely // distant vectors, but we can get the same result by making a copy of our // view matrix, then resetting the view translation to zero. Pretending the // camera has not moved position gives the same result as if the camera // was moving, but the light was infinitely far away. If our flares came // from a local object rather than the sun, we would use the original view // matrix here. Matrix infiniteView = m_view; infiniteView.Translation = Vector3.Zero; // Project the light position into 2D screen space. Viewport viewport = MyMinerGame.Static.GraphicsDevice.Viewport; Vector3 projectedPosition = SharpDXHelper.ToXNA(viewport.Project(SharpDXHelper.ToSharpDX(-directionFromSunNormalized), SharpDXHelper.ToSharpDX(m_projection), SharpDXHelper.ToSharpDX(infiniteView), SharpDXHelper.ToSharpDX(Matrix.Identity))); return(projectedPosition); return(Vector3.Zero); }
internal override SharpDX.Direct3D11.Resource CreateTexture() { var description = new Texture3DDescription { Width = width, Height = height, Depth = depth, MipLevels = _levelCount, Format = SharpDXHelper.ToFormat(_format), BindFlags = BindFlags.ShaderResource, CpuAccessFlags = CpuAccessFlags.None, Usage = ResourceUsage.Default, OptionFlags = ResourceOptionFlags.None, }; if (renderTarget) { description.BindFlags |= BindFlags.RenderTarget; if (mipMap) { // Note: XNA 4 does not have a method Texture.GenerateMipMaps() // because generation of mipmaps is not supported on the Xbox 360. // TODO: New method Texture.GenerateMipMaps() required. description.OptionFlags |= ResourceOptionFlags.GenerateMipMaps; } } return(new SharpDX.Direct3D11.Texture3D(GraphicsDevice._d3dDevice, description)); }
private void DoReset() { var rnd = random.Value; HSBPalette palette = new HSBPalette(); // Create a new array of points for (int i = 0; i < _pointCount; i++) { var point = new Point(rnd.NextDouble(), rnd.NextDouble()); _points[i] = point; var vertices = SharpDXHelper.MakeRectangle((float)point.X, (float)point.Y, 0.05f, 0.05f); for (var j = 0; j < vertices.Count; j++) { _currentArray[i * 6 + j] = vertices[j]; } } // Replace the old array of points with the new array Points = _points; var temp = (Positions as DxVertex[]) ?? new DxVertex[_pointCount * 6]; Positions = _currentArray; PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(Positions))); _currentArray = temp; }
internal override SharpDX.Direct3D11.Resource CreateTexture() { // TODO: Move this to SetData() if we want to make Immutable textures! var desc = new SharpDX.Direct3D11.Texture2DDescription(); desc.Width = width; desc.Height = height; desc.MipLevels = _levelCount; desc.ArraySize = 1; desc.Format = SharpDXHelper.ToFormat(_format); desc.BindFlags = SharpDX.Direct3D11.BindFlags.ShaderResource; desc.CpuAccessFlags = SharpDX.Direct3D11.CpuAccessFlags.None; desc.SampleDescription.Count = 1; desc.SampleDescription.Quality = 0; desc.Usage = SharpDX.Direct3D11.ResourceUsage.Default; desc.OptionFlags = SharpDX.Direct3D11.ResourceOptionFlags.None; if (_renderTarget) { desc.BindFlags |= SharpDX.Direct3D11.BindFlags.RenderTarget; if (_mipmap) { // Note: XNA 4 does not have a method Texture.GenerateMipMaps() // because generation of mipmaps is not supported on the Xbox 360. // TODO: New method Texture.GenerateMipMaps() required. desc.OptionFlags |= SharpDX.Direct3D11.ResourceOptionFlags.GenerateMipMaps; } } if (_shared) desc.OptionFlags |= SharpDX.Direct3D11.ResourceOptionFlags.Shared; return new SharpDX.Direct3D11.Texture2D(GraphicsDevice._d3dDevice, desc); }
internal override SharpDX.Direct3D11.Resource CreateTexture() { var description = new Texture2DDescription { Width = size, Height = size, MipLevels = _levelCount, ArraySize = 6, // A texture cube is a 2D texture array with 6 textures. Format = SharpDXHelper.ToFormat(_format), BindFlags = BindFlags.ShaderResource, CpuAccessFlags = CpuAccessFlags.None, SampleDescription = { Count = 1, Quality = 0 }, Usage = ResourceUsage.Default, OptionFlags = ResourceOptionFlags.TextureCube }; if (_renderTarget) { description.BindFlags |= BindFlags.RenderTarget; if (_mipMap) { description.OptionFlags |= ResourceOptionFlags.GenerateMipMaps; } } return(new SharpDX.Direct3D11.Texture2D(GraphicsDevice._d3dDevice, description)); }
private void PlatformConstruct(GraphicsDevice graphicsDevice, int width, int height, bool mipMap, DepthFormat preferredDepthFormat, int preferredMultiSampleCount, RenderTargetUsage usage, bool shared) { _msSampleDescription = GraphicsDevice.GetSupportedSampleDescription(SharpDXHelper.ToFormat(this.Format), this.MultiSampleCount); GenerateIfRequired(); }
/// <summary> /// Updates emitter position, forward, up and velocity /// </summary> public static void UpdateValues(this Emitter emitter, ref Vector3 position, ref Vector3 forward, ref Vector3 up, ref Vector3 velocity) { emitter.Position = SharpDXHelper.ToSharpDX(position); emitter.OrientFront = SharpDXHelper.ToSharpDX(forward); emitter.OrientTop = SharpDXHelper.ToSharpDX(up); emitter.Velocity = SharpDXHelper.ToSharpDX(velocity); }
private void PlatformGetData <T>(int level, int left, int top, int right, int bottom, int front, int back, T[] data, int startIndex, int elementCount) where T : struct { // Create a temp staging resource for copying the data. // // TODO: Like in Texture2D, we should probably be pooling these staging resources // and not creating a new one each time. // var desc = new Texture3DDescription { Width = _width, Height = _height, Depth = _depth, MipLevels = 1, Format = SharpDXHelper.ToFormat(_format), BindFlags = BindFlags.None, CpuAccessFlags = CpuAccessFlags.Read, Usage = ResourceUsage.Staging, OptionFlags = ResourceOptionFlags.None, }; var d3dContext = GraphicsDevice._d3dContext; using (var stagingTex = new SharpDX.Direct3D11.Texture3D(GraphicsDevice._d3dDevice, desc)) { lock (d3dContext) { // Copy the data from the GPU to the staging texture. d3dContext.CopySubresourceRegion(GetTexture(), level, new ResourceRegion(left, top, front, right, bottom, back), stagingTex, 0); // Copy the data to the array. DataStream stream = null; try { var databox = d3dContext.MapSubresource(stagingTex, 0, MapMode.Read, MapFlags.None, out stream); // Some drivers may add pitch to rows or slices. // We need to copy each row separatly and skip trailing zeros. var currentIndex = startIndex; var elementSize = _format.GetSize(); var elementsInRow = right - left; var rowsInSlice = bottom - top; for (var slice = front; slice < back; slice++) { for (var row = top; row < bottom; row++) { stream.ReadRange(data, currentIndex, elementsInRow); stream.Seek(databox.RowPitch - (elementSize * elementsInRow), SeekOrigin.Current); currentIndex += elementsInRow; } stream.Seek(databox.SlicePitch - (databox.RowPitch * rowsInSlice), SeekOrigin.Current); } } finally { SharpDX.Utilities.Dispose(ref stream); } } } }
public static void Draw() { // We can fill vertex buffer only when in Draw LoadInDraw(); RasterizerState.CullClockwise.Apply(); DepthStencilState.None.Apply(); BlendState.Opaque.Apply(); if (MyRender.CurrentRenderSetup.BackgroundColor != null) { MyMinerGame.Static.GraphicsDevice.Clear(ClearFlags.Target, SharpDXHelper.ToSharpDX(MyRender.CurrentRenderSetup.BackgroundColor.Value), 1, 0); } else { MyEffectBackgroundCube effect = MyRender.GetEffect(MyEffects.BackgroundCube) as MyEffectBackgroundCube; effect.SetViewProjectionMatrix(MyCamera.ViewMatrixAtZero * m_backgroundProjectionMatrix); effect.SetBackgroundTexture(m_textureCube); effect.SetBackgroundColor(MySector.SunProperties.BackgroundColor); MyMinerGame.Static.GraphicsDevice.VertexDeclaration = MyVertexFormatPositionTexture3.VertexDeclaration; MyMinerGame.Static.GraphicsDevice.SetStreamSource(0, m_boxVertexBuffer, 0, MyVertexFormatPositionTexture3.Stride); effect.Begin(); MyMinerGame.Static.GraphicsDevice.DrawPrimitives(PrimitiveType.TriangleList, 0, BOX_TRIANGLES_COUNT); effect.End(); MyPerformanceCounter.PerCameraDraw.TotalDrawCalls++; } }
private void PlatformConstruct(GraphicsDevice graphicsDevice, int width, int height, bool mipMap, DepthFormat preferredDepthFormat, int preferredMultiSampleCount, RenderTargetUsage usage) { // Setup the multisampling description. var multisampleDesc = new SharpDX.DXGI.SampleDescription(1, 0); if (preferredMultiSampleCount > 1) { multisampleDesc.Count = preferredMultiSampleCount; multisampleDesc.Quality = (int)StandardMultisampleQualityLevels.StandardMultisamplePattern; } // Create a descriptor for the depth/stencil buffer. // Allocate a 2-D surface as the depth/stencil buffer. // Create a DepthStencil view on this surface to use on bind. using (var depthBuffer = new SharpDX.Direct3D11.Texture2D(graphicsDevice._d3dDevice, new Texture2DDescription { Format = SharpDXHelper.ToFormat(preferredDepthFormat), ArraySize = 1, MipLevels = 1, Width = width, Height = height, SampleDescription = multisampleDesc, BindFlags = BindFlags.DepthStencil, })) { // Create the view for binding to the device. _depthStencilView = new DepthStencilView(graphicsDevice._d3dDevice, depthBuffer, new DepthStencilViewDescription() { Format = SharpDXHelper.ToFormat(preferredDepthFormat), Dimension = DepthStencilViewDimension.Texture2D }); } }
/// <summary> /// SetupBlendState /// </summary> void SetupBlendState() { var rtbd = new RenderTargetBlendDescription(); bool enabled = true; if (BlendState.DstAlpha == Blend.Zero && BlendState.SrcAlpha == Blend.One && BlendState.DstColor == Blend.Zero && BlendState.SrcColor == Blend.One) { enabled = false; } rtbd.IsBlendEnabled = enabled; rtbd.BlendOperation = Converter.Convert(BlendState.ColorOp); rtbd.AlphaBlendOperation = Converter.Convert(BlendState.AlphaOp); rtbd.RenderTargetWriteMask = (ColorWriteMaskFlags)(int)BlendState.WriteMask; rtbd.DestinationBlend = Converter.Convert(BlendState.DstColor); rtbd.SourceBlend = Converter.Convert(BlendState.SrcColor); rtbd.DestinationAlphaBlend = Converter.Convert(BlendState.DstAlpha); rtbd.SourceAlphaBlend = Converter.Convert(BlendState.SrcAlpha); var bsd = new BlendStateDescription(); bsd.AlphaToCoverageEnable = false; bsd.IndependentBlendEnable = false; bsd.RenderTarget[0] = rtbd; blendFactor = SharpDXHelper.Convert(BlendState.BlendFactor); blendMsaaMask = BlendState.MultiSampleMask; blendState = new D3DBlendState(device.Device, bsd); }
protected internal virtual Texture2DDescription GetTexture2DDescription() { var desc = new Texture2DDescription(); desc.Width = width; desc.Height = height; desc.MipLevels = _levelCount; desc.ArraySize = ArraySize; desc.Format = SharpDXHelper.ToFormat(_format); desc.BindFlags = BindFlags.ShaderResource; desc.CpuAccessFlags = CpuAccessFlags.None; desc.SampleDescription = CreateSampleDescription(); desc.Usage = ResourceUsage.Default; desc.OptionFlags = ResourceOptionFlags.None; if (_shared) { desc.OptionFlags |= ResourceOptionFlags.Shared; } if (_mipmap) { desc.OptionFlags |= ResourceOptionFlags.GenerateMipMaps; desc.BindFlags |= BindFlags.RenderTarget; } return(desc); }
private void UpdateVertexFromSpriteInfo2(ref SpriteInfo spriteInfo, ref MyVertexFormatPositionTextureColor vertex, float deltaX, float deltaY) { var rotation = spriteInfo.Rotation != 0f ? new Vector2((float)Math.Cos(spriteInfo.Rotation), (float)Math.Sin(spriteInfo.Rotation)) : Vector2.UnitX; // Origin scale down to the size of the source texture var origin = spriteInfo.Origin; origin.X /= spriteInfo.Source.Width == 0f ? float.Epsilon : spriteInfo.Source.Width; origin.Y /= spriteInfo.Source.Height == 0f ? float.Epsilon : spriteInfo.Source.Height; for (int j = 0; j < 4; j++) { // Gets the corner and take into account the Flip mode. var corner = CornerOffsets[j]; // Calculate position on destination var position = new Vector2((corner.X - origin.X) * spriteInfo.Destination.Width, (corner.Y - origin.Y) * spriteInfo.Destination.Height); // Apply rotation and destination offset vertex.Position.X = spriteInfo.Destination.X + (position.X * rotation.X) - (position.Y * rotation.Y); vertex.Position.Y = spriteInfo.Destination.Y + (position.X * rotation.Y) + (position.Y * rotation.X); vertex.Position.Z = spriteInfo.Depth; vertex.Color = SharpDXHelper.ToXNA(spriteInfo.Color.ToVector4()); corner = CornerOffsets[j ^ (int)spriteInfo.SpriteEffects]; vertex.TexCoord.X = (spriteInfo.Source.X + corner.X * spriteInfo.Source.Width) * deltaX; vertex.TexCoord.Y = (spriteInfo.Source.Y + corner.Y * spriteInfo.Source.Height) * deltaY; } }
private Vector2 GetScreenPosition(MySolarSystemMapCamera camera, Vector3 worldPosition) { Vector3 target = SharpDXHelper.ToXNA(MyCamera.Viewport.Project(SharpDXHelper.ToSharpDX(worldPosition), SharpDXHelper.ToSharpDX(camera.GetProjectionMatrix()), SharpDXHelper.ToSharpDX(camera.GetViewMatrixAtZero()), SharpDXHelper.ToSharpDX(Matrix.Identity))); Vector2 projected2Dpoint = new Vector2(target.X, target.Y); return(MyGuiManager.GetNormalizedCoordinateFromScreenCoordinate(projected2Dpoint)); }
public void BeginDraw() { if (rotateCamera) { time += 0.02f; } SharpDXHelper.BeginDraw(RenderInfo); }
/// <summary> /// /// </summary> public void RestoreBackbuffer() { SetTargets(BackbufferDepth, BackbufferColor); lock (deviceContext) { deviceContext.Rasterizer.SetViewport(SharpDXHelper.Convert(new ViewportF(0, 0, BackbufferColor.Width, BackbufferColor.Height))); } }
/// <param name="setDefaultRenderInfo">PatchMeshRenderer.RenderInfoをSharpDXHelperがデフォルトで使用するrendering infoとして設定するか</param> public PatchMeshRenderer(IntPtr handle, Size size, bool setDefaultRenderInfo) { RenderInfo = SharpDXHelper.Initialize(handle, size, rawVertices, rawIndices, new Matrix(), "whitePixel.png"); whitePixel = SharpDXHelper.LoadTexture(RenderInfo, "whitePixel.png"); if (setDefaultRenderInfo) { SharpDXHelper.SetDefaultRenderInfo(RenderInfo); } }
private void PlatformConstruct(GraphicsDevice graphicsDevice, bool mipMap, SurfaceFormat preferredFormat, DepthFormat preferredDepthFormat, int preferredMultiSampleCount, RenderTargetUsage usage) { // Create one render target view per cube map face. _renderTargetViews = new RenderTargetView[6]; for (int i = 0; i < _renderTargetViews.Length; i++) { var renderTargetViewDescription = new RenderTargetViewDescription { Dimension = RenderTargetViewDimension.Texture2DArray, Format = SharpDXHelper.ToFormat(preferredFormat), Texture2DArray = { ArraySize = 1, FirstArraySlice = i, MipSlice = 0 } }; _renderTargetViews[i] = new RenderTargetView(graphicsDevice._d3dDevice, GetTexture(), renderTargetViewDescription); } // If we don't need a depth buffer then we're done. if (preferredDepthFormat == DepthFormat.None) { return; } var sampleDescription = new SampleDescription(1, 0); if (preferredMultiSampleCount > 1) { sampleDescription.Count = preferredMultiSampleCount; sampleDescription.Quality = (int)StandardMultisampleQualityLevels.StandardMultisamplePattern; } var depthStencilDescription = new Texture2DDescription { Format = SharpDXHelper.ToFormat(preferredDepthFormat), ArraySize = 1, MipLevels = 1, Width = size, Height = size, SampleDescription = sampleDescription, BindFlags = BindFlags.DepthStencil, }; using (var depthBuffer = new SharpDX.Direct3D11.Texture2D(graphicsDevice._d3dDevice, depthStencilDescription)) { var depthStencilViewDescription = new DepthStencilViewDescription { Dimension = DepthStencilViewDimension.Texture2D, Format = SharpDXHelper.ToFormat(preferredDepthFormat), }; _depthStencilView = new DepthStencilView(graphicsDevice._d3dDevice, depthBuffer, depthStencilViewDescription); } }
private void Form1_Load(object sender, EventArgs e) { // FLib.FileManager.OpenExplorer("output"); canvas.AllowDrop = true; renderer = new PatchMeshRenderer(canvas.Handle, canvas.ClientSize, true); // Magic2Dで作ったセグメントをロードしてパッチに変換 Dictionary <string, PatchSkeletalMesh> dict; Dictionary <string, Bitmap> bitmaps = new Dictionary <string, Bitmap>(); // dict = Magic2D.SegmentToPatch.LoadPatches("../../../../..", "Patchwork_resources/GJ_ED3/3_segmentation", bitmaps, 2); // dict = Magic2D.SegmentToPatch.LoadPatches(@"C:\Users\furaga\Documents\Research\Patchwork\gj_kirara2", "3_segmentation", bitmaps, 4); dict = Magic2D.SegmentToPatch.LoadPatches("./settings", "3_segmentation", bitmaps, 4); System.Diagnostics.Debug.Assert(dict.Count == bitmaps.Count); // テクスチャをアセットに登録 foreach (var kv in bitmaps) { var tex = SharpDXHelper.BitmapToTexture(kv.Value); resources.Add(kv.Key, tex); tex2bmp[tex] = kv.Value; } // パッチをキューに入れる for (int i = 0; i < dict.Count; i++) { string resourceKey = bitmaps.Keys.ElementAt(i); string textureKey = dict.Keys.ElementAt(i); PatchSkeletalMesh patch = dict.Values.ElementAt(i); renderQueryPool[resourceKey] = new RenderQuery(patch, new PatchTree(resourceKey), new List <string>() { textureKey }); } // パッチをリストに表示する foreach (var kv in bitmaps) { var patch = dict[kv.Key.Split(':')[1]]; var skl = patch.CopySkeleton(); var bmp = kv.Value; var bmp2 = DrawSkeltonOnBmp(skl, bmp); patchImageList.Images.Add(kv.Key, bmp2); patchView.Items.Add(kv.Key, kv.Key, kv.Key); } refSkeleton = PatchSkeleton.Load("./settings/refSkeleton.skl"); canvas.MouseWheel += canvas_MouseWheel; }
internal virtual void ResolveSubresource() { lock (GraphicsDevice._d3dContext) { GraphicsDevice._d3dContext.ResolveSubresource( GetMSTexture(), 0, GetTexture(), 0, SharpDXHelper.ToFormat(Format)); } }
internal void ResolveSubresource() { lock (GraphicsDevice._d3dContext) { GraphicsDevice._d3dContext.ResolveSubresource( this._texture, 0, _resolvedTexture._texture, 0, SharpDXHelper.ToFormat(_format)); } }
public Texture3D(GraphicsDevice graphicsDevice, int width, int height, int depth, bool mipMap, SurfaceFormat format) { if (graphicsDevice == null) { throw new ArgumentNullException("graphicsDevice"); } this.GraphicsDevice = graphicsDevice; this.width = width; this.height = height; this.depth = depth; this.levelCount = 1; #if OPENGL this.glTarget = TextureTarget.Texture3D; GL.GenTextures(1, out this.glTexture); GraphicsExtensions.CheckGLError(); GL.BindTexture(glTarget, glTexture); GraphicsExtensions.CheckGLError(); format.GetGLFormat(out glInternalFormat, out glFormat, out glType); GL.TexImage3D(glTarget, 0, glInternalFormat, width, height, depth, 0, glFormat, glType, IntPtr.Zero); GraphicsExtensions.CheckGLError(); if (mipMap) { throw new NotImplementedException("Texture3D does not yet support mipmaps."); } #elif DIRECTX if (mipMap) { this.levelCount = CalculateMipLevels(width, height, depth); } var description = new Texture3DDescription { Width = width, Height = height, Depth = depth, MipLevels = levelCount, Format = SharpDXHelper.ToFormat(format), BindFlags = BindFlags.ShaderResource, CpuAccessFlags = CpuAccessFlags.None, Usage = ResourceUsage.Default, OptionFlags = ResourceOptionFlags.None, }; _texture = new SharpDX.Direct3D11.Texture3D(graphicsDevice._d3dDevice, description); #endif }
private unsafe void PlatformGetData( CubeMapFace cubeMapFace, int level, Rectangle rect, Span <byte> destination) { // Create a temp staging resource for copying the data. // // TODO: Like in Texture2D, we should probably be pooling these staging resources // and not creating a new one each time. var min = Format.IsCompressedFormat() ? 4 : 1; var levelSize = Math.Max(Size >> level, min); var desc = new Texture2DDescription { Width = levelSize, Height = levelSize, MipLevels = 1, ArraySize = 1, Format = SharpDXHelper.ToFormat(Format), SampleDescription = new SampleDescription(1, 0), BindFlags = BindFlags.None, CpuAccessFlags = CpuAccessFlags.Read, Usage = ResourceUsage.Staging, OptionFlags = ResourceOptionFlags.None, }; var subresourceIndex = CalculateSubresourceIndex(cubeMapFace, level); var columns = rect.Width; var rows = rect.Height; var region = new ResourceRegion(rect.Left, rect.Top, 0, rect.Right, rect.Bottom, 1); var d3dContext = GraphicsDevice._d3dContext; using (var stagingTex = new SharpDX.Direct3D11.Texture2D(GraphicsDevice._d3dDevice, desc)) { lock (d3dContext) { // Copy the data from the GPU to the staging texture. d3dContext.CopySubresourceRegion(GetTexture(), subresourceIndex, region, stagingTex, 0); var elementSize = Format.GetSize(); if (Format.IsCompressedFormat()) { // for 4x4 block compression formats an element is one block, so elementsInRow // and number of rows are 1/4 of number of pixels in width and height of the rectangle columns /= 4; rows /= 4; } var box = d3dContext.MapSubresource(stagingTex, 0, MapMode.Read, MapFlags.None); GraphicsDevice.CopyResourceTo(Format, box, columns, rows, destination); } } }
public static void UpdateFromMainCamera(this Listener listener) { if (MySector.MainCamera == null) { return; } listener.Position = SharpDXHelper.ToSharpDX(MySector.MainCamera.Position); listener.OrientFront = -SharpDXHelper.ToSharpDX(MySector.MainCamera.ForwardVector); listener.OrientTop = SharpDXHelper.ToSharpDX(MySector.MainCamera.UpVector); listener.Velocity = SharpDXHelper.ToSharpDX(MySector.MainCamera.Velocity); }
private void GenerateIfRequired() { if (_renderTargetView != null) { return; } // Create a view interface on the rendertarget to use on bind. _renderTargetView = new RenderTargetView(GraphicsDevice._d3dDevice, GetTexture()); // If we don't need a depth buffer then we're done. if (DepthStencilFormat == DepthFormat.None) { return; } // Setup the multisampling description. var multisampleDesc = new SharpDX.DXGI.SampleDescription(1, 0); if (MultiSampleCount > 1) { multisampleDesc.Count = MultiSampleCount; multisampleDesc.Quality = (int)StandardMultisampleQualityLevels.StandardMultisamplePattern; } // Create a descriptor for the depth/stencil buffer. // Allocate a 2-D surface as the depth/stencil buffer. // Create a DepthStencil view on this surface to use on bind. using (var depthBuffer = new SharpDX.Direct3D11.Texture2D(GraphicsDevice._d3dDevice, new Texture2DDescription { Format = SharpDXHelper.ToFormat(DepthStencilFormat), ArraySize = 1, MipLevels = 1, Width = width, Height = height, SampleDescription = multisampleDesc, BindFlags = BindFlags.DepthStencil, })) { // Create the view for binding to the device. _depthStencilView = new DepthStencilView(GraphicsDevice._d3dDevice, depthBuffer, new DepthStencilViewDescription() { Format = SharpDXHelper.ToFormat(DepthStencilFormat), Dimension = DepthStencilViewDimension.Texture2D }); } }
void Draw(List <VertexPositionColorTexture> rawVertices, List <int> rawIndices, Texture2D texture, Size formSize, Vector3 cameraPosition, PrimitiveTopology primitiveType) { var worldViewProj = CameraMatrix(formSize, cameraPosition); worldViewProj.Transpose(); SharpDXHelper.UpdateVertexBuffer(RenderInfo, rawVertices); SharpDXHelper.UpdateIndexBuffer(RenderInfo, rawIndices); SharpDXHelper.UpdateCameraBuffer(RenderInfo, worldViewProj); if (texture != null) { SharpDXHelper.SwitchTexture(RenderInfo, texture); } SharpDXHelper.Draw(RenderInfo, primitiveType); }
private int GetMaxMultiSampleCount(GraphicsDevice device) { var format = SharpDXHelper.ToFormat(device.PresentationParameters.BackBufferFormat); var qualityLevels = 0; var maxLevel = 32; while (maxLevel > 0) { qualityLevels = ((SharpDX.Direct3D11.Device)device.Handle).CheckMultisampleQualityLevels(format, maxLevel); if (qualityLevels > 0) { break; } maxLevel /= 2; } return(maxLevel); }
public RenderTarget3D(GraphicsDevice graphicsDevice, int width, int height, int depth, bool mipMap, SurfaceFormat preferredFormat, DepthFormat preferredDepthFormat, int preferredMultiSampleCount, RenderTargetUsage usage) : base(graphicsDevice, width, height, depth, mipMap, preferredFormat, true) { DepthStencilFormat = preferredDepthFormat; MultiSampleCount = preferredMultiSampleCount; RenderTargetUsage = usage; // If we don't need a depth buffer then we're done. if (preferredDepthFormat == DepthFormat.None) { return; } #if DIRECTX // Setup the multisampling description. var multisampleDesc = new SharpDX.DXGI.SampleDescription(1, 0); if (preferredMultiSampleCount > 1) { multisampleDesc.Count = preferredMultiSampleCount; multisampleDesc.Quality = (int)StandardMultisampleQualityLevels.StandardMultisamplePattern; } // Create a descriptor for the depth/stencil buffer. // Allocate a 2-D surface as the depth/stencil buffer. // Create a DepthStencil view on this surface to use on bind. using (var depthBuffer = new SharpDX.Direct3D11.Texture2D(graphicsDevice._d3dDevice, new Texture2DDescription { Format = SharpDXHelper.ToFormat(preferredDepthFormat), ArraySize = 1, MipLevels = 1, Width = width, Height = height, SampleDescription = multisampleDesc, BindFlags = BindFlags.DepthStencil, })) { // Create the view for binding to the device. _depthStencilView = new DepthStencilView(graphicsDevice._d3dDevice, depthBuffer, new DepthStencilViewDescription() { Format = SharpDXHelper.ToFormat(preferredDepthFormat), Dimension = DepthStencilViewDimension.Texture2D }); } #endif // DIRECTX }
/// <summary> /// Updates emitter position, forward, up and velocity /// </summary> public static void UpdateValues(this Emitter emitter, Vector3 position, Vector3 forward, Vector3 up, Vector3 velocity, MyObjectBuilder_CueDefinition cue, int channelsCount) { emitter.Position = SharpDXHelper.ToSharpDX(position); emitter.OrientFront = SharpDXHelper.ToSharpDX(forward); emitter.OrientTop = SharpDXHelper.ToSharpDX(up); emitter.Velocity = SharpDXHelper.ToSharpDX(velocity); emitter.DopplerScaler = 1f; emitter.CurveDistanceScaler = cue.MaxDistance; if (m_currVolumeCurve != cue.VolumeCurve) { emitter.VolumeCurve = m_curves[(int)cue.VolumeCurve]; m_currVolumeCurve = cue.VolumeCurve; } emitter.InnerRadius = (channelsCount > 2) ? cue.MaxDistance : 0f; emitter.InnerRadiusAngle = (channelsCount > 2) ? 0.5f * SharpDX.AngleSingle.RightAngle.Radians : 0f; }
private int GetMaxMultiSampleCount(GraphicsDevice device) { var format = SharpDXHelper.ToFormat(device.PresentationParameters.BackBufferFormat); // Find the maximum supported level starting with the game's requested multisampling level // and halving each time until reaching 0 (meaning no multisample support). var qualityLevels = 0; var maxLevel = MultiSampleCountLimit; while (maxLevel > 0) { qualityLevels = device._d3dDevice.CheckMultisampleQualityLevels(format, maxLevel); if (qualityLevels > 0) { break; } maxLevel /= 2; } return(maxLevel); }