unitycoder / UnityPointCloudViewer

Point Cloud Viewer and Tools for Unity
https://assetstore.unity.com/packages/tools/utilities/point-cloud-viewer-and-tools-16019?aid=1101lGti
128 stars 15 forks source link

HDRP support #105

Open unitycoder opened 3 years ago

unitycoder commented 3 years ago

not included in the asset store package yet, but can try this: (2019.4.19f1 + HDRP 7.1.8, for V1/V2 viewer (not v3 tiles viewer))

Custom pass script:

using UnityEngine;
using UnityEngine.Rendering.HighDefinition;
using UnityEngine.Rendering;

class NewCustomPass : CustomPass
{
    protected override void Setup(ScriptableRenderContext renderContext, CommandBuffer cmd)
    {
        // Setup code here
    }

    protected override void Execute(ScriptableRenderContext renderContext, CommandBuffer cmd, HDCamera camera, CullingResults cullingResult)
    {
        if (unitycodercom_PointCloudBinaryViewer.PointCloudViewerDX11.instance == null) return;
        cmd.DrawProcedural(Matrix4x4.identity, unitycodercom_PointCloudBinaryViewer.PointCloudViewerDX11.instance.cloudMaterial, 0, MeshTopology.Points, unitycodercom_PointCloudBinaryViewer.PointCloudViewerDX11.instance.points.Length);
        renderContext.ExecuteCommandBuffer(cmd);
    }

    protected override void Cleanup()
    {
        // Cleanup code
    }
}
unitycoder commented 3 years ago

for 2020.2.2f1 + HDRP 10.2.2 same process as above, custom pass script is bit different:

New Custom Pass.cs

using UnityEngine;
using UnityEngine.Rendering.HighDefinition;
using UnityEngine.Rendering;

class NewCustomPass : CustomPass
{
    protected override void Setup(ScriptableRenderContext renderContext, CommandBuffer cmd)
    {
    }

    protected override void Execute(CustomPassContext ctx)
    {
        if (unitycodercom_PointCloudBinaryViewer.PointCloudViewerDX11.instance == null) return;
        ctx.cmd.DrawProcedural(Matrix4x4.identity, unitycodercom_PointCloudBinaryViewer.PointCloudViewerDX11.instance.cloudMaterial, 0, MeshTopology.Points, unitycodercom_PointCloudBinaryViewer.PointCloudViewerDX11.instance.points.Length);
    }

    protected override void Cleanup()
    {
    }
}
unitycoder commented 2 years ago

Just tested this with Unity XR + Oculus, works with HDRP+VR also.

unitycoder commented 2 years ago

for Unity 2020.3.21f1 + HDRP 10.6.0 and V3 tiles viewer:

New Custom PassV3.cs: (or which ever you named it)

using UnityEngine;
using UnityEngine.Rendering.HighDefinition;
using UnityEngine.Rendering;
using UnityEngine.Experimental.Rendering;
using unitycodercom_PointCloudBinaryViewer;

class NewCustomPassV3 : CustomPass
{
    // It can be used to configure render targets and their clear state. Also to create temporary render target textures.
    // When empty this render pass will render to the active camera render target.
    // You should never call CommandBuffer.SetRenderTarget. Instead call <c>ConfigureTarget</c> and <c>ConfigureClear</c>.
    // The render pipeline will ensure target setup and clearing happens in an performance manner.
    protected override void Setup(ScriptableRenderContext renderContext, CommandBuffer cmd)
    {
        // Setup code here
    }

    protected override void Execute(CustomPassContext ctx)
    {
        // Executed every frame for all the camera inside the pass volume.
        // The context contains the command buffer to use to enqueue graphics commands.
        if (PointCloudViewerTilesDX11.instance == null) return;

        for (int i = 0, len = PointCloudViewerTilesDX11.instance.tilesCount; i < len; i++)
        {
            if (PointCloudViewerTilesDX11.instance.tiles[i].isReady == false || PointCloudViewerTilesDX11.instance.tiles[i].isLoading == true || PointCloudViewerTilesDX11.instance.tiles[i].visiblePoints == 0) continue;
            ctx.cmd.DrawProcedural(Matrix4x4.identity, PointCloudViewerTilesDX11.instance.tiles[i].material, 0, MeshTopology.Points, PointCloudViewerTilesDX11.instance.tiles[i].visiblePoints);
        }
    }

    protected override void Cleanup()
    {
        // Cleanup code
    }
}
PascalRunde commented 1 year ago

Will there be a version of the shader that works with instanced singlepass rendering for VR? Or does it already exist and I missed it somehow? Thanks in advance!

unitycoder commented 1 year ago

Ok that doesnt seem to be working. just tested in V3 viewer in hdrp+single pass instanced+oculus : no points rendered (multipass works). I'll look into it.

unitycoder commented 1 year ago

Ok, some progress:

if you can test it, pm me in forums or send email, i'll send the shader.

The main v2 billboard shader almost works, right eye has some distortion (probably related to using direct camera xyz values in shader..), still looking into that.

*ok v2 billboard shader works also, i'll include these in the next asset store update too, hopefully later this month.