Jump to content

  • Log In with Google      Sign In   
  • Create Account

Awesome job so far everyone! Please give us your feedback on how our article efforts are going. We still need more finished articles for our May contest theme: Remake the Classics

#ActualKurask

Posted 11 October 2012 - 03:23 PM

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<modelCount; 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]

#4Kurask

Posted 11 October 2012 - 03:22 PM

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 (Frustrum 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<modelCount; 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]

#3Kurask

Posted 11 October 2012 - 02:25 PM

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 to 1 and only half works. 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<modelCount; 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]

#2Kurask

Posted 11 October 2012 - 02:24 PM

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 to 1 and only half works. 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<modelCount; 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]

#1Kurask

Posted 11 October 2012 - 02:09 PM

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 to 1 and only half works. 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.

PARTNERS