Search Unity

Vertex shader invalidates selection in the editor

Discussion in 'Scripting' started by Deleted User, Jan 18, 2014.

  1. Deleted User

    Deleted User

    Guest

    Hi. I've looked around for a solution to this for a while, but I haven't come up with much of anything.
    I have a written a shader that alters vertices so that the mesh is always oriented towards the camera. It's working well, however the selection system in the editor isn't aware of the adjustment and still selects the mesh based on it's pre-shadered vertex positions. Does anyone know a way to update the editor to recognize the new mesh orientation?
    Thanks for any help you can provide.
     
    Last edited by a moderator: Jan 19, 2014
  2. hpjohn

    hpjohn

    Joined:
    Aug 14, 2012
    Posts:
    2,190
    Seems unlikely. Selection is handled on the CPU, and vert transformation happens on the GPU, after the cpu has 'finished' with an object.
     
  3. shaderbytes

    shaderbytes

    Joined:
    Nov 11, 2010
    Posts:
    900
    I might be wrong but I very much doubt it. You would have to manipulate the actual vertex data in the programs memory via scripting , not at the GPU.
     
  4. Deleted User

    Deleted User

    Guest

    Yeah, that makes sense. Collecting vector-shader output isn't so easy that it'd just be implemented in unity. Ah well.
    I've found a way around the bad selection offsets. I've got a sphere gizmo drawn over the gameobject with an alpha of zero so you can't see it. The new selection area is fuzzy, but adequate. Now I just need to figure out how to disable the selection of the original mesh while leaving the gizmo selectable. It is, perhaps, unavoidable.
     
  5. shaderbytes

    shaderbytes

    Joined:
    Nov 11, 2010
    Posts:
    900
    just asking .. what is stopping you from doing the orientation to camera in an editor script?
     
  6. Deleted User

    Deleted User

    Guest

    It's kind of complicated to explain. I initially wrote this into the editor script as you suggest, and it worked well enough. However, there were a number of things that made the shader a preferable option. One, for instance, was that I still needed stable rotation values while the script was rotating the mesh to face the camera. This prompted moving the MeshRenderer to a sub-object, which actually caused most of the issues.

    A potential side effect is that shader may prove to be more optimized. I'm going to stress test both techniques tomorrow to figure out

    Btw, I'm looking into this issue further for two reasons:
    - Unity actually DOES recognize the vertex shader manipulations. I realized that it is highlighting the altered mesh just fine, meaning that it sees the changes on some level, just not on the selection level... yet.
    - The object culling is also thrown off. Admittedly, this is pretty easily fixable by changing the bounds.
     
  7. Deleted User

    Deleted User

    Guest

    Ooor I am an idiot, and it's just rendering the mesh with line rendering turned on. **facepalm**