Manually Rendering Meshes and Models

How do you use the Mesh and Model Draw() methods? I have tried using them in a PostEffect script and attempted hooking them into some RenderTask callbacks but cannot seem it get it to work. I am attempting to draw a bunch of instances simulate to how I would do it in Unity by submitting a model and an array of Transform information.

I anticipate this might be a longer thread as I have a couple more questions regarding this but this is the first step I need to figure out.

Do you want to render custom meshes into the view or implement a whole custom rendering pass?

Custom drawing pass that uses utility API to draw scene objects into a depth map:

Example how Editor’s gizmos are rendering custom meshes during editor viewport drawing callback:

Currently I am just trying to Render a custom mesh with material using the RenderPipeline.
Here is a simple example of what I am trying.

public class DrawModel : PostProcessEffect
{
    
    public Model Model;

    public Material Material;

    // Just referencing Actor to use transform for debugging
    // I don't want to actualy use the Actor
    public Actor TargetTransform;
    Matrix _matrix;
    public bool Valid;

    public override bool CanRender()
    {
        Valid = (Model != null && Material != null && TargetTransform != null);
        return Valid && this.Actor.IsActiveInHierarchy;
    }

    public override void Render(GPUContext context, ref RenderContext renderContext, GPUTexture input, GPUTexture output)
    {
        _matrix = TargetTransform.Transform.GetWorld();
        Model.Draw(ref renderContext, Material, ref _matrix); // Nothing happens..
    }
}

So to elaborate a little more. I’m trying to understand the graphics pipeline process.
I want to render a list of models/meshes that will render the same as Flax already does but without having to use the Renderer method that takes an actor list.

I am assuming I have to subscribe to multiple callbacks for each stage of the process (depth/gbuffer/forward) and loop through each mesh in the Model and submit a call with the material set to the specific pass.

But right now I’m just traying to get the Model.Draw() to do something lol.

So far using the PostProcessScript render method will draw the objects emission when set to after deffered. I have not been able to get anything to happen using callbacks from MainRenderTask.

Since I am able to atleast get emissions to render on the PostProcessScript I am assuming I might have to bind the targets for Normal and Diffuse as they are most likely multirender targets?

PostFx (as the name suggests) cannot interact with actual scene rendering that much. For this use events from Main Scene Rendering Task as follows:

public class DrawModel : Script
{
    public Model Model;
    public Material Material;
    public Actor TargetTransform;

    /// <inheritdoc />
    public override void OnEnable()
    {
        MainRenderTask.Instance.CollectDrawCalls += OnCollectDrawCalls;
    }

    /// <inheritdoc />
    public override void OnDisable()
    {
        MainRenderTask.Instance.CollectDrawCalls -= OnCollectDrawCalls;
    }

    private void OnCollectDrawCalls(ref RenderContext renderContext)
    {
        // Skip if something is missing
        if (!TargetTransform || !Model || !Material)
            return;

        // Draw model (will submit draw call)
        TargetTransform.GetLocalToWorldMatrix(out Matrix world);
        Model.Draw(ref renderContext, Material, ref world);
    }
}

But there was a bug in Flax 1.6 which was fixed in Fix double engine assembly init in Editor · FlaxEngine/FlaxEngine@03c120b · GitHub (you can use daily master build tomorrow or wait for Flax 1.7 release soon)

Ahh Im glad its a bug because I was going crazy thinking I was not understanding something. Thank you for clarifying and the example