text rendering in 3d scenes - university of...

44
Text rendering in 3D scenes THIERRY DELISLE

Upload: others

Post on 04-Oct-2020

1 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Text rendering in 3D scenes - University of Waterloodberry/ATEP/StudentLectures/ThierryDelisle.… · Green, Chris. Improved alpha-tested magnification for vector textures and special

Text rendering in 3D scenesTHIERRY DELISLE

Page 2: Text rendering in 3D scenes - University of Waterloodberry/ATEP/StudentLectures/ThierryDelisle.… · Green, Chris. Improved alpha-tested magnification for vector textures and special

Classic text renderingFormatter is run on input to set characters.

Formatting with knowledge of page size, resolution, etc.

Character glyphs are converted to bitmaps.

SPRING 2018 – CS846 2

Page 3: Text rendering in 3D scenes - University of Waterloodberry/ATEP/StudentLectures/ThierryDelisle.… · Green, Chris. Improved alpha-tested magnification for vector textures and special

Challenges of 3DViewing Angle:

◦ Text is parallel to screen? Maybe not!

◦ Text is right side up? Maybe not!

Animations:◦ Angle, Distance, Size, etc. can change dynamically.

Interactivity:◦ Users can affect all of the above and expect real-time corrections.

Goal: Transformation resistant rendering algorithms.

SPRING 2018 – CS846 3

Page 4: Text rendering in 3D scenes - University of Waterloodberry/ATEP/StudentLectures/ThierryDelisle.… · Green, Chris. Improved alpha-tested magnification for vector textures and special

A well-known example

SPRING 2018 – CS846 4

Star Wars is a registered trademark and © 1977 Lucasfilm Ltd.

Page 5: Text rendering in 3D scenes - University of Waterloodberry/ATEP/StudentLectures/ThierryDelisle.… · Green, Chris. Improved alpha-tested magnification for vector textures and special

A well-known example

The viewing angle is not perpendicular.

Perspective projections mean the text has depth.

Words will appear to vary in size as they recede from the screen.

SPRING 2018 – CS846 5

Page 6: Text rendering in 3D scenes - University of Waterloodberry/ATEP/StudentLectures/ThierryDelisle.… · Green, Chris. Improved alpha-tested magnification for vector textures and special

ScopeAspects outside the scope of this discussion:

◦ Formatting

◦ Ligatures

◦ Text direction

SPRING 2018 – CS846 6

Page 7: Text rendering in 3D scenes - University of Waterloodberry/ATEP/StudentLectures/ThierryDelisle.… · Green, Chris. Improved alpha-tested magnification for vector textures and special

Rendering BasicsRENDERING PIPELINE AND HARDWARE

SPRING 2018 – CS846 7

Page 8: Text rendering in 3D scenes - University of Waterloodberry/ATEP/StudentLectures/ThierryDelisle.… · Green, Chris. Improved alpha-tested magnification for vector textures and special

Rendering pipeline overview

Pipeline use by most PCs, Phones, Game Consoles, etc.

A rectangular stage is programmable: code dictates its behaviour.

A rounded stage is fixed: configurations dictate its behaviour.

* Several stages have been collapsed together for simplicity.

SPRING 2018 – CS846 8

Primitive Input Stage

Rasterization Stage

Fragment Shading Stage

Blending Stage

Page 9: Text rendering in 3D scenes - University of Waterloodberry/ATEP/StudentLectures/ThierryDelisle.… · Green, Chris. Improved alpha-tested magnification for vector textures and special

Input StageFirst step: Send some geometry to the GPU.

Rasterizer requires triangles/lines.

GPU allows significant transformation on the geometry before rasterization.

◦ Example: transforming quads into triangles.

Common transformations:

◦ Perspective projection

◦ Animation

◦ Tessellation

SPRING 2018 – CS846 9

Page 10: Text rendering in 3D scenes - University of Waterloodberry/ATEP/StudentLectures/ThierryDelisle.… · Green, Chris. Improved alpha-tested magnification for vector textures and special

Rasterization

Converts 3D primitives to pixel information.

Requires lines or triangles.

Linearly interpolates data on vertices.

Handle depth testing.

SPRING 2018 – CS846 10

Source: scratchapixel.com

Page 11: Text rendering in 3D scenes - University of Waterloodberry/ATEP/StudentLectures/ThierryDelisle.… · Green, Chris. Improved alpha-tested magnification for vector textures and special

Fragment Shading

Programmable stage ran on every pixel.

◦ Potentially more than once of covered by several primitives.

Commonly where textures are used.

Hardware can do Bilinear Interpolation automatically when sampling textures.

SPRING 2018 – CS846 11

Source: Wikipedia, creator: Cmglee

Page 12: Text rendering in 3D scenes - University of Waterloodberry/ATEP/StudentLectures/ThierryDelisle.… · Green, Chris. Improved alpha-tested magnification for vector textures and special

BlendingColors the desired pixel.

Overlapping means a given pixel can be colored several times.

Several rules are possible when recoloring:

◦ Replace old color.

◦ Interpolate new and old colors based on transparency.

◦ Etc.

SPRING 2018 – CS846 12

Page 13: Text rendering in 3D scenes - University of Waterloodberry/ATEP/StudentLectures/ThierryDelisle.… · Green, Chris. Improved alpha-tested magnification for vector textures and special

Texture-Based RenderingTHE SIMPLE APPROACH

SPRING 2018 – CS846 13

Page 14: Text rendering in 3D scenes - University of Waterloodberry/ATEP/StudentLectures/ThierryDelisle.… · Green, Chris. Improved alpha-tested magnification for vector textures and special

What’s wrong with bitmaps?Use texture sampling + transparency to render text.

1. Make texture with desired text + transparent background.

2. Render a triangle or a quad (2 triangle forming a flat rectangle).

3. In fragment shader, paste texture onto triangle(s).

4. Done!

SPRING 2018 – CS846 14

Page 15: Text rendering in 3D scenes - University of Waterloodberry/ATEP/StudentLectures/ThierryDelisle.… · Green, Chris. Improved alpha-tested magnification for vector textures and special

Primitive SubmissionSINGLE PRIMITIVE

Submit one big quad.

Write the text in one big texture.

Formatting done in texture.

PRIMITIVE PER CHARACTER

One quad per letter.

Texture contains alphabet.

Formatting done on primitives.

SPRING 2018 – CS846 15

“TEXT”

ABCDEFGHIJKLMNOPQRSTUVWXYZ

TEXT

Page 16: Text rendering in 3D scenes - University of Waterloodberry/ATEP/StudentLectures/ThierryDelisle.… · Green, Chris. Improved alpha-tested magnification for vector textures and special

Direct bitmapSimplest approach.

Works well for printers.

Very easy to use since:

◦ Hardware rasterization

◦ Hardware blending

◦ Hardware sampling

Means texture hardware can be reused with little or no programming.

SPRING 2018 – CS846 16

Page 17: Text rendering in 3D scenes - University of Waterloodberry/ATEP/StudentLectures/ThierryDelisle.… · Green, Chris. Improved alpha-tested magnification for vector textures and special

Result: Blur

SPRING 2018 – CS846 17

Page 18: Text rendering in 3D scenes - University of Waterloodberry/ATEP/StudentLectures/ThierryDelisle.… · Green, Chris. Improved alpha-tested magnification for vector textures and special

Alpha-TestingEliminates the blur using threshold instead.

◦ Opacity > 0.5 → Full Color

◦ Opacity < 0.5 → No Color

Still done in hardware so no additional requirements compared to previous approach.

SPRING 2018 – CS846 18

Page 19: Text rendering in 3D scenes - University of Waterloodberry/ATEP/StudentLectures/ThierryDelisle.… · Green, Chris. Improved alpha-tested magnification for vector textures and special

Result: Blotchy

SPRING 2018 – CS846 19

Page 20: Text rendering in 3D scenes - University of Waterloodberry/ATEP/StudentLectures/ThierryDelisle.… · Green, Chris. Improved alpha-tested magnification for vector textures and special

Bitmap problemMagnification is handled by hardware using bilinear interpolation.

Interpolation is defined on Scalars not on Booleans.

Interpolating bitmaps results in… Something.

SPRING 2018 – CS846 20

1

0.6

0

Inside

Somewhere…Maybe in a galaxy far far away

Outside

Value Meaning

Page 21: Text rendering in 3D scenes - University of Waterloodberry/ATEP/StudentLectures/ThierryDelisle.… · Green, Chris. Improved alpha-tested magnification for vector textures and special

Signed Distance Fields

Use full width of color channel.

Interpolation has proper meaning.

Still using hardware!

Well-known example:

Improved Alpha-Tested Magnification for Vector Textures and Special Effects

Chris Green

Valve

SPRING 2018 – CS846 21

Source: Wikipedia, Creator: Oleg Alexandrov

Page 22: Text rendering in 3D scenes - University of Waterloodberry/ATEP/StudentLectures/ThierryDelisle.… · Green, Chris. Improved alpha-tested magnification for vector textures and special

Using SDFsSubmit a signed distance field instead of the bitmap.

That’s all, the hardware does the rest.

SPRING 2018 – CS846 22

Source: Green, Chris. ‘Improved alpha-tested

magnification for vector textures and special effects.’ ACM SIGGRAPH 2007 courses. ACM,

2007.

Page 23: Text rendering in 3D scenes - University of Waterloodberry/ATEP/StudentLectures/ThierryDelisle.… · Green, Chris. Improved alpha-tested magnification for vector textures and special

Result: Not bad

SPRING 2018 – CS846 23

Page 24: Text rendering in 3D scenes - University of Waterloodberry/ATEP/StudentLectures/ThierryDelisle.… · Green, Chris. Improved alpha-tested magnification for vector textures and special

Anisotropy: the problem

SPRING 2018 – CS846 24

Page 25: Text rendering in 3D scenes - University of Waterloodberry/ATEP/StudentLectures/ThierryDelisle.… · Green, Chris. Improved alpha-tested magnification for vector textures and special

Anisotropy: the solutionHardware to the rescue yet again!

Anisotropic filtering exists for regular textures.

Instead of bilinear sampling 2x2:◦ Sample 4x2, 8x2, 16x2, etc.

Hardware caches result in textures (right).

Better filtering exist by Qin, Zheng from the University of Waterloo.

SPRING 2018 – CS846 25

Source: Wikipedia, creator: Mulad, based on a NASA image.

Page 26: Text rendering in 3D scenes - University of Waterloodberry/ATEP/StudentLectures/ThierryDelisle.… · Green, Chris. Improved alpha-tested magnification for vector textures and special

Anisotropy: 4x2

SPRING 2018 – CS846 26

Page 27: Text rendering in 3D scenes - University of Waterloodberry/ATEP/StudentLectures/ThierryDelisle.… · Green, Chris. Improved alpha-tested magnification for vector textures and special

Anisotropy: 32x2

SPRING 2018 – CS846 27

Page 28: Text rendering in 3D scenes - University of Waterloodberry/ATEP/StudentLectures/ThierryDelisle.… · Green, Chris. Improved alpha-tested magnification for vector textures and special

New problem: Corners

Text rendered using SDFs lose sharp corners.

Fundamental problem of SDF.

SDFs naturally round-off shapes.

SPRING 2018 – CS846 28

Page 29: Text rendering in 3D scenes - University of Waterloodberry/ATEP/StudentLectures/ThierryDelisle.… · Green, Chris. Improved alpha-tested magnification for vector textures and special

Solutions

2-channel SDF from Green07

3-channel SDF from Chlumský

4-channel SDF from Lambda cube

Quasi-SDF from Adam Simmons

It all starts to look like Outline-Based Rendering…

SPRING 2018 – CS846 29

Source: Chlumský, V., J. Sloup, and I. Šimeček. "Improved Corners with

Multi‐Channel Signed Distance Fields." Computer Graphics Forum. Vol. 37. No. 1. 2018.

Source: LambdaCube 3D, creator: cobbpg

Creator: Adam Simmons

Page 30: Text rendering in 3D scenes - University of Waterloodberry/ATEP/StudentLectures/ThierryDelisle.… · Green, Chris. Improved alpha-tested magnification for vector textures and special

Outline-Based RenderingTHE PRETTY APPROACH

SPRING 2018 – CS846 30

Page 31: Text rendering in 3D scenes - University of Waterloodberry/ATEP/StudentLectures/ThierryDelisle.… · Green, Chris. Improved alpha-tested magnification for vector textures and special

What’s wrong with textures?Double rasterization:

1. Text rasterized to texture.

2. Texture ‘rasterized’ again for rendering.

Solution: Go directly from text to final render.

SPRING 2018 – CS846 31

Source: Loop, Charles, and Jim Blinn. ‘Resolution independent curve rendering using programmable graphics hardware.’ ACM Transactions on Graphics (TOG). Vol. 24. No. 3. ACM, 2005.

Page 32: Text rendering in 3D scenes - University of Waterloodberry/ATEP/StudentLectures/ThierryDelisle.… · Green, Chris. Improved alpha-tested magnification for vector textures and special

Direct rasterizationIdea:

Convert the Glyph outline directly by using geometry + shader code to differentiate inside

and outside.

Many techniques exist:◦ Loop-Blinn uses quadratic Béziers.

◦ Slug uses winding order.

◦ Nvidia uses ‘Stencil, then Cover’.

◦ Other techniques exist.

SPRING 2018 – CS846 32

Page 33: Text rendering in 3D scenes - University of Waterloodberry/ATEP/StudentLectures/ThierryDelisle.… · Green, Chris. Improved alpha-tested magnification for vector textures and special

Loop-BlinnFrom Glyph outline create triangulated geometry.

Create implicit curve for each triangle:

𝑓 𝑢, 𝑣 = 𝑢2 − 𝑣

Where 𝑢𝑣 coordinates are 0,0 ,1

2, 0 , 1,1

for all triangles.

Source: Loop, Charles, and Jim Blinn. ‘Resolution independent curve rendering using programmable graphics hardware.’

SPRING 2018 – CS846 33

Inside

Border (convex)

Border (concave)

Page 34: Text rendering in 3D scenes - University of Waterloodberry/ATEP/StudentLectures/ThierryDelisle.… · Green, Chris. Improved alpha-tested magnification for vector textures and special

Use single large primitive.

Cast rays in shape and find intersections.

Add or subtract for each intersection:◦ Total > 0 → means inside.

◦ Total = 0 → means open space.

Source: Lengyel, Eric. ‘GPU-Centered Font Rendering Directly from Glyph

Outlines.’

SPRING 2018 – CS846 34

+1 -1 +1 -1

Page 35: Text rendering in 3D scenes - University of Waterloodberry/ATEP/StudentLectures/ThierryDelisle.… · Green, Chris. Improved alpha-tested magnification for vector textures and special

Stencil, then CoverStarting from Glyph outline:

1. Create Line-edged triangle fans (b).

2. Render to stencil using invert operation.

3. Render curves using Loop-Blinn and same operation (c).

4. Add both stencils and fill, i.e., 𝑑 ⨁ 𝑐 = 𝑓 .

Uses triangle fans instead of regular triangles to avoid triangulating on the CPU.

Source: Kokojima, Yoshiyuki, et al. ‘Resolution independent rendering of deformable vector objects using graphics hardware.’

Nvidia version: Kilgard, Mark J., and Jeff Bolz. ‘GPU-accelerated path rendering.’

SPRING 2018 – CS846 35

Page 36: Text rendering in 3D scenes - University of Waterloodberry/ATEP/StudentLectures/ThierryDelisle.… · Green, Chris. Improved alpha-tested magnification for vector textures and special

Non-Flat TextADAPTING TO THE SCENE

SPRING 2018 – CS846 36

Page 37: Text rendering in 3D scenes - University of Waterloodberry/ATEP/StudentLectures/ThierryDelisle.… · Green, Chris. Improved alpha-tested magnification for vector textures and special

Many casesSeveral techniques depending on the need:

◦ Decals

◦ Curved text

◦ Advanced texture mapping

◦ Innumerable custom or one-off solutions.

SPRING 2018 – CS846 37

Source: Burley, Brent, and Dylan Lacewell. ‘Ptex: Per‐face texture mapping for production rendering.’

Computer Graphics Forum. Vol. 27. No. 4. Oxford, UK: Blackwell Publishing Ltd, 2008.

Source: Unreal Engine DocsDecals

1.4 – Projection on Multiple Surfaces

Source: Loop-Blinn

Page 38: Text rendering in 3D scenes - University of Waterloodberry/ATEP/StudentLectures/ThierryDelisle.… · Green, Chris. Improved alpha-tested magnification for vector textures and special

Decals: Stick Text/Textures onto objectsProject texture on top of objects.

Used both for text and regular textures.

Can be done in advance or dynamically.

SPRING 2018 – CS846 38

Creator: Rob Schluntz

Page 39: Text rendering in 3D scenes - University of Waterloodberry/ATEP/StudentLectures/ThierryDelisle.… · Green, Chris. Improved alpha-tested magnification for vector textures and special

Decals: TechniquesGEOMETRY TO PIXEL

1. Create projector prism.

2. Create duplicate of geometry clipped to a prism.

3. Render clipped geometry.

Disadvantage:◦ Step 2 is hard to get right and slow to process.

PIXEL TO PIXEL

1. Render first pass.

2. Render projector prism.

3. Find affected pixels.

4. Find position of pixels in geometry.

5. Re-shade relevant pixels.

6. Render second pass.

Disadvantage:◦ Requires Deferred Rendering (Multi-Pass)

SPRING 2018 – CS846 39

Page 40: Text rendering in 3D scenes - University of Waterloodberry/ATEP/StudentLectures/ThierryDelisle.… · Green, Chris. Improved alpha-tested magnification for vector textures and special

Curved TextUsing geometry means text can be transformed.

The finer grain the triangulation is, the more transformations can be applied.

SPRING 2018 – CS846 40

Source: Loop, Charles, and Jim Blinn. ‘Resolution independent curve rendering using

programmable graphics hardware.’ACM Transactions on Graphics (TOG).

Vol. 24. No. 3. ACM, 2005.

Page 41: Text rendering in 3D scenes - University of Waterloodberry/ATEP/StudentLectures/ThierryDelisle.… · Green, Chris. Improved alpha-tested magnification for vector textures and special

Advanced Texture Mapping

Example:

Ptex: Per-Face Texture Mapping for Production Rendering

SPRING 2018 – CS846 41

Brent BurleyWalt Disney Animation Studios

Dylan Lacewell University of Utah

Page 42: Text rendering in 3D scenes - University of Waterloodberry/ATEP/StudentLectures/ThierryDelisle.… · Green, Chris. Improved alpha-tested magnification for vector textures and special

Full GeometryTHE EXPENSIVE APPROACH

SPRING 2018 – CS846 42

Page 43: Text rendering in 3D scenes - University of Waterloodberry/ATEP/StudentLectures/ThierryDelisle.… · Green, Chris. Improved alpha-tested magnification for vector textures and special

3D meshes of text

When text needs to be part of the world rather than pasted onto it:

◦ Use 3D meshes.

Appearance limited only by Renderer.

Amount of work required not limited.

SPRING 2018 – CS846 43

Source: Wikipedia, creator: Thomas Wolf

Source: Grand Theft Auto V

Source: Fallout 4

Page 44: Text rendering in 3D scenes - University of Waterloodberry/ATEP/StudentLectures/ThierryDelisle.… · Green, Chris. Improved alpha-tested magnification for vector textures and special

Questions

SPRING 2018 – CS846 44