Search Unity

Question ProBuilder: Get Vertex Color at UV coord

Discussion in 'World Building' started by CaseyHofland, Sep 24, 2022.

  1. CaseyHofland

    CaseyHofland

    Joined:
    Mar 18, 2016
    Posts:
    613
    We're making our game out of materials using vertex colors and now we want to add footsteps sounds. Normally that would be texture-based, but in this case we need it color-based.

    Code (CSharp):
    1.     // Step() is called from an animation event
    2. private void Step()
    3.     {
    4.         if (!Physics.Raycast(transform.position, -transform.up, out var hit, 0.25f, ExtraPhysics.GetLayerCollisionMask(gameObject.layer), QueryTriggerInteraction.Ignore)
    5.             || !hit.transform.TryGetComponent(out Renderer renderer)
    6.             || !renderer.sharedMaterial)
    7.         {
    8.             return;
    9.         }
    10.  
    11.         var material = renderer.sharedMaterial;
    12.         var textureCoord = hit.textureCoord;
    13.         // Get Vertex Color
    14.     }
    How do we do that though? The Standard Vertex Color shader (from the URP Sample) doesn't have a texture where this information is stored, which is probably not how vertex colors work but I'm noob and need help :|