Scalable multi-gpu cloud raytracing with OpenGL University of Žilina Digital technologies 2014, Žilina, Slovakia
Overview Goals Rendering distant details in visualizations Raytracing Multi-GPU programming using OpenGL Cloud trace Algorithm Implementation Results Future work
Goals Research Methods of distant detail rendering Simple raytracing algorithms Using modern GPUs for raytracing Using multiple GPUs in OpenGL Develop An efficient algorithm fitting the GPU pipeline and architecture Implement a working prototype Evaluate the usability for other purposes Medical or volumetric data visualization Solid geometry raytracing
Distant detail rendering Sky Atmosphere Clouds Celestial bodies Distant landscapes Distant landmarks and skylines Used in Computer games Outdoor simulations and visualizations Source: X-Ray engine / S.T.A.L.K.E.R.
Sky and cloudscape rendering Sky planes Sky spheres or sky domes Sky boxes Combinations and extensions of the above
Sky plane One or several planes, with cloud textures applied, rendered above the ground Can be animated by transforming texture coordinates by exchanging different texture images Simple to implement Can appear flat and unconvincing especially if the observer s altitude changes Source: http://indiegorenderer.com
Sky sphere, sky dome One or several concentric spheres or hemi-spheres with textures applied Centered at or near the observer The texture mapping (from 2D planar to spherical coordinates) causes the texture to be distorted Lack of detail in certain areas The textured sphere geometry is more complex
Sky box One or several (nearly) concentric cubes with textures applied The cub(es) are centered at the observer They can be moved slightly at a different pace to simulate view parallax effect. Requires textures for 5 (without the ground) or 6 faces Animation by texture coordinates does not work well Animated by exchanging texture images Simple geometry Clouds do not appear flat
Combined A combination of sky boxes sky domes sky planes particle systems post-processing effects bloom lens flare light rays etc. Distant segments of regular geometry can be blended into the sky box Source: Half life 2 / http://half-life.wikia.com
Important properties of sky textures Visual properties Realistic cloud sizes, shapes and distributions. Realistic lighting and (self) shadowing. Realistic atmospheric light scattering. The texture image pixels can encode basic data that can be finalized later Cloud density Cloud distance Cloud lighting Atmosperic density Atmosphere lighting and shadowing etc. Dynamic finishing of a static texture One texture can result in multiple final images which can be smoothly animated HDR and other effects can be applied The light direction must be static More demanding that just a plain colorized texture
Sources of sky textures Textures for a skybox can be obtained in several ways: Real sky photography (usually requires post-processing) Static Limited number or requires a lot of storage space Can be difficult to photoshop into a full cube-map Simple generating algorithms (Perlin noise, etc.) Fast and simple Low quality Sometimes looking unnatural Advanced algorithms (usually raytracing) Computationaly expensive and slow High quality
Raytracing Visualization technique for generating an image by tracing the path of light through pixels in an image plane and simulating the effects of its encounters with virtual objects. Capable of producing a very high degree of visual realism. Greater computational cost than other techniques. Is recursive. Source: http://en.wikipedia.org
Raytracing Scenes in ray tracing can be described mathematically. Scenes may also incorporate Polygonal models Images Volumetric data Light sources Properties of the surfaces and interiors of objects in the scene determine further raytracing steps Raytracing can simulate various optical effects Reflection Refraction Scattering Dispersion Incandescence Emission Using multiple rays per pixel can be used for Antialiasing Simulation of depth-of-field Motion blur
Basic raytracing algorithm 1 For each pixel on the virtual screen, cast one or multiple rays originating at the position of the observer through the position of the screen pixel in world space. 2 Find the nearest object that the ray intersects with. 3 Cast secondary rays from the point where the object was hit to all light sources. 4 For any light source not obstructed by other objects calculate the amount of light hitting the surface of the object. 5 Take into account the surface and interior properties of the object the properties of the light and the angle at which the light arrives. 6 Calculate the final color of the light reaching the observer.
Raytracing algorithm extensions 1 When an object is hit by the primary ray, recursivelly shoot rays from the surface along vectors determined by the surface properties and find intersections with other objects Reflection Refraction Scattering 2 For volumetric objects sample along the ray through the defining data. 3 etc.
Cloud trace - overview Purpose Generator of skybox cube-map texture images. Provides also basic ray-trace data for dynamic finishing. Testbed for other multi-gpu raytracing applications. Properties Open-source. Multi-platform. Implemented using OpenGL (OGLplus 1 ). Utilizes multiple GPUs if available (currently only nvidia+glx). Is usable from the command line to allow scripting. Allows to import cloud scenes from CSV and Blender. Has a build-in cloud volume and placement generator. 1 http://oglplus.org/
Architecture Thread(s) GPU resources Renderer Raytracer(s) Copier Loader Main Saver Generator Main-glX Main-GLFW
Components Main Initializes the GL contexts and other components Currently has two implementations: glx multi-gpu, GLFW multi-platform, single GPU. Loaders load cloud volume and placement data Generators generate cloud volume and placement data Saver saves raytrace output or finalized images GPU resources manage used GPU resources (textures, shaders, etc.) Raytracers raytrace the cloudscape, generate output data Threads execute the raytracers Copier does efficient data copying between GPUs Renderer renders the final image from the raytrace data by using a finishing shader
Cloud representation Cloud volume and structure is represented by a cubic 3D texture Individual clouds are represented as spheres enclosing the cube. Finding ray-sphere intersections consists of very simple vector operations well suited for the GPU. Cloud parametes are stored in a buffer on the GPU Position Radius Rotation Unit density Unit light attenuation etc.
Main rendering algorithm 1 Parse input parameters 2 Load or generate the cloud volume texture 3 Load or generate the cloud placement and parameters 4 Initialization (threads, GL contexts, components). 5 Face set rendering for each of the 6 cube faces: 1 Cleanup output buffer 2 Setup raytracer(s) 3 Activate raytracer(s) (each in its own thread) 4 Face tile rendering for each tile on a face: 1 Raytrace a batch of tiles 2 Copy the raytraced tiles into a shared buffer 5 Suspend raytracer(s) 6 Render the final image, using finishing shadera 7 Save face final image and/or intemediate raytrace data
Raytracing algorithm CPU 1 Each cube face is divided into rectangular tiles 2 The individual tiles are assigned to idle raytracers in batches 3 Each raytracer processes a single tile on the GPU 4 After all tiles in a batch are processes they are copied by the copier into a shared texture. Ray-cloud intersection search
Raytracing algorithm GPU 1 Find ray direction 2 Search for intersections 3 Sample the interior of the intesected cloud-spheres 1 For each sample in the interior of the cloud, cast a secondary ray to the light source, calculating the sample lighting. 4 Backtrace all samples along the primary ray and blend them into the final value according to the sample density. 5 Output raytrace data Cloud interior sampling Casting secondary rays
Performance testing Hardware CPU Intel Xeon W3550, 8 cores @3.07 GHz RAM 8 GB GPU 2 x nvidia Quadro 600 (GPU 0, GPU 1 ) Testing scenes S 2 2 cloud spheres S 4 4 cloud spheres... S 512 512 cloud spheres S 1024 1024 cloud spheres Test cases T(A) GPU 0 : Finisher + Raytracer T(B) GPU 0 : Finisher GPU 1 : Raytracer T(C) GPU 0 : Finisher + Raytracer GPU 1 : Raytracer
Typical rendering times and scalability 00:30 00:25 T(A off-screen) T(B off-screen) T(C off-screen) 18:00 16:00 14:00 T(A off-screen) T(B off-screen) T(C off-screen) 30:00 27:00 24:00 T(A on-screen) T(B on-screen) T(C on-screen) Real rendering time 00:20 00:15 00:10 Real rendering time 12:00 10:00 08:00 06:00 Real rendering time 21:00 18:00 15:00 12:00 09:00 00:05 04:00 02:00 06:00 03:00 00:00 S 2 S 4 S 8 S 16 S 32 Scene 00:00 S 64 S 128 S 256 S 512 S 1024 Scene 00:00 S 2 S 4 S 8 S 16 S 32 S 64 S 128 S 256 S 512 S 1024 Scene Rendering times in off-screen mode Rendering times in on-screen mode
Multi-GPU execution speedup Speedup 1.8 1.7 1.6 1.5 1.4 1.3 1.2 1.1 1 0.9 0.8 0.7 S16 S8 S4 S2 Off-screen T(A)/T(B) T(A)/T(C) S32 S1024 S512 S256 S128 S64 Speedup 70 60 50 40 30 20 10 0 On-screen T(A)/T(B) T(A)/T(C) S1024 S512 S256 S128 S64 S32 S16 S8 S4 S2 Scene Scene Execution speedup T (A) T (A) and in Scenario 2 in off-screen and on-screen modes. T (B) T (C)
Raytrace output data Cloud density data (inverted) Primary lighting data Cloud distance data (normalized) Secondary lighting data
Finished output
Finished output
Finished output
Finished output
Animations Cloud trace allows command line invocation. Cloud placement data is animated and prepared for each frame by an external script. Each frame is rendered by a single invocation of Cloud trace.
Planned features for Cloud trace Optimizations Network rendering Raytracers as separate network servers Common broker dispatching raytrace tasks Other output parameters Cloud age usable in animations Cloud light emission Cloud altitude Multiple light sources Multiple textures Improved cloud texture generator Other finishing shaders
Multi-GPU medical imaging data visualization Raytraced data volume from an MRI brain scan