• Advertisement
Sign in to follow this  

about math in implementing frustum culling

Recommended Posts

this code is from introduction to DX11 by Frank D Luna.
I kind of understand the theory of this.
first get frustum coordinates in view space.
get model's world matrix and view matrix.
get inverse matrix to find out frustum's coordinates in model's local.

my question is, why do I only need X component of scale matrix?
what if the object got stretched by z,y axis?
 


    for(UINT i = 0; i < mInstancedData.size(); ++i)
          {
             XMMATRIX W = XMLoadFloat4x4(&mInstancedData.World);
             XMMATRIX invWorld = XMMatrixInverse(&XMMatrixDeterminant(W), W);
         // View space to the object's local space.
         XMMATRIX toLocal = XMMatrixMultiply(invView, invWorld);
      
         // Decompose the matrix into its individual parts.
         XMVECTOR scale;
         XMVECTOR rotQuat;
         XMVECTOR translation;
         XMMatrixDecompose(&scale, &rotQuat, &translation, toLocal);

         // Transform the camera frustum from view space to the object's local space.
         XNA::Frustum localspaceFrustum;
         //TransformFrustum(&localspaceFrustum, &mCamFrustum, XMVectorGetX(scale), rotQuat, translation);
         XNA::TransformFrustum(&localspaceFrustum, &mCamFrustum, XMVectorGetX(scale), rotQuat, translation);
         
         // Perform the box/frustum intersection test in local space.
         if(XNA::IntersectAxisAlignedBoxFrustum(&mSkullBox, &localspaceFrustum) != 0)
         {
            // Write the instance data to dynamic VB of the visible objects.
            dataView[mVisibleObjectCount++] = mInstancedData;
         }
      }

      md3dImmediateContext->Unmap(mInstancedBuffer, 0);
   }
 

Share this post


Link to post
Share on other sites
Advertisement

It looks like TransformFrustum only takes a single value as a scale, so even though the matrix supports full XYZ 3d scaling, this just breaks it down to 1D scaling, so the X scale is used for all XYZ values.

Oddly, if you look inside the TransformFrustum call, it actually creates a full XYZ 3D vector from the single scale value, then uses that with its internal transformations.  It seems like the function should just take a XYZ scale to begin with, instead of converting from/to.

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  

  • Advertisement
  • Advertisement
  • Popular Tags

  • Advertisement
  • Popular Now

  • Similar Content

    • By austin blaschke
      My Name is Austin Blaschke,
      Dear Everyone, I'm starting a big project and I need a team to help me with it. I'm mainly doing this for a full pitch purpose but also to make something valuable for the community. You will not be paid but if any of the projects makes a profit, it will be split equally among all members after we pitch the game. I'm looking for people who enjoy what they are doing and are willing to improve their skills and learn from their mistakes. I need anyone from music/sound production to game designers to code writers to visual designers and the whole yard. You do not need to be a professional and also no age limits are set but if possible i would like skilled investors to make this amazing. I'm not going to be doing this a 100% of the time because of educational purposes (College). I will be on every day, for around 2/3 hours but that doesn't mean that the whole operation is stopped. The development can still continue even without my presence.
      Im looking for a group of people that work well together and can work with anyone on this project looking for anyone. 
      Msg me at ablaschke99@gmail.com or join this discord server https://discord.gg/snhBvwF
    • By mister345
      Hi, I'm on Rastertek series 42, soft shadows, which uses a blur shader and runs extremely slow.
      http://www.rastertek.com/dx11tut42.html
      He obnoxiously states that there are many ways to optimize his blur shader, but gives you no idea how to do it.
      The way he does it is :
      1. Project the objects in the scene to a render target using the depth shader.
      2. Draw black and white shadows on another render target using those depth textures.
      3. Blur the black/white shadow texture produced in step 2 by 
      a) rendering it to a smaller texture
      b) vertical / horizontal blurring that texture
      c) rendering it back to a bigger texture again.
      4. Send the blurred shadow texture into the final shader, which samples its black/white values to determine light intensity.
       
      So this uses a ton of render textures, and I just added more than one light, which multiplies the render textures required.
       
      Is there any easy way I can optimize the super expensive blur shader that wouldnt require a whole new complicated system?
      Like combining any of these render textures into one for example?
       
      If you know of any easy way not requiring too many changes, please let me know, as I already had a really hard time
      understanding the way this works, so a super complicated change would be beyond my capacity. Thanks.
       
      *For reference, here is my repo, in which I have simplified his tutorial and added an additional light.
       
      https://github.com/mister51213/DX11Port_SoftShadows/tree/MultiShadows
       
    • By Matt_Aufderheide
      I have never quite been a master of the d3d9 blend modes.. I know the basic stuff, but have been trying for a while to get a multiply/add blending mode... the best I can figure out is mult2x by setting:
      SetRenderState(D3DRS_DESTBLEND, D3DBLEND_SRCCOLOR);
      SetRenderState(D3DRS_SRCBLEND, D3DBLEND_DESTCOLOR);
      //this isn't quite what I want.. basically I wonder if there is a way to like multiply by any color darker than 0.5 and add by any color lighter than that..? I don't know, maybe this system is too limited...
    • By Ward Correll
      I include the source code from what I am playing with. It's an exercise from Frank Luna's DirectX 12 book about rendering a skull from a text file. I get a stack overflow error and the program quits. I don't know where I went wrong it's messy programming on the parts I added but maybe one of you masterminds can tell me where I went wrong.
      Chapter_7_Drawing_in_Direct3D_Part_II.zip
  • Advertisement