How would you do a tiled grass shader?

Hey guys!

I’ve been obsessed with trying to recreate this tiled grass in A Monster’s Expedition.

I have a grass geometry shader, but the tile coloring is what stumps me. Is it possible to get that hand-painted organic tile coloring effect if my tiles are individual objects, and not one whole landmass object that can have a tiled texture map applied to it?

I’m super new to shaders, any help is appreciated!

Since your tiles are individual objects, what you can do is convert the object space position of the object to world space and use the resulting world space position to shift some color (or whatever other) values how you’d like. Since every tile will have a unique world-space position (as long as they haven’t been static-batched, because then they become one object in the GPU with a shared pivot), then each one will look uniquely colored.

Or you can use that world space position as the UV to sample a tiled noise texture to apply as tint for example. The possibilities are vast.

In your vertex program you can get the world position of the pivot of your object using float3 worldCenterPos = mul(_Object2World, float4(0.0,0.0,0.0,1.0)).xyz;.

The Object2World transformation matrix is being used to convert an object-space value of (0,0,0), which would effectively be the object pivot’s position in object-space, to a world-space value (its position in the world)

Or you can skip the matrix multiply and just grab the world transform with worldCenterPos = _Object2World[3]; :wink:

Then use the value however you see fit.

And if you’re using ShaderGraph, it has a Object node with a position value that is in world space.

Thanks! This gives me some good ideas. I’ll see what I can whip up :smile: