32
HASSO - PLATTNER - INSTITUT at the university of Potsdam Florian Kirsch OpenCSG: A Library for Image-Based CSG Rendering

OpenCSG: A Library for Image-Based CSG Rendering · 2008. 2. 6. · Image-Based CSG Rendering. HASSO - PLATTNER - INSTITUT at the university of Potsdam Florian Kirsch, FREENIX 2005,

  • Upload
    others

  • View
    4

  • Download
    0

Embed Size (px)

Citation preview

Page 1: OpenCSG: A Library for Image-Based CSG Rendering · 2008. 2. 6. · Image-Based CSG Rendering. HASSO - PLATTNER - INSTITUT at the university of Potsdam Florian Kirsch, FREENIX 2005,

HASSO - PLATTNER - INSTITUTat the university of Potsdam

Florian Kirsch

OpenCSG: A Library for Image-Based CSG Rendering

Page 2: OpenCSG: A Library for Image-Based CSG Rendering · 2008. 2. 6. · Image-Based CSG Rendering. HASSO - PLATTNER - INSTITUT at the university of Potsdam Florian Kirsch, FREENIX 2005,

HASSO - PLATTNER - INSTITUTat the university of Potsdam

Florian Kirsch, FREENIX 2005, 15. April 2

Introduction

§ Modeling using CSG (Constructive Solid Geometry)

Page 3: OpenCSG: A Library for Image-Based CSG Rendering · 2008. 2. 6. · Image-Based CSG Rendering. HASSO - PLATTNER - INSTITUT at the university of Potsdam Florian Kirsch, FREENIX 2005,

HASSO - PLATTNER - INSTITUTat the university of Potsdam

Florian Kirsch, FREENIX 2005, 15. April 3

Introduction

§ CSG requires: Primitives• Leaf nodes of CSG tree• Must be closed

§ and: Boolean operations• Inner nodes of CSG tree• Union, Intersection, Subtraction

∩∪ –

Page 4: OpenCSG: A Library for Image-Based CSG Rendering · 2008. 2. 6. · Image-Based CSG Rendering. HASSO - PLATTNER - INSTITUT at the university of Potsdam Florian Kirsch, FREENIX 2005,

HASSO - PLATTNER - INSTITUTat the university of Potsdam

Florian Kirsch, FREENIX 2005, 15. April 4

Introduction

§ CSG is available in offline rendering systems• RenderMan• POV-Ray

Page 5: OpenCSG: A Library for Image-Based CSG Rendering · 2008. 2. 6. · Image-Based CSG Rendering. HASSO - PLATTNER - INSTITUT at the university of Potsdam Florian Kirsch, FREENIX 2005,

HASSO - PLATTNER - INSTITUTat the university of Potsdam

Florian Kirsch, FREENIX 2005, 15. April 5

Introduction

§ CSG cannot be directly rendered with graphics hardware

§ How to use CSG in real-time?

1. Object-based CSG• Calculate boundary of CSG shape mathematically,

render mesh• Too expensive for dynamically manipulated models

2. Image-based CSG rendering• Compose final image in frame buffer• Suitable for interactive manipulation• Advanced use of graphics hardware

Page 6: OpenCSG: A Library for Image-Based CSG Rendering · 2008. 2. 6. · Image-Based CSG Rendering. HASSO - PLATTNER - INSTITUT at the university of Potsdam Florian Kirsch, FREENIX 2005,

HASSO - PLATTNER - INSTITUTat the university of Potsdam

Florian Kirsch, FREENIX 2005, 15. April 6

Algorithms

§ Two basic algorithms for image-based CSG

§ Goldfeather algorithm

§ SCS algorithm

§ Both require normalization of CSG tree to union of CSG products

§ CSG product: (…((x1 ⊗ x2) ⊗ x3) … ⊗ xn)

(⊗ is intersection or subtraction)

Page 7: OpenCSG: A Library for Image-Based CSG Rendering · 2008. 2. 6. · Image-Based CSG Rendering. HASSO - PLATTNER - INSTITUT at the university of Potsdam Florian Kirsch, FREENIX 2005,

HASSO - PLATTNER - INSTITUTat the university of Potsdam

Florian Kirsch, FREENIX 2005, 15. April 7

Algorithms

§ Normalization of CSG tree to union of CSG products

∪ Normalization −

Partial Product

Page 8: OpenCSG: A Library for Image-Based CSG Rendering · 2008. 2. 6. · Image-Based CSG Rendering. HASSO - PLATTNER - INSTITUT at the university of Potsdam Florian Kirsch, FREENIX 2005,

HASSO - PLATTNER - INSTITUTat the university of Potsdam

Florian Kirsch, FREENIX 2005, 15. April 8

Algorithms

§ Goldfeather algorithm: all kinds of primitives

§ Handle each primitiveseparately

even

odd

even

odd

Page 9: OpenCSG: A Library for Image-Based CSG Rendering · 2008. 2. 6. · Image-Based CSG Rendering. HASSO - PLATTNER - INSTITUT at the university of Potsdam Florian Kirsch, FREENIX 2005,

HASSO - PLATTNER - INSTITUTat the university of Potsdam

Florian Kirsch, FREENIX 2005, 15. April 9

Algorithms

§ Goldfeather algorithm

§ Different handling ofsubtracted primitives

even

odd

even

odd

Page 10: OpenCSG: A Library for Image-Based CSG Rendering · 2008. 2. 6. · Image-Based CSG Rendering. HASSO - PLATTNER - INSTITUT at the university of Potsdam Florian Kirsch, FREENIX 2005,

HASSO - PLATTNER - INSTITUTat the university of Potsdam

Florian Kirsch, FREENIX 2005, 15. April 10

Algorithms

§ SCS algorithm: only convex primitives

Page 11: OpenCSG: A Library for Image-Based CSG Rendering · 2008. 2. 6. · Image-Based CSG Rendering. HASSO - PLATTNER - INSTITUT at the university of Potsdam Florian Kirsch, FREENIX 2005,

HASSO - PLATTNER - INSTITUTat the university of Potsdam

Florian Kirsch, FREENIX 2005, 15. April 11

Algorithms

§ Problems: Algorithms are complicated

§ Seldom used in real applications

§ Currently no abstraction layer available

→ OpenCSG

Page 12: OpenCSG: A Library for Image-Based CSG Rendering · 2008. 2. 6. · Image-Based CSG Rendering. HASSO - PLATTNER - INSTITUT at the university of Potsdam Florian Kirsch, FREENIX 2005,

HASSO - PLATTNER - INSTITUTat the university of Potsdam

Florian Kirsch, FREENIX 2005, 15. April 12

API: Overview

Design Goals

§ Minimal interface

§ Only for CSG rendering

§ Possibility to use user-defined primitives

§ No external dependencies except OpenGL

§ ...

Page 13: OpenCSG: A Library for Image-Based CSG Rendering · 2008. 2. 6. · Image-Based CSG Rendering. HASSO - PLATTNER - INSTITUT at the university of Potsdam Florian Kirsch, FREENIX 2005,

HASSO - PLATTNER - INSTITUTat the university of Potsdam

Florian Kirsch, FREENIX 2005, 15. April 13

API: Overviewnamespace OpenCSG {

enum Operation { Intersection, Subtraction };class Primitive {public:

Primitive(Operation, unsigned int convexity);virtual ~Primitive();void setOperation(Operation);Operation getOperation() const;void setConvexity(unsigned int);unsigned int getConvexity() const;void setBoundingBox(float minx, float miny, float minz,

float maxx, float maxy, float maxz);void getBoundingBox(float& minx, float& miny, float& minz,

float& maxx, float& maxy, float& maxz) const;virtual void render() = 0;

};enum Algorithm {

Automatic, Goldfeather, SCS };enum DepthComplexityAlgorithm {

NoDepthComplexitySampling, OcclusionQuery, DepthComplexitySampling };void render(const std::vector<Primitive*>& primitives,

Algorithm = Automatic, DepthComplexityAlgorithm = NoDepthComplexitySampling);

}

Page 14: OpenCSG: A Library for Image-Based CSG Rendering · 2008. 2. 6. · Image-Based CSG Rendering. HASSO - PLATTNER - INSTITUT at the university of Potsdam Florian Kirsch, FREENIX 2005,

HASSO - PLATTNER - INSTITUTat the university of Potsdam

Florian Kirsch, FREENIX 2005, 15. April 14

API: Overview

Basic facts

§ C++ interface

§ Namespace OpenCSG

§ Abstract primitive class

§ Render function for CSG rendering

Page 15: OpenCSG: A Library for Image-Based CSG Rendering · 2008. 2. 6. · Image-Based CSG Rendering. HASSO - PLATTNER - INSTITUT at the university of Potsdam Florian Kirsch, FREENIX 2005,

HASSO - PLATTNER - INSTITUTat the university of Potsdam

Florian Kirsch, FREENIX 2005, 15. April 15

API: Abstract primitive class

enum Operation { Intersection, Subtraction };class Primitive {public:

Primitive(Operation, unsigned int convexity);virtual ~Primitive();void setOperation(Operation);Operation getOperation() const;void setConvexity(unsigned int);unsigned int getConvexity() const;void setBoundingBox(float minx, float miny, float minz,

float maxx, float maxy, float maxz);void getBoundingBox(float& minx, float& miny, float& minz,

float& maxx, float& maxy, float& maxz) const;virtual void render() = 0;

};

§ Operation: Whether primitive in CSG product is intersected or subtracted

Page 16: OpenCSG: A Library for Image-Based CSG Rendering · 2008. 2. 6. · Image-Based CSG Rendering. HASSO - PLATTNER - INSTITUT at the university of Potsdam Florian Kirsch, FREENIX 2005,

HASSO - PLATTNER - INSTITUTat the university of Potsdam

Florian Kirsch, FREENIX 2005, 15. April 16

API: Abstract primitive class

enum Operation { Intersection, Subtraction };class Primitive {public:

Primitive(Operation, unsigned int convexity);virtual ~Primitive();void setOperation(Operation);Operation getOperation() const;void setConvexity(unsigned int);unsigned int getConvexity() const;void setBoundingBox(float minx, float miny, float minz,

float maxx, float maxy, float maxz);void getBoundingBox(float& minx, float& miny, float& minz,

float& maxx, float& maxy, float& maxz) const;virtual void render() = 0;

};

§ Convexity

Page 17: OpenCSG: A Library for Image-Based CSG Rendering · 2008. 2. 6. · Image-Based CSG Rendering. HASSO - PLATTNER - INSTITUT at the university of Potsdam Florian Kirsch, FREENIX 2005,

HASSO - PLATTNER - INSTITUTat the university of Potsdam

Florian Kirsch, FREENIX 2005, 15. April 17

API: Abstract primitive class

enum Operation { Intersection, Subtraction };class Primitive {public:

Primitive(Operation, unsigned int convexity);virtual ~Primitive();void setOperation(Operation);Operation getOperation() const;void setConvexity(unsigned int);unsigned int getConvexity() const;void setBoundingBox(float minx, float miny, float minz,

float maxx, float maxy, float maxz);void getBoundingBox(float& minx, float& miny, float& minz,

float& maxx, float& maxy, float& maxz) const;virtual void render() = 0;

};

§ Bounding Box: Maximum extent of primitive in screen space

§ Used for rendering optimizations

Page 18: OpenCSG: A Library for Image-Based CSG Rendering · 2008. 2. 6. · Image-Based CSG Rendering. HASSO - PLATTNER - INSTITUT at the university of Potsdam Florian Kirsch, FREENIX 2005,

HASSO - PLATTNER - INSTITUTat the university of Potsdam

Florian Kirsch, FREENIX 2005, 15. April 18

API: Abstract primitive class

enum Operation { Intersection, Subtraction };class Primitive {public:

Primitive(Operation, unsigned int convexity);virtual ~Primitive();void setOperation(Operation);Operation getOperation() const;void setConvexity(unsigned int);unsigned int getConvexity() const;void setBoundingBox(float minx, float miny, float minz,

float maxx, float maxy, float maxz);void getBoundingBox(float& minx, float& miny, float& minz,

float& maxx, float& maxy, float& maxz) const;virtual void render() = 0;

};

§ render method: Renders a primitive

§ Implemented by subclasses

§ Don‘t set colors!

Page 19: OpenCSG: A Library for Image-Based CSG Rendering · 2008. 2. 6. · Image-Based CSG Rendering. HASSO - PLATTNER - INSTITUT at the university of Potsdam Florian Kirsch, FREENIX 2005,

HASSO - PLATTNER - INSTITUTat the university of Potsdam

Florian Kirsch, FREENIX 2005, 15. April 19

API: Render function for CSG rendering

enum Algorithm { Automatic, Goldfeather, SCS

};enum DepthComplexityAlgorithm {

NoDepthComplexitySampling, OcclusionQuery, DepthComplexitySampling };void render(const std::vector<Primitive*>& primitives,

Algorithm = Automatic, DepthComplexityAlgorithm = NoDepthComplexitySampling);

§ Render function for CSG rendering

§ Initializes Z-Buffer with values of CSG product

Page 20: OpenCSG: A Library for Image-Based CSG Rendering · 2008. 2. 6. · Image-Based CSG Rendering. HASSO - PLATTNER - INSTITUT at the university of Potsdam Florian Kirsch, FREENIX 2005,

HASSO - PLATTNER - INSTITUTat the university of Potsdam

Florian Kirsch, FREENIX 2005, 15. April 20

API: Render function for CSG rendering

enum Algorithm { Automatic, Goldfeather, SCS

};enum DepthComplexityAlgorithm {

NoDepthComplexitySampling, OcclusionQuery, DepthComplexitySampling };void render(const std::vector<Primitive*>& primitives,

Algorithm = Automatic, DepthComplexityAlgorithm = NoDepthComplexitySampling);

§ Initializes Z-Buffer with values of CSG product

§ Arguments:• List of primitives

Page 21: OpenCSG: A Library for Image-Based CSG Rendering · 2008. 2. 6. · Image-Based CSG Rendering. HASSO - PLATTNER - INSTITUT at the university of Potsdam Florian Kirsch, FREENIX 2005,

HASSO - PLATTNER - INSTITUTat the university of Potsdam

Florian Kirsch, FREENIX 2005, 15. April 21

API: Render function for CSG rendering

enum Algorithm { Automatic, Goldfeather, SCS

};enum DepthComplexityAlgorithm {

NoDepthComplexitySampling, OcclusionQuery, DepthComplexitySampling };void render(const std::vector<Primitive*>& primitives,

Algorithm = Automatic, DepthComplexityAlgorithm = NoDepthComplexitySampling);

§ Initializes Z-Buffer with values of CSG product

§ Arguments:• List of primitives• Specifier to choose CSG algorithm

Page 22: OpenCSG: A Library for Image-Based CSG Rendering · 2008. 2. 6. · Image-Based CSG Rendering. HASSO - PLATTNER - INSTITUT at the university of Potsdam Florian Kirsch, FREENIX 2005,

HASSO - PLATTNER - INSTITUTat the university of Potsdam

Florian Kirsch, FREENIX 2005, 15. April 22

API: Render function for CSG rendering

enum Algorithm { Automatic, Goldfeather, SCS

};enum DepthComplexityAlgorithm {

NoDepthComplexitySampling, OcclusionQuery, DepthComplexitySampling };void render(const std::vector<Primitive*>& primitives,

Algorithm = Automatic, DepthComplexityAlgorithm = NoDepthComplexitySampling);

§ Initializes Z-Buffer with values of CSG product

§ Arguments:• List of primitives• Specifier to choose CSG algorithm • Optimization strategy

Page 23: OpenCSG: A Library for Image-Based CSG Rendering · 2008. 2. 6. · Image-Based CSG Rendering. HASSO - PLATTNER - INSTITUT at the university of Potsdam Florian Kirsch, FREENIX 2005,

HASSO - PLATTNER - INSTITUTat the university of Potsdam

Florian Kirsch, FREENIX 2005, 15. April 23

Example

GLuint id1 = glGenLists(1);glNewList(id1, GL_COMPILE); glutSolidCube(1.8);glEndList();GLuint id2 = glGenLists(1);glNewList(id2, GL_COMPILE); glutSolidSphere(1.2, 20, 20);glEndList();

§ Basic shapes generated by helper library GLUT

§ Stored as OpenGL display lists

§ Box and Sphere

Page 24: OpenCSG: A Library for Image-Based CSG Rendering · 2008. 2. 6. · Image-Based CSG Rendering. HASSO - PLATTNER - INSTITUT at the university of Potsdam Florian Kirsch, FREENIX 2005,

HASSO - PLATTNER - INSTITUTat the university of Potsdam

Florian Kirsch, FREENIX 2005, 15. April 24

Example

class DisplayListPrimimitive : public OpenCSG::Primitive {...

};namespace OpenCSG;DisplayListPrimitive* box=new DisplayListPrimitive(id1, Intersection, 1);DisplayListPrimitive* sphere=new DisplayListPrimitive(id2, Subtraction, 1);std::vector<Primitive*> primitives;primitives.push_back(box);primitives.push_back(sphere);

§ Class derived from Primitive class

§ Invokes display list in render method

§ Create objects for Box and Sphere

§ Append to CSG product

Page 25: OpenCSG: A Library for Image-Based CSG Rendering · 2008. 2. 6. · Image-Based CSG Rendering. HASSO - PLATTNER - INSTITUT at the university of Potsdam Florian Kirsch, FREENIX 2005,

HASSO - PLATTNER - INSTITUTat the university of Potsdam

Florian Kirsch, FREENIX 2005, 15. April 25

Example

OpenCSG::render(primitives,Goldfeather, NoDepthComplexitySampling);

§ Call render function

§ This initializes Z-Buffer with values of CSG product

glDepthFunc(GL_EQUAL);// setup lighting and shadingbox->render();sphere->render();glDepthFunc(GL_LESS);

§ Must shade the primitives now

§ Render with z-equal depth test

Page 26: OpenCSG: A Library for Image-Based CSG Rendering · 2008. 2. 6. · Image-Based CSG Rendering. HASSO - PLATTNER - INSTITUT at the university of Potsdam Florian Kirsch, FREENIX 2005,

HASSO - PLATTNER - INSTITUTat the university of Potsdam

Florian Kirsch, FREENIX 2005, 15. April 26

Implementation

§ Implementation as described in

Rendering Techniques for Hardware-Accelerated Image-Based CSG

(WSCG 2004)

Page 27: OpenCSG: A Library for Image-Based CSG Rendering · 2008. 2. 6. · Image-Based CSG Rendering. HASSO - PLATTNER - INSTITUT at the university of Potsdam Florian Kirsch, FREENIX 2005,

HASSO - PLATTNER - INSTITUTat the university of Potsdam

Florian Kirsch, FREENIX 2005, 15. April 27

Applications

§ Modeling applications

§ Screenshot: RenderMan modeler Ayam

Page 28: OpenCSG: A Library for Image-Based CSG Rendering · 2008. 2. 6. · Image-Based CSG Rendering. HASSO - PLATTNER - INSTITUT at the university of Potsdam Florian Kirsch, FREENIX 2005,

HASSO - PLATTNER - INSTITUTat the university of Potsdam

Florian Kirsch, FREENIX 2005, 15. April 28

Applications

§ Beyond traditional uses of CSG

Gaming

Page 29: OpenCSG: A Library for Image-Based CSG Rendering · 2008. 2. 6. · Image-Based CSG Rendering. HASSO - PLATTNER - INSTITUT at the university of Potsdam Florian Kirsch, FREENIX 2005,

HASSO - PLATTNER - INSTITUTat the university of Potsdam

Florian Kirsch, FREENIX 2005, 15. April 29

Applications

§ Beyond traditional uses of CSG

Interactive road design

Page 30: OpenCSG: A Library for Image-Based CSG Rendering · 2008. 2. 6. · Image-Based CSG Rendering. HASSO - PLATTNER - INSTITUT at the university of Potsdam Florian Kirsch, FREENIX 2005,

HASSO - PLATTNER - INSTITUTat the university of Potsdam

Questions?

www.opencsg.org

Page 31: OpenCSG: A Library for Image-Based CSG Rendering · 2008. 2. 6. · Image-Based CSG Rendering. HASSO - PLATTNER - INSTITUT at the university of Potsdam Florian Kirsch, FREENIX 2005,

HASSO - PLATTNER - INSTITUTat the university of Potsdam

Florian Kirsch, FREENIX 2005, 15. April 31

OpenCSG: Internals

Size of invisible frame buffer

§ Constant, even if used from different windows

§ Important for multi-window applications

§ And multipass algorithms (e.g., shadow mapping)

Page 32: OpenCSG: A Library for Image-Based CSG Rendering · 2008. 2. 6. · Image-Based CSG Rendering. HASSO - PLATTNER - INSTITUT at the university of Potsdam Florian Kirsch, FREENIX 2005,

HASSO - PLATTNER - INSTITUTat the university of Potsdam

Florian Kirsch, FREENIX 2005, 15. April 32

OpenCSG: Internals

Further optimizations

§ Based on bounding-boxes

§ Batching of primitives

§ Scissoring