public void SetAsShaderInput(Effect shader) { SharpDX.Toolkit.Graphics.SamplerState sampler = context.Device.SamplerStates.LinearClamp; shader.Parameters["gbDepthTexture"].SetResource(DepthTarget); shader.Parameters["gbDepthSampler"].SetResource(sampler); shader.Parameters["gbNormalTexture"].SetResource(NormalTarget); shader.Parameters["gbNormalSampler"].SetResource(sampler); shader.Parameters["gbAlbedoTexture"].SetResource(AlbedoTarget); shader.Parameters["gbAlbedoSampler"].SetResource(sampler); }
static SamplerState() { AnisotropicClamp = new SamplerState() { Filter = TextureFilter.Anisotropic, AddressU = TextureAddress.Clamp, AddressV = TextureAddress.Clamp, AddressW = TextureAddress.Clamp, }; AnisotropicWrap = new SamplerState() { Filter = TextureFilter.Anisotropic, AddressU = TextureAddress.Wrap, AddressV = TextureAddress.Wrap, AddressW = TextureAddress.Wrap, }; LinearClamp = new SamplerState() { Filter = TextureFilter.Linear, AddressU = TextureAddress.Clamp, AddressV = TextureAddress.Clamp, AddressW = TextureAddress.Clamp, }; LinearWrap = new SamplerState() { Filter = TextureFilter.Linear, AddressU = TextureAddress.Wrap, AddressV = TextureAddress.Wrap, AddressW = TextureAddress.Wrap, }; PointClamp = new SamplerState() { Filter = TextureFilter.Linear, AddressU = TextureAddress.Clamp, AddressV = TextureAddress.Clamp, AddressW = TextureAddress.Clamp, }; PointWrap = new SamplerState() { Filter = TextureFilter.Linear, AddressU = TextureAddress.Wrap, AddressV = TextureAddress.Wrap, AddressW = TextureAddress.Wrap, }; }
private SharpDX.Toolkit.Graphics.SamplerState GetState() { if (sampler == null) { SharpDX.Direct3D11.SamplerStateDescription desc = new SharpDX.Direct3D11.SamplerStateDescription(); desc.Filter = SharpDX.Direct3D11.Filter.ComparisonMinMagLinearMipPoint; desc.AddressU = SharpDX.Direct3D11.TextureAddressMode.Border; desc.AddressV = SharpDX.Direct3D11.TextureAddressMode.Border; desc.AddressW = SharpDX.Direct3D11.TextureAddressMode.Border; desc.BorderColor = SharpDX.Color4.Black; desc.ComparisonFunction = SharpDX.Direct3D11.Comparison.LessEqual; sampler = SharpDX.Toolkit.Graphics.SamplerState.New(device, desc); } return(sampler); }
public TerrainRaymarcher(GraphicsDevice graphicsDevice, float aspectRatio) { var shaderMacros = new List<EffectData.ShaderMacro>(); #if CONEMAPPING_RAYMARCH computeRelaxedConeShader = new ShaderAutoReload("shader/computerelaxedconemap.fx", GraphicsDevice); shaderMacros.Add(new EffectData.ShaderMacro("CONEMAPPING_RAYMARCH", "1")); #else maxmapGenShader = new ShaderAutoReload("shader/maxmapgen.fx", graphicsDevice); #endif terrainShader = new ShaderAutoReload("shader/terrainRaymarch.fx", graphicsDevice, shaderMacros); terrainShader.Effect.Parameters["ScreenAspectRatio"].SetValue(aspectRatio ); terrainShader.OnReload += () => SetupTerrainConstants(graphicsDevice); // linear sampler var samplerStateDesc = SharpDX.Direct3D11.SamplerStateDescription.Default(); samplerStateDesc.AddressV = SharpDX.Direct3D11.TextureAddressMode.Border; samplerStateDesc.AddressU = SharpDX.Direct3D11.TextureAddressMode.Border; samplerStateDesc.Filter = SharpDX.Direct3D11.Filter.MinMagMipLinear; samplerStateDesc.BorderColor = Color4.Black; linearBorderSamplerState = SamplerState.New(graphicsDevice, "TerrainHeightmapSampler", samplerStateDesc); }
public VisionEffect(Effect effect, SamplerState samplerState = null) { GraphicsDevice = effect.GraphicsDevice; Effect = effect; Name = effect.Name; _epTextureSampler = effect.Parameters["TextureSampler"]; if(_epTextureSampler!=null) Sampler = samplerState ?? GraphicsDevice.SamplerStates.LinearWrap; _epWorld = effect.Parameters["World"]; _epWorldInverseTranspose = effect.Parameters["WorldInverseTranspose"]; _epView = effect.Parameters["View"]; _epProjection = effect.Parameters["Projection"]; _epCameraPosition = effect.Parameters["CameraPosition"]; _epClipPlane = effect.Parameters["ClipPlane"]; _epSunlightDirection = effect.Parameters["SunlightDirection"]; _epTexture = effect.Parameters["Texture"]; _epDiffuseColor = effect.Parameters["DiffuseColor"]; _epDoShadowMapping = effect.Parameters["DoShadowMapping"]; _epShadowMap = effect.Parameters["ShadowMap"]; _epShadowViewProjection = effect.Parameters["ShadowViewProjection"]; _epShadowFarPlane = effect.Parameters["ShadowFarPlane"]; _epShadowMult = effect.Parameters["ShadowMult"]; _techStandard = effect.Techniques["TechStandard"]; _techClipPlane = effect.Techniques["TechClipPlane"]; _techDepthMap = effect.Techniques["TechDepthMap"]; //Debug.Assert( _epView != null ); //Debug.Assert(_techDepthMap != null); if ( _epSunlightDirection != null) _epSunlightDirection.SetValue(VisionContent.SunlightDirection); }
public ShadowMapComparisonSampler(FearGraphicsDevice dev) { device = dev.Device; sampler = null; }
public void SetSampler(SharpDX.Toolkit.Graphics.SamplerState samplerState, string param) { gbufferEffect.Parameters[param].SetResource(samplerState); }
protected override void LoadContent() { _spriteBatch = ToDisposeContent(new SpriteBatch(GraphicsDevice)); _depthRectangle = new Rectangle(0, 0, RoomAliveToolkit.Kinect2Calibration.depthImageWidth, RoomAliveToolkit.Kinect2Calibration.depthImageHeight); int depthWidth = RoomAliveToolkit.Kinect2Calibration.depthImageWidth; int depthHeight = RoomAliveToolkit.Kinect2Calibration.depthImageHeight; _roomAliveEffect = Content.Load <Effect>("Holographic"); _fromUintEffect = Content.Load <Effect>("FromUint"); _gaussianEffect = Content.Load <Effect>("BilateralFilter"); _colorSamplerState = ToDisposeContent(SharpDX.Toolkit.Graphics.SamplerState.New(this.GraphicsDevice, new SamplerStateDescription() { Filter = Filter.MinMagMipLinear, AddressU = TextureAddressMode.Border, AddressV = TextureAddressMode.Border, AddressW = TextureAddressMode.Border, BorderColor = new SharpDX.Color4(0.5f, 0.5f, 0.5f, 1.0f), ComparisonFunction = Comparison.Never, MaximumAnisotropy = 16, MipLodBias = 0, MinimumLod = -float.MaxValue, MaximumLod = float.MaxValue })); List <VertexPosition> vertices = new List <VertexPosition>(); List <int> indices = new List <int>(); // vertex buffer if (_camera.calibration != null) { var table = _camera.calibration.ComputeDepthFrameToCameraSpaceTable(); for (int i = 0; i < depthHeight; i++) { for (int j = 0; j < depthWidth; j++) { var point = table[RoomAliveToolkit.Kinect2Calibration.depthImageWidth * i + j]; vertices.Add(new VertexPosition(new SharpDX.Vector4(point.X, point.Y, j, i))); } } for (int i = 0; i < depthHeight - 1; i++) { for (int j = 0; j < depthWidth - 1; j++) { int baseIndex = depthWidth * i + j; indices.Add(baseIndex); indices.Add(baseIndex + depthWidth + 1); indices.Add(baseIndex + 1); indices.Add(baseIndex); indices.Add(baseIndex + depthWidth); indices.Add(baseIndex + depthWidth + 1); } } _vertexArray = vertices.ToArray(); _indexArray = indices.ToArray(); // build the plane geometry of the specified size and subdivision segments _geometry = ToDisposeContent(new GeometricPrimitive <VertexPosition>(GraphicsDevice, _vertexArray, _indexArray, true)); } else { Console.WriteLine("Camera '{0}' is missing calibration", _camera.name); Visible = false; Enabled = false; } if (!string.IsNullOrEmpty(_colorImageFilePath)) { _tex2DColorImage1 = SharpDX.Toolkit.Graphics.Texture2D.Load(GraphicsDevice, _colorImageFilePath, TextureFlags.ShaderResource, ResourceUsage.Dynamic); _tex2DColorImage2 = SharpDX.Toolkit.Graphics.Texture2D.Load(GraphicsDevice, _colorImageFilePath, TextureFlags.ShaderResource, ResourceUsage.Dynamic); } _imagingFactory = new SharpDX.WIC.ImagingFactory(); if (!string.IsNullOrEmpty(_depthImageFilePath)) { var depthImage = new RoomAliveToolkit.ShortImage(RoomAliveToolkit.Kinect2Calibration.depthImageWidth, RoomAliveToolkit.Kinect2Calibration.depthImageHeight); RoomAliveToolkit.ProjectorCameraEnsemble.LoadFromTiff(_imagingFactory, depthImage, _depthImageFilePath); UpdateDepthImage(this.GraphicsDevice, depthImage.DataIntPtr); } var floatDepthImageTextureDesc = new Texture2DDescription() { Width = depthWidth, Height = depthHeight, MipLevels = 1, ArraySize = 1, Format = SharpDX.DXGI.Format.R32_Float, SampleDescription = new SharpDX.DXGI.SampleDescription(1, 0), Usage = ResourceUsage.Default, BindFlags = BindFlags.RenderTarget | BindFlags.ShaderResource, CpuAccessFlags = CpuAccessFlags.None, }; _floatDepthImageFinal = ToDisposeContent(RenderTarget2D.New(GraphicsDevice, floatDepthImageTextureDesc)); _floatDepthImageSubpass = ToDisposeContent(RenderTarget2D.New(GraphicsDevice, floatDepthImageTextureDesc)); base.LoadContent(); }
protected override void LoadContent() { if (!string.IsNullOrEmpty(_effectName)) { _customEffect = Content.Load <Effect>(_effectName); } _mediaPlayer = new MediaPlayer(); _mediaPlayer.Looping = true; _mediaPlayer.Initialize(GraphicsDevice); _spriteBatch = ToDisposeContent(new SpriteBatch(GraphicsDevice)); if (DestinationRectangle.Width == 0 || DestinationRectangle.Height == 0) { DestinationRectangle = new RectangleF(0, 0, GraphicsDevice.BackBuffer.Width, GraphicsDevice.BackBuffer.Height); } // Create texture to be used as rendertarget for our video frames. // Make it the current backbuffer size var texture2D = new SharpDX.Direct3D11.Texture2D(this.GraphicsDevice, new SharpDX.Direct3D11.Texture2DDescription() { Width = (int)(DestinationRectangle.Width), Height = (int)DestinationRectangle.Height, ArraySize = 1, BindFlags = SharpDX.Direct3D11.BindFlags.ShaderResource | BindFlags.RenderTarget, Usage = SharpDX.Direct3D11.ResourceUsage.Default, CpuAccessFlags = SharpDX.Direct3D11.CpuAccessFlags.None, Format = SharpDX.DXGI.Format.B8G8R8A8_UNorm, MipLevels = 1, OptionFlags = SharpDX.Direct3D11.ResourceOptionFlags.None, SampleDescription = new SharpDX.DXGI.SampleDescription(count: 1, quality: 0), }); _textureView = new ShaderResourceView(this.GraphicsDevice, texture2D); // Bind the media player with this output texture _mediaPlayer.OutputVideoTexture = texture2D; _samplerState = ToDisposeContent(SharpDX.Toolkit.Graphics.SamplerState.New(this.GraphicsDevice, new SamplerStateDescription() { Filter = Filter.MinMagMipLinear, AddressU = TextureAddressMode.Clamp, AddressV = TextureAddressMode.Clamp, AddressW = TextureAddressMode.Clamp, BorderColor = Color.Black, ComparisonFunction = Comparison.Never, MaximumAnisotropy = 16, MipLodBias = 0, MinimumLod = -float.MaxValue, MaximumLod = float.MaxValue })); if (!string.IsNullOrEmpty(_filePath) && File.Exists(_filePath)) { try { var fileStream = File.Open(_filePath, FileMode.Open); // Plays the video _mediaPlayer.Url = _filePath; _mediaPlayer.SetBytestream(fileStream); _videoExists = true; } catch (Exception ex) { Debug.WriteLine("Failed to open video '{0}'", _filePath); } } base.LoadContent(); }
public VoxelRenderer(GraphicsDevice graphicsDevice, ContentManager contentManager) { _cubeVertexBuffer = Buffer.Vertex.New( graphicsDevice, new[] { // 3D coordinates UV Texture coordinates new CubeVertex() { Position = new Vector3(-1.0f, -1.0f, -1.0f), Normal = -Vector3.UnitZ, Texcoord = new Vector2(0.0f, 1.0f) }, // Front new CubeVertex() { Position = new Vector3(-1.0f, 1.0f, -1.0f), Normal = -Vector3.UnitZ, Texcoord = new Vector2(0.0f, 0.0f) }, new CubeVertex() { Position = new Vector3(1.0f, 1.0f, -1.0f ), Normal = -Vector3.UnitZ, Texcoord = new Vector2(1.0f, 0.0f) }, new CubeVertex() { Position = new Vector3(-1.0f, -1.0f, -1.0f), Normal = -Vector3.UnitZ, Texcoord = new Vector2(0.0f, 1.0f) }, new CubeVertex() { Position = new Vector3(1.0f, 1.0f, -1.0f ), Normal = -Vector3.UnitZ, Texcoord = new Vector2(1.0f, 0.0f) }, new CubeVertex() { Position = new Vector3(1.0f, -1.0f, -1.0f ), Normal = -Vector3.UnitZ, Texcoord = new Vector2(1.0f, 1.0f) }, new CubeVertex() { Position = new Vector3(-1.0f, -1.0f, 1.0f), Normal = Vector3.UnitZ, Texcoord = new Vector2(1.0f, 0.0f) }, // BACK new CubeVertex() { Position = new Vector3(1.0f, 1.0f, 1.0f ), Normal = Vector3.UnitZ, Texcoord = new Vector2(0.0f, 1.0f) }, new CubeVertex() { Position = new Vector3(-1.0f, 1.0f, 1.0f), Normal = Vector3.UnitZ, Texcoord = new Vector2(1.0f, 1.0f) }, new CubeVertex() { Position = new Vector3(-1.0f, -1.0f, 1.0f), Normal = Vector3.UnitZ, Texcoord = new Vector2(1.0f, 0.0f) }, new CubeVertex() { Position = new Vector3(1.0f, -1.0f, 1.0f ), Normal = Vector3.UnitZ, Texcoord = new Vector2(0.0f, 0.0f) }, new CubeVertex() { Position = new Vector3(1.0f, 1.0f, 1.0f ), Normal = Vector3.UnitZ, Texcoord = new Vector2(0.0f, 1.0f) }, new CubeVertex() { Position = new Vector3(-1.0f, 1.0f, -1.0f ), Normal = Vector3.UnitY, Texcoord = new Vector2(0.0f, 1.0f) }, // Top new CubeVertex() { Position = new Vector3(-1.0f, 1.0f, 1.0f ), Normal = Vector3.UnitY, Texcoord = new Vector2(0.0f, 0.0f) }, new CubeVertex() { Position = new Vector3(1.0f, 1.0f, 1.0f ), Normal = Vector3.UnitY, Texcoord = new Vector2(1.0f, 0.0f) }, new CubeVertex() { Position = new Vector3(-1.0f, 1.0f, -1.0f ), Normal = Vector3.UnitY, Texcoord = new Vector2(0.0f, 1.0f) }, new CubeVertex() { Position = new Vector3(1.0f, 1.0f, 1.0f ), Normal = Vector3.UnitY, Texcoord = new Vector2(1.0f, 0.0f) }, new CubeVertex() { Position = new Vector3(1.0f, 1.0f, -1.0f ), Normal = Vector3.UnitY, Texcoord = new Vector2(1.0f, 1.0f) }, new CubeVertex() { Position = new Vector3(-1.0f,-1.0f, -1.0f ), Normal = -Vector3.UnitY, Texcoord = new Vector2(1.0f, 0.0f) }, // Bottom new CubeVertex() { Position = new Vector3(1.0f,-1.0f, 1.0f ), Normal = -Vector3.UnitY, Texcoord = new Vector2(0.0f, 1.0f) }, new CubeVertex() { Position = new Vector3(-1.0f,-1.0f, 1.0f ), Normal = -Vector3.UnitY, Texcoord = new Vector2(1.0f, 1.0f) }, new CubeVertex() { Position = new Vector3(-1.0f,-1.0f, -1.0f ), Normal = -Vector3.UnitY, Texcoord = new Vector2(1.0f, 0.0f) }, new CubeVertex() { Position = new Vector3(1.0f,-1.0f, -1.0f ), Normal = -Vector3.UnitY, Texcoord = new Vector2(0.0f, 0.0f) }, new CubeVertex() { Position = new Vector3(1.0f,-1.0f, 1.0f ), Normal = -Vector3.UnitY, Texcoord = new Vector2(0.0f, 1.0f) }, new CubeVertex() { Position = new Vector3(-1.0f, -1.0f, -1.0f), Normal = -Vector3.UnitX, Texcoord = new Vector2(0.0f, 1.0f) }, // Left new CubeVertex() { Position = new Vector3(-1.0f, -1.0f, 1.0f), Normal = -Vector3.UnitX, Texcoord = new Vector2(0.0f, 0.0f) }, new CubeVertex() { Position = new Vector3(-1.0f, 1.0f, 1.0f), Normal = -Vector3.UnitX, Texcoord = new Vector2(1.0f, 0.0f) }, new CubeVertex() { Position = new Vector3(-1.0f, -1.0f, -1.0f), Normal = -Vector3.UnitX, Texcoord = new Vector2(0.0f, 1.0f) }, new CubeVertex() { Position = new Vector3(-1.0f, 1.0f, 1.0f), Normal = -Vector3.UnitX, Texcoord = new Vector2(1.0f, 0.0f) }, new CubeVertex() { Position = new Vector3(-1.0f, 1.0f, -1.0f), Normal = -Vector3.UnitX, Texcoord = new Vector2(1.0f, 1.0f) }, new CubeVertex() { Position = new Vector3(1.0f, -1.0f, -1.0f ), Normal = Vector3.UnitX, Texcoord = new Vector2(1.0f, 0.0f) }, // Right new CubeVertex() { Position = new Vector3(1.0f, 1.0f, 1.0f ), Normal = Vector3.UnitX, Texcoord = new Vector2(0.0f, 1.0f) }, new CubeVertex() { Position = new Vector3(1.0f, -1.0f, 1.0f ), Normal = Vector3.UnitX, Texcoord = new Vector2(1.0f, 1.0f) }, new CubeVertex() { Position = new Vector3(1.0f, -1.0f, -1.0f ), Normal = Vector3.UnitX, Texcoord = new Vector2(1.0f, 0.0f) }, new CubeVertex() { Position = new Vector3(1.0f, 1.0f, -1.0f ), Normal = Vector3.UnitX, Texcoord = new Vector2(0.0f, 0.0f) }, new CubeVertex() { Position = new Vector3(1.0f, 1.0f, 1.0f ), Normal = Vector3.UnitX, Texcoord = new Vector2(0.0f, 1.0f) } }, SharpDX.Direct3D11.ResourceUsage.Immutable); // Create an input layout from the vertices _vertexInputLayout = VertexInputLayout.New( VertexBufferLayout.New(0, new VertexElement[]{new VertexElement("POSITION_CUBE", 0, SharpDX.DXGI.Format.R32G32B32_Float, 0), new VertexElement("NORMAL", 0, SharpDX.DXGI.Format.R32G32B32_Float, sizeof(float) * 3), new VertexElement("TEXCOORD", 0, SharpDX.DXGI.Format.R32G32_Float, sizeof(float) * 6)}, 0), VertexBufferLayout.New(1, new VertexElement[]{new VertexElement("POSITION_INSTANCE", SharpDX.DXGI.Format.R32_SInt)}, 1)); // Create instance buffer for every VoxelInfo _voxelTypeRenderingData = new VoxelTypeInstanceData[TypeInformation.GetNumTypes()-1]; for (int i = 0; i < _voxelTypeRenderingData.Length; ++i) _voxelTypeRenderingData[i] = new VoxelTypeInstanceData(graphicsDevice, (VoxelType)(i+1)); LoadTextures(contentManager); // load shader EffectCompilerFlags compilerFlags = EffectCompilerFlags.None; #if DEBUG compilerFlags |= EffectCompilerFlags.Debug; #endif var voxelShaderCompileResult = EffectCompiler.CompileFromFile("Content/voxel.fx", compilerFlags); if (voxelShaderCompileResult.HasErrors) { System.Console.WriteLine(voxelShaderCompileResult.Logger.Messages); System.Diagnostics.Debugger.Break(); } _voxelEffect = new SharpDX.Toolkit.Graphics.Effect(graphicsDevice, voxelShaderCompileResult.EffectData); // setup states var rasterizerStateDesc = SharpDX.Direct3D11.RasterizerStateDescription.Default(); rasterizerStateDesc.CullMode = SharpDX.Direct3D11.CullMode.Back; _backfaceCullingState = RasterizerState.New(graphicsDevice, "CullModeBack", rasterizerStateDesc); rasterizerStateDesc.CullMode = SharpDX.Direct3D11.CullMode.None; _noneCullingState = RasterizerState.New(graphicsDevice, "CullModeNone", rasterizerStateDesc); var depthStencilStateDesc = SharpDX.Direct3D11.DepthStencilStateDescription.Default(); depthStencilStateDesc.IsDepthEnabled = true; _depthStencilStateState = DepthStencilState.New(graphicsDevice, "NormalZBufferUse", depthStencilStateDesc); var samplerStateDesc = SharpDX.Direct3D11.SamplerStateDescription.Default(); samplerStateDesc.AddressV = SharpDX.Direct3D11.TextureAddressMode.Mirror; samplerStateDesc.AddressU = SharpDX.Direct3D11.TextureAddressMode.Mirror; samplerStateDesc.Filter = SharpDX.Direct3D11.Filter.MinMagMipPoint; _pointSamplerState = SamplerState.New(graphicsDevice, "PointSampler", samplerStateDesc); _voxelEffect.Parameters["PointSampler"].SetResource(_pointSamplerState); var blendStateDesc = SharpDX.Direct3D11.BlendStateDescription.Default(); _blendStateOpaque = BlendState.New(graphicsDevice, "Opaque", blendStateDesc); blendStateDesc.RenderTarget[0].IsBlendEnabled = true; blendStateDesc.RenderTarget[0].SourceBlend = SharpDX.Direct3D11.BlendOption.SourceAlpha; blendStateDesc.RenderTarget[0].DestinationBlend = SharpDX.Direct3D11.BlendOption.InverseSourceAlpha; blendStateDesc.RenderTarget[0].BlendOperation = SharpDX.Direct3D11.BlendOperation.Add; _blendStateTransparent = BlendState.New(graphicsDevice, "AlphaBlend", blendStateDesc); // vertexbuffer for a single instance _singleInstanceBuffer = Buffer.Vertex.New<Int32>(graphicsDevice, 1, SharpDX.Direct3D11.ResourceUsage.Dynamic); }