Procedural Rendering
Procedurally draw shapes and paths in Unity using Rive
This article is out of date! Find the new version here.
In this section, you’ll learn how to create custom paint and path objects. This enables you to perform custom computed draw commands using the Rive Renderer.
Overview
The following classes are available:
BlendMode: determines how the source pixels are blended with the destination pixels.
Color: determines the color of the shape.
Gradient: determines the color gradient of the shape (
LinearGradient
orRadialGradient
)Paint: describes how to draw a shape - see Paint.
PaintingStyle: determines if the shape is filled or stroked.
Path: defines a shape's outline or a clipping mask - see Path.
StrokeCap: determines how the path's endpoints are drawn.
StrokeJoin: the kind of finish to place on the joins between segments.
RenderQueue
Create a Rive.RenderQueue
and a Rive.Renderer
:
Call draw
on the renderer and pass in a Path
and Paint
object.
Path
A path is a series of drawing commands. The path is used to define a shape's outline or a clipping mask.
Create a new path:
The Path
class provides various methods to construct a path:
moveTo
: Moves the current point to the given point.lineTo
: Adds a straight line from the current point to the given point.circle
: Adds a circle to the path.cubicTo
: Adds a cubic bezier curve to the path.quadTo
: Adds a quadratic bezier segment that curves from the current point.addPath
: Adds the sub-paths of path to this path, transformed by the provided matrix.close
: Closes the path. This will draw a line from the current point to the first point in the path.reset
: Resets the path to an empty state.flush
: to flush the path to native memory.
Paint
Paint is used to describe how to draw a shape.
Create a new paint:
The paint describes the color, gradient, style, thickness, blend mode, stroke cap, and stroke join for a shape.
Call .Flush()
to flush the paint to native memory. See the Examplebelow.
Example
This example demonstrates drawing an animated triangle to a RenderTexture.
The MonoBehaviour
to create the above:
Additional Resources
See the getting-started project in the examples repository for a complete example and open the ProceduralRenderingScene scene.
Last updated