Jump to content
  • Advertisement

AlexSenko

Member
  • Content Count

    10
  • Joined

  • Last visited

Community Reputation

104 Neutral

About AlexSenko

  • Rank
    Member

Personal Information

  1. I share RenderTarget Texture from DX10.1 to DX9Ex to draw it in WPF. Everithing works perfectly on Windows 7 + GeForce GTS450/GTS560(and many other configurations). But on Windows Server 2008 + Nvidia NVS 300 I got an "An invalid parameter was passed to the returning function" exception in line: sharedTexture = new Texture(D3DDevice, Texture.Description.Width, Texture.Description.Height, 1, Usage.RenderTarget, format, Pool.Default, ref handle); if I remove last parameter "ref handle" - no exception and everthing is running(but with blank screen). Latest drivers, SlimDX and DirectX are installed. Nvidia NVS 300 supports DirectX 10.1.     D3D10.1 device initialization: device = new Device(DriverType.Hardware, DeviceCreationFlags.BgraSupport , FeatureLevel.Level_10_1); D3D10.1 shared texture initialization: var renderTexDescShared = new Texture2DDescription() { BindFlags = BindFlags.RenderTarget | BindFlags.ShaderResource, Format = Format.B8G8R8A8_UNorm, Width = windowWidth, Height = windowHeight, MipLevels = 1, SampleDescription = new SampleDescription(1, 0), Usage = ResourceUsage.Default, OptionFlags = ResourceOptionFlags.Shared, CpuAccessFlags = CpuAccessFlags.None, ArraySize = 1 }; SharedTexture = new Texture2D(device, renderTexDescShared); D3D9Ex device initialization: D3DContext = new Direct3DEx(); PresentParameters presentparams = new PresentParameters(); presentparams.Windowed = true; presentparams.SwapEffect = SwapEffect.Copy; presentparams.DeviceWindowHandle = GetDesktopWindow(); presentparams.PresentationInterval = PresentInterval.Immediate; D3DDevice = new DeviceEx(D3DContext, 0, DeviceType.Hardware, IntPtr.Zero, CreateFlags.HardwareVertexProcessing | CreateFlags.Multithreaded | CreateFlags.FpuPreserve, presentparams); D3D9Ex texture: SlimDX.DXGI.Resource resource = new SlimDX.DXGI.Resource(SharedTexture); IntPtr handle = resource.SharedHandle; sharedTexture = new Texture(D3DDevice, Texture.Description.Width, Texture.Description.Height, 1, Usage.RenderTarget, format, Pool.Default, ref handle);
  2. AlexSenko

    SlimDX WPF No Z-Buffer

    yes, here was my first mistake: Matrix.PerspectiveFovLH((float)Math.PI / 4f, 1f, 100f, 0f) the result of this mistake was like Z-Buffer not work and i tried everything about Z-Buffer, but nothing about projection matrices. And my last hope was to make depth calculations manually in shader(or something like this) and I started write something in shader Now everything works fine, even in WPF. Thanks to unbird. P.S. Really I see that DirectX/SlimDX rendering cannot depend on WPF, because rendering to shared texture is made just in .Net, not in WPF or WinForms. So I think chlerub can also solve his problem.
  3. AlexSenko

    SlimDX WPF No Z-Buffer

    i forgot to remove reference, sorry, it is not used, can be removed.
  4. AlexSenko

    SlimDX WPF No Z-Buffer

    WinForms sources: http://www.rush.by/source.zip System config: i5-2500, Win7 x64, nVidia GTS450 with latest drivers and updates. When I change in DepthStencilStateDescription DepthComparison = Comparison.Less to DepthComparison = Comparison.LessEqual I see that something changed, when peak(as on video) is in far side of scene Z-buffer is ok, but if peak is in near side - z-buffer fault. On video "DepthComparison = Comparison.Less".
  5. AlexSenko

    SlimDX WPF No Z-Buffer

    I have just tested my code in WinForms, the same result, Z-Buffer do not work. May be any problems with shader? struct VS_IN { float4 pos : POSITION; float4 col : COLOR; }; struct PS_IN { float4 pos : SV_POSITION; float4 col : COLOR; }; float4x4 WorldViewProj : WORLDVIEWPROJECTION; PS_IN VS( VS_IN input ) { PS_IN output = (PS_IN)0; output.pos = mul(input.pos, WorldViewProj); output.col = input.col; return output; } float4 PS( PS_IN input ) : SV_Target { return input.col; } technique10 Render { pass P0 { SetGeometryShader( 0 ); SetVertexShader( CompileShader( vs_4_0, VS() ) ); SetPixelShader( CompileShader( ps_4_0, PS() ) ); } }
  6. AlexSenko

    SlimDX WPF No Z-Buffer

    It was my last hope
  7. AlexSenko

    SlimDX WPF No Z-Buffer

    Video: [media][/media]
  8. AlexSenko

    SlimDX WPF No Z-Buffer

    In such way? Initialization: var renderTexDescShared = new Texture2DDescription() { BindFlags = BindFlags.RenderTarget | BindFlags.ShaderResource, Format = Format.B8G8R8A8_UNorm, Width = WindowWidth, Height = WindowHeight, MipLevels = 1, SampleDescription = new SampleDescription(1, 0), Usage = ResourceUsage.Default, OptionFlags = ResourceOptionFlags.Shared, CpuAccessFlags = CpuAccessFlags.None, ArraySize = 1 }; SharedTexture = new Texture2D(device, renderTexDescShared); sampleRenderViewShared = new RenderTargetView(device, SharedTexture); var renderTexDesc = new Texture2DDescription() { BindFlags = BindFlags.RenderTarget, Format = Format.B8G8R8A8_UNorm, Width = WindowWidth, Height = WindowHeight, MipLevels = 1, SampleDescription = new SampleDescription(1, 0), Usage = ResourceUsage.Default, OptionFlags = ResourceOptionFlags.None, CpuAccessFlags = CpuAccessFlags.None, ArraySize = 1 }; renderTexture = new Texture2D(device, renderTexDesc); sampleRenderView = new RenderTargetView(device, renderTexture); Render: public void Render(int arg) { device.OutputMerger.DepthStencilState = depthStencilState; device.OutputMerger.SetTargets(depthStencilView, sampleRenderView); device.Rasterizer.SetViewports(new Viewport(0, 0, WindowWidth, WindowHeight, 0.0f, 1.0f)); device.ClearRenderTargetView(sampleRenderView, new Color4(0.0f, 0.0f, 0.0f)); device.ClearDepthStencilView(depthStencilView, DepthStencilClearFlags.Depth, 1.0f, 0); Matrix worldMatrix = GetWorldViewProj(arg); DataStream ds = new DataStream(worldMatrix.ToArray(), true, false); SampleEffect.GetVariableByName("WorldViewProj").AsMatrix().SetMatrix(worldMatrix); EffectTechnique technique = SampleEffect.GetTechniqueByIndex(0); EffectPass pass = technique.GetPassByIndex(0); for (int i = 0; i < technique.Description.PassCount; ++i) { pass.Apply(); renderDataManager.Render(worldMatrix); } device.Flush(); device.CopyResource(renderTexture, SharedTexture); OnSceneRender(); } The same problems I'll prepare video in several minutes
  9. AlexSenko

    SlimDX WPF No Z-Buffer

    Yes, I do in such way, this part of code left from sample and it works pretty well except Z-Buffer. RenderTarget Texture initialization: var renderTexDesc = new Texture2DDescription() { BindFlags = BindFlags.RenderTarget | BindFlags.ShaderResource, Format = Format.B8G8R8A8_UNorm, Width = WindowWidth, Height = WindowHeight, MipLevels = 1, SampleDescription = new SampleDescription(1, 0), Usage = ResourceUsage.Default, OptionFlags = ResourceOptionFlags.Shared, CpuAccessFlags = CpuAccessFlags.None, ArraySize = 1 }; SharedTexture = new Texture2D(device, renderTexDesc); sampleRenderView = new RenderTargetView(device, SharedTexture); DepthStencil initialization: var depthDesc = new Texture2DDescription() { BindFlags = BindFlags.DepthStencil, Format = Format.D32_Float, Width = WindowWidth, Height = WindowHeight, MipLevels = 1, SampleDescription = new SampleDescription(1, 0), Usage = ResourceUsage.Default, OptionFlags = ResourceOptionFlags.None, CpuAccessFlags = CpuAccessFlags.None, ArraySize = 1 }; DepthTexture = new Texture2D(device, depthDesc); depthStencilView = new DepthStencilView(device, DepthTexture); var dsDesc = new DepthStencilStateDescription { IsDepthEnabled = true, IsStencilEnabled = false, DepthWriteMask = DepthWriteMask.All, DepthComparison = Comparison.Less }; depthStencilState = DepthStencilState.FromDescription(device, dsDesc); Rasterizer initialization: var rasterizerState = new RasterizerStateDescription() { CullMode = CullMode.None, FillMode = FillMode.Solid, IsFrontCounterclockwise = false, DepthBias = 0, DepthBiasClamp = 0, SlopeScaledDepthBias = 0, IsDepthClipEnabled = true, IsScissorEnabled = false, IsMultisampleEnabled = true, IsAntialiasedLineEnabled = true }; device.Rasterizer.State = RasterizerState.FromDescription(device, rasterizerState); Render: public void Render(int arg) { device.OutputMerger.DepthStencilState = depthStencilState; device.OutputMerger.SetTargets(depthStencilView, sampleRenderView); device.Rasterizer.SetViewports(new Viewport(0, 0, WindowWidth, WindowHeight, 0.0f, 1.0f)); device.ClearRenderTargetView(sampleRenderView, new Color4(0.0f, 0.0f, 0.0f)); device.ClearDepthStencilView(depthStencilView, DepthStencilClearFlags.Depth, 1.0f, 0); Matrix worldMatrix = GetWorldViewProj(arg); DataStream ds = new DataStream(worldMatrix.ToArray(), true, false); SampleEffect.GetVariableByName("WorldViewProj").AsMatrix().SetMatrix(worldMatrix); EffectTechnique technique = SampleEffect.GetTechniqueByIndex(0); EffectPass pass = technique.GetPassByIndex(0); for (int i = 0; i < technique.Description.PassCount; ++i) { pass.Apply(); renderDataManager.Render(worldMatrix); } device.Flush(); OnSceneRender(); }
  10. I spend a lot of time to find why z-buffer don't work in my modified WpfSample10 and then founded information from microsoft site(http://msdn.microsof...4(v=vs.85).aspx): [color="#2A2A2A"]When a buffer is used as a render target, depth-stencil testing and multiple render targets are not supported.[/quote]. And the only way to use SlimDX in WPF is to use texture as render target? Is there any way to make Z-buffer working in SlimDX WPF?
  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!