CyRay: Real-Time Ray Tracing on the PlayStation3
CprE491: MAY08-38
Brendan Campbell, Sean Godinez,
Daniel Risse, Aaron Westphal
12 December 2007
DISCLAIMER: This document was developed as part of the requirements of an electrical and computer engineering course at Iowa State University, Ames, Iowa. The document does not constitute a professional engineering design or a professional land surveying document. Although the information is intended to be accurate, the associated students, faculty, and Iowa State University make no claims, promises, or guarantees about the accuracy, completeness, quality, or adequacy of the information. Document users shall ensure that any such use does not violate any laws with regard to professional licensing and certification requirements. Such use includes any work resulting from this student-prepared document that is required to be under the responsible charge of a licensed engineer or surveyor. This document is copyrighted by the students who produced the document and the associated faculty advisors. No part may be reproduced without the written permission of the senior design course coordinator.
Overview
End Goal To produce realistic looking scenes using the most impressive set of
features capable of running interactively in real time (20 fps or faster) on the PlayStation3.
Tasks Implement a multi-threaded ray tracing program that utilizes the Cell
Broadband Engine’s SPEs. Expand functionality, optimize throughput, and test repeatedly. Spread the workload over multiple PS3s (Future Project).
Users Those interested in achieving real-time ray tracing using IBM’s Cell
Processor.
Definitions
Cell Broadband Engine (CBE) A processor developed by IBM that is the CPU of Sony’s Playstation3 console, also
referred to as the Cell Processor.
Single Instruction, Multiple Data (SIMD) Performing the same instruction in parallel over multiple blocks of data.
Power Processing Element (PPE) This is the main core of the Cell Processor.
Synergistic Processing Element (SPE) This is a co-processor that specializes in SIMD instructions and is a supplemental part of
the Cell Processor.
Anti-Aliasing This is a technique that gets rid of jagged edges on objects. The image is constrained to
being rendered on pixels, but anti-aliasing can dampen the effects of pixelation.
Definitions (cont’d)
Bump Mapping This is a technique that perturbs the surface normals of the object's texture, varying the results of
surface shading.
Diffuse Shading Shading is calculated based on the angle at which a light source hits a surface. The more directly the
surface is hit, the more intensely the surface is lit.
Phong Shading This is a model for shading and interpolation that creates smooth surfaces that have
realistic glossiness and coloration.
Specular Shading Shading is calculated like a reflection. This determines how a camera sees a light
source as a reflection.
kd-Tree K-dimensional tree. This is a space partitioning data structure.
The Concept
System Block Diagram
Camera Data
Display
Object Storage
User Input
Ray Tracer
Frame Buffer
Data File
Operating Environment
System Interface: Linux OS and PS3 Linux Fedora Core 7 OS operates on the PS3 Ray Tracing Program operates within the Linux OS
Hardware Interface: Display screen provides visual output IBM’s Cell Processor runs the ray tracing application USB keyboard controls movement in scene PS3 Controller also shall permit movement through scene
User Interface
Display of rendered scene through PS3 video outputs to compatible monitor
Interactivity via USB keyboard Linux on PS3 supports keyboard usage Controls allow manipulation of camera May also map PS3 controller to input
Requirements
Functional: Program shall have a fast frame rate to simulate real-time Program shall have low latency to reacting to user inputs Program shall avoid branching functions due to frame-rate loss
on cell processor Program shall implement color User shall be able to modify camera positioning
Non-Functional: Should run at an approximate rate of 20 fps Shall be able to store all required memory in available cell
processor memory Should be capable of being run across multiple machines Shall not be cross-compatible with other OS or processor types
Features to Implement: Shadows Reflection Refraction Material Effects Diffuse Shading Specular Shading Texture Mapping Anti-aliasing
Requirements (cont’d)
Market and Literature Survey
Desirable features of Interactive Ray Tracer High frame rate (20+ fps at 1280x720 resolution) Low latency for user input Fully rendered color (24 bits) Diffuse and Specular shading Shadows Reflection and Refraction Anti-aliasing Textures and Bump-mapping
Solution Strategies
Means to Achieve Features Hierarchies (spatial sub-division of objects for
intersection testing) Task Grouping (based on data dependency)
Iterative vs. Recursive design
Deliverables
Source Code Executable Documentation Testing Outputs Benchmarks
Project Plan
Work Breakdown Several iterative stages Distributed evenly at each stage
Budget: Estimated “$7680” $10/hr per member over two semesters
Project Schedule Risks
Implementation Complications
Design Method
Development Model :
Incremental Development / Rework strategy
Design
Expected Features and Timeline1. Simple Ray Tracer that runs on the PS3
2. Simple Ray Tracer utilizing Cell SPEs and kd-tree scene
3. Specular Shading
4. Shadows
5. Phong Interpolation
6. Reflections
7. Refractive Transparency
8. Textures
9. Bump Mapping
10. Anti-Aliasing & Ambient Occlusion
Design (cont’d)
The transition to more and more features:
•No shading
•Diffuse
•Specular
•Shadows
•Reflections
Design (cont’d)
General Ray Tracing Strategy Making the Collision Search More Efficient Lighting Model
Ambient Color Diffuse Specular Reflectiveness Transmissiveness Index of Refraction
Design (cont’d)
Interpolation Model Phong Shading – Linear interpolation of vertex
normals for a point on a polygon to get better resolution of specular and diffuse shading, as well as reflections
Parallel Ray Tracing Strategy Initial Distribution - Dividing responsibility amongst SPEs
Ray Task Deferral - Work on other tasks until ray data is ready
Ray Task Grouping – Group rays with similar data dependencies
Specifications
Input Scene Description File Keyboard PS3 Controller
Output LCD Monitor
Currently configured at 576x384 pixelsMaybe increased later, such as to 1280x720
Specifications (cont’d)
Hardware Sony PlayStation 3 Console Cell Broadband Engine
Power Processing Element Synergistic Processing Elements
Relevent Peripherals PS3 Power Cord LCD Monitor HDMI to DVI Adaptor Cable USB Keyboard PlayStation 3 Controller
Specifications (cont’d)
Software Use Case:
The user utilizes an input device to produce a camera movement command.
The system translates the command into a coordinate change for the active camera. This change takes effect before for the next frame that has yet to start rendering.
The system renders the scene using the new camera coordinates.
Specifications (cont’d)
Testing Feature-wise Appearance Frame Rate Latency General Behavior
Detailed Design
Data Flow Diagram Class Diagram
Model File
PS3 PPE
OutputMemory
Memory Bus
Camera Input Device
File Load
Raytrace
Raytrace
Raytr
ace
Raytrace
Raytrace
Raytr
ace
SPE
SPE
SPE SPE
SPE
SPE
+cSceneSet () : cSceneSet+~cSceneSet () : cSceneSet+AddLight (cLight*) : void+AddSphere (cObject*) : void+AddTriangle (cObject*) : void+GetLights () : cLights+GetTriangles () : cObject+GetSpheres () : cObject
cSceneSet
+cRayPacketQueue (int) : cRayPacketQueue+cRayPacketQueue (RayPacket*, int) : cRayPacketQueue+~cRayPacketQueue () : cRayPacketQueue+push (RayPacket*, int) : int+pop (RayPacket*, int) : int
cRayPacketQueue
+cLight () : cLights+cLight (float, float, float) : cLights+~cLight () : cLights-m_fXpos : float-m_fYpos : float-m_fZpos : float
cLights
+cObject () : cObject+~cObject () : cObject+GetMaterial () : cMaterial-m_iShape : int-m_Material : cMaterial
cObject
+cMaterial () : cObject+~cMaterial () : cObject+cMaterial (cColor&, float, float, float) : cObject+SetColor (cColor&) : void+SetColor (Color) : void+SetColor (BYTE, BYTE, BYTE) : void+SetSpecular (float) : void+SetRefract (float) : void+SetReflect (float) : void+GetColor ()+GetSpecular () : float+GetRefract () : float+GetReflect () : float-m_clrDiffuse-m_fSpecular : float-m_fRefract : float-m_fReflect : float
cMaterial
+cColor () : cColor+~cColor () : cColor+cColor (BYTE, BYTE, BYTE) : cColor+SetColor (cColor&) : void+SetColor (Color) : void+SetColor (BYTE, BYTE, BYTE) : void+SetRed (BYTE) : void+SetBlue (BYTE) : void+SetGreen (BYTE) : void+GetColor ()+GetRed ()+GetBlue ()+GetGreen ()-m_sColor
cColor
-End1
1
-End2
*
-End31
-End4*
+cSphere () : cColor+~cSphere () : cColor+cSphere (cVector3, float) : cColor+Intersect (Ray&, float) : int-m_V3Center-m_fRadius : float
cSphere
+cTriangle () : cColor+~cTriangle () : cColor+cTriangle (cVector3*) : cColor+Intersect (Ray&, float) : int-m_Position[3]-m_U : float-m_V : float-nu : float-nv : float-nd : float-k : int-bnu : float-bnv : float-cnu : float-cnv : float-m_N
cTriangle+cVector3 () : cColor+~cVector3 () : cColor+cVector3 (float, float, float) : cColor+Set (float, float, float) : void+Normalize () : void+Length () : float+SqrLength () : float+Dot (various) : float+Cross (various) : cColor-m_fX : float-m_fY : float-m_fZ : float
cVector3
RayTrace
+cCamera () : cCamera+~cCamera () : cCamera+Origin () : cVector3+X_Size () : int+Y_Size() : int+Distance () : int+A_X () : int+B_X () : int+A_Y () : int+B_Y () : int+CurrentPixel ()+RenderRay () : RayPacket-mOrigin : cVector3-mX : int-mY : int-mDist : int-mA_X : int-mA_Y : int-mB_X : int-mB_Y : int-m_Pix
cCamera
Class Design SceneSet
Contains all the objects in the scene, essentially the root node of the ObjectTree. Geometries, Lights, and a Camera can be added to this object which will be added to the ObjectTree. All objects can be referenced through this object. Ray Tracing requests are called through this object. This object is also responsible for subdividing the object tree into easier-to-work-with parts for the SPEs
FrameBufferContains a front and back buffer for displaying the scene. Each pixel will be represented by 24-bit r,g,b values, and stored in a 32-bit slot for alignment purposes. All pixel updates will take place on the back buffer. The frames will ip with VSYNC.
ObjectTreeThis is a kd-tree containing the objects within the scene. This tree is an ecient way to reference only parts of the scene that are needed.
ObjectThis object an interface to many types of primitives, such as spheres and triangles. This object contains a Material object.
References
ISU Senior Design Homepage http://seniord.ece.iastate.edu/
Wikipedia: KD-Tree, Bump Mapping. http://en.wikipedia.org/wiki/
Real-Time Ray Tracing on the PS3 http://seniord.ece.iastate.edu/may0838/index.html