Presentation is loading. Please wait.

Presentation is loading. Please wait.

Ray Tracing using Programmable Graphics Hardware

Similar presentations


Presentation on theme: "Ray Tracing using Programmable Graphics Hardware"— Presentation transcript:

1 Ray Tracing using Programmable Graphics Hardware
Andrew Wood, Brendan McCane & Scott A. King Graphics & Vision Research Group Department of Computer Science University of Otago IVCNZ 2004

2 Outline Using Cg with OpenGL
Where does Cg fit in? Benefits of Programmable Graphics Hardware Mapping applications as Graphics processes General purpose processing on the GPU Ray Casting model Extensions

3 OpenGL Graphics Pipeline
3D Application 3D API: OpenGL Or DirectX GPU Front End Primitive Assembly Rasterization & Interpolation Framebuffer Tests Framebuffer Programmable Vertex Processor Programmable Fragment Processor Explain normal pipeline Bottom pictures - geometry is rasterized into the fragments that will appear for each pixel Programmable cards allow us to add programs that operate on a per-vertex or per-fragment level Only one vertex and fragment program is active at a time

4 Cg API-specific runtime
Cg Application model Application Cg - high level, c-like language Cg compiler to generate assembler Cg Runtime Communication with Hardware Cg API-specific runtime (OpenGL, DX8 or DX9) OpenGL or Direct3D Graphics Driver Graphics Hardware Cg common runtime (includes compiler) Cg compiler to generate assembly code Cg runtime - currently bound program Communication with Hardware - using 3D API Mark et al. SIGGRAPH 2003

5 GPU Performance Sourced from NVIDIA
GPU’s making use of the same technology improvements Improved performance more apparent in parallel Work can be offloaded to an additional processing unit Improved performance for applications that map well as a graphics process Sourced from NVIDIA

6 Cg Processing model Vertex Program Fragment Program Register
Input Registers Output Registers Register Interpolation Input Registers Output Registers Vertex Program Fragment Program Application Rasterization Display Textures Input/output for shaders. Register/texture input, colour/depth output. Register Interpolation alongside rasterization Multiple parallel fragment processors - data-parallel program on indepentant processors Idea is to map your application as a graphics process - processing done at a vertex/fragment level

7 Images sourced from NVIDIA
Example: Image Filter Draw screen-sized quad Input image to be processed as texture Edge-detection fragment program is run once per pixel Output results to screen or save to texture Laplacian Filter Fragment Program Draw Screen-Sized Quad Input image to be processed as a texture Bind and execute Fragment Program - Which is then run once per pixel Output result The four-component colour output could also be stored in a texture. Images sourced from NVIDIA

8 Cg code example Laplacian Filter Fragment Program
half4 main(half2 coords: TEX0, sampler2D texture) : COLOUR { const half offset = 1.0 / 256; half4 c = tex2D(texture, coords); half4 bl = tex2D(texture, coords + half2(-offset, offset)); half4 l = tex2D(texture, coords + half2(offset, 0)); half4 b = tex2D(texture, coords + half2(0, offset)); return 8 * (c * (bl + l + … + b)); } Laplacian Filter Fragment Program Can include Cg as a .cg file - compiled at runtime Can still write your own assembler, or modify compiler generated assembler

9 Ray Tracing model Ray Tracing model - types of rays, primary rays cast from the eye, through the centre of each pixel into the scene Traced primitives using our graphics hardware method Need only one intersection test between a ray and each primitive. If we were using triangles to approximate these primitives, we would need many more intersection tests - requiring ray intersection optimisations.

10 Current Ray Casting method
CPU Current Object Eye ray texture Stream of Objects Object Intersection Shader Object Intersection Shaders Current Intersection texture Eye Rays Quadric Intersection Shader Triangle Intersection Shader Current Object Intersections New Intersection Texture Closest Intersections Render to Texture used to store results Updated intersection texture set as input for next pass Lights Colour Calculation Shader Object Materials Output Image Current Intersection Shader maintains intersection buffer Render to Texture allows storage directly as a texture Updated intersection texture set as input to the next pass ~ depth buffer Using Four component colour output to store vector information in textures - 32bit floating point per component

11 Sphereflake test scene
Results Sphereflake test scene Number of primitives affects performance - method requires an extra texture readback for each object Texture readbacks are slow - fast to send data to a graphics card, slow to get anything back. This is currently a limitation under linux only, not windows Each primitive is being intersected with all rays, no ray optimisation

12 Extensions Full recursive model
Different rays can be in different states State based processing Limiting processing to one type of ray Application for method: Constructive Solid Geometry Different rays can be in different states (rays stored as pixels) Can only operate on one type of ray at a time (only one frag prog bound per pass) State based processing method to limit processing of only those fragments in the current state Constructive Solid Geometry - We can implement a lot of different primitives with this method, a general CSG solution will allow very complex pictures to be drawn.

13 Summary & Questions OpenGL Graphics Pipeline
Cg Application & Processing models Example: Image Filter Ray Tracing model Current Ray Casting method Results Extensions


Download ppt "Ray Tracing using Programmable Graphics Hardware"

Similar presentations


Ads by Google