Ztest is not working for Immediate-Mode Drawing(URP)
URP
Unity built in rendering pipeline
URP
Unity built in rendering pipeline
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
}
}
it should be in the Shapes namespace! so either add using Shapes; at the top, or extend from Shapes.ImmediateModeShapeDrawer
narrator, 3 months later: it did indeed, take some major restructuring
however, it is now fixed in the coming 3.0.0 update ❤
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!
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)
Looking into this now - this seems to work fine in 2019.4 URP as far as I can tell. testing 2020 now!
I can confirm that, Using lastest version of URP 9 :
The path is inside the cube but still visible
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);
narrator, 3 months later: it did indeed, take some major restructuring
however, it is now fixed in the coming 3.0.0 update ❤