Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

URP Support #126

Open
unitycoder opened this issue Dec 6, 2021 · 5 comments
Open

URP Support #126

unitycoder opened this issue Dec 6, 2021 · 5 comments

Comments

@unitycoder
Copy link
Owner

unitycoder commented Dec 6, 2021

using Unity 2019.4.25f1 + URP 7.7.1

temporary fix for URP+WorldSpace Canvas issue (point cloud get "stuck" inside canvas)
You dont need to do this, if you don't have world space canvas.
This is only for V1 (.bin) and V2 (.ucpc) formats.

  • Create script CustomRenderPassFeature.cs (copy below)
  • Select UniversalRenderPipelineAsset_Renderer
  • Click Add Renderer Feature/CustomRenderPassFeature *this wont be visible, if you didnt create the script first
  • Modify PointCloudViewerDX11.cs, add this line to class variables (somewhere before Awake() line):
    public static PointCloudViewerDX11 instance;
    Modify Awake() to:
void Awake()
{
    instance = this;
    applicationStreamingAssetsPath = Application.streamingAssetsPath;
}
using UnityEngine;
using UnityEngine.Rendering;
using UnityEngine.Rendering.Universal;

public class CustomRenderPassFeature : ScriptableRendererFeature
{
    class CustomRenderPass : ScriptableRenderPass
    {
        CommandBuffer commandBuffer;

        public override void Configure(CommandBuffer cmd, RenderTextureDescriptor cameraTextureDescriptor)
        {
            commandBuffer = new CommandBuffer { name = "PointCloudViewer" };
        }

        public override void Execute(ScriptableRenderContext context, ref RenderingData renderingData)
        {
            if (unitycodercom_PointCloudBinaryViewer.PointCloudViewerDX11.instance == null) return;
            commandBuffer.Clear();
            commandBuffer.DrawProcedural(Matrix4x4.identity, unitycodercom_PointCloudBinaryViewer.PointCloudViewerDX11.instance.cloudMaterial, 0, MeshTopology.Points, unitycodercom_PointCloudBinaryViewer.PointCloudViewerDX11.instance.points.Length);
            context.ExecuteCommandBuffer(commandBuffer);
        }

        public override void FrameCleanup(CommandBuffer cmd)
        {
        }
    }

    CustomRenderPass m_ScriptablePass;
    public override void Create()
    {
        m_ScriptablePass = new CustomRenderPass();
        m_ScriptablePass.renderPassEvent = RenderPassEvent.AfterRenderingOpaques;
    }

    public override void AddRenderPasses(ScriptableRenderer renderer, ref RenderingData renderingData)
    {
        renderer.EnqueuePass(m_ScriptablePass);
    }
}


Using Unity 2020.3.21f1 + URP 10.6.0 + V3 (.pcroot) viewer

  • Create script CustomRenderPassFeature.cs (copy contents below)
  • Select UniversalRenderPipelineAsset_Renderer
  • Click Add Renderer Feature/CustomRenderPassFeature *this wont be visible, if you didn't create the script first
  • Modify PointCloudViewerTilesDX11.cs, add these changes:
// BEFORE
PointCloudTile[] tiles;
// AFTER
internal PointCloudTile[] tiles;
// BEFORE
int tilesCount = 0;
// AFTER
internal int tilesCount = 0;
// BEFORE
        void Awake()
        {
            applicationStreamingAssetsPath = Application.streamingAssetsPath;
            FixMainThreadHelper();
        }
// AFTER
        public static PointCloudViewerTilesDX11 instance;
        void Awake()
        {
            instance = this;
            applicationStreamingAssetsPath = Application.streamingAssetsPath;
            FixMainThreadHelper();
        }
// BEFORE
public void OnRenderObject()
// AFTER
public void DisabledOnRenderObject()

CustomRenderPassFeature .cs:

using unitycodercom_PointCloudBinaryViewer;
using UnityEngine;
using UnityEngine.Rendering;
using UnityEngine.Rendering.Universal;

public class CustomRenderPassFeature : ScriptableRendererFeature
{
    class CustomRenderPass : ScriptableRenderPass
    {
        CommandBuffer commandBuffer;

        public override void Configure(CommandBuffer cmd, RenderTextureDescriptor cameraTextureDescriptor)
        {
            commandBuffer = new CommandBuffer { name = "PointCloudViewer" };
        }

        public override void Execute(ScriptableRenderContext context, ref RenderingData renderingData)
        {
            if (PointCloudViewerTilesDX11.instance == null) return;

            commandBuffer.Clear();
            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;
                commandBuffer.DrawProcedural(Matrix4x4.identity, PointCloudViewerTilesDX11.instance.tiles[i].material, 0, MeshTopology.Points, PointCloudViewerTilesDX11.instance.tiles[i].visiblePoints);
            }
            context.ExecuteCommandBuffer(commandBuffer);
        }

        public override void FrameCleanup(CommandBuffer cmd)
        {
        }
    }

    CustomRenderPass m_ScriptablePass;
    public override void Create()
    {
        m_ScriptablePass = new CustomRenderPass();
        m_ScriptablePass.renderPassEvent = RenderPassEvent.AfterRenderingOpaques;
    }

    public override void AddRenderPasses(ScriptableRenderer renderer, ref RenderingData renderingData)
    {
        renderer.EnqueuePass(m_ScriptablePass);
    }
}

@Rickmc3280
Copy link

Unable to test due to using PointCloudViewerTilesDX11.CS instead of non-tiled version. Question though regarding the CustomRenderPassFeature Script.

Where do you load the data into the command buffer for it to "commandBuffer.DrawProcedural(); I dont see anywhere for the data to be loaded, let alone to be drawn.

@unitycoder
Copy link
Owner Author

ah ok, ill need to check on the tiles viewer. (le me know your unity/urp version also)
that custompass feature, it uses data from my viewer, so its already loaded (and assigned to that cloudmaterial)
and commandBuffer.DrawProcedural() is the method to actually draw.

@Rickmc3280
Copy link

Interesting. So the data is stored in the material? Since I do a lot procedurally, it always revolves around uploading it to Mesh.Vertices, Mesh.Colors etc. Guess it is a different way of thinking

URP 12.1.1/ Unity 2021.2.XX

@unitycoder
Copy link
Owner Author

ok then that script above might not work, ill check with that version.

@unitycoder
Copy link
Owner Author

Now first message contains steps for V3 format also. @Rickmc3280

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants