Rendering Notes

IGL

All transform handles and gizmos implement IGL interface in order to be rendered in the scene


namespace Battlehub.RTCommon
{
    public interface IGL
    {
        void Draw(int cullingMask);
    }
}

GLRenderer

Located in Assets/Battlehub/RTCommon/Scripts/Graphics/GLRenderer.cs , GLRenderer is a singleton used by GLCamera script to render all registered IGL objects. To register object for rendering call void Add(IGL gl) method. To cancel object rendering call void Remove(IGL gl) method.

Here is how to create and register gizmo for rendering:


namespace Battlehub.RTCommon
{
    public class MyGizmo : MonoBehaviour, IGL
    {
        [SerializeField]
        private Material m_material;

        private void OnEnable() 
        {
            if (GLRenderer.Instance != null) 
            {
                GLRenderer.Instance.Add(this);
            }
        }

        private void OnDisable()
        {
            if (GLRenderer.Instance != null) 
            {
                GLRenderer.Instance.Remove(this);
            }
        }

        private void Draw(int cullingMask)
        {
            m_material.SetPass(0);
            RuntimeGraphics.DrawQuad(transform.localToWorldMatrix);
        }
    }
}

Note

It is possible that above code will not work with new scriptable rendering pipeline.
In this case Runtime Graphics Layer will be used to draw gizmos in future versions .

GLCamera

Located in Assets/Battlehub/RTCommon/Scripts/Graphics/GLCamera.cs
Add GLCamera component to Camera and it will render IGL objects.

Runtime Graphics Layer

Located in Assets/Battlehub/RTCommon/Scripts/Graphics/RuntimeGraphicsLayer.cs.
This component is created automatically in case if position handle, rotation handle or scale handle has reference to corresponding model (Model field is not null). This script will create Graphics Layer Camera parented to scene camera (main camera by default) and will set Clear Flags to the Depth only and Culling Mask to the RuntimeGraphicsLayer. At the same time RuntimeGraphicsLayer will be excluded from Culling Mask of scene camera. Transform handle models belong to RuntimeGraphicsLayer and therefore they will be renderer by Graphics Layer Camera only.

Screenshot

Note

Runtime Editor use 6 layers [19-24]: for ui, for asset previews and for runtime graphics.

Screenshot