Declare Global Variable from a shader (in context of Terrain Mesh Blending)

Let say, i have a terrain shader. It’s made using Amplify Shader Editor, and below here is my terrain shader. Ignore the Landscape name LOL:smile:

And thanks to the internet, i can create such depth shader. I create ortogprhc camera placed on top of the terrain, assign a render texture, and use that depth shader as Replacement Shader, so my camera render the depth of the terrain only (using layer) to the render texture. Then, (in the rock shader) i’m gonna use this depth data as a mask to Lerp between the terrain texture and the rock texture. To do that, i guess i have to get the terrain final albedo data and declare it as a global variable. Here is simple pict of mask in my Rock shader. currently, its only showing the mask because the mask is connected to the debug node.

So my question is, how to declare final albedo of my terrain shader, as global variable, so the rock shader can use it? What about GrabPass?
Every help would be very appreciated :slight_smile:

Don’t do it that way. Instead assign the terrain heightmap texture (need to be using GPU instanced terrain I think) to your rock shader then you can blend based on the y difference between the rock pixel world height and the terrain height under the rock.

1 Like

But don’t you need then assign all the same diffuse textures to the rock shader?

1 Like

Yes. The standard way to do this would be to only allow it to blend with 1 terrain material, or use virtual texturing for the terrain. The first one involves a custom shader, the second involves a custom terrain system.

1 Like