• 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
Kurask

Using D3D11_QUERY_OCCLUSION

5 posts in this topic

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] Edited by Kurask
0

Share this post


Link to post
Share on other sites
Hey there, I've been working on it here still.

I see what you mean about fetching results immediately, and I fixed that. I also now create the array of query objects prior to runtime. Both improved the performance, however, I'm still doing something wrong as it does not actually do any culling.

Here's my new code. The render count always shows up as 0, therefore nothing is being set as OK to render with the correct texture. However, all of the object are rendered with the 20x20 texture, so the first loop is working.

[source lang="cpp"] // Go through all the models
for(int index = 0; index < modelCount; index++)
{
// Get the position of the model
m_ModelList->GetData(index, positionX, positionY, positionZ, color);

// Leftovers
radius = 1.0f;

// Check if the model is in the frustum
renderModel = m_Frustum->CheckCube(positionX, positionY, positionZ, radius);

// If it can be seen...
if(renderModel)
{
// Move the model to the location it should be rendered at.
D3DXMatrixTranslation(&worldMatrix, positionX, positionY, positionZ);

// Prime the buffers
m_Model->Render(m_D3D->GetDeviceContext());

// Start the query
m_D3D->GetDeviceContext()->Begin(m_pPredicate[index]);

// Render the model to the world using the 20x20 texture
result = m_LightShader->Render(m_D3D->GetDeviceContext(), m_Model->GetIndexCount(), worldMatrix, viewMatrix, projectionMatrix,
m_Model->GetTexture(2), m_Light->GetDirection(), m_Light->GetAmbientColor(), m_Light->GetDiffuseColor());

// End the query
m_D3D->GetDeviceContext()->End(m_pPredicate[index]);

// Reset the world matrix
m_D3D->GetWorldMatrix(worldMatrix);
}
}

// Go through all the models
for (int index = 0; index < modelCount; index++)
{
// Stores the result of the query
bool renderM = 0;

// Get the result of the query and store it to renderM
m_D3D->GetDeviceContext()->GetData(m_pPredicate[index], &renderM, sizeof(BOOL), 0);

// If the query said the object was OK to render... (IS NOT WORKING AT ALL)
if (renderM == true)
{
// Reset the status to false
m_D3D->GetDeviceContext()->SetPredication(m_pPredicate[index], FALSE);

// Get the model information
m_ModelList->GetData(index, positionX, positionY, positionZ, color);

// Move the model to the right location
D3DXMatrixTranslation(&worldMatrix, positionX, positionY, positionZ);

// Prime the buffers
m_Model->Render(m_D3D->GetDeviceContext());

int texture;
if (positionY == 0)
texture = 3;
else
if (positionY >= -16)
texture = 2;
else
texture = 1;

// Render the model to the screen with the right 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());

// Reset to the original world matrix.
m_D3D->GetWorldMatrix(worldMatrix);

// Since this model was rendered then increase the count for this frame.
renderCount++;
}
}[/source]


And now I have to ask, how is everyone else handling this? It doesn't appear to be a common question on the internet at all! Right now my testing is done with 1 model rendered in 10,000 different locations, but that will increase massively once I find a good method for occlusion. The FPS performance is already far less than I want for what I currently have.
0

Share this post


Link to post
Share on other sites
Fair enough, I figured it wasn't that great of a way.

I'll look for another method then. In the end, I only plan on having maybe 5 different models and have them rendered thousands of times each. Edited by Kurask
0

Share this post


Link to post
Share on other sites
[quote name='MJP' timestamp='1350682551' post='4991944']
The reason you can't find much information is because not many people are doing it. Plenty have tried, and failed. It's really hard to make occlusion queries work for a general visibility system, due to the latency and batching problems.
[/quote]

+1; there is wisdom in this.

Occlusion queries are one of those features that look [b]great[/b] on paper, but when you actually start implementing something and dealing with all of the nasty edge cases you quickly realise that they're not exactly all they're cracked up to be.

What they [i]may[/i] be good for is pre-processing a map to determine visibility info, but at runtime there are just too many places where they can fail to give you a good result to make them of much utility for a general case solution.
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