Real-Time Volume Graphics [02] GPU Programming

15
REAL-TIME VOLUME GRAPHICS Christof Rezk Salama Computer Graphics and Multimedia Group, University of Siegen, Germany Eurographics 2006 Real-Time Volume Graphics [02] GPU Programming RTVG4Me

description

Real-Time Volume Graphics [02] GPU Programming. RTVG4Me. Host. Cull/Clip/Setup. Z-Cull. Rasterization. Texture Cache. Fragment Crossbar. Memory. Memory. Memory. Memory. Partition. Partition. Partition. Partition. Graphics Processor. Example NVidia Geforce6. Vertex Processors. - PowerPoint PPT Presentation

Transcript of Real-Time Volume Graphics [02] GPU Programming

REAL-TIME VOLUME GRAPHICSChristof Rezk SalamaComputer Graphics and Multimedia Group, University of Siegen, Germany Eurographics 2006

Real-Time Volume Graphics

[02] GPU ProgrammingRTVG4Me

REAL-TIME VOLUME GRAPHICSChristof Rezk SalamaComputer Graphics and Multimedia Group, University of Siegen, Germany Eurographics 2006

Graphics ProcessorHost

Cull/Clip/Setup

Z-Cull Rasterization

Fragment Crossbar

Texture Cache

MemoryPartition

MemoryPartition

MemoryPartition

MemoryPartition

Vertex Processors

Fragment Processors

Memory AccessZ-Compare andBlending

ExampleNVidia Geforce6

REAL-TIME VOLUME GRAPHICSChristof Rezk SalamaComputer Graphics and Multimedia Group, University of Siegen, Germany Eurographics 2006

PC Architecture

CPU

NorthBridge

SystemMemory

SouthBridge

GPU

VideoMemory

6.4 GB/s

6.4 GB/s

up to 8 GB/s

up to 35 GB/s

REAL-TIME VOLUME GRAPHICSChristof Rezk SalamaComputer Graphics and Multimedia Group, University of Siegen, Germany Eurographics 2006

Pixels

Graphics Hardware

Vertices Primitives Fragments

GeometryProcessing

FragmentOperations

Scene Description Raster Image

Rasterization

REAL-TIME VOLUME GRAPHICSChristof Rezk SalamaComputer Graphics and Multimedia Group, University of Siegen, Germany Eurographics 2006

What can the hardware do?

Rasterization Decomposition into fragments Interpolation of color Texturing

Interpolation/Filtering Fragment Shading

Fragment Operations Depth Test (Z-Test) Alpha Blending (Compositing)

REAL-TIME VOLUME GRAPHICSChristof Rezk SalamaComputer Graphics and Multimedia Group, University of Siegen, Germany Eurographics 2006

Geometry Processing

Per-VertexLighting

ProjectiveTransform.

PrimitiveAssembly

AffineTransform.

Multiplicationwith Transforma-

tion Matrix

Per-VertexLocal Illumination

(Blinn/Phong)

GeometricPrimitives

(Points, LinesTriangles)

Primitives

Transformationto Canonical

Viewing Volume

Vertices

GeometryProcessin

gRasterization

FragmentOperations

REAL-TIME VOLUME GRAPHICSChristof Rezk SalamaComputer Graphics and Multimedia Group, University of Siegen, Germany Eurographics 2006

GeometryProcessin

gRasterization

FragmentOperations

GeometryProcessin

gRasterization

FragmentOperations

TextureFetch

TextureApplication

Polygon Rasterization

Per-VertexLighting

ProjectiveTransform.

PrimitiveAssembly

AffineTransform.

Multiplication with Transforma-

tion Matrix

Per-VertexLocal Illumination

(Blinn/Phong)

GeometricPrimitives

(Points, LinesTriangles)

Primitive

Transformationto Canonical

Viewing Volume

Vertices

Decompositionof primitives

into fragments

Interpolation oftexture coordinates

Filtering of texture color

Combination ofprimary color with

texture color

Primitives Fragments

Geometry ProcessingRasterization

REAL-TIME VOLUME GRAPHICSChristof Rezk SalamaComputer Graphics and Multimedia Group, University of Siegen, Germany Eurographics 2006

FragmentsFragments

Combine the fragment color with the color

already in the frame buffer

TextureFetch

TextureApplication

Polygon Rasterization

Decompositionof primitives

into fragments

Interpolation oftexture coordinates

Filtering of texture color

Combination ofprimary color with

texture color

Primitives Fragments

Fragment Operations

StencilTest

AlphaBlending

DepthTest

AlphaTest

Discard allfragments within

a certain alpha range

Discard afragment ifthe stencil buffer is set

Discard alloccluded

fragments

RasterizationGeometryProcessin

gRasterization

FragmentOperations

REAL-TIME VOLUME GRAPHICSChristof Rezk SalamaComputer Graphics and Multimedia Group, University of Siegen, Germany Eurographics 2006

Pixels

Graphics Hardware

Vertices Primitives Fragments

GeometryProcessing

FragmentOperations

Scene Description Raster Image

RasterizationVertexShader

FragmentShader

Programmable Pipeline

REAL-TIME VOLUME GRAPHICSChristof Rezk SalamaComputer Graphics and Multimedia Group, University of Siegen, Germany Eurographics 2006

Vertex ShaderImportant Features:

Vertex Shader has information about one single Vertex only (no topological information)!For each set of vertex-attributes, the vertex shader generatesexactly one vertex

The vertex shader cannot create additional vertices!The vertex shader cannot discard vertices from the stream!

The term „shader“ is somehow misleading, since the vertex shader can change the geometry!

REAL-TIME VOLUME GRAPHICSChristof Rezk SalamaComputer Graphics and Multimedia Group, University of Siegen, Germany Eurographics 2006

Vertex Shader Instructions

Assembly-Language, such as ABS absolute valueADD additionDP3 scalar product (dot product)DP4 scalar product 4-componentsDST distance vectorLIT illumination termsMUL multiplicationMAD multiply and addSUB subtractionXPD cross product

Most commands are vector commands (4 components)

REAL-TIME VOLUME GRAPHICSChristof Rezk SalamaComputer Graphics and Multimedia Group, University of Siegen, Germany Eurographics 2006

High-Level Shading Languages

Who wants to write assembler code?Stanford Shading LanguageCg (developed by Nvidia) for OpenGL and DirectXDirectX 9.0 HLSL (DirectX only, Syntax similar to Cg)GLSL (OpenGL shading language)

Syntax similar to C plus vector variables und vector instructions:float4 v1; // same as float v1[4] in C

int3 v2; // same as int v2[3] in C

Swizzling: float4 v3 = v1.xzzy;

REAL-TIME VOLUME GRAPHICSChristof Rezk SalamaComputer Graphics and Multimedia Group, University of Siegen, Germany Eurographics 2006

Programmable Vertex Processor

copy vertexattributes to

input registers

BeginVertex Fetch next

instruction

Read input-or temporary

registers

Mapping:NegationSwizzling

Executecommand

Write tooutput or

temp. registers

VertexProgram

Instructions

Input-Registers

TemporaryRegisters

Output-Registers

Finished?

no

yesEmit Vertex

REAL-TIME VOLUME GRAPHICSChristof Rezk SalamaComputer Graphics and Multimedia Group, University of Siegen, Germany Eurographics 2006

Write to output or temporary

registers

executeinstruction

TextureInstruction?

Mapping:NegationSwizzling

Read inputof temporary

registers

Fragment Processor

copy fragmentattributes toInput register

BeginFragment Fetch next

instruction

OutputRegisters

no

yes

Emit Fragment

Finished?interpolatetexel color

Calculate textureaddress and

sample textureTextureMemory

yes

no

FragmentProgram

Instructions

Input-Registers

TemporaryRegisters

REAL-TIME VOLUME GRAPHICSChristof Rezk SalamaComputer Graphics and Multimedia Group, University of Siegen, Germany Eurographics 2006

Phong ShadingPer-Pixel Lighting: Local illumination in a fragement shadervoid main(float4 position : TEXCOORD0,

float3 normal : TEXCOORD1,

out float4 oColor : COLOR,

uniform float3 ambientCol, uniform float3 lightCol, uniform float3 lightPos, uniform float3 eyePos, uniform float3 Ka, uniform float3 Kd, uniform float3 Ks, uniform float shiny){

float3 P = position.xyz; float3 N = normal; float3 V = normalize(eyePosition - P); float3 H = normalize(L + V);

float3 ambient = Ka * ambientCol;

float3 L = normalize(lightPos - P); float diffLight = max(dot(L, N), 0); float3 diffuse = Kd * lightCol * diffLight;

float specLight = pow(max(dot(H, N), 0), shiny); float3 specular = Ks * lightCol * specLight;

oColor.xyz = ambient + diffuse + specular; oColor.w = 1;}