/Realtime-GPU-Contour-Curves-from-3D-Mesh

A real-time, GPU-driven method to generate 2D curves from 3D mesh’s contour.

Primary LanguageC#GNU General Public License v3.0GPL-3.0

StrokeGen: Realtime Contour Curve Generation

Generated strokes with different colors.

No existing GPU-based NPR method (inverted hull, post-processing, etc.) can generate stroke curves, essential for expressive line drawings.

StrokeGen, a real-time method to generate 2D curves from 3D mesh’s contour, implemented as a prototype of our paper “GPU-Driven Real-Time Mesh Contour Vectorization” at EGSR 2022.

  • Reaches up to 800x acceleration over CPU-based offline alternatives (Pencil+4, Line Art, Freestyle, Active Strokes).
  • High efficiency: only costs 1ms for mesh of 300k tris, under 1920x1080 screen resolution.
  • Produces stroke curves comparable to these CPU-based approaches.

How to setup

StrokeGen is a research prototype, developed in Unity Engine, with its Universal Render Pipeline. All runtime procedures are implemented on the GPU with HLSL (mainly compute shaders).

To run this project:

  • Make sure that your hardware supports DX12 and HLSL Shader Model 6.0;
  • Download and install Unity Editor 2021.2.11f1 (from Unity Hub or here);
  • Open the project, following packages are required:
    • Official: Core RP Library, Universal RP, Unity UI, Mathematics;
    • Third Party: Odin Inspector
  • Open “Assets/Scenes/SampleScene.unity”;
  • Set screen resolution to 1920x1080;
  • Click “Play”.

Implementation Notes

Supported Mesh Type

Currently only support to render a single static mesh. However, in theory, it can be adapted for a skeletal mesh easily. Multiple meshes is also possible, but I’m too lazy to deal with the mesh api in Unity.

Temporal Coherence

I’ve worked over a year on an real-time optimizer for smooth stroke animation. Due to its massive complexity, I decided not to upload the newest branch. Hence, strokes can change quickly under animation in this version.

Stroke Styles

You can tune some basic parameters (brush texture, width, etc.) at Main Camera - Line Drawing Panel.

I removed stamping (similar to paint brush in Photoshop) style, only kept the sweeping (similar to brush path in Illustrator), since the branch for stamping is kind of messy. For details, see “Assets\Resources\ShaderLibrary\BrushToolBox.hlsl”.

If the texture mapping doesn’t work properly, select the curve textures and re-bake.

Compatibility

Tested on Windows, with Nvidia GPUs (GTX 1070, GTX 1080, Quadro M2000).

Any questions or problems, feel free to email jwtstone@gmail.com.

June 17, 2022