My game’s got procedural levels, where it randomly spawns floating islands and stuff around. Everything looks a bit hard right now, and I’d like to soften it with some grass but I’ve no idea how. Do I just perform a bunch of downward raycasts in random spots to find out where to place the grass? Is there some kind of shader trickery I can do? What should I do?
Bump
Depends on what kind of grass you want.
If grass is purely visual, googling “Unity procedural grass shader” will yield tons of results.
If grass has properties (can be cut down, slows down cars, …) you might want them to be actual objects (but not necessarily), in which case googling “Unity procedural object placement” will yield tons of results.
Yeah, the grass is purely for visuals. Problem is that grass shaders need a lot of geometry, as it’s one blade per vertex. My game is low poly styled and can’t really do that.
I dont understand your problem to be honest. You are implementing it. So you have full control over what gets implemented. Noone said you should copy&paste code you found on one of those google results. You will never find exactly what you need for your project. Adjust it, do what fits your project.
I’m not entirely sure whether you are concerned about performance or looks here. A shader, where applicable, is usually the most performance efficient option unless you are already heavily using the GPU. If you fear a shader might be too slow, how would something less efficient be any better? If you are concerned about looks: again you are the one implementing it. Make the grass look however you feel fit.
im more just worried that i’ll have to subdivide my mesh a bunch. Unless grass shaders DON’T place one for each vertex but I think they do
Yes and no. There is different ways to approach grass shaders, but most commonly, you’d place the grass blades at certain points over your existing mesh. Naively, yes, this means vertices. But you yourself wont have to touch your actual mesh at all. As a rule of thumb, you are never the first person to encounter a specific problem, so chances are somebody else already encountered and solved it for you.
In this case the technique you can use is Tessellation. It basically subdivides triangles into more triangles to generate additional control points you can place your grass on. So while technically we are subdividing the mesh after all, you dont have to touch your actual mesh whatsoever. Instead you can write the shader in such way that it can scale the density of grass independantly to the complexity of the underlying surface - which is generally a good idea.
You should find plenty on that online, even in most grass shader tutorials, as it’s a common topic.
This seemed well made, but i only skipped through it so i cant vouch for it:
https://roystan.net/articles/grass-shader.html

Just as a quick side note, you need something like that anyways in order to let the player adjust grass density for performance or visual reasons. Manually subdividing your mesh to get more grass wouldnt help players that try to reduce it and vice versa.
I mean this shader’s grass placement seems to be (at least loosely) based on geometry, as the middle of the island (where there’s less) gets less grass placed. The grass also doesn’t stick out right
I cant say too much about the specific shader. However, it should be clear that while Tessellation enables you to scale your grass quantity up independant to how low poly your mesh is, if your mesh is inconsistant in polygon count you will still need to handle that separately. It’s a different topic.
I was thinking, maybe there’s a way involving rendering the map from the top? not exactly sure where I’m going with it but its a direction