Ztest is not working for Immediate-Mode Drawing(URP)

Avatar
  • updated
  • Fixed

URP

Image 151

Unity built in rendering pipeline

Image 152

Reporting a bug? please specify Unity version:
2020.1.10f1
Reporting a bug? please specify Shapes version:
2.3.2
Reporting a bug? please specify Render Pipeline:
Pinned replies
Avatar
Freya Holmér creator
  • Answer
  • Fixed

narrator, 3 months later: it did indeed, take some major restructuring

however, it is now fixed in the coming 3.0.0 update ❤

Avatar
sylmerria

Yup it's that, I never import sample and co

Thanks :)

Avatar
Freya Holmér creator

oh, you know what - that script is in the samples folder, so if you excluded samples that script won't be found

I'll move it into the main scripts folder for 3.0.1 :)

in the meantime, here's its code:

using UnityEngine;
#if UNITY_2019_1_OR_NEWER
using UnityEngine.Rendering;

#endif

// Shapes © Freya Holmér - https://twitter.com/FreyaHolmer/
// Website & Documentation - https://acegikmo.com/shapes/
namespace Shapes {

public class ImmediateModeShapeDrawer : MonoBehaviour {

/// <summary>
/// Override this to draw Shapes in immediate mode. This is called once per camera. You can draw using this code: using(Draw.Command(cam)){ // Draw here }
/// </summary>
/// <param name="cam">The camera that is currently rendering</param>
public virtual void DrawShapes( Camera cam ) {
// override this and draw shapes in immediate mode here
}

void OnCameraPreRender( Camera cam ) {
switch( cam.cameraType ) { // Don't render in preview windows or in reflection probes in case we run this script in the editor
case CameraType.Preview:
case CameraType.Reflection:
return;
}

DrawShapes( cam );
}

#if (SHAPES_URP || SHAPES_HDRP)
#if UNITY_2019_1_OR_NEWER
public virtual void OnEnable() => RenderPipelineManager.beginCameraRendering += DrawShapesSRP;
public virtual void OnDisable() => RenderPipelineManager.beginCameraRendering -= DrawShapesSRP;
void DrawShapesSRP( ScriptableRenderContext ctx, Camera cam ) => OnCameraPreRender( cam );
#else
public virtual void OnEnable() => Debug.LogWarning( "URP/HDRP immediate mode doesn't really work pre-Unity 2019.1, as there is no OnPreRender or beginCameraRendering callback" );
#endif
#else
public virtual void OnEnable() => Camera.onPreRender += OnCameraPreRender;
public virtual void OnDisable() => Camera.onPreRender -= OnCameraPreRender;
#endif

}

}
Avatar
sylmerria

I can confirm you It's not in my project files ( I have only a IMDrawer) and Rider can't find it either.

And I'm 3.0.0 with a fresh import ( delete=> import )

Avatar
Freya Holmér creator

it should be in the Shapes namespace! so either add using Shapes; at the top, or extend from Shapes.ImmediateModeShapeDrawer

Avatar
sylmerria

I can't find class 'ImmediateModeShapeDrawer' as the doc says in the 3.0.0 package it seems :/ 

Avatar
Freya Holmér creator
  • Answer
  • Fixed

narrator, 3 months later: it did indeed, take some major restructuring

however, it is now fixed in the coming 3.0.0 update ❤

Avatar
Freya Holmér creator

Alright, it looks like this might require some major restructuring to make it work in SRP I'm afraid, so, we'll see when/how this might land. I'll keep looking into this tomorrow!

Avatar
Freya Holmér creator

Ah, looks like this is actually an issue with the timing of OnPostRender, as far as I can tell. it looks like there is no depth information anymore at this stage in the render pipeline D:

This works in OnDrawGizmos - but not during RenderPipelineManager.endCameraRendering, correct? I'm guessing you're having the same behavior (looking into it further now)

Avatar
Freya Holmér creator

Looking into this now - this seems to work fine in 2019.4 URP as far as I can tell. testing 2020 now!

Avatar
sylmerria

I can confirm that, Using lastest version of URP 9 :

The path is inside the cube but still visible

Code : https://pastebin.com/2cVek44L

Avatar
Freya Holmér creator

haven't looked into it yet! so we'll see. I'll let you know

Avatar
George

Freya Holmér, were you able to reproduce the bug?

Avatar
George
Quote from Freya Holmér

could you show me the code you are using to draw?

Shapes.Draw.BlendMode = ShapesBlendMode.Transparent;

Shapes.Draw.LineGeometry = LineGeometry.Volumetric3D;

Shapes.Draw.ZTest = CompareFunction.LessEqual;

Shapes.Draw.LineThicknessSpace = ThicknessSpace.Pixels;

Shapes.Draw.LineThickness = 4; // 4px wide

Shapes.Draw.Line(point1, point2, shape.Color);

Avatar
Freya Holmér creator

could you show me the code you are using to draw?

Avatar
George
Quote from Freya Holmér

can you be more specific with what you're trying to do?

I use Shapes.Draw.Line. I want that part of the line which obstructed by another object won't render. It works in Unity built-in rendering pipeline but it's not work in URP.

Avatar
Freya Holmér creator

can you be more specific with what you're trying to do?

Avatar
George

immediate mode drawing

Avatar
Freya Holmér creator
  • Under Review

is this using components or immediate mode drawing?