• Content count

  • Joined

  • Last visited

Community Reputation

2317 Excellent

About KaiserJohan

  • Rank

Personal Information

  • Interests
  1. StructuredBuffer and matrix layout

    Sorry for bump but I just stumbled upon this recently. Was frustrated as I already had my matrices column-major when sending to the shader so I couldn't understand why it got sampled transposed. I just transposed() the matrix after sampling in the shader.
  2. I need to bind a shader resource as a structured buffer. Textures (t#) and constant buffers (b#) are listed as expected but not StructuredBuffers? I've looked at https://msdn.microsoft.com/en-us/library/windows/desktop/dd607359(v=vs.85).aspx and it still puzzles me - what is the register type used for Structured Buffers in HLSL?
  3. Just a really quick question - is there any overhead to using DrawIndexedInstanced even for geometry you just render once vs using DrawIndexed? Or is the details obfuscated by the graphics driver? I would assume no but you never know
  4. Terrain tessellation and frustum culling

      Makes sense. The 'BoundsY' for a quad is calculated on the CPU once by reading the heightmap and making an AABB? Can this be used in conjunction with other terrain tessellation alghorithms (like http://www.frostbite.com/wp-content/uploads/2013/05/adaptive_terrain_tessellation.pdf)?
  5. So I'm trying to implement terrain tessellation. I suppose it should be as simple as draw an enormous quad patch, generate new vertices and then offset the y-coordinate using a heightmap. Am I correct that far? :) What I'm curious is how do you perform any form of culling of the terrain geometry at this point. Say only a small part of this large quad is visible, how do you prevent it from tessellating alot of soon-to-be-unused vertices?
  6. As the title says :) Using my mouse, I want to pick out a texel on a mesh I have rendered and modify that texel. I start by picking a screen coordinate using my mouse. I then convert this screen coordinate to a world coordinate (using depth value at that pixel + inverse wvp matrix). This world coordinate is on the mesh at the pixel of the texture I want to modify. The question is how do I then go from world coordinate to texture coordinate on that specific texture?
  7. Custom world editor?

      Great post. I'm at the point where I extracted world pos successfully, the question is how do I obtain heigthmap coords from that?
  8. DX11 Reading one texel from depthbuffer

      almost sounds like a  raypick vs ground mesh problem.      It probably very much is :) do you have any light to shed on the subject?
  9. DX11 Reading one texel from depthbuffer

    I do use the stencil buffer for reducing overdraw when doing point lights. 
  10. DX11 Reading one texel from depthbuffer

    I am doing this in my editor to raise/lower terrain (i.e increment/decrement values in a heightmap). To do that I first need to reconstruct the 3d point from 2d screen coords and for that I need depth for that pixel (afaik) and then somehow go from that 3d point to modify the correct hieghtmap texel (but that is a later problem).
  11. DX11 Reading one texel from depthbuffer

      What do you estimate would be the most efficient way of doing it (copy entire depthbuffer and read one texel -VS- use a CS/PS to output to a 1x1 staging texture and read that?)
  12. DX11 Reading one texel from depthbuffer

    This is my depthbuffer, also used for my staging texture except for cpuAccess, usage and bindflags: // create depth buffer D3D11_TEXTURE2D_DESC depthStencilBufferDesc; ZeroMemory(&depthStencilBufferDesc, sizeof(D3D11_TEXTURE2D_DESC)); depthStencilBufferDesc.ArraySize = 1; depthStencilBufferDesc.BindFlags = D3D11_BIND_SHADER_RESOURCE | D3D11_BIND_DEPTH_STENCIL; depthStencilBufferDesc.Format = DXGI_FORMAT_R24G8_TYPELESS; depthStencilBufferDesc.Width = backbufferTextureDesc.Width; depthStencilBufferDesc.Height = backbufferTextureDesc.Height; depthStencilBufferDesc.MipLevels = 1; depthStencilBufferDesc.SampleDesc.Count = 1; depthStencilBufferDesc.Usage = D3D11_USAGE_DEFAULT; depthStencilBufferDesc.SampleDesc.Count = 1 is not multisampled right? (i.e it should work?)
  13. I was trying to find something similiar to glReadPixel() and stumbled upon this post: https://www.gamedev.net/topic/594722-reading-one-pixel-from-texture-to-cpu-in-dx11/   Seemed reasonable, tried it but lo and behold didnt work.   Sample code; { DX11DepthBufferReadback::DX11DepthBufferReadback(ID3D11DevicePtr device, ID3D11DeviceContextPtr context, ID3D11Texture2DPtr depthBuffer) : mContext(context), mDepthbuffer(depthBuffer), mStaging1x1(nullptr) { D3D11_TEXTURE2D_DESC depthTextureDesc; ZeroMemory(&depthTextureDesc, sizeof(depthTextureDesc)); depthBuffer->GetDesc(&depthTextureDesc); depthTextureDesc.Usage = D3D11_USAGE_STAGING; depthTextureDesc.BindFlags = 0; depthTextureDesc.CPUAccessFlags = D3D11_CPU_ACCESS_READ; device->CreateTexture2D(&depthTextureDesc, NULL, &mStaging1x1); } float DX11DepthBufferReadback::GetDepthValue(const WindowPosition& position) const { D3D11_BOX box; ZeroMemory(&box, sizeof(box)); box.left = position.x; box.right = box.left + 1; box.top = position.y; box.bottom = box.top + 1; box.front = 0; box.back = 1; mContext->CopySubresourceRegion(mStaging1x1, 0, 0, 0, 0, mDepthbuffer, 0, &box); D3D11_MAPPED_SUBRESOURCE mappedRes; mContext->Map(mStaging1x1, 0, D3D11_MAP_READ, 0, &mappedRes); float depth = *static_cast<float*>(mappedRes.pData); mContext->Unmap(mStaging1x1, 0); return depth; } } This is the debug ouput I get: D3D11 ERROR: ID3D11DeviceContext::CopySubresourceRegion: If CopySubresourceRegion is used with Multisampled or D3D11_BIND_DEPTH_STENCIL Resources, then the whole Subresource must be copied. DstX, DstY, and DstZ must all be 0, while pSrcBox must be NULL. [ RESOURCE_MANIPULATION ERROR #280: COPYSUBRESOURCEREGION_INVALIDSOURCEBOX] So this dosn't seem to work. Is there any similiarly easy/straight forward solution that works?