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

Instancing for trees/foliage

9 posts in this topic

Hi,

 

I was thinking about creating trees for my game. I have created instancing but after I have created 300 trees it made everything very slow. After that problem I was thinking about mixing instancing with octrees, but I wonder whether it's an overkill. Would just multiple tree objects (without instancing) with the octrees be enough? It would let me stay away from the more complicated octrees with instanced data.

 

I am talking about bigger terrain, let's say 1/3 of the skyrim.

 

I know that I could check it by myself, but it will take me at least a few days to implement and I don't know if it's even woth it, so maybe some of you already know this?

 

Thanks for some advices.

Edited by jajcek
0

Share this post


Link to post
Share on other sites
Without profiling you won't know what the slow part is, so try to do that.

You should certainly be culling trees that are offscreen, but there's no way you would need an octree with a mere 300 so I doubt that's the sole solution. Once you have more, yes, you will need some sort of structure.

Instancing is useful, it saves memory and speeds up rendering, but it may not be worth the complexity (as long as you still share buffers and textures). You'll only find out by experimenting.
2

Share this post


Link to post
Share on other sites

Thanks for the answer.

 

The 300 trees was just an example I calculate oveer 1k + some other objects like rocks etc.

 

Actually I wasn't asking if some method will give me 3 FPS more, but whether it could be a hard bottleneck - the multiple objects for trees without instancing, only with octree. I have never written any 3D game yet, so I don't even have any general view on it. I'm gonna experiment then with pure objects + octree.

0

Share this post


Link to post
Share on other sites

a. Define "Slow"

b. What was the vertex count of those trees?

c. Do you use a heavy vertex shader?

d. Do you alpha blend or alpha test the leaves?

e. Do you also alpha blend/test the trunk?

f. Do you write your own custom depth? (you shouldn't be doing that)

g. Are you doing shadow maps? If so, are you using cascades?

h. Don't think in adding "3 fps" more, think in gaining "10 ms" more (milliseconds)

 

There was a massive lack of information in order to help you.

Edited by Matias Goldberg
0

Share this post


Link to post
Share on other sites

Uhm, well...

 

a. Just that feeling while moving mouse and it doesn't give you the fluency (lol).

b. Hmm, before I have posted the question I thought my tree has around 300 vertices that's why I was wondering why the game is not fluent with 300 trees, but actually it has 2800... I don't know how could I overlook this.

c. I don't think it's heavy. I calculate there instance data like position, scale and rotation + multiplying it by the primary matrices (world, view, projection).

d. Alpha blend with black&white map.

e. No.

f. What is that? I am passing depth to the pixel shader in order to calculate fog.

g. No shadows yet. Don't even know what the cascades are.

 

Sorry for the irritating questions/sentences, I am a beginner in game dev.

0

Share this post


Link to post
Share on other sites

a. Just that feeling while moving mouse and it doesn't give you the fluency (lol).

Ugh, measure the framerate. Possibly in milliseconds & (less priority) in fps.

b. Hmm, before I have posted the question I thought my tree has around 300 vertices that's why I was wondering why the game is not fluent with 300 trees, but actually it has 2800... I don't know how could I overlook this.

2800v * 300 instances = 840.000 vertices per frame.
At 30 fps that's 25.200.000 vertices per second. That's still way below what a decent GPU can perform (i.e. a quick Google shows that the old Geforce 6600 can do 375 million vertices per second, divide that value by 4 to 10 because those are raw specs)

But of course, it's not the same if you're running in an Intel HD 3000 series than a GeForce 690 or Radeon HD 7990. What GPU do you have? (and what CPU btw.)

c. I don't think it's heavy. I calculate there instance data like position, scale and rotation + multiplying it by the primary matrices (world, view, projection).

Ok, fair enough. May be there's some inefficiency that has been unnoticed (i.e. I assume you pass the worldViewProj matrix, instead of passing the 3 matrices and concatenating them in the shader)

d. Alpha blend with black&white map.
e. No.

Gotcha! This is most likely the culprit. Alpha blending is expensive. It consumes a lot of bandwidth. Switch to alpha test. If you don't like the results, consider using alpha blending for the close trees, and alpha blending for the far trees.
Using CSAA for nice, smooth leaves while using alpha testing is also another possibility (though this topic is probably more advanced)

f. What is that? I am passing depth to the pixel shader in order to calculate fog.

Good, don't worry. Just checking. Btw. That feature allows you to alter from the depth in pixel shader that was going to be passed to Z Buffer that was calculated from the vertex shader. However this has severe performance impacts.
If you don't know what it is, then you're probably not using it.

g. No shadows yet. Don't even know what the cascades are.

Ok, just checking. Don't worry, you'll get there.

Cheers Edited by Matias Goldberg
1

Share this post


Link to post
Share on other sites

Hey, thank you for your interest.

 

 

Ugh, measure the framerate. Possibly in milliseconds & (less priority) in fps.

My debug says that it's ~70 fps (and frame time is like 0.015 up to 0.02ms), but I cannot believe it... I'm sure the 60 fps make the game very fluent, but still I have feeling that it's not fluent in my game.

 

 

What GPU do you have? (and what CPU btw.)

 

It's GeForce 8800GT 512MB. CPU is Intel Quad Q6600 2.4 GHz.

 

 

I assume you pass the worldViewProj matrix, instead of passing the 3 matrices and concatenating them in the shader)

 

I pass to shader 3 matrices separately.

Edited by jajcek
0

Share this post


Link to post
Share on other sites
If the frame time is 15-20ms (you actually gave seconds above) then perhaps the lack of smoothness is due to inconsistency, especially if you have vsync turned on. You need to be at or under 16ms for a smooth 60fps.

The good news is you're not far off. Unfortunately I can't tell you what the slow part is. Could be GPU, could be draw calls, could be something else. Hence the advice to profile it.

Easy way to tell if alpha blending/overdraw is the culprit: halve the resolution and see if it makes a difference.
1

Share this post


Link to post
Share on other sites

If you are going to do arbitrary matrix manipulation for some instances, that's a good reason to switch to dynamic vertex buffers. Your second stream (instance) would contain the dynamic buffer. 

 

For me, high polycount was the bottleneck because I was able to brute-force cull many thousands of instanced cubes no problem with >60 FPS. But trees are obviously more complex and my engine is not the same as yours so you would need your own approach to profiling it. Unless these objects are over 100k triangles each, instancing 30 of each usually shouldn't cause a problem.

 

Eventually I plan to go with impostors for rendering most of the trees, so you may consider that or simpler billboard sprites. Only the closest trees will be full meshes with instancing.

1

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