The OpenRT Application Programming Interface - Towards a Common API for Interactive Ray Tracing –...
-
Upload
ariana-malone -
Category
Documents
-
view
218 -
download
0
Transcript of The OpenRT Application Programming Interface - Towards a Common API for Interactive Ray Tracing –...
TheTheOpenRTOpenRT
Application Programming InterfaceApplication Programming Interface - - Towards a Common API for Interactive Ray Tracing –Towards a Common API for Interactive Ray Tracing –
OpenSG 2003OpenSG 2003Darmstadt, GermanyDarmstadt, Germany
Andreas DietrichAndreas Dietrich Ingo WaldIngo Wald Carsten Benthin Philipp Slusallek Carsten Benthin Philipp Slusallek
Computer Graphics LabComputer Graphics Lab
Saarland UniversitySaarland University
http://www.openrt.dehttp://www.openrt.de
OpenSG 2003OpenSG 2003 The OpenRT Application Programming InterfaceThe OpenRT Application Programming Interface 22
CO
MPU
TE
R G
RA
PH
IK – U
NIV
ER
SIT
ÄT
DE
S S
AA
RL
AN
DE
S
IntroductionIntroduction
• Interactive rendering performance available even on Interactive rendering performance available even on standard PCsstandard PCs– Interactive systems typically limited to simple illumination modelsInteractive systems typically limited to simple illumination models
– High-quality image generation still dominated by offline rendering High-quality image generation still dominated by offline rendering systems systems
• High-quality interactive rendering now possibleHigh-quality interactive rendering now possible– Ray Tracing will play a larger role in future applicationsRay Tracing will play a larger role in future applications
– Current application programming interfaces not well suitedCurrent application programming interfaces not well suited
Need for an API, which combines best of both worldsNeed for an API, which combines best of both worlds
OpenSG 2003OpenSG 2003 The OpenRT Application Programming InterfaceThe OpenRT Application Programming Interface 33
CO
MPU
TE
R G
RA
PH
IK – U
NIV
ER
SIT
ÄT
DE
S S
AA
RL
AN
DE
S
RasterizationRasterization
• Most of today’Most of today’ss interactive rendering systems build on interactive rendering systems build on rasterization techniques rasterization techniques – Projection of polygons onto the image planeProjection of polygons onto the image plane– Each polygon is processed locally without relation to any otherEach polygon is processed locally without relation to any other
Rasterization pipelineRasterization pipeline Efficient hardware implementationsEfficient hardware implementations
• Absence of global information has certain drawbacksAbsence of global information has certain drawbacks– Linear in the number of trianglesLinear in the number of triangles– Limited to local illuminationLimited to local illumination
High-quality images require multiple rendering passesHigh-quality images require multiple rendering passes (e.g. to produce shadows) (e.g. to produce shadows)
Extensive manual tuningExtensive manual tuning
– Physically-accurate lighting effects are beyond the capabilities of Physically-accurate lighting effects are beyond the capabilities of rendering “tricks” even with programmable GPUsrendering “tricks” even with programmable GPUs
OpenSG 2003OpenSG 2003 The OpenRT Application Programming InterfaceThe OpenRT Application Programming Interface 44
CO
MPU
TE
R G
RA
PH
IK – U
NIV
ER
SIT
ÄT
DE
S S
AA
RL
AN
DE
S
Ray TracingRay Tracing
• Most architectures incorporating sophisticated illumination perform Most architectures incorporating sophisticated illumination perform ray tracingray tracing– Close modeling of physical light propagationClose modeling of physical light propagation– Shooting of imaginary rays into the sceneShooting of imaginary rays into the scene
• Advantages over rasterizationAdvantages over rasterization– Physical correctnessPhysical correctness
- Shooting of arbitrary raysShooting of arbitrary rays- Accurate computation of global and advanced lighting effectsAccurate computation of global and advanced lighting effects
(e.g. shadows, reflections, refractions on arbitrary surfaces)(e.g. shadows, reflections, refractions on arbitrary surfaces)
– Plug and play shadingPlug and play shading- Combination of different shading effects in correct orderCombination of different shading effects in correct order- Independent building of individual Independent building of individual shadersshaders
– Complex scenesComplex scenes- Logarithmic in the number of trianglesLogarithmic in the number of triangles- Handling of scenes with billions of trianglesHandling of scenes with billions of triangles- Inherent Inherent occlusion-cullingocclusion-culling, , demand drivendemand driven and and output-sensitiveoutput-sensitive
OpenSG 2003OpenSG 2003 The OpenRT Application Programming InterfaceThe OpenRT Application Programming Interface 55
CO
MPU
TE
R G
RA
PH
IK – U
NIV
ER
SIT
ÄT
DE
S S
AA
RL
AN
DE
S
An InteractiveAn InteractiveRay Tracing APIRay Tracing API
• Available rendering APIsAvailable rendering APIs– Pixar’s RenderManPixar’s RenderMan
- Oriented towards high-quality rendering, especially ray tracingOriented towards high-quality rendering, especially ray tracing
- Missing support for interactive applicationsMissing support for interactive applications
– OpenGL Performer, OpenInventor, OpenSGOpenGL Performer, OpenInventor, OpenSG- No single candidateNo single candidate
- Mostly used for a specific application domainMostly used for a specific application domain
– OpenGLOpenGL- Flexible and popularFlexible and popular
- Too tightly coupled to the rasterization pipelineToo tightly coupled to the rasterization pipeline
APIs for interactive ray tracing simply not yet availableAPIs for interactive ray tracing simply not yet available
Introduction of a new API called Introduction of a new API called OpenRTOpenRT
OpenSG 2003OpenSG 2003 The OpenRT Application Programming InterfaceThe OpenRT Application Programming Interface 66
CO
MPU
TE
R G
RA
PH
IK – U
NIV
ER
SIT
ÄT
DE
S S
AA
RL
AN
DE
S
OpenRTOpenRT
• Low-level graphics interface in the spirit of OpenGLLow-level graphics interface in the spirit of OpenGL– Syntactically similar to OpenGLSyntactically similar to OpenGL
- Easy-to-useEasy-to-use
- Aids the porting of applicationsAids the porting of applications
– Allows to layer scene graph APIs on topAllows to layer scene graph APIs on top
– But: Neither simple extension nor subset of OpenGLBut: Neither simple extension nor subset of OpenGL- Fundamental differences between rasterization and ray tracingFundamental differences between rasterization and ray tracing
• Supports high-quality image generationSupports high-quality image generation– Physically-correct lighting simulationsPhysically-correct lighting simulations
– Arbitrary programmable shadingArbitrary programmable shading
– Highly complex scenes possibleHighly complex scenes possible
• Development not finalized but already used in practiceDevelopment not finalized but already used in practice– Saarland University’s Real-Time Ray Tracing system [Wald 01]Saarland University’s Real-Time Ray Tracing system [Wald 01]
– SaarCOR hardware ray tracing architecture [Schmittler 02]SaarCOR hardware ray tracing architecture [Schmittler 02]
OpenSG 2003OpenSG 2003 The OpenRT Application Programming InterfaceThe OpenRT Application Programming Interface 77
CO
MPU
TE
R G
RA
PH
IK – U
NIV
ER
SIT
ÄT
DE
S S
AA
RL
AN
DE
S
OpenRT API OpenRT API StructureStructure
• OpenRT API actually comprises three sub-interfacesOpenRT API actually comprises three sub-interfaces– OpenRT application interfaceOpenRT application interface
- Specify geometry objects, transformations, textures, …Specify geometry objects, transformations, textures, …
- Similar to OpenGLSimilar to OpenGL
– OpenSRT programmable shader interfaceOpenSRT programmable shader interface- Specify and load shader programsSpecify and load shader programs
- Communication with shaders via shader parametersCommunication with shaders via shader parameters
– OpenRTS shading languageOpenRTS shading language- Shader plug-in programming interfaceShader plug-in programming interface
- Not used by front-end applicationsNot used by front-end applications
- Could be replaced by other shading languages (e.g. RenderMan)Could be replaced by other shading languages (e.g. RenderMan)
For many calls simply replace OpenGL´s “gl” with “rt”For many calls simply replace OpenGL´s “gl” with “rt”
OpenSG 2003OpenSG 2003 The OpenRT Application Programming InterfaceThe OpenRT Application Programming Interface 88
CO
MPU
TE
R G
RA
PH
IK – U
NIV
ER
SIT
ÄT
DE
S S
AA
RL
AN
DE
S
OpenRT and OpenRT and OpenGLOpenGL
OpenRT and OpenGL differ in four main areasOpenRT and OpenGL differ in four main areas
1. Rendering semantics 1. Rendering semantics – Unlike OpenGL’s drawing approach OpenRT uses Unlike OpenGL’s drawing approach OpenRT uses objectsobjects
– Shader objects are bound to geometry objectsShader objects are bound to geometry objects
2. Objects and instantiation2. Objects and instantiation– Geometric objects serve as simple containersGeometric objects serve as simple containers
– Efficient reuse of objectsEfficient reuse of objects
3. Multi-pass rendering vs. programmable shading3. Multi-pass rendering vs. programmable shading– Possible but not necessary due to programmable shader objectsPossible but not necessary due to programmable shader objects
4. Fragment and 2D operations4. Fragment and 2D operations– OpenRT serves as a pure 3D graphics libraryOpenRT serves as a pure 3D graphics library
– Mix of OpenRT and OpenGL under evaluationMix of OpenRT and OpenGL under evaluation
OpenSG 2003OpenSG 2003 The OpenRT Application Programming InterfaceThe OpenRT Application Programming Interface 99
CO
MPU
TE
R G
RA
PH
IK – U
NIV
ER
SIT
ÄT
DE
S S
AA
RL
AN
DE
S
Application Application ExampleExample
FrameworkFramework#include <rtut/rtut.h>#include <rtut/rtut.h>#include <openrt/rt.h>#include <openrt/rt.h>
RTint objId;RTint objId;
void Display()void Display(){ rtutSwapBuffers(); }{ rtutSwapBuffers(); }
void Idle() {void Idle() { static int rot = 0;static int rot = 0; rot++;rot++; rtDeleteAllInstances();rtDeleteAllInstances(); for (int i=0; i<8; i++) {for (int i=0; i<8; i++) { int dx = (i&1)?-1:1;int dx = (i&1)?-1:1; int dy = (i&2)?-1:1;int dy = (i&2)?-1:1; int dz = (i&4)?-1:1;int dz = (i&4)?-1:1;
// position individual objects// position individual objects rtTranslatef(dx,dy,dz);rtTranslatef(dx,dy,dz); rtRotatef(4*rot*dx,dz,dy,dx);rtRotatef(4*rot*dx,dz,dy,dx); rtScalef(.5,.5,.5);rtScalef(.5,.5,.5); rtInstantiateObject(objId);rtInstantiateObject(objId); } } rtutPostRedisplay();rtutPostRedisplay();}}int main(int argc, char *argv[]) {int main(int argc, char *argv[]) { rtutInit(&argc, argv);rtutInit(&argc, argv); rtutInitWindowSize(640, 480);rtutInitWindowSize(640, 480); rtutCreateWindow("Eight Cubes");rtutCreateWindow("Eight Cubes"); rtutIdleFunc(Idle);rtutIdleFunc(Idle); rtutDisplayFunc(Display);rtutDisplayFunc(Display);
objId = createColorCubeObject();objId = createColorCubeObject(); rtPerspective(65, 1, 1, 100000);rtPerspective(65, 1, 1, 100000); rtLookAt(2,4,3, 0,0,0, 0,0,1);rtLookAt(2,4,3, 0,0,0, 0,0,1);
rtutMainLoop();rtutMainLoop(); return 0;return 0;}}
rtutInit(&argc, argv);rtutInit(&argc, argv);
rtutInitWindowSize(640, 480);rtutInitWindowSize(640, 480);
rtutCreateWindow("Eight Cubes");rtutCreateWindow("Eight Cubes");
rtutIdleFunc(Idle);rtutIdleFunc(Idle);
rtutDisplayFunc(Display);rtutDisplayFunc(Display);
… …
rtutMainLoop();rtutMainLoop();
Applications can make use of theApplications can make use of the
OpenRT Utility Toolkit, RTUTOpenRT Utility Toolkit, RTUT
Handling of windows, events, devices, …Handling of windows, events, devices, …
Virtually operated like OpenGL’s GLUTVirtually operated like OpenGL’s GLUT
OpenSG 2003OpenSG 2003 The OpenRT Application Programming InterfaceThe OpenRT Application Programming Interface 1010
CO
MPU
TE
R G
RA
PH
IK – U
NIV
ER
SIT
ÄT
DE
S S
AA
RL
AN
DE
S
Application Application ExampleExampleInstantiationInstantiation#include <rtut/rtut.h>#include <rtut/rtut.h>
#include <openrt/rt.h>#include <openrt/rt.h>
RTint objId;RTint objId;
void Display()void Display(){ rtutSwapBuffers(); }{ rtutSwapBuffers(); }
void Idle() {void Idle() { static int rot = 0;static int rot = 0; rot++;rot++; rtDeleteAllInstances();rtDeleteAllInstances(); for (int i=0; i<8; i++) {for (int i=0; i<8; i++) { int dx = (i&1)?-1:1;int dx = (i&1)?-1:1; int dy = (i&2)?-1:1;int dy = (i&2)?-1:1; int dz = (i&4)?-1:1;int dz = (i&4)?-1:1;
// position individual objects// position individual objects rtTranslatef(dx,dy,dz);rtTranslatef(dx,dy,dz); rtRotatef(4*rot*dx,dz,dy,dx);rtRotatef(4*rot*dx,dz,dy,dx); rtScalef(.5,.5,.5);rtScalef(.5,.5,.5); rtInstantiateObject(objId);rtInstantiateObject(objId); } } rtutPostRedisplay();rtutPostRedisplay();}}int main(int argc, char *argv[]) {int main(int argc, char *argv[]) { rtutInit(&argc, argv);rtutInit(&argc, argv); rtutInitWindowSize(640, 480);rtutInitWindowSize(640, 480); rtutCreateWindow("Eight Cubes");rtutCreateWindow("Eight Cubes"); rtutIdleFunc(Idle);rtutIdleFunc(Idle); rtutDisplayFunc(Display);rtutDisplayFunc(Display);
objId = createColorCubeObject();objId = createColorCubeObject(); rtPerspective(65, 1, 1, 100000);rtPerspective(65, 1, 1, 100000); rtLookAt(2,4,3, 0,0,0, 0,0,1);rtLookAt(2,4,3, 0,0,0, 0,0,1);
rtutMainLoop();rtutMainLoop(); return 0;return 0;}}
rtDeleteAllInstances();rtDeleteAllInstances();
for (int i=0; i<8; i++) {for (int i=0; i<8; i++) {
int dx = (i&1)?-1:1;int dx = (i&1)?-1:1;
int dy = (i&2)?-1:1;int dy = (i&2)?-1:1;
int dz = (i&4)?-1:1;int dz = (i&4)?-1:1;
// position individual objects// position individual objects
rtTranslatef(dx,dy,dz);rtTranslatef(dx,dy,dz);
rtRotatef(4*rot*dx,dz,dy,dx);rtRotatef(4*rot*dx,dz,dy,dx);
rtScalef(.5,.5,.5);rtScalef(.5,.5,.5);
rtInstantiateObject(objId);rtInstantiateObject(objId);
}}
Objects have to be instantiated Objects have to be instantiated
rtInstantiatedObject()rtInstantiatedObject()
Instance = geometry + transformationInstance = geometry + transformation
rtTranslatef(), rtRotatef(), …rtTranslatef(), rtRotatef(), …
Remove current instances usingRemove current instances using
rtDeleteAllInstances()rtDeleteAllInstances()
OpenSG 2003OpenSG 2003 The OpenRT Application Programming InterfaceThe OpenRT Application Programming Interface 1111
CO
MPU
TE
R G
RA
PH
IK – U
NIV
ER
SIT
ÄT
DE
S S
AA
RL
AN
DE
S
Application Application ExampleExample
Geometry ObjectsGeometry Objects#include <openrt/rt.h>#include <openrt/rt.h>#define VERTEX_COLOR_SHADER_ID 0#define VERTEX_COLOR_SHADER_ID 0#define VERTEX_COLOR_SHADERFILE_ID 1#define VERTEX_COLOR_SHADERFILE_ID 1
RTint createColorCubeObject()RTint createColorCubeObject() {{ srtShaderFile(VERTEX_COLOR_SHADERFILE_ID, srtShaderFile(VERTEX_COLOR_SHADERFILE_ID, "VertexColor","VertexColor", "libVertexColor.so"); "libVertexColor.so"); srtCreateShader(VERTEX_COLOR_SHADER_ID);srtCreateShader(VERTEX_COLOR_SHADER_ID);
RTint objId = rtGenObjects(1);RTint objId = rtGenObjects(1); rtNewObject(objId, RT_COMPILE);rtNewObject(objId, RT_COMPILE);
rtMatrixMode(RT_MODELVIEW);rtMatrixMode(RT_MODELVIEW); rtPushMatrix();rtPushMatrix(); rtTranslatef(-1, -1, -1);rtTranslatef(-1, -1, -1); rtScalef(2, 2, 2);rtScalef(2, 2, 2);
// first cube side// first cube side rtBegin(RT_POLYGON);rtBegin(RT_POLYGON); rtColor3f(0, 0, 0); rtColor3f(0, 0, 0); rtVertex3f(0, 0, 0);rtVertex3f(0, 0, 0); rtColor3f(0, 1, 0); rtColor3f(0, 1, 0); rtVertex3f(0, 1, 0);rtVertex3f(0, 1, 0); rtColor3f(1, 1, 0);rtColor3f(1, 1, 0); rtVertex3f(1, 1, 0);rtVertex3f(1, 1, 0); rtColor3f(1, 0, 0);rtColor3f(1, 0, 0); rtVertex3f(1, 0, 0);rtVertex3f(1, 0, 0); rtEnd();rtEnd();
// other cube sides// other cube sides ...... rtPopMatrix();rtPopMatrix();
rtEndObject()rtEndObject();; return objId;return objId;}}
RTint objId = rtGenObjects(1);RTint objId = rtGenObjects(1);
rtNewObject(objId, RT_COMPILE);rtNewObject(objId, RT_COMPILE);
… …
rtEndObject()rtEndObject();;
Geometry objects are allocated usingGeometry objects are allocated using
rtGenObjects()rtGenObjects()
New object encapsulated betweenNew object encapsulated between
rtNewObject()/rtEndObject()rtNewObject()/rtEndObject()
Just like OpenGL’sJust like OpenGL’s
glGenLists()glGenLists()
glNewList()/glEndList()glNewList()/glEndList()
OpenSG 2003OpenSG 2003 The OpenRT Application Programming InterfaceThe OpenRT Application Programming Interface 1212
CO
MPU
TE
R G
RA
PH
IK – U
NIV
ER
SIT
ÄT
DE
S S
AA
RL
AN
DE
S
Application Application ExampleExample
PrimitivesPrimitives#include <openrt/rt.h>#include <openrt/rt.h>#define VERTEX_COLOR_SHADER_ID 0#define VERTEX_COLOR_SHADER_ID 0#define VERTEX_COLOR_SHADERFILE_ID 1#define VERTEX_COLOR_SHADERFILE_ID 1
RTint createColorCubeObject()RTint createColorCubeObject() {{ srtShaderFile(VERTEX_COLOR_SHADERFILE_ID, srtShaderFile(VERTEX_COLOR_SHADERFILE_ID, "VertexColor","VertexColor", "libVertexColor.so"); "libVertexColor.so"); srtCreateShader(VERTEX_COLOR_SHADER_ID);srtCreateShader(VERTEX_COLOR_SHADER_ID);
RTint objId = rtGenObjects(1);RTint objId = rtGenObjects(1); rtNewObject(objId, RT_COMPILE);rtNewObject(objId, RT_COMPILE);
rtMatrixMode(RT_MODELVIEW);rtMatrixMode(RT_MODELVIEW); rtPushMatrix();rtPushMatrix(); rtTranslatef(-1, -1, -1);rtTranslatef(-1, -1, -1); rtScalef(2, 2, 2);rtScalef(2, 2, 2);
// first cube side// first cube side rtBegin(RT_POLYGON);rtBegin(RT_POLYGON); rtColor3f(0, 0, 0); rtColor3f(0, 0, 0); rtVertex3f(0, 0, 0);rtVertex3f(0, 0, 0); rtColor3f(0, 1, 0); rtColor3f(0, 1, 0); rtVertex3f(0, 1, 0);rtVertex3f(0, 1, 0); rtColor3f(1, 1, 0);rtColor3f(1, 1, 0); rtVertex3f(1, 1, 0);rtVertex3f(1, 1, 0); rtColor3f(1, 0, 0);rtColor3f(1, 0, 0); rtVertex3f(1, 0, 0);rtVertex3f(1, 0, 0); rtEnd();rtEnd();
// other cube sides// other cube sides ...... rtPopMatrix();rtPopMatrix();
rtEndObject()rtEndObject();; return objId;return objId;}}
rtBegin(RT_POLYGON);rtBegin(RT_POLYGON);
rtColor3f(0, 0, 0); rtColor3f(0, 0, 0);
rtVertex3f(0, 0, 0);rtVertex3f(0, 0, 0);
rtColor3f(0, 1, 0); rtColor3f(0, 1, 0);
rtVertex3f(0, 1, 0);rtVertex3f(0, 1, 0);
rtColor3f(1, 1, 0);rtColor3f(1, 1, 0);
rtVertex3f(1, 1, 0);rtVertex3f(1, 1, 0);
rtColor3f(1, 0, 0);rtColor3f(1, 0, 0);
rtVertex3f(1, 0, 0);rtVertex3f(1, 0, 0);
rtEnd();rtEnd();
Primitives are defined usingPrimitives are defined using
rtBegin( primType )/rtEnd()rtBegin( primType )/rtEnd()
With standard typesWith standard types
RT_TRIANGLE, RT_POLYGON, …RT_TRIANGLE, RT_POLYGON, …
Vertex data supplied byVertex data supplied by
rtVertex3f(), rtColor3f(), …rtVertex3f(), rtColor3f(), …
OpenRT VideoOpenRT Video
OpenSG 2003OpenSG 2003 The OpenRT Application Programming InterfaceThe OpenRT Application Programming Interface 1414
CO
MPU
TE
R G
RA
PH
IK – U
NIV
ER
SIT
ÄT
DE
S S
AA
RL
AN
DE
S
SummarySummary
• Ray tracing is much more powerful then rasterizationRay tracing is much more powerful then rasterization– More accurate, fully automatic, more efficientMore accurate, fully automatic, more efficient
• Interactive ray tracing now possibleInteractive ray tracing now possible– Need for an API that combines interactivity and high-quality Need for an API that combines interactivity and high-quality
image generationimage generation
• OpenRT can serve as such an APIOpenRT can serve as such an API– Low-level graphics interfaceLow-level graphics interface
– As easy to use as OpenGLAs easy to use as OpenGL
– Supports all the advantages of interactive ray tracingSupports all the advantages of interactive ray tracing
– Successfully applied in practiceSuccessfully applied in practice
Questions ?Questions ?
For more information seeFor more information seehttp://www.openrt.dehttp://www.openrt.de