Search Unity

Question Read pixel value from specific target?

Discussion in 'General Graphics' started by RZR_SRT, May 20, 2023.

  1. RZR_SRT

    RZR_SRT

    Joined:
    Dec 18, 2012
    Posts:
    18
    Hi there! I'm working on semi-wet/wet/dry road shader for my game. Wonder is there any simple way too get value from smoothness target? Purpose is to make more interaction. Splashes when wheels run over water(for example) .
    As far I understand GetPixel would' not work in that case. Theoretically there is runaround. Create separate camera which will render to texture smoothness target and attach above vehicle. Than attach plane with generated render texture under vehicle. Than shot rays from wheels position on to plane, and read pixels.
    May be there is shorter way?

    I'm using 2020.3.19f1/Built-in/DX11
     
    Last edited: May 20, 2023
  2. c0d3_m0nk3y

    c0d3_m0nk3y

    Joined:
    Oct 21, 2021
    Posts:
    672
    Maybe this would work:
    - Get the smoothness values from the texture and cache them somewhere
    - Make the road mesh CPU-readable
    - Create a MeshCollider with it and put it on a separate layer
    - Run a Physics.Raycast for each wheel for that layer
    - Use RaycastHit.textureCoordinate to look up the corresponding smoothness value from the array
    It is similar to what you said just without a separate camera, plane or render target

    Alternatively, you could store the smoothness in texCoord2 or lightmapCoord of the vertices, then you wouldn't have to look it up in the array (if the mesh is dense enough)

    Disclaimer: I have no idea if this actually works