private void FillMipSlice(SharpDX.Toolkit.Graphics.GraphicsDevice device, Material computeShader, int textureSize, UnorderedAccessView UAVMip, Vector4 fillColour) { computeShader.SetParameterResource("gOutput", UAVMip); computeShader.SetParameterValue("fillColour", fillColour); computeShader.Apply(); device.Dispatch(1, textureSize, 1); }
private void CreateAndInitializeDevice() { var swapChainDescription = new SwapChainDescription() { BufferCount = 1, IsWindowed = true, ModeDescription = new ModeDescription(renderForm.ClientSize.Width, renderForm.ClientSize.Height, new Rational(60, 1), Format.R8G8B8A8_UNorm), OutputHandle = renderForm.Handle, SampleDescription = new SampleDescription(1, 0), SwapEffect = SwapEffect.Discard, Usage = Usage.RenderTargetOutput }; DeviceCreationFlags flags = DeviceCreationFlags.None; #if DEBUG flags |= DeviceCreationFlags.Debug; #endif SharpDX.Direct3D11.Device.CreateWithSwapChain(SharpDX.Direct3D.DriverType.Hardware, flags, swapChainDescription, out device, out swapChain); deviceContext = device.ImmediateContext; #if TEXT_RENDERER __2dGraphicsDevice = SharpDX.Toolkit.Graphics.GraphicsDevice.New(device); #endif var factory = SwapChain.GetParent <Factory>(); factory.MakeWindowAssociation(renderForm.Handle, WindowAssociationFlags.IgnoreAll); SetRasterizerState(); SetDepthBufferState(); SetSamplerState(); SetBlendState(); CreateConstantBuffers(); renderForm.Resize += OnFormResized; PerformResizing(); SetRegularTargets(); }
private Texture2D CopyFilledTextureLocally(SharpDX.Toolkit.Graphics.GraphicsDevice device, SharpDX.Direct3D11.Texture2D emptyTexture) { Texture2DDescription bufferDesc = CreateLocalBufferDesc(); SharpDX.Direct3D11.Texture2D localbuffer = new SharpDX.Direct3D11.Texture2D(device, bufferDesc); device.Copy(emptyTexture, localbuffer); return(localbuffer); }
private static Material LoadComputeShader(SharpDX.Toolkit.Graphics.GraphicsDevice device) { MaterialLoader loader = new MaterialLoader(new SharpDXGraphicsDevice(device)); ResourceInformation info = new MaterialResourceInformation(); info.UpdateInformation("Filepath", "C:\\Users\\Andy\\Documents\\Coding\\Visual Studio 2012\\Projects\\FearEngine\\Resources\\Shaders\\ComputeTest.fx"); info.UpdateInformation("Technique", "FillTexture"); return((Material)loader.Load(info)); }
public FearEngineNinjectModule( SharpDX.Toolkit.Graphics.GraphicsDevice device, MouseManager mouseMan, KeyboardManager keyMan) { existingDevice = new SharpDXGraphicsDevice(device); mouseManager = mouseMan; keyManager = keyMan; }
public BasicShadowTechnique(FearGraphicsDevice dev, FearResourceManager resMan, [Named("ShadowBiasedDepth")] RasteriserState depthRasState, [Named("ShadowMapComparison")] FearEngine.DeviceState.SamplerStates.SamplerState samp) { device = dev.Device; depthMaterial = resMan.GetMaterial("DepthWrite"); depthRS = depthRasState; sampler = samp; }
public void LoadCubemap() { //Given SharpDX.Toolkit.Graphics.GraphicsDevice device = SharpDX.Toolkit.Graphics.GraphicsDevice.New(DeviceCreationFlags.Debug); TextureLoader loader = new TextureLoader(new SharpDXGraphicsDevice(device)); ResourceInformation cubeInfo = new TextureResourceInformation(); cubeInfo.UpdateInformation("Filepath", "C:\\Users\\Andy\\Documents\\Coding\\Visual Studio 2012\\Projects\\FearEngine\\Resources\\Textures\\Cubemaps\\LancellottiChapel\\LancellottiChapelCube.dds"); cubeInfo.UpdateInformation("IsCubemap", "true"); //When TextureCube texture = (TextureCube)loader.Load(cubeInfo); device.Dispose(); }
public void Startup(FearEngineImpl engine) { cam = engine.GameObjectFactory.CreateGameObject("Camera"); device = engine.Device; scene = engine.SceneFactory.CreateSceneWithSingleLight( engine.CameraFactory.CreateDebugCamera(cam), engine.LightFactory.CreateDirectionalLight()); GameObject cube = new BaseGameObject("Cube"); Mesh mesh = engine.Resources.GetMesh("BOX"); Material material = engine.Resources.GetMaterial("NormalLit"); SceneObject litCube = new SceneObject(cube, mesh, material); scene.AddSceneObject(litCube); }
public void LoadComputeShader() { //Given SharpDX.Toolkit.Graphics.GraphicsDevice device = SharpDX.Toolkit.Graphics.GraphicsDevice.New(DeviceCreationFlags.Debug); MaterialLoader loader = new MaterialLoader(new SharpDXGraphicsDevice(device)); ResourceInformation info = new MaterialResourceInformation(); info.UpdateInformation("Filepath", "C:\\Users\\Andy\\Documents\\Coding\\Visual Studio 2012\\Projects\\FearEngine\\Resources\\Shaders\\ComputeTest.fx"); info.UpdateInformation("Technique", "FillTexture"); //When Material material = (Material)loader.Load(info); //Then Assert.IsTrue(material.IsLoaded()); device.Dispose(); }
public void LoadTexture() { //Given SharpDX.Toolkit.Graphics.GraphicsDevice device = SharpDX.Toolkit.Graphics.GraphicsDevice.New(DeviceCreationFlags.Debug); TextureLoader loader = new TextureLoader(new SharpDXGraphicsDevice(device)); ResourceInformation info = new TextureResourceInformation(); info.UpdateInformation("Filepath", "C:\\Users\\Andy\\Documents\\Coding\\Visual Studio 2012\\Projects\\FearEngine\\Resources\\Textures\\DefaultTexture.png"); //When Texture texture = (Texture)loader.Load(info); //Then Assert.IsTrue(texture.Width == 1024); Assert.IsTrue(texture.Height == 1024); device.Dispose(); }
void IScene.Attach(ISceneHost host) { this.Host = host; keyboardInput = new InputDevices.KeyboardInputDevice(); gamepadInput = new InputDevices.GamepadInputDevice(); navigatorInput = new InputDevices.NavigatorInputDevice(); _device = host.Device; if (_device == null) { throw new Exception("Scene host device is null"); } graphicsDevice = SharpDX.Toolkit.Graphics.GraphicsDevice.New(_device); customEffect = Headset.GetCustomEffect(graphicsDevice); MediaDecoder.Instance.OnContentChanged += ContentChanged; projectionMatrix = Matrix.PerspectiveFovRH((float)(72f * Math.PI / 180f), (float)16f / 9f, 0.0001f, 50.0f); worldMatrix = Matrix.Identity; //primitive = GraphicTools.CreateGeometry(projectionMode, graphicsDevice); _device.ImmediateContext.Flush(); ResetRotation(); var devices = SharpDX.RawInput.Device.GetDevices(); devices.ForEach(dev => { if (dev.DeviceType == SharpDX.RawInput.DeviceType.Mouse) { SharpDX.RawInput.Device.RegisterDevice(SharpDX.Multimedia.UsagePage.Generic, SharpDX.Multimedia.UsageId.GenericMouse, SharpDX.RawInput.DeviceFlags.None, dev.Handle); } Console.WriteLine($"Scene::Attach DX device: {dev.DeviceName} :: {dev.DeviceType}"); }); }
public void Startup(FearEngineImpl engine) { cam = engine.GameObjectFactory.CreateGameObject("Camera"); device = engine.Device; scene = engine.SceneFactory.CreateSceneWithSingleLight( engine.CameraFactory.CreateDebugCamera(cam), engine.LightFactory.CreateDirectionalLight()); GameObject cube = new BaseGameObject("Cube"); Mesh mesh = engine.Resources.GetMesh("BOX"); Material material = engine.Resources.GetMaterial("NormalLit"); SceneObject litCube = new SceneObject(cube, mesh, material); scene.AddSceneObject(litCube); FearGraphicsDevice dev2 = new SharpDXGraphicsDevice(engine.Device); Material computeShader = LoadComputeShader(dev2); irrCubeGen = new IrradianceCubeMapGenerator(dev2, computeShader); source = LoadOriginalCubemap(dev2); }
public void MipGenerationSimple2LevelsOn2DTexture() { //Given SharpDX.Toolkit.Graphics.GraphicsDevice device = SharpDX.Toolkit.Graphics.GraphicsDevice.New(DeviceCreationFlags.Debug); Material computeShader = LoadComputeShader(device); List <Vector4> mipColours = new List <Vector4>( new Vector4[] { new Vector4(0.1f, 0.2f, 0.3f, 1.0f), new Vector4(0.0f, 0.5f, 0.0f, 1.0f), new Vector4(0.7f, 0.4f, 0.15f, 1.0f) }); Texture2DDescription emptyTextureDesc = CreateTextureDescription(); Texture2D emptyTexture = new Texture2D(device, emptyTextureDesc); List <UnorderedAccessView> mipViews = new List <UnorderedAccessView>(); for (int mip = 0; mip < numOfMips; mip++) { UnorderedAccessViewDescription uavDesc = CreateUAVDescription(mip); mipViews.Add(new UnorderedAccessView(device, emptyTexture, uavDesc)); } //When for (int mip = 0; mip < numOfMips; mip++) { FillMipSlice(device, computeShader, textureSize / (mip + 1), mipViews[mip], mipColours[mip]); } Texture2D readableTexture = CopyFilledTextureLocally(device, emptyTexture); for (int mip = 0; mip < numOfMips; mip++) { float variance = CheckVariationBetweenValueAndExpectedValue(device, textureSize / (mip + 1), mip, mipColours[mip], readableTexture); Assert.IsTrue(variance < 0.0005f); } }
public TextureLoader(FearGraphicsDevice dev) { device = dev.Device; }
private void CreateAndInitializeDevice() { var swapChainDescription = new SwapChainDescription() { BufferCount = 1, IsWindowed = true, ModeDescription = new ModeDescription(renderForm.ClientSize.Width, renderForm.ClientSize.Height, new Rational(60, 1), Format.R8G8B8A8_UNorm), OutputHandle = renderForm.Handle, SampleDescription = new SampleDescription(1, 0), SwapEffect = SwapEffect.Discard, Usage = Usage.RenderTargetOutput }; DeviceCreationFlags flags = DeviceCreationFlags.None; #if DEBUG flags |= DeviceCreationFlags.Debug; #endif SharpDX.Direct3D11.Device.CreateWithSwapChain(SharpDX.Direct3D.DriverType.Hardware, flags, swapChainDescription, out device, out swapChain); deviceContext = device.ImmediateContext; #if TEXT_RENDERER __2dGraphicsDevice = SharpDX.Toolkit.Graphics.GraphicsDevice.New(device); #endif var factory = SwapChain.GetParent<Factory>(); factory.MakeWindowAssociation(renderForm.Handle, WindowAssociationFlags.IgnoreAll); SetRasterizerState(); SetDepthBufferState(); SetSamplerState(); SetBlendState(); CreateConstantBuffers(); renderForm.Resize += OnFormResized; PerformResizing(); SetRegularTargets(); }
public VRUI(Device device, SharpDX.Toolkit.Graphics.GraphicsDevice gd) { Texture2DDescription uiTextureDescription = new Texture2DDescription() { Width = 1024, Height = 512, MipLevels = 1, ArraySize = 1, Format = Format.B8G8R8A8_UNorm, Usage = ResourceUsage.Default, SampleDescription = new SampleDescription(1, 0), BindFlags = BindFlags.RenderTarget | BindFlags.ShaderResource, CpuAccessFlags = CpuAccessFlags.None, OptionFlags = ResourceOptionFlags.Shared }; uiTexture = new SharpDX.Direct3D11.Texture2D(device, uiTextureDescription); using (DX2D.Factory factory2d = new DX2D.Factory(SharpDX.Direct2D1.FactoryType.SingleThreaded, DX2D.DebugLevel.Information)) { DX2D.RenderTargetProperties renderTargetProperties = new DX2D.RenderTargetProperties() { DpiX = 96, DpiY = 96, PixelFormat = new DX2D.PixelFormat(Format.B8G8R8A8_UNorm, DX2D.AlphaMode.Premultiplied), Type = DX2D.RenderTargetType.Hardware, MinLevel = DX2D.FeatureLevel.Level_10, Usage = DX2D.RenderTargetUsage.None }; using (var uiSurface = uiTexture.QueryInterface <Surface>()) target2d = new DX2D.RenderTarget(factory2d, uiSurface, renderTargetProperties) { AntialiasMode = DX2D.AntialiasMode.PerPrimitive }; } // 2D materials uiEffect = new SharpDX.Toolkit.Graphics.BasicEffect(gd) { PreferPerPixelLighting = false, Texture = SharpDX.Toolkit.Graphics.Texture2D.New(gd, uiTexture), TextureEnabled = true, LightingEnabled = false }; BlendStateDescription blendStateDescription = new BlendStateDescription() { AlphaToCoverageEnable = false }; blendStateDescription.RenderTarget[0].IsBlendEnabled = true; blendStateDescription.RenderTarget[0].SourceBlend = BlendOption.SourceAlpha; blendStateDescription.RenderTarget[0].DestinationBlend = BlendOption.InverseSourceAlpha; blendStateDescription.RenderTarget[0].BlendOperation = BlendOperation.Add; blendStateDescription.RenderTarget[0].SourceAlphaBlend = BlendOption.Zero; blendStateDescription.RenderTarget[0].DestinationAlphaBlend = BlendOption.Zero; blendStateDescription.RenderTarget[0].AlphaBlendOperation = BlendOperation.Add; blendStateDescription.RenderTarget[0].RenderTargetWriteMask = ColorWriteMaskFlags.All; using (var blendState = SharpDX.Toolkit.Graphics.BlendState.New(gd, blendStateDescription)) gd.SetBlendState(blendState); uiPrimitive = SharpDX.Toolkit.Graphics.GeometricPrimitive.Plane.New(gd, 2, 1); using (SharpDX.DirectWrite.Factory factoryDW = new SharpDX.DirectWrite.Factory()) { textFormat = new SharpDX.DirectWrite.TextFormat(factoryDW, "Segoe UI Light", 34f) { TextAlignment = SharpDX.DirectWrite.TextAlignment.Center, ParagraphAlignment = SharpDX.DirectWrite.ParagraphAlignment.Center }; textFormatSmall = new SharpDX.DirectWrite.TextFormat(factoryDW, "Segoe UI Light", 20f) { TextAlignment = SharpDX.DirectWrite.TextAlignment.Center, ParagraphAlignment = SharpDX.DirectWrite.ParagraphAlignment.Center }; } textBrush = new SharpDX.Direct2D1.SolidColorBrush(target2d, new Color(1f, 1f, 1f, 1f)); blueBrush = new SharpDX.Direct2D1.SolidColorBrush(target2d, new Color(0, 167, 245, 255)); uiInitialized = true; }
public void Start() { running = true; Task.Factory.StartNew(() => { form = new SharpDX.Windows.RenderForm("Oculus UI Debug"); form.Width = 1024 + 16; form.Height = 512 + 39; form.AllowUserResizing = false; // Create DirectX drawing device. SharpDX.Direct3D11.Device device = new Device(SharpDX.Direct3D.DriverType.Hardware, DeviceCreationFlags.Debug); // Create DirectX Graphics Interface factory, used to create the swap chain. Factory factory = new Factory(); DeviceContext immediateContext = device.ImmediateContext; // Define the properties of the swap chain. SwapChainDescription swapChainDescription = new SwapChainDescription(); swapChainDescription.BufferCount = 1; swapChainDescription.IsWindowed = true; swapChainDescription.OutputHandle = form.Handle; swapChainDescription.SampleDescription = new SampleDescription(1, 0); swapChainDescription.Usage = Usage.RenderTargetOutput | Usage.ShaderInput; swapChainDescription.SwapEffect = SwapEffect.Sequential; swapChainDescription.Flags = SwapChainFlags.AllowModeSwitch; swapChainDescription.ModeDescription.Width = 1024; swapChainDescription.ModeDescription.Height = 512; swapChainDescription.ModeDescription.Format = Format.R8G8B8A8_UNorm; swapChainDescription.ModeDescription.RefreshRate.Numerator = 0; swapChainDescription.ModeDescription.RefreshRate.Denominator = 1; // Create the swap chain. SharpDX.DXGI.SwapChain swapChain = new SwapChain(factory, device, swapChainDescription); // Retrieve the back buffer of the swap chain. Texture2D backBuffer = swapChain.GetBackBuffer <Texture2D>(0); RenderTargetView backBufferRenderTargetView = new RenderTargetView(device, backBuffer); // Create a depth buffer, using the same width and height as the back buffer. Texture2DDescription depthBufferDescription = new Texture2DDescription(); depthBufferDescription.Format = Format.D32_Float; depthBufferDescription.ArraySize = 1; depthBufferDescription.MipLevels = 1; depthBufferDescription.Width = 1024; depthBufferDescription.Height = 512; depthBufferDescription.SampleDescription = new SampleDescription(1, 0); depthBufferDescription.Usage = ResourceUsage.Default; depthBufferDescription.BindFlags = BindFlags.DepthStencil; depthBufferDescription.CpuAccessFlags = CpuAccessFlags.None; depthBufferDescription.OptionFlags = ResourceOptionFlags.None; // Define how the depth buffer will be used to filter out objects, based on their distance from the viewer. DepthStencilStateDescription depthStencilStateDescription = new DepthStencilStateDescription(); depthStencilStateDescription.IsDepthEnabled = true; depthStencilStateDescription.DepthComparison = Comparison.Less; depthStencilStateDescription.DepthWriteMask = DepthWriteMask.Zero; // Create the depth buffer. Texture2D depthBuffer = new Texture2D(device, depthBufferDescription); DepthStencilView depthStencilView = new DepthStencilView(device, depthBuffer); DepthStencilState depthStencilState = new DepthStencilState(device, depthStencilStateDescription); Viewport viewport = new Viewport(0, 0, 1024, 512, 0.0f, 1.0f); immediateContext.OutputMerger.SetDepthStencilState(depthStencilState); immediateContext.OutputMerger.SetRenderTargets(depthStencilView, backBufferRenderTargetView); immediateContext.Rasterizer.SetViewport(viewport); SharpDX.Toolkit.Graphics.GraphicsDevice gd = SharpDX.Toolkit.Graphics.GraphicsDevice.New(device); var blendStateDescription = new BlendStateDescription(); blendStateDescription.AlphaToCoverageEnable = false; blendStateDescription.RenderTarget[0].IsBlendEnabled = true; blendStateDescription.RenderTarget[0].SourceBlend = BlendOption.SourceAlpha; blendStateDescription.RenderTarget[0].DestinationBlend = BlendOption.InverseSourceAlpha; blendStateDescription.RenderTarget[0].BlendOperation = BlendOperation.Add; blendStateDescription.RenderTarget[0].SourceAlphaBlend = BlendOption.Zero; blendStateDescription.RenderTarget[0].DestinationAlphaBlend = BlendOption.Zero; blendStateDescription.RenderTarget[0].AlphaBlendOperation = BlendOperation.Add; blendStateDescription.RenderTarget[0].RenderTargetWriteMask = ColorWriteMaskFlags.All; var blendState = SharpDX.Toolkit.Graphics.BlendState.New(gd, blendStateDescription); gd.SetBlendState(blendState); var resource = sharedTexture.QueryInterface <SharpDX.DXGI.Resource>(); var texture = device.OpenSharedResource <Texture2D>(resource.SharedHandle); var basicEffect = new SharpDX.Toolkit.Graphics.BasicEffect(gd); basicEffect.PreferPerPixelLighting = false; basicEffect.Texture = SharpDX.Toolkit.Graphics.Texture2D.New(gd, texture); basicEffect.TextureEnabled = true; basicEffect.LightingEnabled = false; // background texture var backgroundTexture = SharpDX.Toolkit.Graphics.Texture2D.Load(gd, "Graphics/debug.png"); var backEffect = new SharpDX.Toolkit.Graphics.BasicEffect(gd); backEffect.PreferPerPixelLighting = false; backEffect.Texture = backgroundTexture; backEffect.TextureEnabled = true; backEffect.LightingEnabled = false; var primitive = SharpDX.Toolkit.Graphics.GeometricPrimitive.Plane.New(gd, 2f, 2f, 1); // Retrieve the DXGI device, in order to set the maximum frame latency. using (SharpDX.DXGI.Device1 dxgiDevice = device.QueryInterface <SharpDX.DXGI.Device1>()) { dxgiDevice.MaximumFrameLatency = 1; } RenderLoop.Run(form, () => { immediateContext.ClearRenderTargetView(backBufferRenderTargetView, new Color4(1f, 0.5f, 0.3f, 1f)); immediateContext.ClearDepthStencilView(depthStencilView, DepthStencilClearFlags.Depth | DepthStencilClearFlags.Stencil, 1.0f, 0); backEffect.World = basicEffect.World = Matrix.Identity; backEffect.View = basicEffect.View = Matrix.Identity; backEffect.Projection = basicEffect.Projection = Matrix.Identity; primitive.Draw(backEffect); primitive.Draw(basicEffect); swapChain.Present(0, PresentFlags.None); if (!running) { form.Close(); } }); }); }
public void Dispose() { if (_rtv != null) _rtv.Dispose(); _rtv = null; if (_swap != null) _swap.Dispose(); _swap = null; if (ToolkitDevice != null) ToolkitDevice.Dispose(); ToolkitDevice = null; if (_context != null) _context.Dispose(); _context = null; if (_device != null) _device.Dispose(); _device = null; _width = 0; _height = 0; }
public void Initialise(int width, int height, params SharpDX.Direct3D.FeatureLevel[] featureLevels) { // Create device var dev = new D3D11.Device(SharpDX.Direct3D.DriverType.Hardware, D3D11.DeviceCreationFlags.None, featureLevels); _device = ComObject.As<D3D11.Device1>(dev.NativePointer); _context = _device.ImmediateContext1; ToolkitDevice = SharpDX.Toolkit.Graphics.GraphicsDevice.New(_device); InitSwapChain(width, height); RetrieveSetBuffers(); _ready = true; }
public IrradianceCubeMapGenerator(FearGraphicsDevice dev, Material compShader) { device = dev.Device; computeShader = compShader; }