Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

How do i get albedo informatian from some material, using script?

Discussion in 'General Discussion' started by sammtan, May 8, 2021.


Which do u prefer?

  1. Unity Default Terrain

  2. Mesh as Terrain

  1. sammtan


    Jul 2, 2019
    Hi guys, im a noob at scripting.
    How do i get albedo information from some material?
    Basic material have albedo, normal, metallic, specular, anything else base on the shader. Then i want access that albedo, so my script can read that albedo data, for to use with my own purposes.

    For example, i have a mesh, and a terrain. I want to lerp my terrain albedo, with my mesh albedo. Then i create a script, at my mesh, to get the albedo from my terrain. How to do that?

    Also, i need another help.
    Which do you (guys) prefer, unity default terrain or terrain using mesh? Vote at the poll below. Plz

    Every solution and advice are acceptable. Built-in RP.
    Sorry for bad English
  2. neginfinity


    Jan 27, 2013
    It would be better if you said what you're trying to achieve.

    You can't do that easily, because albedo changes for each pixel, if the material is textured.

    If you use Raycast, then you can determine individual triangle you hit from the hit result, and coordinates within the triangle.
    Based on that data you could try determining which material you hit, and then you could manually sample texture, which will only work if the data is readable by the script in the first place.

    You could also try rendering the part of the terrain/mesh you want with a tiny render target and a replacement shader, and read the data from there.

    And in case of built-in terrain, you'd be using this:

    Which will give you access to blend values used by terrain, and then derive the values from there.

    That's why I said it would be a good idea to know what you're trying to do...


    Jun 1, 2017
    I can't tell you how but I know this is done with microsplat/megasplat. I think you can get a free version from the asset store - you could reverse engineer that.