amcs / cs 247 – scientific visualization lecture 9: iso...

27
AMCS / CS 247 – Scientific Visualization Lecture 9: Iso-Surface Lighting; GPU Texturing Markus Hadwiger, KAUST

Upload: others

Post on 14-Jul-2020

2 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: AMCS / CS 247 – Scientific Visualization Lecture 9: Iso ...faculty.kaust.edu.sa/sites/markushadwiger/... · 3 Reading Assignment #6 (until Oct. 21) Read (required): • Real-Time

AMCS / CS 247 – Scientific VisualizationLecture 9: Iso-Surface Lighting; GPU Texturing

Markus Hadwiger, KAUST

Page 2: AMCS / CS 247 – Scientific Visualization Lecture 9: Iso ...faculty.kaust.edu.sa/sites/markushadwiger/... · 3 Reading Assignment #6 (until Oct. 21) Read (required): • Real-Time

2

Reading Assignment #5 (until Oct. 14)

Read (required):• Real-Time Volume Graphics, Chapter 2 (GPU Programming)

• Real-Time Volume Graphics, Chapter 5.3 (Gradient-Based Illumination)

• Real-Time Volume Graphics, Chapter 5.4.1 (Blinn-Phong Illumination)

Page 3: AMCS / CS 247 – Scientific Visualization Lecture 9: Iso ...faculty.kaust.edu.sa/sites/markushadwiger/... · 3 Reading Assignment #6 (until Oct. 21) Read (required): • Real-Time

3

Reading Assignment #6 (until Oct. 21)

Read (required):• Real-Time Volume Graphics, Chapter 1

(Theoretical Background and Basic Approaches),from beginning to 1.4.4 (inclusive)

• Real-Time Volume Graphics, Chapter 3.2.3 (Compositing)

• Data Visualization book, Chapter 5 until 5.2 (inclusive)

Page 4: AMCS / CS 247 – Scientific Visualization Lecture 9: Iso ...faculty.kaust.edu.sa/sites/markushadwiger/... · 3 Reading Assignment #6 (until Oct. 21) Read (required): • Real-Time

4

Reading Assignment #7 (until Nov. 4)

Read (required):• Real-Time Volume Graphics, Chapters 5.3, 5.4, 5.5, 5.6

• Real-Time Volume Graphics, Chapter 7(GPU-Based Ray Casting)

• Real-Time Volume Graphics, Chapter 4 (Transfer Functions)until Sec. 4.4 (inclusive)

Page 5: AMCS / CS 247 – Scientific Visualization Lecture 9: Iso ...faculty.kaust.edu.sa/sites/markushadwiger/... · 3 Reading Assignment #6 (until Oct. 21) Read (required): • Real-Time

5

Programming Assignments Schedule (updated)

Assignment 2:• Iso-surface rendering due: Oct 10

Assignment 3:• Volume ray-casting due: Oct 24

----- Eid Al Adha: Oct 25-Nov 2 -----

Assignment 4:• Vector field visualization due: Nov 14

Assignment 5:• Flow visualization due: Nov 28

Page 6: AMCS / CS 247 – Scientific Visualization Lecture 9: Iso ...faculty.kaust.edu.sa/sites/markushadwiger/... · 3 Reading Assignment #6 (until Oct. 21) Read (required): • Real-Time

6

Next Lecture Dates

Lecture 9: 7.10.2012 9:00

Lecture 10: 7.10.2012 16:00, seminar room GMSV (bldg 1, 2nd floor)

Lecture 11: 10.10.2012 9:00

Lecture 12: 10.10.2012 16:00, seminar room GMSV (bldg 1, 2nd floor)

Q&A programming assignment #3: 15.10.2012 17:30Contact: [email protected]

Lecture 13: 14.10.2012 9:00

Lecture 14: 17.10.2012 9:00

Lecture 15: 4.11.2012 9:00

Page 7: AMCS / CS 247 – Scientific Visualization Lecture 9: Iso ...faculty.kaust.edu.sa/sites/markushadwiger/... · 3 Reading Assignment #6 (until Oct. 21) Read (required): • Real-Time

What About Volume Illumination?

Crucial for perceiving shape anddepth relationships

this is a scalar volume (3D distance field)!

Page 8: AMCS / CS 247 – Scientific Visualization Lecture 9: Iso ...faculty.kaust.edu.sa/sites/markushadwiger/... · 3 Reading Assignment #6 (until Oct. 21) Read (required): • Real-Time

Signed Distance Fields

Special case of general volume / scalar field for objects

Volume discretizes embedding

Signed distance to surface

Implicit surface:zero level set

Page 9: AMCS / CS 247 – Scientific Visualization Lecture 9: Iso ...faculty.kaust.edu.sa/sites/markushadwiger/... · 3 Reading Assignment #6 (until Oct. 21) Read (required): • Real-Time

Local Illumination in Volumes

Interaction between light source and point in the volume

Local shading equation; evaluate at each point along a ray

Use color from transfer function asmaterial color; multiply with light intensity

This is the new "emissive" color in theemission/absorption optical model

Composite as usual

Page 10: AMCS / CS 247 – Scientific Visualization Lecture 9: Iso ...faculty.kaust.edu.sa/sites/markushadwiger/... · 3 Reading Assignment #6 (until Oct. 21) Read (required): • Real-Time

Local Shading Equations

Standard volume shading adapts surface shading

Most commonly Blinn/Phong model

But what about the "surface" normal vector?

nl l

n

v

h r

specular reflectiondiffuse reflection

Page 11: AMCS / CS 247 – Scientific Visualization Lecture 9: Iso ...faculty.kaust.edu.sa/sites/markushadwiger/... · 3 Reading Assignment #6 (until Oct. 21) Read (required): • Real-Time

The Gradient as Normal Vector

Gradient of the scalar field is direction of highest change

Local approximation to isosurface at any point:tangent plane = plane orthogonal to gradient

Normal of this isosurface:normalized gradient

-g

largerscalar values

smallerscalar values

Page 12: AMCS / CS 247 – Scientific Visualization Lecture 9: Iso ...faculty.kaust.edu.sa/sites/markushadwiger/... · 3 Reading Assignment #6 (until Oct. 21) Read (required): • Real-Time

Gradient Reconstruction

We need to reconstruct the derivatives of acontinuous function given as discrete samples

Central differences• Cheap and quality often sufficient (2+2+2 neighbors in 3D)

Discrete convolution filters on grid• Image processing filters; e.g. Sobel (3x3x3 neighbors)

Continuous convolution filters• Derived continuous reconstruction filters

• E.g., the cubic B-spline and its derivatives(4x4x4 neighbors)

Page 13: AMCS / CS 247 – Scientific Visualization Lecture 9: Iso ...faculty.kaust.edu.sa/sites/markushadwiger/... · 3 Reading Assignment #6 (until Oct. 21) Read (required): • Real-Time

Central Differences

Need only two neighboring voxels per derivative

Most common method

gx = 0.5( f(x+1, y, z) – f(x-1, y, z) )

gy = 0.5( f(x, y+1, z) – f(x, y-1, z) )

gz = 0.5( f(x, y, z+1) – f(x, y, z-1) )

f(x-1, y, z) f(x+1, y, z)

f(x, y+1, z)

f(x, y-1, z)

f(x, y, z+1)

f(x, y, z-1)

on a curve

in a volume

Page 14: AMCS / CS 247 – Scientific Visualization Lecture 9: Iso ...faculty.kaust.edu.sa/sites/markushadwiger/... · 3 Reading Assignment #6 (until Oct. 21) Read (required): • Real-Time

Pre-compute gradients at grid points with any method

Store normalized gradient directions in RGB texture

Sample gradient texture in fragment shader: interpolation

Re-normalize after fetch!

nX

nY

nZ

RGB

Pre-Computed Gradients

RGB gradient texture lerp of texture filter renormalize!

Page 15: AMCS / CS 247 – Scientific Visualization Lecture 9: Iso ...faculty.kaust.edu.sa/sites/markushadwiger/... · 3 Reading Assignment #6 (until Oct. 21) Read (required): • Real-Time

15

GPU Texturing

Rage / id Tech 5 (id Software)

Page 16: AMCS / CS 247 – Scientific Visualization Lecture 9: Iso ...faculty.kaust.edu.sa/sites/markushadwiger/... · 3 Reading Assignment #6 (until Oct. 21) Read (required): • Real-Time

Vienna University of Technology 16

Shading Recap

Flat shadingcompute light interaction per polygonthe whole polygon has the same color

Gouraud shadingcompute light interaction per vertexinterpolate the colors

Phong shadinginterpolate normals per pixel

Remember: difference betweenPhong Lighting Model (specular lighting)Phong Shading

Page 17: AMCS / CS 247 – Scientific Visualization Lecture 9: Iso ...faculty.kaust.edu.sa/sites/markushadwiger/... · 3 Reading Assignment #6 (until Oct. 21) Read (required): • Real-Time

Vienna University of Technology 17

Traditional OpenGL Lighting

Phong lighting model at each vertex (glLight, …)Local model only (no shadows, radiosity, …)ambient + diffuse + specular (glMaterial!)

Fixed function: Gouraud shadingNote: need to interpolate specular separately!

Phong shading: evaluate Phong lighting model in fragment shader (per-fragment evaluation!)

Page 18: AMCS / CS 247 – Scientific Visualization Lecture 9: Iso ...faculty.kaust.edu.sa/sites/markushadwiger/... · 3 Reading Assignment #6 (until Oct. 21) Read (required): • Real-Time

Eduard Gröller, Stefan Jeschke 18

Why Texturing?

Idea: enhance visual appearance of surfaces by applying fine / high-resolution details

Page 19: AMCS / CS 247 – Scientific Visualization Lecture 9: Iso ...faculty.kaust.edu.sa/sites/markushadwiger/... · 3 Reading Assignment #6 (until Oct. 21) Read (required): • Real-Time

Vienna University of Technology 19

OpenGL Texture Mapping

Basis for most real-time rendering effectsLook and feel of a surfaceDefinition:

A regularly sampled function that is mapped onto every fragment of a surfaceTraditionally an image, but…

Can hold arbitrary informationTextures become general data structuresSampled and interpreted by fragment programsCan render into textures important!

Page 20: AMCS / CS 247 – Scientific Visualization Lecture 9: Iso ...faculty.kaust.edu.sa/sites/markushadwiger/... · 3 Reading Assignment #6 (until Oct. 21) Read (required): • Real-Time

Vienna University of Technology 20

Types of Textures

Spatial layoutCartesian grids: 1D, 2D, 3D, 2D_ARRAY, …Cube maps, …

Formats (too many), e.g. OpenGLGL_LUMINANCE16_ALPHA16GL_RGB8, GL_RGBA8, …: integer texture formatsGL_RGB16F, GL_RGBA32F, …: float texture formatscompressed formats, high dynamic range formats, …

External format vs. internal (GPU) formatOpenGL driver converts from external to internal

Page 21: AMCS / CS 247 – Scientific Visualization Lecture 9: Iso ...faculty.kaust.edu.sa/sites/markushadwiger/... · 3 Reading Assignment #6 (until Oct. 21) Read (required): • Real-Time

21

Texturing: General Approach

Texture space (u,v) Object space (xO,yO,zO) Image Space (xI,yI)

Parametrization Rendering(Projection etc.)

Texels

Vienna University of Technology

Page 22: AMCS / CS 247 – Scientific Visualization Lecture 9: Iso ...faculty.kaust.edu.sa/sites/markushadwiger/... · 3 Reading Assignment #6 (until Oct. 21) Read (required): • Real-Time

Vienna University of Technology 22

Texture Wrap Mode

How to extend texture beyond the border?Border and repeat/clamp modesArbitrary (s,t,…) [0,1] x [0,1] [0,255] x [0,255]

repeat mirror/repeat clamp border

Page 23: AMCS / CS 247 – Scientific Visualization Lecture 9: Iso ...faculty.kaust.edu.sa/sites/markushadwiger/... · 3 Reading Assignment #6 (until Oct. 21) Read (required): • Real-Time

Eduard Gröller, Stefan Jeschke 23

Texture Reconstruction: Magnification

Bilinear reconstruction for texture magnification (D<0)("upsampling")

Weight adjacent texels by distance to pixel position

Texture space u

-v

X

T(u+du,v+dv) = du·dv·T(u+1,v+1)+ du·(1–dv)·T(u+1,v)+ (1-du)·dv·T(u,v+1)+ (1-du)·(1-dv)·T(u,v)

du

dv(u,v) (u+1,v)

(u+1,v+1)(u,v+1)

Page 24: AMCS / CS 247 – Scientific Visualization Lecture 9: Iso ...faculty.kaust.edu.sa/sites/markushadwiger/... · 3 Reading Assignment #6 (until Oct. 21) Read (required): • Real-Time

Eduard Gröller, Stefan Jeschke 24

Magnification (Bilinear Filtering Example)

Original image

Nearest neighbor Bilinear filtering

Page 25: AMCS / CS 247 – Scientific Visualization Lecture 9: Iso ...faculty.kaust.edu.sa/sites/markushadwiger/... · 3 Reading Assignment #6 (until Oct. 21) Read (required): • Real-Time

25

Solid Texturing

texture defined in 3D

every position in space has a color

coherent textures across corners

Page 26: AMCS / CS 247 – Scientific Visualization Lecture 9: Iso ...faculty.kaust.edu.sa/sites/markushadwiger/... · 3 Reading Assignment #6 (until Oct. 21) Read (required): • Real-Time

26

Solid Texturing Examples

examples for application of 3D textures on a scull and a face

© Univ.Swansea

© Univ.Swansea

Page 27: AMCS / CS 247 – Scientific Visualization Lecture 9: Iso ...faculty.kaust.edu.sa/sites/markushadwiger/... · 3 Reading Assignment #6 (until Oct. 21) Read (required): • Real-Time

Thank you.

Thanks for material• Helwig Hauser

• Eduard Gröller

• Daniel Weiskopf

• Torsten Möller

• Ronny Peikert

• Philipp Muigg

• Christof Rezk-Salama