#Capturing BaseColor of terrain

1 messages · Page 1 of 1 (latest)

lime sentinel
#

Hi guys,

I would like to capture the BaseColor (also World Normals, but that's something for later) of my terrain to be used to tint my grass. So basically, that the terrains texture is directing the color of the grass.

With this post I would like to ask you, what your approach would be.

I am pretty new to this whole stuff, but this is what my current attempt looked like:

First, I've created a orthogonal camera and have set all the necessary stuff to match my terrain so that only my terrain get rendered.
As an output I have set a render texture and thought, well, there might be an option to capture only the BaseColors.
Well, there wasn't, but then I've found the feature called Custom Passes. And this is the moment, I am kind of lost.

I create the custom pass volume and set the mode from global to camera. After choosing the right camera, I've created a Fullscreen Custom Pass and there is a field to insert a shader to inject something. So when I understand it correctly:

The camera is doing it's thing - rendering the whole scene from above.
This get rendered to a render texture.
Between these two, the custom pass , a shader, get injected and modifies what is rendered to the render texture.
This shader just outputs the BaseColor.

Is this correct so far?

Thanks for helping 🙂

rough bobcat
#

If it works, then that's great! Only change it if it breaks or if performance is too bad.
You could also use the ortho cam once, and disable it afterwards. This was the texture for the grass should stay there, without the costs of another camera!
This cost is just texture sampling, which is good.

YouTube has a lot of content about how to render grass btw, worth a deep dive even if it is just for education

lime sentinel
#

Okay, so theoretically this would work?
My problem was to get access to the gbuffer within the shader :/

Beside this, I've found the RenderGraph as a feature ... this could also work in that scneario?
I am still pretty new to Unity and I am a bit overwhelmed with the options, to recognize later, that it does not work at all.

I also wanted to capture just one frame and deactivate the camera/render texture later to get just a static Texture2D.
So I think, hope, this won't affect the performance that much.

dire copper
#

Couldn't you just derive the color from the splatmap instead of using a render texture?

#

Similarly for normals and using heightmaps

#

Otherwise it's probably fine to use a secondary camera and just capture the terrain only and throw that onto a texture.

gusty echo
#

I would try to just sample the splat map directly in a shader

lime sentinel
#

Wait a minute? How can you so easily get access to the SplatAlpha? This would be really helpful actually for other stuff like shrinking the grass when it is transitioning to soil for example!
Anyway, doing it like this feels a bit wasteful - sampling the same texture twice in to different shaders.

My goal was to save resources to capture the terrain with a fairly low resolution once at the beginning of the game and tint the grass with it. Thats it.

Otherwise, @dire copper , what do you mean deriving it by using the splatmap? The same Spazi suggested?
Beside this, I would like to avoid capturing the terrain in its lit state. I do not want to have shadows for example to tint the grass albedo .. or the general lighting.

dire copper
#

Well, you can sample it twice or edit the actual shader code which I doubt you'd want to touch

#

There's a package called TerrainToolbox or something like that which will extract the splatmap for you otherwise

#

Unless there's a better way to get that information, but I don't really like messing with the terrain shader lel

gusty echo
#

If you want a low resolution sample you can use SampleTexture2DLOD but I doubt that makes much of a difference, GPUs are good at picking the right texture LOD automatically for best balance of quality and performance

#

The difference is that it won't be a color image of the terrain, but the splat map so you'd need to sample textures for the texture blending again, or do the blending with colors only
I would not worry about a few extra texture samples but if you have a lot of layers, it could be viable to save those to a color texture so you only need to sample it

#

But I'd only worry about doing that in editor where you have much more tools available to do it

#

For example, if you enable Rendering Debugger's Material Override: Albedo it affects RT cameras too

#

So copying it to a persistent texture at that moment should preserve the effect

#

And no need to design your own render pass to do it
Or even to figure out how unity's own is meant to be used "correctly" if you want to invoke it on command