Sign in to follow this  
amadeus12

about math in implementing frustum culling

Recommended Posts

amadeus12    108

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
xycsoscyx    1150

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  

  • Similar Content

    • By noodleBowl
      I've gotten to part in my DirectX 11 project where I need to pass the MVP matrices to my vertex shader. And I'm a little lost when it comes to the use of the constant buffer with the vertex shader
      I understand I need to set up the constant buffer just like any other buffer:
      1. Create a buffer description with the D3D11_BIND_CONSTANT_BUFFER flag 2. Map my matrix data into the constant buffer 3. Use VSSetConstantBuffers to actually use the buffer But I get lost at the VertexShader part, how does my vertex shader know to use this constant buffer when we get to the shader side of things
      In the example I'm following I see they have this as their vertex shader, but I don't understand how the shader knows to use the MatrixBuffer cbuffer. They just use the members directly. What if there was multiple cbuffer declarations like the Microsoft documentation says you could have?
      //Inside vertex shader cbuffer MatrixBuffer { matrix worldMatrix; matrix viewMatrix; matrix projectionMatrix; }; struct VertexInputType { float4 position : POSITION; float4 color : COLOR; }; struct PixelInputType { float4 position : SV_POSITION; float4 color : COLOR; }; PixelInputType ColorVertexShader(VertexInputType input) { PixelInputType output; // Change the position vector to be 4 units for proper matrix calculations. input.position.w = 1.0f; // Calculate the position of the vertex against the world, view, and projection matrices. output.position = mul(input.position, worldMatrix); output.position = mul(output.position, viewMatrix); output.position = mul(output.position, projectionMatrix); // Store the input color for the pixel shader to use. output.color = input.color; return output; }  
    • By Armantium
      Lip-syncing and believable facial expressions.
      I have Maya licence for 3 years, but I haven't explored this aspect yet, as I've focused on mechanistic animations so far. I was wondering if there is a specialized software outside of Maya  that would make this very easy and quick. I would only need it for 3-5 characters, but I suppose I could use the exact same facial animation mechanism for all of them.
      If you are an experienced Maya user, I would appreciate your response even more. If the easy and quick solution already exists in Maya 2018, I would hate the expenditure of an additional specialized software(also, how time-consuming would it be if if you have about 1000 words of dialog).
       
       
       
       
    • By khawk
      CRYENGINE has released their latest version with support for Vulkan, Substance integration, and more. Learn more from their announcement and check out the highlights below.
      Substance Integration
      CRYENGINE uses Substance internally in their workflow and have released a direct integration.
       
      Vulkan API
      A beta version of the Vulkan renderer to accompany the DX12 implementation. Vulkan is a cross-platform 3D graphics and compute API that enables developers to have high-performance real-time 3D graphics applications with balanced CPU/GPU usage. 

       
      Entity Components
      CRYENGINE has addressed a longstanding issue with game code managing entities within the level. The Entity Component System adds a modular and intuitive method to construct games.
      And More
      View the full release details at the CRYENGINE announcement here.

      View full story
    • By khawk
      CRYENGINE has released their latest version with support for Vulkan, Substance integration, and more. Learn more from their announcement and check out the highlights below.
      Substance Integration
      CRYENGINE uses Substance internally in their workflow and have released a direct integration.
       
      Vulkan API
      A beta version of the Vulkan renderer to accompany the DX12 implementation. Vulkan is a cross-platform 3D graphics and compute API that enables developers to have high-performance real-time 3D graphics applications with balanced CPU/GPU usage. 

       
      Entity Components
      CRYENGINE has addressed a longstanding issue with game code managing entities within the level. The Entity Component System adds a modular and intuitive method to construct games.
      And More
      View the full release details at the CRYENGINE announcement here.
  • Popular Now