You are on page 1of 53

GPU Pro 360 Guide to Mobile Devices

1st Edition Wolfgang Engel


Visit to download the full and correct content document:
https://textbookfull.com/product/gpu-pro-360-guide-to-mobile-devices-1st-edition-wolf
gang-engel/
More products digital (pdf, epub, mobi) instant
download maybe you interests ...

GPU Pro 360 Guide to Geometry Manipulation 1st Edition


Wolfgang Engel

https://textbookfull.com/product/gpu-pro-360-guide-to-geometry-
manipulation-1st-edition-wolfgang-engel/

GPU PRO 360: Guide to GPGPU 1st Edition Wolfgang Engel


(Editor)

https://textbookfull.com/product/gpu-pro-360-guide-to-gpgpu-1st-
edition-wolfgang-engel-editor/

GPU Pro 360 Guide to Image Space 1st Edition Wolfgang


Engel (Author)

https://textbookfull.com/product/gpu-pro-360-guide-to-image-
space-1st-edition-wolfgang-engel-author/

GPU Pro 360 Guide to 3D Engine Design 1st Edition


Wolfgang Engel (Author)

https://textbookfull.com/product/gpu-pro-360-guide-to-3d-engine-
design-1st-edition-wolfgang-engel-author/
GPU Zen Advanced Rendering Techniques Wolfgang Engel
(Editor)

https://textbookfull.com/product/gpu-zen-advanced-rendering-
techniques-wolfgang-engel-editor/

Game AI Pro 360: Guide to Architecture 1st Edition


Steve Rabin (Author)

https://textbookfull.com/product/game-ai-pro-360-guide-to-
architecture-1st-edition-steve-rabin-author/

Game AI Pro 360: Guide to Character Behavior 1st


Edition Steve Rabin (Author)

https://textbookfull.com/product/game-ai-pro-360-guide-to-
character-behavior-1st-edition-steve-rabin-author/

Game AI Pro 360: Guide to Movement and Pathfinding 1st


Edition Steve Rabin (Author)

https://textbookfull.com/product/game-ai-pro-360-guide-to-
movement-and-pathfinding-1st-edition-steve-rabin-author/

Game AI Pro 360: Guide to Tactics and Strategy 1st


Edition Steve Rabin (Author)

https://textbookfull.com/product/game-ai-pro-360-guide-to-
tactics-and-strategy-1st-edition-steve-rabin-author/
GPU Pro 360
Guide to Mobile Devices
GPU Pro 360
Guide to Mobile Devices

Edited by Wolfgang Engel


CRC Press
Taylor & Francis Group
6000 Broken Sound Parkway NW, Suite 300
Boca Raton, FL 33487-2742

© 2019 by Taylor & Francis Group, LLC


CRC Press is an imprint of Taylor & Francis Group, an Informa business

No claim to original U.S. Government works

Printed on acid-free paper

International Standard Book Number-13: 978-0-8153-5281-5 (Paperback)


International Standard Book Number-13: 978-0-8153-5283-9 (Hardback)

This book contains information obtained from authentic and highly regarded sources. Reasonable efforts have
been made to publish reliable data and information, but the author and publisher cannot assume responsibility
for the validity of all materials or the consequences of their use. The authors and publishers have attempted to
trace the copyright holders of all material reproduced in this publication and apologize to copyright holders if
permission to publish in this form has not been obtained. If any copyright material has not been acknowledged
please write and let us know so we may rectify in any future reprint.

Except as permitted under U.S. Copyright Law, no part of this book may be reprinted, reproduced, transmitted,
or utilized in any form by any electronic, mechanical, or other means, now known or hereafter invented,
including photocopying, microfilming, and recording, or in any information storage or retrieval system, without
written permission from the publishers.

For permission to photocopy or use material electronically from this work, please access www.copyright.com
(http://www.copyright.com/) or contact the Copyright Clearance Center, Inc. (CCC), 222 Rosewood Drive,
Danvers, MA 01923, 978-750-8400. CCC is a not-for-profit organization that provides licenses and registration
for a variety of users. For organizations that have been granted a photocopy license by the CCC, a separate
system of payment has been arranged.

Trademark Notice: Product or corporate names may be trademarks or registered trademarks, and are used
only for identification and explanation without intent to infringe.

Library of Congress Cataloging-in-Publication Data

Names: Engel, Wolfgang F., editor.


Title: GPU pro 360 guide to mobile devices / edited by Wolfgang Engel.
Description: Boca Raton : Taylor & Francis, CRC Press, [2018]
Identifiers: LCCN 2017060054| ISBN 9780815352815 (pbk. : alk. paper)
| ISBN 9780815352839 (hardback : alk. paper)
Subjects: LCSH: Computer graphics. | Graphics processing units--Programming.
| Pocket computers--Programming. | Mobile computing. | Rendering (Computer graphics)
Classification: LCC T385 .G68885 2018 | DDC 621.39/96--dc23
LC record available at https://lccn.loc.gov/2017060054

Visit the eResources: www.crcpress.com/9780815352815

Visit the Taylor & Francis Web site at


http://www.taylorandfrancis.com

and the CRC Press Web site at


http://www.crcpress.com
Contents

Introduction xi

Web Materials xv

1 Touchscreen-Based User Interaction 1


Andrea Bizzotto
1.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
1.2 Motion Estimation . . . . . . . . . . . . . . . . . . . . . . . . 1
1.3 Position Prediction . . . . . . . . . . . . . . . . . . . . . . . . 4
1.4 Application: Controlling a Camera in a Spherical Coordinate
System . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
1.5 Algorithm Overview . . . . . . . . . . . . . . . . . . . . . . . . 7
1.6 Conclusion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
1.7 Acknowledgments . . . . . . . . . . . . . . . . . . . . . . . . . 9

2 Optimizing a 3D UI Engine for Mobile Devices 11


Hyunwoo Ki
2.1 Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
2.2 Optimization Methods . . . . . . . . . . . . . . . . . . . . . . 13
2.3 Conclusion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
Bibliography . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24

3 A Shader-Based eBook Renderer 27


Andrea Bizzotto
3.1 Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27
3.2 Page-Peeling Effect . . . . . . . . . . . . . . . . . . . . . . . . 28
3.3 Enabling Two Pages Side-by-Side . . . . . . . . . . . . . . . . 33
3.4 Improving the Look and Antialiasing Edges . . . . . . . . . . 35
3.5 Direction-Aligned Triangle Strip . . . . . . . . . . . . . . . . . 36
3.6 Performance Optimizations and Power Consumption . . . . . 37
3.7 Putting it Together . . . . . . . . . . . . . . . . . . . . . . . . 37
3.8 Future Work . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38

v
vi Contents

3.9 Conclusion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38
3.10 Acknowledgments . . . . . . . . . . . . . . . . . . . . . . . . . 39
Bibliography . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39

4 Post-Processing Effects on Mobile Devices 41


Marco Weber and Peter Quayle
4.1 Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41
4.2 Technical Details . . . . . . . . . . . . . . . . . . . . . . . . . 44
4.3 Case Study: Bloom . . . . . . . . . . . . . . . . . . . . . . . . 46
4.4 Implementation . . . . . . . . . . . . . . . . . . . . . . . . . . 48
4.5 Conclusion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54
Bibliography . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55

5 Shader-Based Water Effects 57


Joe Davis and Ken Catterall
5.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57
5.2 Techniques . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57
5.3 Optimizations . . . . . . . . . . . . . . . . . . . . . . . . . . . 68
5.4 Conclusion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 75
Bibliography . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 75

6 Realistic Real-Time Skin Rendering on Mobile 77


Renaldas Zioma and Ole Ciliox
6.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . 77
6.2 Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 77
6.3 Power of Mobile GPU . . . . . . . . . . . . . . . . . . . . . . . 79
6.4 Implementation . . . . . . . . . . . . . . . . . . . . . . . . . . 80
6.5 Results . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 84
6.6 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 85
Bibliography . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 86

7 Deferred Rendering Techniques on Mobile Devices 87


Ashley Vaughan Smith
7.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . 87
7.2 Review . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 87
7.3 Overview of Techniques . . . . . . . . . . . . . . . . . . . . . . 88
7.4 OpenGL ES Extensions . . . . . . . . . . . . . . . . . . . . . . 94
7.5 Conclusion and Future Work . . . . . . . . . . . . . . . . . . . 96
Bibliography . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 96
Contents vii

8 Bandwidth Efficient Graphics with the ARM Mali GPUs 99


Marius Bjørge
8.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . 99
8.2 Shader Framebuffer Fetch Extensions . . . . . . . . . . . . . . 99
8.3 Shader Pixel Local Storage . . . . . . . . . . . . . . . . . . . . 103
8.4 Deferred Shading Example . . . . . . . . . . . . . . . . . . . . 107
8.5 Conclusion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 111
Bibliography . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 112

9 Efficient Morph Target Animation Using OpenGL ES 3.0 113


James L. Jones
9.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . 113
9.2 Previous Work . . . . . . . . . . . . . . . . . . . . . . . . . . . 113
9.3 Morph Targets . . . . . . . . . . . . . . . . . . . . . . . . . . . 114
9.4 Implementation . . . . . . . . . . . . . . . . . . . . . . . . . . 115
9.5 Conclusion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 119
9.6 Acknowledgments . . . . . . . . . . . . . . . . . . . . . . . . . 119
Bibliography . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 119

10 Tiled Deferred Blending 121


Ramses Ladlani
10.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . 121
10.2 Algorithm . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 123
10.3 Implementation . . . . . . . . . . . . . . . . . . . . . . . . . . 124
10.4 Optimizations . . . . . . . . . . . . . . . . . . . . . . . . . . . 130
10.5 Results . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 132
10.6 Conclusion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 133
Bibliography . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 134

11 Adaptive Scalable Texture Compression 137


Stacy Smith
11.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . 137
11.2 Background . . . . . . . . . . . . . . . . . . . . . . . . . . . . 137
11.3 Algorithm . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 138
11.4 Getting Started . . . . . . . . . . . . . . . . . . . . . . . . . . 140
11.5 Using ASTC Textures . . . . . . . . . . . . . . . . . . . . . . . 141
11.6 Quality Settings . . . . . . . . . . . . . . . . . . . . . . . . . . 142
11.7 Other Color Formats . . . . . . . . . . . . . . . . . . . . . . . 147
11.8 3D Textures . . . . . . . . . . . . . . . . . . . . . . . . . . . . 149
11.9 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 149
Bibliography . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 150
viii Contents

12 Optimizing OpenCL Kernels for the ARM Mali-T600 GPUs 151


Johan Gronqvist and Anton Lokhmotov
12.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . 151
12.2 Overview of the OpenCL Programming Model . . . . . . . . . 152
12.3 ARM Mali-T600 GPU Series . . . . . . . . . . . . . . . . . . . 152
12.4 Optimizing the Sobel Image Filter . . . . . . . . . . . . . . . . 155
12.5 Optimizing the General Matrix Multiplication . . . . . . . . . 163
Bibliography . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 181

13 Hybrid Ray Tracing on a PowerVR GPU 183


Gareth Morgan
13.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . 183
13.2 Review . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 183
13.3 Combining Ray Tracing with Rasterization . . . . . . . . . . . 187
13.4 Hard Shadows . . . . . . . . . . . . . . . . . . . . . . . . . . . 189
13.5 Soft Shadows . . . . . . . . . . . . . . . . . . . . . . . . . . . 190
13.6 Reflections . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 191
13.7 Transparency . . . . . . . . . . . . . . . . . . . . . . . . . . . 192
13.8 Performance . . . . . . . . . . . . . . . . . . . . . . . . . . . . 194
13.9 Results . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 196
13.10 Conclusion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 200
Bibliography . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 200

14 Implementing a GPU-Only Particle-Collision System with ASTC


3D Textures and OpenGL ES 3.0 201
Daniele Di Donato
14.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . 201
14.2 GPU-Only Particle System . . . . . . . . . . . . . . . . . . . . 202
14.3 Physics Simulation . . . . . . . . . . . . . . . . . . . . . . . . 204
14.4 Rendering the Particles . . . . . . . . . . . . . . . . . . . . . . 211
14.5 Conclusion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 216
Bibliography . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 217

15 Animated Characters with Shell Fur for Mobile Devices 219


Andrew Girdler and James L. Jones
15.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . 219
15.2 Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 219
15.3 Creating a Shell Fur Texture . . . . . . . . . . . . . . . . . . . 220
15.4 Bone Batches or Single Pass? . . . . . . . . . . . . . . . . . . 221
15.5 Model Data and Setup . . . . . . . . . . . . . . . . . . . . . . 221
15.6 Animation with TF . . . . . . . . . . . . . . . . . . . . . . . . 223
15.7 Instancing for Fur Shells . . . . . . . . . . . . . . . . . . . . . 223
Contents ix

15.8 Lighting and Other Effects . . . . . . . . . . . . . . . . . . . . 225


15.9 Conclusion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 227
Bibliography . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 227

16 High Dynamic Range Computational Photography on Mobile GPUs 229


Simon McIntosh-Smith, Amir Chohan, Dan Curran, and Anton Lokhmotov
16.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . 229
16.2 Background . . . . . . . . . . . . . . . . . . . . . . . . . . . . 230
16.3 Tone-Mapping Operators . . . . . . . . . . . . . . . . . . . . . 233
16.4 Related Work . . . . . . . . . . . . . . . . . . . . . . . . . . . 238
16.5 GPGPU Using OpenCL . . . . . . . . . . . . . . . . . . . . . 239
16.6 OpenGL ES and Android . . . . . . . . . . . . . . . . . . . . . 243
16.7 Implementing an HDR Pipeline Using OpenCL and OpenGL ES 244
16.8 Android Implementation . . . . . . . . . . . . . . . . . . . . . 253
16.9 Performance of Our HDR Effects . . . . . . . . . . . . . . . . 258
16.10 Conclusions . . . . . . . . . . . . . . . . . . . . . . . . . . . . 261
Bibliography . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 262

17 Efficient Soft Shadows Based on Static Local Cubemap 265


Sylwester Bala and Roberto Lopez Mendez
17.1 Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 265
17.2 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . 265
17.3 Algorithm Overview . . . . . . . . . . . . . . . . . . . . . . . . 266
17.4 What Is a Local Cubemap? . . . . . . . . . . . . . . . . . . . 267
17.5 Creating a Shadow Cubemap . . . . . . . . . . . . . . . . . . 268
17.6 Applying Shadows . . . . . . . . . . . . . . . . . . . . . . . . . 269
17.7 Smoothness . . . . . . . . . . . . . . . . . . . . . . . . . . . . 272
17.8 Combining the Shadow Technique with Others . . . . . . . . . 273
17.9 Performance and Quality . . . . . . . . . . . . . . . . . . . . . 274
17.10 Future Work . . . . . . . . . . . . . . . . . . . . . . . . . . . . 275
17.11 Conclusion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 275
Bibliography . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 276

18 Physically Based Deferred Shading on Mobile 277


Ashley Vaughan Smith and Mathieu Einig
18.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . 277
18.2 Physically Based Shading . . . . . . . . . . . . . . . . . . . . . 277
18.3 An Efficient Physically Based Deferred Renderer . . . . . . . . 280
18.4 Experiments . . . . . . . . . . . . . . . . . . . . . . . . . . . . 285
18.5 Conclusion and Future Work . . . . . . . . . . . . . . . . . . . 285
Bibliography . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 288

Contributors 289
Introduction
With all devices now touch-driven and offering few physical keys, the effective
usage of touch screens is critical. The chapter, “Touchscreen-Based User Inter-
action,” by Andrea Bizzotto, provides basic insight into the complexities and
solutions required to achieve the best possible user-interaction and experience
through a touch-based interface.
“Optimizing a 3D UI Engine for Mobile Devices,” by Hyunwoo Ki, offers
early insights into optimizing a user interface for mobile devices, looking at the
importance of font rendering engines and “dirty region”-based optimizations to
avoid rendering more than is actually required.
The chapter, “A Shader-Based eBook Renderer,” by Andrea Bizzotto illus-
trates a vertex-shader-based implementation of the page-peeling effect of a basic
eBook renderer. It covers high-quality procedural antialiasing of the page edges,
as well as some tricks that achieve a polished look. Two pages can be combined
side-by-side to simulate a real book, and additional techniques are introduced
to illustrate how to satisfy additional constraints and meet power-consumption
requirements.
The next chapter, “Post-Processing Effects on Mobile Devices,” by Marco We-
ber and Peter Quayle describes a general approach to implement post-processing
on handheld devices by showing how to implement a bloom effect with efficient
convolution.
Joe Davis and Ken Catterall show in “Shader-Based Water Effects” how to
render high-quality water effects at a low computational cost. Although there are
many examples of water effects using shaders that are readily available, they are
designed mainly for high-performance graphics chips on desktop platforms. This
chapter shows how to tailor a technique discussed by Kurt Pelzer (in ShaderX2 ,
“Advanced Water Effects,” 2004) to mobile platforms.
In “Realistic Real-Time Skin Rendering on Mobile,” Renaldas Zioma and Ole
Ciliox share how they implemented skin rendering using physically based shading
models for the Unity “The Chase” demo. Their method makes use of approxi-
mations and lookup textures in order to balance the arithmetic and texture load.
In “Deferred Rendering Techniques on Mobile Devices,” Ashley Vaughan
Smith explores various techniques for doing deferred rendering on mobile devices.
This chapter steps through deferred shading, light pre-pass rendering, and light

xi
xii Introduction

indexed rendering, and also details extensions that allow efficient read-access to
individual render targets to further improve performance.
In “Bandwidth Efficient Graphics with the ARM Mali GPUs,” Marius Bjørge
presents new ARM Mali GPU extensions that allow applications to efficiently
read and write data to the on-chip tile buffer. Applications can read the current
color, depth, and stencil values as well as treat the tile buffer as a local storage
with full read and write access. The chapter also contains example use-cases such
as soft particles and deferred shading.
In “Efficient Morph Target Animation Using OpenGL ES 3.0,” James L. Jones
shows how OpenGL ES 3.0 can be used to do morph target animation efficiently
on mobile devices. Transform feedback is used to blend a set of poses, and the
chapter also describes how to batch blend multiple poses to reduce the number
of passes.
In “Tiled Deferred Blending,” Ramses Ladlani describes a method for doing
deferred blending. Blended primitives are first tiled to screen-space tiles, and then
each tile is rendered while blending the primitives in a single fragment shader pass.
The method has proven efficient on immediate mode renderers where blending
involves an expensive read-modify-write operation with the framebuffer.
In “Adaptive Scalable Texture Compression,” Stacy Smith presents ASTC, a
new texture compression format that has been accepted as a Khronos standard.
ASTC is set to pretty much replace all existing compressed texture formats. It
supports bit rates ranging from 0.89 bpp up to 8 bpp for both LDR and HDR
textures. This chapter explains how it works, how to use it, and how to get the
most out of it.
In “Optimizing OpenCL Kernels for the ARM Mali-T600 GPUs,” Johan
Gronqvist and Anton Lokhmotov go into the details of writing efficient OpenCL
kernels for the ARM Mali-T600 GPUs. This chapter introduces the ARM Mali-
T600 GPU series and goes into a deep discussion of the performance character-
istics of various OpenCL kernels.
“Hybrid Ray Tracing on a PowerVR GPU” by Gareth Morgan describes how
an existing raster-based graphics engine can use ray tracing to add high-quality
effects like hard and soft shadows, reflection, and refraction while continuing to
use rasterization as the primary rendering method. The chapter also gives an
introduction to the OpenRL API.
“Implementing a GPU-Only Particle-Collision System with ASTC 3D Tex-
tures and OpenGL ES 3.0” by Daniele Di Donato shares how the author used
OpenGL ES 3.0 and ASTC 3D textures to do bandwidth-friendly collision detec-
tion of particles on the GPU. The 3D texture stores a voxel representation of the
scene, which is used to do direct collision tests as well as to look up the nearest
surface.
ARM is a registered trademark of ARM Limited (or its subsidiaries) in the EU and/or
elsewhere. Mali is a trademark of ARM Limited (or its subsidiaries) in the EU and/or elsewhere.
All rights reserved.
Introduction xiii

“Animated Characters with Shell Fur for Mobile Devices” by Andrew Girdler
and James L. Jones presents how the authors were able to optimize a high-quality
animation system to run efficiently on mobile devices. With OpenGL ES 3.0, they
made use of transform feedback and instancing in order to reach the performance
target.
“High Dynamic Range Computational Photography on Mobile GPUs” by Si-
mon McIntosh-Smith, Amir Chohan, Dan Curran, and Anton Lokhmotov ex-
plores HDR computational photography on mobile GPUs using OpenCL and
shares some very interesting results.
In “Efficient Soft Shadows Based on Static Local Cubemap,” Sylwester Bala
and Roberto Lopez Mendes introduce a novel soft shadow technique that makes
use of local cubemaps. The technique allows for very nice looking smooth shadows
at minimal performance cost.
In “Physically Based Deferred Shading on Mobile,” Ashley Vaughan Smith
and Mathieu Einig describe how to implement physically based deferred shading
on a power-constrained mobile device using extensions such as pixel local storage
and framebuffer fetch. The chapter also explains how these extensions can be
used to implement deferred decal rendering very easily on mobile GPUs.
Lastly, I would like to thank all the contributors in this book for their great
work and excellent chapters.
Web Materials
Example programs and source code to accompany some of the chapters are avail-
able on the CRC Press website: go to https://www.crcpress.com/9780815352815
and click on the “Downloads” tab.
The directory structure follows the book structure by using the chapter num-
bers as the name of the subdirectory.

General System Requirements


The material presented in this book was originally published between 2010 and
2016, and the most recent developments have the following system requirements:
• The DirectX June 2010 SDK (the latest SDK is installed with Visual Studio
2012).
• DirectX 11 or DirectX 12 capable GPUs are required to run the examples.
The chapter will mention the exact requirement.
• The OS should be Microsoft Windows 10, following the requirement of
DirectX 11 or 12 capable GPUs.
• Visual Studio C++ 2012 (some examples might require older versions).
• 2GB RAM or more.

• The latest GPU driver.

xv
1

Touchscreen-Based
User Interaction
Andrea Bizzotto

1.1 Introduction
The touchscreen plays a major role in user interaction on mobile devices. Al-
though some of these systems come with high-level APIs that could be used by
the programmer to detect gestures, others provide just raw access to the samples
read from the hardware. This chapter illustrates a mathematical framework that
can be used to estimate the motion and position of the input pointer on screen
(see Figure 1.1). An application for controlling the position of a camera in a
three-dimensional spherical coordinate system is presented as an usage example.

1.2 Motion Estimation


Let us approach the problem of estimating the motion on screen, given a set of
samples described by three values:

• The time when the sample was read.

• The position of the sample along the x axis.

• The position of the sample along the y axis.

The context of this problem is a main-loop based graphics application. With


this respect, the platform-specific touchscreen implementation might provide one
sample per-frame, or multiple samples (as it is the case if the touchscreen sub-
system is independent from the main loop).

1
2 1. Touchscreen-Based User Interaction

Figure 1.1. Touchscreen input: while the user drags the pointer on screen, the new
samples become available and at the beginning of each frame they can be used to
estimate the motion and position.

A very simple approach would be to calculate the motion as the velocity


between two consecutive samples as in Equation (1.1), where ti is the time of the
sample i, s(ti ) the corresponding position and v(ti ) the velocity:

s(tn ) − s(tn−1 )
v(tn ) = . (1.1)
tn − tn−1
Given the small screen size of mobile devices and their relatively high reso-
lution, reading consecutive samples can result in different x- and y-coordinates,
even if the pointer is not moving on screen. This effect was observed on OMAP
Zoom platforms, where a set of samples with slightly different positions was re-
turned even when the input position was fixed.
We can take in account this behavior in our model by assuming that the
samples are affected by Gaussian noise, whose variance is platform-dependent. If
on a particular device this side effect does not exist, our model is still valid as it
means that the variance of the noise is zero. Since we want our motion estimation
algorithm to be virtually unaffected by the presence of noise, we introduce a
method for noise reduction followed by a thresholding operation.
A very common technique for noise reduction is to apply an average filter on
the set of available samples, therefore reducing the error by a factor of N (where
N is the size of the set).
If the user drags the pointer on screen and we want to estimate the motion
of such interaction, we can use a more effective approach that reduces the noise
and makes use of all the samples in a given time interval:
1.2. Motion Estimation 3

1. Choose a “time window” that contains all the most recent samples. To do
so, we store all the samples that we want to process in an circular queue.
At each frame we update our queue by adding all the samples that were
read since the previous frame, and discarding the ones that are too old. If
no samples are read for some time, the queue will quickly empty and we
can set the motion to 0.
2. Calculate all the velocities between consecutive samples in the queue.
3. Obtain the average on those velocities.
This method is much more reliable than the previous one and introduces a
trade-off between accuracy and responsiveness of the filter:
Bigger window. More samples are stored: the accuracy increases but the re-
sponsiveness of the filter decreases. Since we are using a causal filter, if ∆T
is the length of the window, we are introducing a delay equal to ∆T /2.
Smaller window. Fewer samples are stored: the accuracy decreases but the
responsiveness increases.

void update ( Sample * pSamples , int num , float & mx , float & my ) {
// Add the samples read in the last frame .
queue . add ( pSamples , num );
// Deletes old samples
queue . remove ( getTime () - timeWindow );
if ( queue . size () < 2) {
mx = my = 0.0 f ;
return ;
}
int i = 0;
Iterator iter = queue . begin ();
Sample curr , prev = iter . data ();
while ( iter . next ()) {
curr = iter . data ();
// Motion is an array that stores motions of consecutive
samples .
motion [ i ]. dx = ( curr . x - prev . x ) / ( curr . t - prev . t );
motion [ i ]. dy = ( curr . y - prev . y ) / ( curr . t - prev . t );
prev = curr ;
i ++;
}
Calculat eAverage ( motion , i , mx , my );
// Apply thresholds
if ( mx < thresholdX ) mx = 0.0 f ;
if ( my < thresholdY ) my = 0.0 f ;
}

Listing 1.1. Motion estimation routine.


4 1. Touchscreen-Based User Interaction

The method can be made even more robust: we can define a platform-
dependent threshold that is proportional to the variance of the noise, and if
the estimated motion is smaller than this threshold, we set it to zero. This will
guarantee that no motion is detected if the input position does not change (taking
noise into account).
The complete method for updating the motion is summarized in Listing 1.1.
Such an approach has been successfully tested on several platforms. For the
purpose of motion estimation, choosing a time interval of 0.2 seconds gives good
results on an OMAP Zoom platform, while on the Samsung Omnia the read
input coordinates are constant if the pointer doesn’t move on screen, and the
time interval and threshold can be smaller as no noise needs to be removed. The
same applies on Windows emulation, where the mouse is used as a pointing device
to simulate the touchscreen.

1.3 Position Prediction


Position estimation seems to be an easy task as the position of the last sample
can be used directly. Some considerations can be made nevertheless:

• The instant when the input is processed (beginning of the new frame) is
not necessarily the same as the time of the last read sample.

• The graphics pipeline takes some time to render the frame and swap the
buffers, so if the input position is used to draw a target on screen (for
example a cursor), it might be worth to adjust this position according to
the time when the frame will be actually rendered.

These two contributions are put together in Equation (1.2), where △read is the
difference between the current time and the time of the last sample, and △frame
is the time to render the current frame, equal to the time to render the previous
frame (we can assume that the framerate is locally constant):

△total = △read + △frame . (1.2)

The predicted position is then as in Equation (1.3), where v(tlast ) is the motion
estimated as described and tlast the time of the last read sample:

s(tnew ) = s(tlast ) + v(tlast ) · (tlast + △total ). (1.3)


1.4. Application: Controlling a Camera in a Spherical Coordinate System 5

1.4 Application: Controlling a Camera in a Spherical


Coordinate System
A possible application is to use our new motion primitives to move a camera
around an object in the center of the scene. The target of the camera is therefore
fixed to the origin of the world coordinate system. If required, this constraint
can be relaxed by setting the target on an arbitrary point in three-dimensional
space, as with a simple translation this case can be included in the former one.
The position of the camera is determined by a vector (x, y, z) of coordinates,
while only the motion in the x- and y-directions of the screen is available. As it is
not intuitive to map these directions to a point in a cartesian coordinate system,
we can use an alternative representation for the position of the camera:

Yaw. Rotation around the y-axis.

Pitch. Rotation around the x-axis.

Radius. Distance of the camera from the origin.

This allows us to use the x- and y-motion on the touchscreen to update the
yaw and pitch angles of the camera, while leaving the radius fixed or adjustable
through other input controls.
Figure 1.2 shows the concept. The camera position is initially set to (0, 0, R)T .
At each frame the yaw and pitch angles are updated according to the motion on
the touchscreen, and the position is updated.

Figure 1.2. Three-dimensional spherical coordinate system: upon application of the


yaw and pitch angles the camera moves from the initial position (marked in blue) to
the final one (green). The camera defines a coordinate system defined by the position
and the three orthonormal vectors (Vx , Vy , Vz ).
6 1. Touchscreen-Based User Interaction

To render our scene from the viewpoint of the camera we need to calculate
the roto-translation matrix that transforms a point from world space coordinates
to camera space coordinates. In OpenGL such a matrix is known as model-view
matrix and can be computed once the position, target and up direction of the
camera are known; therefore, we want to find these values first.
The spherical coordinate system is useful to update the yaw and pitch angles,
but to find the model-view matrix the position needs to be expressed again in the
canonical coordinate system. This is done by applying the rotation matrices that
correspond to the two angles to the initial position, as in Equations (1.4), (1.5)
and (1.6).
   
cos (α) 0 − sin (α) 1 0 0
Ry (α) =  0 1 0  Rx (α) =  0 cos (α) − sin (α)  .
sin (α) 0 cos (α) , 0 sin (α) cos (α)
(1.4)

Mrot = Ry (yaw) · Rx (pitch). (1.5)

 
0
Vpos = Mrot ·  0  . (1.6)
R
The target of our camera is fixed at the origin, as Equation (1.7) states, and
the up direction (Vy ) is determined by Equation (1.8).

Vtarget = 0T . (1.7)


0
Vy = Mrot ·  1  . (1.8)
0
The model-view matrix is composed by a translation that shifts the coordinate
system to the position of the camera and by a rotation that takes into account its
relative orientation. Such rotation can be expressed as a matrix formed by three
orthonormal vectors that can be immediately derived from the position, target
and up direction of the camera. Equations (1.9), (1.10) and (1.11) illustrate the
concept:

Vtarget − Vpos
Vz = − . (1.9)
||Vtarget − Vpos ||

Vx = Vy × Vz . (1.10)
1.5. Algorithm Overview 7

 
VxT 0 ( )
 VyT 0  −Vpos
Mview =  · 03x3 . (1.11)
 VzT 0  0T 1
0T 1
It can be noticed that the vectors Vx , Vy , and Vz represent the axes of a right-
handed reference frame. For this reason the direction of the camera is opposite
of the vector Vz .
This mathematical framework allows the setup of an interactive system where
the user can spin the camera around the observed object. The yaw and pitch
angles can be updated at each frame by adding the motion on the x- and y-axes,
but once the user releases the pointer, the camera movement immediately stops.
It would be more realistic if the camera had a residual inertial motion, and the
next section illustrates how to implement this.

1.4.1 Adding Inertia


The desired effect consists in letting the camera spin for a short amount of time,
until the residual motion is zero. Such effect is best modeled by a decreasing
exponential function like the one in Equation (1.12):
{
0, t < 0,
f (t) = (1.12)
1 − e−τ t , t ≥ 0.
If tr is the time when the input is released and Mx the corresponding motion
on the x-axis, the residual speed at any instant in time is given by x(t) = Mx ·
f (t − tr ).
This value can be integrated over time to update the yaw angle (the same
procedure is valid for the y-axis / pitch angle). The integration is a discrete
operation as it can be performed at each frame, and Equation (1.13) provides a
method to update the angle frame by frame:

n
x(tn ) = Mx ·f (ti −tr )(ti −ti−1 ) = x(tn−1 )+Mx ·f (tn −tr )(tn −tn−1 ). (1.13)
i=0

1.5 Algorithm Overview


The general algorithm for updating the camera position within the main loop is
illustrated in Listing 1.2.
The motion is estimated using the discussed technique and used to update
the yaw and pitch angles. When the input is released the current time and the
motion are saved and later used to add the inertial contribution to the angles
8 1. Touchscreen-Based User Interaction

t = getTime () ;
touchscreen . GetMotion ( motionX , motionY ) ;
if ( touchscreen . Released () ) {
releaseMotionX = motionX ;
releaseMotionY = motionY ;
tr = t ;
}
yaw = yaw + motionX + rel easeM otionX * f ( t - tr ) ;
pitch = pitch + motionY + r elease Motion Y * f ( t - tr ) ;
MView = Calculat e Ma t ri x ( yaw , pitch , radius ) ;

RenderGeometry ( MView ) ;

Listing 1.2. Render loop.

(appropriate scaling factors can be used when updating the angles in order to
calibrate the speed of the camera position as desired). Finally, the model-view
matrix can be calculated with the techique previously described and the geometry
can be rendered using that matrix.
Figure 1.3 illustrates how the presented techniques have been used in an
OpenGL ES 2.0 demo developed at Imagination Technologies.

Figure 1.3. Flowers demo. This demo shows procedural plant growth with detailed
flowers and makes use of the described touchscreen implementation to spin the camera
around the growing plant.
1.6. Conclusion 9

1.6 Conclusion
This chapter showed how to approach motion estimation by means of a robust
algorithm whose parameters can be adapted on different platforms to get optimal
results. The length of the time window and the threshold can be tweaked as
necessary according to the requirements of the final application.
A simple OpenGL ES 2.0 demo that allows to control the camera in the
spherical coordinate system previously described is available in the book’s web
materials on the CRC Press website, together with full source code for OMAP
Zoom1, Zoom2 and Windows emulation, where the mouse is used to simulate the
touchscreen interaction.

1.7 Acknowledgments
The author would like to thank Kristof Beets and the whole BizDev and DevTech
teams for their work, contribution, and feedback.
2

Optimizing a 3D UI Engine
for Mobile Devices
Hyunwoo Ki

A graphical user interface (GUI) is the preferred type of user interface (UI). It
provides more intuitive visual components with images or animations, as opposed
to a text-based interface. Such a GUI is essential for both graphics applications
(for example, games) and non-graphics applications (for example, a phonebook).
It should offer us convenience as well as beauty. With advancement of embedded
systems, UI design shows a trend toward presenting three-dimensional graphical
looks. Because the UI is a fundamental component for all applications, a UI en-
gine should provide high performance and low memory consumption. The major
mission of our UX development group at INNOACE Co., Ltd., is developing an
optimized three-dimensional UI engine and an authoring tool for various mobile
devices to maximize user experience. Our core engine supports two-dimensional
and three-dimensional widgets, scene management, resource management, True-

Figure 2.1. Examples using a three-dimensional UI engine base on OpenGL ES 2.0.

11
12 2. Optimizing a 3D UI Engine for Mobile Devices

Type font rendering, three-dimensional transition, visibility culling, occlusion


culling, widget caching, partial rendering, etc. Based on this core engine, we
migrated our UI engine to various platforms, for example LINUX, Windows Mo-
bile, Android and GPOS. We developed a hardware renderer based on OpenGL
ES 2.0 for high-end smartphones and PMPs, and a software renderer for com-
mon mobile phones. This chapter presents practical optimization methods for
a three-dimensional UI engine based on OpenGL ES 2.0 with our development
experience (see Figure 2.1). However, we expect some features of our core engine
would be useful for OpenGL ES 1.1 or software renderers.

2.1 Overview
Optimization methods presented in this chapter include rendering pipeline op-
timization, TrueType font rendering, widget caches with partial update, and
resource management.

1. Rendering pipeline optimization. We describe fundamental development


guidelines of OpenGL ES 2.0 for a three-dimensional UI engine. We show
our usage examples of render states, shaders, textures, draw calls, and etc.

2. TrueType font rendering. Texts are a very important component of the


UI, and rendering texts requires higher costs than rendering other widgets.
Particularly, processing Asian languages (e.g., Korean and Chinese) lower
engine efficiency because it must handle many font glyphs. We present our
text renderer’s design and implementation issues to minimize draw calls
and texture changes with low memory consumption.

3. Widget caches with partial update. We render a composite widget to a


render texture, and consider this texture as a widget cache until a sub-
widget of the composite widget is changed. This widget cache accelerates
rendering a composite widget. Furthermore, according to interaction and
logic, we partially update this widget cache to reduce update costs.

4. Resource management. We developed an efficient resource management


system based on DirectX, one with resource garbage collectors. For exam-
ple, if a managed texture has not been used for a long time, we dispose it
on memory, and this texture is automatically restored from storage when
we use it. We describe design and implementation issues of our resource
management system.
Another random document with
no related content on Scribd:
Deacon. Again and again.... Vide page 142.
Kathisma, tone vi.
Verily everything is vain, and life a shadow is, a dream; for vainly
every earth-born one disquieteth himself, as saith the scripture.
When we have gain’d the world, then dwell we in the grave, where
kings and beggars are as one. Therefore, Christ God, as lover of
mankind, to thy departed servant give thou rest.
Glory. Both now. Theotokion.
All-holy Bringer-forth of God, in my life’s time forsake me not, to
human mediation leave me not; but me thyself defend, and be thou
merciful to me.
Ode iv. Irmos.
Christ is my might, the God and Lord....
Of greatest wisdom shewing sign, and of rewards’ perfectionment,
O gracious Lord, with Angels thou the choirs of martyrs number’d
hast.
Of thy narrateless glory count him worthy to participate, who unto
thee translated is, where, Christ, their dwelling is who joy, and where
pure gladness’ voice resounds.
Glory.
Him that extols thy might divine, whom thou from earth received
hast, do thou accept, creating him a child of light; and cleanse him
from the gloom of sin, O thou Most Merciful.
Both now. Theotokion.
O tabernacle thou most pure, temple all-undefil’d, all-holy ark,
virginal place of sanctity, of Jacob thou the excellence, the Lord hath
chosen thee.
Ode v. Irmos.
With thy divine light, O Blessed One....
Like an oblation sacred, and human nature’s first-fruits, the
martyrs, who were offer’d for God’s glorifying, for our salvation ever
mediate.
Of heavenly dwelling, of grace’s distribution, thy faithful servant
gone before, count worthy, Lord, and give him ransom from
iniquities.
Glory.
Thou that alone by nature life-effector art, and grace’s trackless
depth, him that is gone, count worthy of thy kingdom, Pitiful, thou
sole immortal one.
Both now. Theotokion.
The strength, and song, and saving of the lost is he become that
to the world was born of thee, O Queen, delivering them, who thee in
faith call bless’d, from hades’ gates.
Ode vi. Irmos.
Life’s sea perturb’d....
Nail’d on the cross the choir of martyrs thou hast gather’d to
thyself, them that thy passion imitate, O Blessed One. Therefore, we
thee beseech, Rest him that now betaketh him to thee.
When thou in thy narrateless glory all the world to judge shalt on
the clouds in terror come, Deliverer, be thou pleas’d that he, thy
faithful servant, whom thou from earth received hast, may meet thee
shiningly.
Glory.
Being life’s fount, O Lord, who, through divine humanity, didst lead
the fetter’d forth; thy servant, who to thee in faith is gone, place thou
in joys of paradise.
Both now. Theotokion.
We have been turned back to earth for breaking the divine
command of God; but, through thee, Virgin, unto heaven from earth
are rais’d again, shaking off death’s corruption.
Deacon. Again and again.... Vide page 142.
Condakion, tone viii.
Rest with the Saints, O Christ, thy servant’s soul, where is no pain,
nor grief, nor sighing, but life that endeth not.
Icos.
Thyself alone immortal art, who madest and didst fashion man; for
out of earth we mortals fashion’d were, and unto that same earth
shall go, as thou who madest me hast given command, and sayest
unto me, Earth thou art, and unto earth shalt thou return. And thither
all we mortals go, making the funeral wail, even the song, the
Alleluia.
And again.
Rest with the Saints, O Christ....
Ode vii. Irmos.
The angel made the furnace to bedew....
From the primeval fall were sav’d the martyrs by thy blood, and,
with their own blood sprinkled, they clearly thy slaying image forth.
Blessed art thou, our fathers’ God.
O life-originating Word, thou hast slain raging death; and him O
now receive, O Christ, who sleeps in faith, and sings, and says,
Blessed art thou, our fathers’ God.
Glory.
Divine-originating Lord, who me, a man, with breath divine
sufflated hast; vouchsafe thy kingdom unto him departed hence,
who, Saviour, sings to thee, Blessed art thou, our fathers’ God.
Both now. Theotokion.
Most undefil’d, conceiving God, who crush’d death’s gates and
burst the bars, thou higher than all creatures art. Therefore, we
faithful thee, O pure, extol as Mother of God.
Ode viii. Irmos.
From flame thou didst a dew outpour on reverend ones....
Martyrs of Christ, who sufferings bore, who in the strifes were
steadfast prov’d, ye are adorn’d with victory’s crown, crying, O
Christ, to ages thee we set on high.
The faithful ones who life depart in sacred wise, and unto thee, O
Master, go, gently, as loving-kind, receive, that they may rest, and
thee to ages set on high.
Glory.
Now in the land of gentle ones, Saviour, be pleas’d to stablish all
who fallen have on sleep afore, and who in thee, by faith and grace,
are justified, and thee to ages set on high.
Both now. Theotokion.
All-blessed one, we thee all bless, who didst bring forth the Word
who is blessed indeed, who for our sake incarnate was, and whom
on high to ages we set up.
Ode ix. Irmos.
Mortals may not see God....
Hope made the choirs of martyrs strong, and flam’d them ardently
towards thy love, prefiguring unto those to come a rest in verity
undisturb’d; and unto this, O Blessed One, may thy departed faithful
one be counted worthy to attain.
Of thine illumination, Christ, which bright and godlike is, be pleas’d
that he, departed hence in faith, may share, to him, as being
merciful, in Abraham’s bosom giving rest, and granting him eternal
blessedness.
Glory.
O thou that art by nature good and loving-kind, and mercy willest,
and a depth of loving-kindness art, his lot, whom, Saviour, thou from
this ill place removed hast, and from the shades of death, appoint
where shines thy light.
Both now. Theotokion.
A holy tabernacle thee we own to be, O Pure, an ark likewise, and
breastplate of the law and grace; for pardon is bestow’d, through
thee, on them, All-undefil’d, that have, by his blood justified been,
who of thy womb incarnate was.
Deacon. Again and again in peace let us pray to the Lord. Vide
page 142.
We begin the idiomela of John the monk.
Tone i.
What sweet of life abideth unaccompanied with grief? what glory
stayeth upon earth unchang’d? All is the feeblest shade, all the most
cheating dream: one moment, and death taketh all these things. But
in thy face’s light, O Christ, and in the sweetness of thy beauty, grant
rest to him whom thou hast call’d, as lover of mankind.
Tone ii.
Woe unto me, what agony hath the soul when it is from the body
torn! alas, then how it weeps, and none is merciful to it! To Angels
lifting eyes, without effect it prays; to men extending hands, it findeth
none to help. Therefore, my brethren lov’d, musing on our brief life,
let us for the departed ask for rest from Christ, and for great mercy
for our souls.
Tone iii.
All human things are vanity which last not after death: riches abide
not, nor doth glory stay; for when death cometh, these all disappear.
Then let us cry to the immortal Christ, O rest him who is gone away
from us where is the dwelling-place of all that joy.
Tone iv.
Where is the predilection of the world? where their imaginings who
fade? where is the silver and the gold? where servants’ multitude
and noise? All dust, all ashes, all a shade. But, come ye, let us say
to the immortal King, O Lord, him, who hath been remov’d from us,
of thine eternal blessings worthy count, him resting in thine ageless
happiness.
Tone v.
I remember’d what the prophet said, I am earth, and I am dust;
and again I meditated in the graves, and saw the naked bones, and
said, Who now is king, or warrior who, or who is rich, or who is poor,
or who the just, or he that sinn’d? But, with the just, thy servant rest,
O Lord.
Tone vi.
To me thy life-effecting bidding was substance and origin; for,
willing me to form a living one from nature that unseen is and is
seen, my body thou didst make of earth, and, by thy breathing life-
creating and divine, me gavest soul. Therefore, O Christ, thy servant
rest in tract of them that living are, and in the dwellings of the just.
Tone vii.
After thine image and resemblance in the beginning making man,
in paradise thou him didst place to be of thy creation lord; but, by the
devil’s enviousness beguil’d, he ate the fruit, transgressing thy
commands. Therefore, again to earth, whence he was taken, thou
hast doom’d him to return, O Lord, and beg for rest.
Tone viii.
I weep and I lament when I reflect on death, and see the
comeliness, according to God’s image, that was shap’d for us lying
in the graves disfigured, and bereft of glory and of form. O wonder!
what is this mystery concerning us? how to corruption have we been
assign’d? how unto death conjoin’d? Verily by God’s command, as it
is written, who giveth the departed rest.
The beatitudes, tone vi.
When in thy kingdom thou shalt come, O Lord, remember us.
Blessed are the poor in spirit, for theirs is the kingdom of heaven.
Blessed are they that mourn, for they shall be comforted.
Blessed are the meek, for they shall inherit the earth.
Blessed are they that hunger and thirst after righteousness, for
they shall be filled.
Blessed are the merciful, for they shall obtain mercy.
Christ, who, aforetime, for his penitence, didst make the thief a
citizen of paradise when on the cross to thee he cried, Remember
me, of this even me, unworthy, worthy count.
Blessed are the pure in heart, for they shall see God.
Thou who dominion hast o’er life and death, rest in the courts of
saints him whom from things of time thou taken hast; and think on
me, when in thy kingdom thou shalt come.
Blessed are the peacemakers, for they shall be called the children
of God.
Thou who o’er souls and bodies lordship hast, thou in whose hand
is held our breath, who mourners’ consolation art; rest in the land of
righteous ones thy servant whom thou hast removed hence.
Blessed are they that are persecuted for righteousness’ sake....
Christ rest thee in the land of living ones, and open paradise’s
gates to thee, and of the kingdom thee declare a citizen, and give
thee pardon of those things wherein in life thou sinned hast, O thou
of Christ belov’d.
Blessed are ye when men shall revile you....
Let us go forth and muse among the graves; for man is naked
bones, the food of worms, and of an odour ill; and let us learn what
riches are, yea, beauty, strength, and comeliness.
Rejoice, and be exceeding glad....
Let us give ear to what the Almighty saith, Woe unto them that
seek to see the Lord’s most fearful day! for it is one of gloom: for
everything with fire shall be tried.
Glory.
By the unbeginningness, and the begetting, and the proceeding, I
bow me to the Father who begat, the Son begotten I extol, I sing the
Holy Ghost, co-shining with the Father and the Son.
Both now. Theotokion.
How, Virgin, from thy breast flow’d milk? how didst thou nurture
him, creation’s nurturer? It was as was the springing forth of water
from the rock, as streams of waters for a thirsty folk, as hath been
written.
After this the deacon saith, Let us attend.
Priest. Peace to all.
And the choir singeth, prokimenon, tone vi,
Blessed is the way wherein thou goest to-day, O soul, because a
place of rest hath been prepared for thee.
Verse. Unto thee have I cried, O Lord.
Deacon. Wisdom.
Reader. The epistle to the Thessalonians, section cclxx.
Brethren, I would not have you to be ignorant ... ending, be ever
with the Lord.[31]
Priest. Peace to thee. Alleluia.
Tone vi.
Blessed is he whom thou hast chosen and received, O Lord.
The gospel from John, section xvi.
The Lord spake unto the Jews that came unto him, Verily, verily, I
say unto you ... ending, the Father which hath sent me.[32]
Deacon.
Have mercy upon us, O God, according to thy great mercy, we
pray thee, hear, and have mercy.
Lord, have mercy, thrice.
Furthermore let us pray for the repose of the soul of the servant of
God, name, who hath fallen asleep, and that to him may be remitted
every transgression, voluntary and involuntary.
Lord, have mercy, thrice.
That the Lord God may place his soul where the righteous rest.
Lord, have mercy, thrice.
The mercy of God, the kingdom of heaven, and the forgiveness of
his sins let us ask of Christ, our immortal King and God.
Vouchsafe, O Lord.
Deacon. Let us pray to the Lord.
Lord, have mercy.
And after the conclusion of this the first of the priests, or the
archpriest, if one happen to be there, saith the prayer, O God of
spirits.... with a loud voice, standing nigh unto the dead.
And in like manner all the priests that be present.
And be it known that as many times as the petition is said by the
deacon, while the petition is being said by him, each of the priests in
his order saith the above mentioned prayer in a low voice nigh unto
the dead, and exclaimeth,
For thou art the resurrection....
And now by the first priest, or by the archpriest, the prayer, O God
of spirits.... is said with a loud voice, as is mentioned above.
And, after the exclamation, the kiss is given.
And we sing the present stichera of similar rhythm.
When from the tree....
Tone ii.
Come, brethren, let us give the last kiss to the dead, and render
thanks to God; for he hath left his kinsfolk, and hasteneth to the
grave: to him there is no care concerning vanities and carnal toil.
Where now are kinsfolk and where friends? Lo, we are parted from
him, whom, Lord, we pray thee to give rest.
What, O ye brethren, is this parting? what this weeping? what this
wailing in the present hour? Come, kiss ye then him whom but lately
was with us; for he is given to the grave, is cover’d with a stone, in
darkness dwelleth, is buried with the dead, and now is parted from
all kinsfolk and from friends; and him, O Lord, we pray thee to give
rest.
Now is life’s evil boast of vanity destroy’d; for from its dwelling-
place the soul is gone, the clay is ashen, the casket broken, it
voiceless is, no feeling hath, is dead and motionless. And him
consigning to the grave, let us beseech the Lord to give him
everlasting rest.
What is our life? a flower, a smoke, and, verily, a morning dew. O
come ye then, let us, with open eyes, regard the graves. Where is
the beauty of the body? where youth? where eyes, and carnal form?
All are consum’d as grass, all vanish’d. Come, fall we down to Christ
in tears.
Great is the weeping and the wailing, great is the sighing and the
need at parting from the soul. Hades and destruction wait; and
transitory life appears a fleeting shade, a dream of error; and the toil
of earthly life unseemly phantasy. Far let us fly from every worldly
sin, that heaven may be our heritage.
Gazing on him that lieth dead, O take we all a likeness of our final
hour; for he is pass’d as vapour from the earth, is wither’d as a
flower, as grass cut down, wrapp’d in a winding-sheet, and hid in
earth. And, leaving him unseen, let us pray Christ to give him
everlasting rest.
Adam’s descendants, come ye, let us see laid low in earth a
likeness of ourselves, which hath all beauty lost, is in the grave’s
decay dissolv’d, in darkness is by worms consum’d, and in the earth
is hid. And, leaving him unseen, let us pray Christ to give him
everlasting rest.
When from the body parted is the soul by force by Angels dread,
all kinsfolk and acquaintance it forgets, and is impress’d concerning
standing at the judgment-seat to come, that shall decide the things of
vanity and carnal toil. Then, praying to the judge, let us all beg the
Lord to pardon him what he hath done.
Come, brethren, let us within the grave behold the ashes and the
dust whereof we formed were. Where go we now? and what
become? what is the poor, or what the rich? or what the lord, and
what the free? Are not all dust? The beauty of the countenance is
gone, and death hath wasted all the flower of youth.
Verily vain and perishing are all the things of life, seeming, and
gloriousless; for we all go away, all die, kings and princes, judges
and them that mighty be, the rich and poor, and every mortal man;
for now they that aforetime liv’d are cast into the grave, whom that
the Lord may rest we pray.
Now all the organs of the body idle are beheld, which active were
but late, all without motion, without feeling, dead; for closed are the
eyes, the feet are bound, the hands are listless, and with them the
ears; the tongue is clos’d in silence, consigned to the grave: all
human things are vanity indeed.
Save them that put their trust in thee, O Mother of the Sun that
setteth not, thou Bringer-forth of God: with thine entreaties, we
beseech thee, pray the most good God to rest him now departed
hence where rest the righteous souls; him of divine good things
declare thou heir in halls of righteous ones, unto remembrance
everlasting, thou all undefil’d.
Glory. Tone vi.
Me, lying voiceless and depriv’d of breath, beholding, bewail ye
me, O brethren and O friends, O kinsfolk and acquaintances; for
yesterday I spake with you, and suddenly on me came the dread
hour of death. But, come ye, all that love me, and kiss me with the
final kiss; for never shall I go with you again, or further converse hold
with you. For I depart unto the judge, where no respect of persons is,
where slave and lord together stand, the king and warrior, rich and
poor, in equal worthiness; for each, according to his deeds, is
glorified or sham’d. But I beg all, and all entreat unceasingly to pray
Christ God for me, that, for my sins, I be not bidden unto torment’s
place, but that he may appoint my lot where is the light of life.
Both now. Theotokion, the same tone.
Through her entreaties who to thee gave birth, O Christ, and those
of thy forerunner, and of apostles, prophets, hierarchs, venerables,
and just, and of all Saints, unto thy sleeping servant give thou rest.
Then, Trisagion. O most holy Trinity.... Our Father....
Priest. For thine is the kingdom....
Then, With the spirits of the righteous.... and the rest.
The petition by the deacon, Have mercy upon us, O God,
according to thy great mercy....
Vide page 142. And after the exclamation, Glory. Both now. And
the dismissal.
He that arose from the dead, Christ our true God, through the
prayers of his most pure Mother, of the holy glorious and all-praised
apostles, of our venerable and God-bearing fathers, and of all the
Saints, place the soul of his servant, name, departed from us, in the
tabernacles of the just, rest it in the bosom of Abraham, and number
it with the righteous, and have mercy upon us, as being good and
the lover of mankind. Amen.
And the archpriest, or the principal priest, saith himself this thrice.
Thy remembrance is everlasting, O our deservedly blessed and
ever remembered brother.
Thrice.
Then the singers sing thrice,
Everlasting remembrance.
And straightway the archpriest, if he happen to be there, or the
priest, readeth the prayer of absolution with a loud voice.
The Lord Jesus Christ our God, who gave divine commandments
unto his holy disciples and apostles to bind and loose the sins of the
fallen, and from whom we have again received authority to do the
like, forgive thee, O spiritual child, whatever thou hast done in the life
that now is, voluntarily or involuntarily, now and ever, and to ages of
ages. Amen.
And so, taking up the remains, we go forth to the grave, followed
by all the people, and preceded by the priests, and singing, Holy
God.... O most holy Trinity.... Our Father.... and the rest.
And they lay the remains in the grave; and the archpriest, or the
priest, taking earth upon a shovel, casteth it crosswise over the
remains, saying,
The earth is the Lord’s, and the fulness thereof, the world and all
they that dwell therein.
And after this he poureth over the remains oil from the lamp, or
scattereth ashes out of the censer, and so they fill up the grave as
customarily, meantime singing the troparia, With the spirits of the
righteous.... and all the rest. Vide page 138.
And the dismissal.
Chapter XVII.
THE ORDINANCE THAT IS OBSERVED
CONCERNING THE CARRYING FORTH OF THEM
THAT FALL ASLEEP IN HOLY PASCHA, AND IN
ALL THE BRIGHT WEEK.

It behoveth to know that if any pass away on holy pascha, or on


any day whatever of the bright week until the sunday of Thomas,
somewhat less of the customary song for them that have fallen
asleep is sung, because of the majesty and honour of the joyful
festival of the resurrection; for it is a festival of joy and gladness, and
not of lamentation. And since all who die in hope of resurrection and
eternal life are through the resurrection of Christ, removed from the
griefs of this world to things that are joyful and glad, the church at the
time when Christ is risen proclaimeth this by the resurrection song
over them that have fallen asleep; and, by somewhat less song,
ectenias and prayer for them that have fallen asleep, we are assured
that he that dieth in penitence, if he have not yet made satisfaction
concerning his iniquities, these are remitted to him by the prayers of
the church, and that he is freed from their bond.
The priest then having come, with his clerks, to the house in which
the body of the dead lieth, and put on him the epitrachelion and the
phelonion, and censed the remains, beginneth as customarily,
Blessed be our God.... And the clerk singeth, Christ is risen.... in
tone v. And the priest saith the customary verses, that is to say, Let
God arise.... and all the rest.
And while these are being sung, the priest sprinkleth the body of
the dead with sanctified water, and his coffin without and within, and
straightway they lay him therein. And, the song being ended, the
deacon saith the customary ectenias for them that have fallen
asleep. And the priest in a low voice readeth the prayer, that is to
say, O God of Spirits.... Vide page 139. And after the exclamation
they read,
Having seen the resurrection of Christ....
And taking up the remains of him that hath fallen asleep, they go
forth to the church, the priests, deacons, and every clerk going
before, and the lay people following; and, as they go, the clerks and
singers sing the paschal canon, that is to say, It is the day of
resurrection....
This in order until they come even unto the church. And in the
church, having put down the remains, they conclude the canon that
hath been begun, while the priests cense according to the customary
rite. And at the fourth ode, the customary diaconals for them that
have fallen asleep, with the prayer.
And he exclaimeth,
For thou art the resurrection, and the life....
Then, Preventing the dawn....
And after this the ivth ode is sung in order.
And after the sixth ode, the customary diaconals for them that
have fallen asleep with the prayer.
And he exclaimeth, For thou art the resurrection and the life....
Then the condakion, Rest with the saints.
And the icos, Thyself alone immortal art.... Vide page 149.
And, instead of the trisagion,
As many as have been baptized into Christ....
The epistle in the Acts for the day being.[33] Alleluia in tone ii.
The first resurrection gospel.[34]
And after this, Having seen the resurrection of Christ, we adore....
And the other odes of the canon.
And after the conclusion of the canon is read or sung the
exapostilarion, Asleep in flesh.... twice.
After these we sing, Blessed art thou, O Lord: O teach me thy
statutes.
The angelic council was amaz’d....
Then the stichera of pascha, with their verses.
Glory. Both now.
It is the day of resurrection.... and Christ is risen.... thrice.
And these stichera having been sung, the customary kiss of him
that hath fallen asleep taketh place, saying,
Christ is risen.
And after the stichera the customary diaconals for them that have
fallen asleep with the prayer, which is read with a loud voice by the
archpriest, or the priest, nigh unto the remains.
And he exclaimeth,
For thou art the resurrection and the life....
And the customary dismissal is made.
Then the prayer of absolution.
The Lord Jesus Christ our God.... Vide page 163.
And we go forth to the grave, bearing the body of him that hath
fallen asleep to the burial. And the priests with all the clerks,
preceding the remains, sing,
Christ is risen....
And they bury them with thanksgiving and joy, doing and saying all
that is written at page 157 for the burial of a lay person.
And singing the troparion.
O earth that yawnest, take thou that that out of thee was made.
End of the order of the burial of them that fall asleep in the days of
the bright week.
Chapter XVIII.
THE MORTUARY ORDER OVER A DEPARTED
PRIEST.

When one of the secular priests departeth to the Lord, three


priests come and lift him from the bed, and lay him on the floor upon
a mat. And since it behoveth not that he be washed, being naked, by
the priests, they sponge him with pure oil. Then they clothe him in
his customary garments, and after that with all the priestly
vestments, and cover his face with the aër, and lay the holy gospel
upon him. Then the priests come vested in the priestly vestments.
And the president maketh, Blessed be our God....
And they that are standing by begin,
Holy God.... O most holy Trinity.... and Our Father.... For thine is
the kingdom....
And straightway they sing these troparia, tone iv.
With the spirits of the righteous.... Page 138.
The deacon saith,
Have mercy upon us, O God.... Vide page 139.
And straightway the priests take the remains, and carry them into
the porch of the temple, and lay the holy gospel over him, as
aforesaid, and candlesticks crosswise with tapers, and the singer
beginneth,
The undefiled in the way, alleluia.
In tone vi.
Then, Blessed are the undefiled.... Page 141.
After the first stasis, deacon, Again and again.... Page 142.

You might also like