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

Grass Rendering Questions

8 posts in this topic

Hey all,

 

I've been working on grass rendering trying to achieve an effect much like Flower achieved.

 

I've got a basic setup working using points in the cells of a heightfield which are then extruded to grass blades in a geometry shader (I have the distribution set to 1 blade per cell while debugging). I'm running into a nasty hang up and wanted to ping the community for some ideas:

 

Right now I generate a one sided (although culling is disabled) triangle strip, this means I only have normals for 1 side of the strip. Ideally I'd like both sides to have normals so the blade is properly lit on both sides, but I see no way of doing that without either generating double the geometry or billboarding the grass blade (which I really don't want to do). Any thoughts?

 

Screenshot attached (note the blades are unlit currently and they need a random rotation applied since they currently look pretty nasty whenever you are perpendicular to them).

0

Share this post


Link to post
Share on other sites

Alright, Unbird is trying to keep me honest and requested an update so here we go.

 

I've mainly been working on partitioning up the grass into various cells so I can enable a greater density without the framerate hit. Even in this very early stage it seems to be working (the red lines are the cell bounds):

 

[attachment=23108:moarGrass.png]

 

That's at 5 x 5 blades per 1 cell of the heightmap (although I have some doubts about what is actually being rendered which I'll get to in a moment). Previously that would slam my system down to 20 - 30 FPS but now it sits at 60FPS without any trouble. Success! Right now I have a 512M x 512M divided up in 8 x 8 chunks, obviously there is a balance there between doing visibility tests against each cell's bounds (as well as the overhead of more draw calls) but right now my system does that in another thread happily so I may play with how finely I divide up my grass cells.

 

I also turned on some very basic LOD to help smooth things out, Ideally I'd like to just toss the vertex away if the vertex is far away enough (and thus avoid the GS work), but I'm not sure how I could do that in the vertex shader. If anyone has any suggestions I'd appreciate it.

 

Here you can see the LOD zones (these are just really simply first passes, I probably need to get more aggressive):

 

[attachment=23109:lodDebug.png]

 

Red > Orange > Blue > Green

 

Finally I noticed an annoying issue where my HLSL random function doesn't seem to actually be generating random values. Hence the large amount of uniformity in all these screenshots. You can see here where there's some small random being introduced, but then directly next to those blades sit a bunch of uniform blades:

 

[attachment=23110:grassRandom.png]

 

I'm currently using the very basic GLSL random (in HLSL):

float GetRandomValue(float2 uv)
{
	// Internet magic numbers follow...
	float2 noise = (frac(sin(dot(uv, float2(12.9898, 78.233)*2.0)) * 43758.5453));
	return abs(noise.x + noise.y) * 0.5;
}

In my shader I have a table of prime numbers which I just multiple the root vertex's UV coords by, using the GS Instance as the key into the prime numbers table:

// IN = Root position vertex passed from the Vertex Shader
// primeTable = Array of prime numbers.
// instanceId = SV_GSInstanceID

float random = GetRandomValue(IN.Uv * (float)(primeTable[instanceId]);

My thoughts are:

  • Not sure how well this works if you have UV (0.0, 0.0).
  • It probably just makes more sense to populate a texture coordinate with some random numbers rather than key off the UVs of the root vertex.
  • I'm curious if this is causing some blades to stack on top of each other so I'm not getting the full effect currently.

Anyway, that's the latest. Comments / Thoughts / Suggestions always welcomed.

 

1

Share this post


Link to post
Share on other sites
Thanks for the update wink.png

Procedural randomness (or rather randomness on the fly) sounds attractive, but I found it tricky get right. Since you can't use a PRNG with state you end up using a hash of some sort. This looks like one of those typical float based hashes (some transcendental functions and magic numbers). They're cheap but I found that they can expose a pattern. Integer based ones look better but aren't that cheap. I also wonder if you can get e.g. blue noise or something this way (cheaply, that is). So yeah, a lookup (vertex stream or texture) sounds reasonable. One can of course combine the two approaches.
 

Not sure how well this works if you have UV (0.0, 0.0).

Currently, you just multiply, so all instances get the same random feed. You have to experiment here, e.g. use a offset:

float random = GetRandomValue(IN.Uv + primeTable[instanceId].xx);
And I wonder why primes. Also check the dimensions. You could provide a random (float2) offset table.

I'm curious if this is causing some blades to stack on top of each other so I'm not getting the full effect currently.

Depends on how you apply the randomness. If you don't offset the position more than half a blade's cell size, they should never intersect.
2

Share this post


Link to post
Share on other sites

Thanks for the update wink.png

 

Being on the hook helped me knock out quite a bit yesterday, so thanks for proding me.

 

 

Procedural randomness (or rather randomness on the fly) sounds attractive, but I found it tricky get right. Since you can't use a PRNG with state you end up using a hash of some sort. This looks like one of those typical float based hashes (some transcendental functions and magic numbers). They're cheap but I found that they can expose a pattern. Integer based ones look better but aren't that cheap. I also wonder if you can get e.g. blue noise or something this way (cheaply, that is). So yeah, a lookup (vertex stream or texture) sounds reasonable. One can of course combine the two approaches.

 

Yea, I'm finding this to be very true. My plan is to overhaul how I'm currently doing random with the shader. Doing something like white/blue noise during mesh construction wouldn't be the end of the world. The problem being is that each blade generated needs its own "Randomness", this means up to 32 random values need to be generated per root vertex (one for each possible blade). A better solution would might be to use some noise texture, maybe randomly rotate it based on some initial seed value, and then just have each blade sample that. But I'm just thinking out loud here and will need to experiment.

 

 

And I wonder why primes. Also check the dimensions. You could provide a random (float2) offset table.

 

Using primes was just an attempt to alter the hash enough per blade to get unique values - obviously didn't work too well. :)

 

 

Depends on how you apply the randomness. If you don't offset the position more than half a blade's cell size, they should never intersect.

 

Correct, I believe I'm currently doing that but I saw some blades intersected but that could be just bad math in how I apply the randomness. I'll need to verify.

 

Thanks for all the feedback / suggestions.

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