Original Post
Has anyone used this for the purpose of occlusion culling and had it work for them?
I must be doing something wrong because it drops me from 70FPS (Frustum Culling only, 10,000 objects) to 1FPS and only half works (only one block works as an occlusion culler). If there is a better method for occlusion culling, please let me know. This appears to work well when used correctly, but I'm not sure how to correctly use it.... and I find Microsoft's reference guide to be useless for learning.
[source lang="cpp"] // Setup how the query functions
queryDesc.Query = D3D11_QUERY_OCCLUSION;
queryDesc.MiscFlags = 0;
// Create the query
m_D3D->GetDevice()->CreateQuery(&queryDesc, &pQuery);
// Go through all the models and render them only if they can be seen by the camera view.
for(index=0; index {
// Get the position and color of the object model at this index.
m_ModelList->GetData(index, positionX, positionY, positionZ, color);
// Texture number that holds the low resolution occlusion texture
texture = 4;
// Start the query
m_D3D->GetDeviceContext()->Begin(pQuery);
// Matrix translation
D3DXMatrixTranslation(&worldMatrix, positionX, positionY, positionZ);
// Render the object's occlusion texture
result = m_LightShader->Render(m_D3D->GetDeviceContext(), m_Model->GetIndexCount(), worldMatrix, viewMatrix, projectionMatrix,
m_Model->GetTexture(texture), m_Light->GetDirection(), m_Light->GetAmbientColor(), m_Light->GetDiffuseColor());
// End the query
m_D3D->GetDeviceContext()->End(pQuery);
// Get the data from the query and determine if object should be rendered
// Returns whether or not a object is in view. If 0, then the object is not in view.
while ( S_OK != m_D3D->GetDeviceContext()->GetData(pQuery, &queryData, sizeof(UINT64), 0 ) )
{
// If object is not in view
if (queryData == 0)
// Should not be rendered
renderModel = false;
// If object is in view
else
// Should be rendered
renderModel = true;
}
// Render the model if it was in view
if(renderModel)
{
// Move the model to the location it should be rendered at.
D3DXMatrixTranslation(&worldMatrix, positionX, positionY, positionZ);
// Put the model vertex and index buffers on the graphics pipeline to prepare them for drawing.
m_Model->Render(m_D3D->GetDeviceContext());
// Random texture thing (worked before this occlusion culling. now the culling texture takes over)
if (positionY == 0)
texture = 3;
else
if (positionY >= -16)
texture = 2;
else
texture = 1;
// Render the model using the light shader.
result = m_LightShader->Render(m_D3D->GetDeviceContext(), m_Model->GetIndexCount(), worldMatrix, viewMatrix, projectionMatrix,
m_Model->GetTexture(texture), m_Light->GetDirection(), m_Light->GetAmbientColor(), m_Light->GetDiffuseColor());
// Reset to the original world matrix.
m_D3D->GetWorldMatrix(worldMatrix);
// Since this model was rendered then increase the count for this frame.
renderCount++;
}
}
[/source]
I must be doing something wrong because it drops me from 70FPS (Frustum Culling only, 10,000 objects) to 1FPS and only half works (only one block works as an occlusion culler). If there is a better method for occlusion culling, please let me know. This appears to work well when used correctly, but I'm not sure how to correctly use it.... and I find Microsoft's reference guide to be useless for learning.
[source lang="cpp"] // Setup how the query functions
queryDesc.Query = D3D11_QUERY_OCCLUSION;
queryDesc.MiscFlags = 0;
// Create the query
m_D3D->GetDevice()->CreateQuery(&queryDesc, &pQuery);
// Go through all the models and render them only if they can be seen by the camera view.
for(index=0; index
// Get the position and color of the object model at this index.
m_ModelList->GetData(index, positionX, positionY, positionZ, color);
// Texture number that holds the low resolution occlusion texture
texture = 4;
// Start the query
m_D3D->GetDeviceContext()->Begin(pQuery);
// Matrix translation
D3DXMatrixTranslation(&worldMatrix, positionX, positionY, positionZ);
// Render the object's occlusion texture
result = m_LightShader->Render(m_D3D->GetDeviceContext(), m_Model->GetIndexCount(), worldMatrix, viewMatrix, projectionMatrix,
m_Model->GetTexture(texture), m_Light->GetDirection(), m_Light->GetAmbientColor(), m_Light->GetDiffuseColor());
// End the query
m_D3D->GetDeviceContext()->End(pQuery);
// Get the data from the query and determine if object should be rendered
// Returns whether or not a object is in view. If 0, then the object is not in view.
while ( S_OK != m_D3D->GetDeviceContext()->GetData(pQuery, &queryData, sizeof(UINT64), 0 ) )
{
// If object is not in view
if (queryData == 0)
// Should not be rendered
renderModel = false;
// If object is in view
else
// Should be rendered
renderModel = true;
}
// Render the model if it was in view
if(renderModel)
{
// Move the model to the location it should be rendered at.
D3DXMatrixTranslation(&worldMatrix, positionX, positionY, positionZ);
// Put the model vertex and index buffers on the graphics pipeline to prepare them for drawing.
m_Model->Render(m_D3D->GetDeviceContext());
// Random texture thing (worked before this occlusion culling. now the culling texture takes over)
if (positionY == 0)
texture = 3;
else
if (positionY >= -16)
texture = 2;
else
texture = 1;
// Render the model using the light shader.
result = m_LightShader->Render(m_D3D->GetDeviceContext(), m_Model->GetIndexCount(), worldMatrix, viewMatrix, projectionMatrix,
m_Model->GetTexture(texture), m_Light->GetDirection(), m_Light->GetAmbientColor(), m_Light->GetDiffuseColor());
// Reset to the original world matrix.
m_D3D->GetWorldMatrix(worldMatrix);
// Since this model was rendered then increase the count for this frame.
renderCount++;
}
}
[/source]