How to add custom editor scene picking and outline to custom vertex/fragment shader

I am writing a Unity Package that is intended for generating raymarching shaders in Unity. As a reference for what it generally looks like, here is another (not mine) similar project.

My package is used mainly in the editor (not runtime) and primitives are handled by regular game objects in the hierarchy. I would like to add support for selecting the objects with mouse in the scene view. I already have a shader that can return some ID for a given fragment, but I have no idea how to integrate this with the unity editor. The intended implementation would look similar to this.

I have been looking everywhere, including generated ShaderGraph shaders, and the only thing relevant in any way were passes defined with “LightMode” = “Picking” and “LightMode” = “SceneSelectionPass”

Shader graph has something related to that topic, but there is no documentation, no examples and no info how to support that. I found a bunch of relevant snippets and links:

// -- Property used by ScenePickingPass
#ifdef SCENEPICKINGPASS
float4 _SelectionID;
#endif

// -- Properties used by SceneSelectionPass
#ifdef SCENESELECTIONPASS
int _ObjectId;
int _PassValue;
#endif
#define SHADERPASS ScenePickingPass
  #define BUILTIN_TARGET_API 1
  #define SCENEPICKINGPASS 1
Pass {
  Name "ScenePickingPass"
  Tags {
    "LightMode" = "Picking"
  }
// ...
}

Does anyone how I can do that? In BIRP first, in URP second (but optional for now).

1 Like