• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
Matthew Meeks

DX11
DX11 Shadow Map

5 posts in this topic

Back again with a new problem, I'm having issues rendering a shadow map and then using it in another shader.

 

I create a 256x256 texture here with R32_Float as the format:

 

            Texture2D shadowBuffer = new Texture2D(device, new Texture2DDescription()
            {
                ArraySize = 1,
                BindFlags = BindFlags.RenderTarget | BindFlags.ShaderResource,
                CpuAccessFlags = CpuAccessFlags.None,
                Format = Format.R32_Float,
                Height = 256,
                Width = 256,
                MipLevels = 1,
                OptionFlags = ResourceOptionFlags.None,
                SampleDescription = new SampleDescription(1, 0),
                Usage = ResourceUsage.Default
            });
            var shadowView = new RenderTargetView(device, shadowBuffer, new RenderTargetViewDescription()
            {
                Format = Format.R32_Float,
                Dimension = RenderTargetViewDimension.Texture2D,
                MipSlice = 0,
            });
            shadowSView = new ShaderResourceView(device, shadowBuffer, new ShaderResourceViewDescription()
            {
                Format = Format.R32_Float,
                Dimension = ShaderResourceViewDimension.Texture2D,
                MostDetailedMip = 0,
                MipLevels = 1,
            });

 

 

I then render depth values to this texture and use it in another shader.  My problem is that when the values are sampled from the texture, they are clamped to 0-1.

Any help is appreciated.

 

EDIT: It has occured to me that the problem may lie in light matrices.  I create a orthographic projection and view matrix to act as a view from the sun:

 

        private static void SetUpSun()
        {
            SunProj = Matrix.OrthoLH(512, 512, 256, 1024);
        }

        private static void UpdateSun()
        {
            Vector3 SunPos = new Vector3((float)Math.Sin(wt / 1f) * -512, (float)Math.Cos(wt / 1f) * -512, 0) + Camera.Position;
            SunView = Matrix.LookAtLH(SunPos, Camera.Position, Vector3.UnitY);
        }
Edited by Matthew Meeks
0

Share this post


Link to post
Share on other sites

Typically the depth values stored in the shadow map are in range 0..1.

 

I don't understand from your post what is the actual problem.

 

Best regards!

1

Share this post


Link to post
Share on other sites

Yeah sorry wrote that with a migraine and tried to do it as fast as possible, it didn't work.  I've changed some things around and got closer to what I wanted, getting values in-between 0 and 1, except now the farther objects are 0 and the closer are 1.  My understanding is that farther objects return depths closer to 1.

In the vs:

float4 worldPosition = mul(Output.position, World);
float4 viewPosition = mul(worldPosition, View);
Output.position = mul(viewPosition, Projection);

 

 

In the ps:

 

return input.position.z / input.position.w;

 

Really simple yet I still can't figure out why.

 

And just in case the problem lies in the matrices:

View:

View = Matrix.LookAtLH(Position, cameraFinalTarget, up);

Projection:

Projection = Matrix.PerspectiveFovLH((float)Math.PI / 4, (float)Width / (float)Height, 0.01f, 800f);

 

Thanks for the help and apologies for the vagueness of the original post.

Edited by Matthew Meeks
0

Share this post


Link to post
Share on other sites

Yeah the z-values should be in between 0..1 where 0 is closer and 1 is further.

 

Why are you dividing your z-value by w? Isn't the division by w done automatically?

 

If you are doing basic shadow mapping, you may even disable your pixel shader if you are outputting to a depth-stencil buffer.

 

Best regards!

0

Share this post


Link to post
Share on other sites

I have tried both with and without dividing by w with the same result.  I had placed the division of w to ensure that w was always one as it should have been.  I am not outputting to a depth-stencil buffer but rather a Texture2D render target.  Not sure if this is the preferred method but i choose this because I eventually want to do more with the shadow map (different levels of light from the same source for semitransparent objects).

 

EDIT: I will try binding a depth buffer and attempt that way.

 

Thanks for the help!

Edited by Matthew Meeks
0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0

  • Similar Content

    • By lonewolff
      Hi Guys,
      I am revisiting an old DX11 framework I was creating a while back and am scratching my head with a small issue.
      I am trying to set the pixel shader resources and am getting the following error on every loop.
      As you can see in the below code, I am clearing out the shader resources as per the documentation. (Even going overboard and doing it both sides of the main PSSet call). But I just can't get rid of the error. Which results in the render target not being drawn.
      ID3D11ShaderResourceView* srv = { 0 }; d3dContext->PSSetShaderResources(0, 1, &srv); for (std::vector<RenderTarget>::iterator it = rtVector.begin(); it != rtVector.end(); ++it) { if (it->szName == name) { //std::cout << it->srv <<"\r\n"; d3dContext->PSSetShaderResources(0, 1, &it->srv); break; } } d3dContext->PSSetShaderResources(0, 1, &srv);  
      I am storing the RT's in a vector and setting them by name. I have tested the it->srv and am retrieving a valid pointer.
      At this stage I am out of ideas.
      Any help would be greatly appreciated
       
    • By bowerbirdcn
      hi, guys, how to understand the math used in CDXUTDirectionWidget ::UpdateLightDir 
      the  following code snippet is taken from MS DXTU source code
       
        D3DXMATRIX mInvView;
          D3DXMatrixInverse( &mInvView, NULL, &m_mView );
          mInvView._41 = mInvView._42 = mInvView._43 = 0;
          D3DXMATRIX mLastRotInv;
          D3DXMatrixInverse( &mLastRotInv, NULL, &m_mRotSnapshot );
          D3DXMATRIX mRot = *m_ArcBall.GetRotationMatrix();
          m_mRotSnapshot = mRot;
          // Accumulate the delta of the arcball's rotation in view space.
          // Note that per-frame delta rotations could be problematic over long periods of time.
          m_mRot *= m_mView * mLastRotInv * mRot * mInvView;
          // Since we're accumulating delta rotations, we need to orthonormalize 
          // the matrix to prevent eventual matrix skew
          D3DXVECTOR3* pXBasis = ( D3DXVECTOR3* )&m_mRot._11;
          D3DXVECTOR3* pYBasis = ( D3DXVECTOR3* )&m_mRot._21;
          D3DXVECTOR3* pZBasis = ( D3DXVECTOR3* )&m_mRot._31;
          D3DXVec3Normalize( pXBasis, pXBasis );
          D3DXVec3Cross( pYBasis, pZBasis, pXBasis );
          D3DXVec3Normalize( pYBasis, pYBasis );
          D3DXVec3Cross( pZBasis, pXBasis, pYBasis );
       
       
      https://github.com/Microsoft/DXUT/blob/master/Optional/DXUTcamera.cpp
    • By YixunLiu
      Hi,
      I have a surface mesh and I want to use a cone to cut a hole on the surface mesh.
      Anybody know a fast method to calculate the intersected boundary of these two geometries?
       
      Thanks.
       
      YL
       
    • By hiya83
      Hi, I tried searching for this but either I failed or couldn't find anything. I know there's D11/D12 interop and there are extensions for GL/D11 (though not very efficient). I was wondering if there's any Vulkan/D11 or Vulkan/D12 interop?
      Thanks!
    • By lonewolff
      Hi Guys,
      I am just wondering if it is possible to acquire the address of the backbuffer if an API (based on DX11) only exposes the 'device' and 'context' pointers?
      Any advice would be greatly appreciated
  • Popular Now