Immediate mode Draw.Line not appearing in standalone build.

Avatar
  • updated
  • Fixed

I am attempting to use the new ImmediateModeShapeDrawer to compare drawing a parametric curve in immediate mode using Draw.Polyline and Draw.Line respectively.


While both approaches work in the editor's Game View, Draw.Line calls do not appear to work in a standalone build:

Image 247

(Left is standalone build, right is editor Game view).

The complete test code is as follows:

using Shapes;
using UnityEngine;

[ExecuteAlways]
public class ShapesLineTest : ImmediateModeShapeDrawer
{
public bool usePolyLine;
public Color color = Color.red;

const float thickness = 0.2f;
const int count = 128;

public override void DrawShapes(Camera cam)
{
using (Draw.Command(cam))
using(PolylinePath polyPath = new PolylinePath())
{
for (int i = 0; i < count + 1; ++i)
{
float param01 = i / (float)count;
Vector3 point = GetPoint(param01);
polyPath.AddPoint(point);
}

Draw.ResetAllDrawStates();
Draw.Matrix = transform.localToWorldMatrix;
Draw.BlendMode = ShapesBlendMode.Opaque;
Draw.LineGeometry = LineGeometry.Volumetric3D;
Draw.LineThicknessSpace = ThicknessSpace.Meters;         Draw.LineThickness = 1;

if (usePolyLine)
{
Draw.Polyline(polyPath, closed: false, thickness: thickness, color: color);
}
else
{
Vector3 lastPoint = polyPath[0].point;
for (int i = 1; i < polyPath.Count; ++i)
{
Vector3 curPoint = polyPath[i].point;
Draw.Line(lastPoint, curPoint, thickness, color);
lastPoint = curPoint;
}
}
}
}

private static Vector3 GetPoint(float param01)
{
float param = Mathf.Lerp(-Mathf.PI, Mathf.PI, param01);
return new Vector3(param, Mathf.Sin(param * 2), 0);
}
}

Is there a reason why Draw.Line calls might not be showing up for me in a standalone build, while Draw.Polyline calls are? This is a test project that only contains this code and I have not changed any Shapes settings from their defaults. The camera is unchanged except for its clear mode being set to color instead of Skybox.

I used the examples on https://acegikmo.com/shapes/docs/#immediate-mode and was unable to find anything there that might explain this behavior, but I'm hoping I just missed something obvious.

Best,

Johannes

Reporting a bug? please specify Unity version:
2019.4.16f1
Reporting a bug? please specify Shapes version:
3.0.0
Reporting a bug? please specify Render Pipeline:
Built-in render pipeline
Pinned replies
Avatar
Freya Holmér creator
  • Answer
  • Fixed

this has now been fixed in 3.0.1

Avatar
Freya Holmér creator
  • Under Review

what platform are you building it to / running it on

Avatar
JohannesMP
Quote from Freya Holmér

what platform are you building it to / running it on

Standalone Windows.

Full Repro Steps:

  • Create new 2019.4.16f1 Project from Unity Hub using the default '3D' Template, and open the project.
  • Import Shapes 3.0.0 to default location from 'My Assets' in Asset Store
  • Add ShapesLineTest.cs to /Assets/
  • Open /Scenes/SampleScene.unity scene
  • Set MainCamera Clear Flag to 'Solid Color'
  • Create new GameObject named "Lines" at 0,2,0 and add 'Shapes Line Test' component with 'Use Poly Line' unchecked and red color
  • Create new GameObject named "Polylines' at 0,-2,0 and add 'Shapes Line Test' component with 'Use Poly Line' checked and green color
  • Save scene
  • Click Edit > Project Settings and add scene to Scenes in Build
  • Ensure Platform 'PC, Mac & Linux Stanadlone' is selected with Target Platform 'Windows':
  • Click 'Player Settings...' and in 'Resolution and Presentation' set Fullscreen Mode to 'Windowed', check 'Resizable Window' and in 'Splash Image' uncheck 'Show Splash Screen'.
  • Close Player Settings and back in Build Settings click 'Build And Run'
  • Select a build folder and wait for it to compile and open
  • This is what I see:
Avatar
Freya Holmér creator

yep, got a repro, thanks a ton for the detailed report! now to figure out what eldritch horror Unity is doing to my code that prevents this from working

Avatar
Freya Holmér creator

looks like immediate mode GPU instancing is not fully working in builds then - disabling IM instancing in the Shapes settings made everything work for me

(it should work though, so I'll keep looking into it)

Avatar
JohannesMP

Sweet, that's an acceptable workaround for the time being then. 

In my use case (camera often closely crossing the plane that the lines are on), Polyline billboards exhibit undesirable visual artifacts such as stairstepping, so it would have been unfortunate if Draw.Lines was not usable :)

Still hoping to one day get volumetric 3D polylines, but am also aware of the technical challenges there

Avatar
Freya Holmér creator
Quote from JohannesMP

Sweet, that's an acceptable workaround for the time being then. 

In my use case (camera often closely crossing the plane that the lines are on), Polyline billboards exhibit undesirable visual artifacts such as stairstepping, so it would have been unfortunate if Draw.Lines was not usable :)

Still hoping to one day get volumetric 3D polylines, but am also aware of the technical challenges there

making billboarded polylines artifact-less would be near impossible, so it would have to be done with volumetric polylines yeah, but, those in turn are also complicated, mostly because of polyline joins and from a performance perspective, since they need to handle roll/rotation, which is relatively nontrivial unfortunately :c

that being said, feel free to open feature request topics on the 3D polyline one if it doesn't already exist

Avatar
Freya Holmér creator
  • Planned

this is caused by shader stripping - Unity removes the instancing variants from the project on build, because it doesn't detect any assets using them

I'll work on a proper solution to always have them included, but in the meantime, you can fix it by always including instancing variants in Unity's Graphics Settings:

Avatar
Freya Holmér creator
  • Answer
  • Fixed

this has now been fixed in 3.0.1

Avatar
JohannesMP

Excellent! Is there an ETA when that might go live, or would there be any way to get a hold of that version now?

Avatar
Freya Holmér creator
Quote from JohannesMP

Excellent! Is there an ETA when that might go live, or would there be any way to get a hold of that version now?

should go live next week! the graphics settings fix above should work in the meantime though :)