31
Fluid Surface Rendering in CUDA Andrei Monteiro Marcelo Gattass Assignment 4 June 2010

Fluid Surface Rendering in CUDA

Embed Size (px)

DESCRIPTION

Fluid Surface Rendering in CUDA. Andrei Monteiro Marcelo Gattass Assignment 4 June 2010. Topics. Introduction Related Work Algorithm CUDA Implementation Shading Results Conclusion References. Introduction. Fluids are part of our daily lives. Difficult to reproduce - PowerPoint PPT Presentation

Citation preview

Page 1: Fluid Surface Rendering in CUDA

Fluid Surface Rendering in CUDA

Andrei MonteiroMarcelo GattassAssignment 4June 2010

Page 2: Fluid Surface Rendering in CUDA

Topics

IntroductionRelated WorkAlgorithmCUDA ImplementationShadingResultsConclusionReferences

Page 3: Fluid Surface Rendering in CUDA

Introduction

Fluids are part of our daily lives. Difficult to reproduce Simulations are expensive

Water Smoke Explosions

It is typically simulated off-line and then visualized.

In this work we are focusing in rendering the fluid in real time.

Page 4: Fluid Surface Rendering in CUDA

Introduction

Fluids are simulated using particle system using the Smoothed-Particle Hydrodynamics (SPH) method It is made up of thousands to millions of particles (in a large

scale simulation) The objective is to extract the isosurface from this cluster of

particles.

Page 5: Fluid Surface Rendering in CUDA

Introduction

262,144 particles

Page 6: Fluid Surface Rendering in CUDA

Introduction

Surface Rendering techniquesMarching CubesPoint SplattingSurfels

In this work, we use the Marching Cubes tecnique which is faster than the others.

Page 7: Fluid Surface Rendering in CUDA

Related Work

NVIDIA´s Notes on Parallel Marching Cubes Algorithm

Screen Space Fluid Rendering with Curvature Flow, Simon Green , NVIDIA

LORENSEN, W. E., AND CLINE, H. E. 1987. Marching cubes: A high resolution 3d surface construction algorithm. SIGGRAPH, Comput. Graph. 21, 4, 163–169.

Real-Time Animation of Water, Takashi Amada.

Page 8: Fluid Surface Rendering in CUDA

Algorithm

Marching Cubes Is based on a grid method where it evaluates a scalar field on

the vertices. We take advantage of the Uniform Grid already implemented in

our SPH simulation. If the scalar field on a vertex is less than a threshold

(isosurface value), the vertex is inside the isosurface / fluid and outside otherwise.

The most difficult part of the algorithm is to obtain a good scalar field function as the smoothness of the surface generated depends greatly on it.

We then use these information to triangulate the surface. Normals are also calculated using, for example, the gradient

of the scalar field.

Page 9: Fluid Surface Rendering in CUDA

Algorithm

outsideinside

isosurface

Page 10: Fluid Surface Rendering in CUDA

Algorithm

outsideinside

Page 11: Fluid Surface Rendering in CUDA

Algorithm

Same algorithm applies in 3D, but the there are 256 voxel-triangle configurations:

8 vertices per voxel Total number of configurations is 28 = 256.

However, if we rotate and/or reflect the 15 cases below, we obtain 256 configurations.

In this work we use all 256 configurations.

Page 12: Fluid Surface Rendering in CUDA

CUDA Implementation

Triangle configurations (number of vertices, triangles) are stores in tables and written in textures.

1. Calculate number of vertices needed per voxel.2. Count number of occupied voxels (excluding empy

voxels with which do not contain the isosurface).3. Compact the occupied voxels to be tightly packed.4. Count the total number of vertices used to generate

the surface.5. Generate the triangles.

Page 13: Fluid Surface Rendering in CUDA

CUDA Implementation

1. Calculate number of vertices needed per voxel.

1 thread per voxel Check if 8 corners have scalar

fields less than the isosurafce value.

If so, increment voxel vertex counter.

Use the vertex counter to access the Vertices Table, which contains the number of vertices with that specific configuration.

Page 14: Fluid Surface Rendering in CUDA

CUDA Implementation

2. Count number of occupied voxels The previous step returns an array with the number of

vertices per voxel and an array indicating if each voxel is occupied (1) or not (0).

Scan this array and return the number of occupied voxels. Array elements with 0 indicates an unoccupied voxel.

Use the cudppScan from SDK, a fast scan function.

Page 15: Fluid Surface Rendering in CUDA

CUDA Implementation

3. Compact the occupied voxels to be tightly packed The previous step returns an array of occupied scan where elements = 1

(occupied) have their values changed to the occupied index (0,1,2,3...), and elements = 0 have their values unchanged.

This kernel compacts the occupied voxels indices by looking at the occupied scan array values.

int index = current Thread;if (voxelOccupied[index] ) { compactedVoxelArray[ voxelOccupiedScan[index] ] = index; }

1 0 1 1 0 0 1 1 1

0 0 1 2 0 0 3 4 5

Occupied Array

Scanned Occupied Array

0 2 3 6 7 8 0 0 0 Compacted Voxel Array

Page 16: Fluid Surface Rendering in CUDA

CUDA Implementation

4. Count the total number of vertices used to generate the surface.

Same idea of step 2. Use cudppScan to accumulate the number of vertices in each voxel position in the array.

Page 17: Fluid Surface Rendering in CUDA

CUDA Implementation

5. Generate Triangles Use all information obtained in the previous steps. 1 thread per occupied voxel.

Each thread obtains the current voxel index from the compacted voxel Array and use it to access the data such as number of vertices and scalar fields.

Linearly interpolate vertices and normals from each voxel edge:

Page 18: Fluid Surface Rendering in CUDA

CUDA Implementation

f0 = scalar field´s value and gradient from one edge vertex;f1 = scalar field´s value and gradient from other edge vertex;float t = (isolevel - f0.w) / (f1.w - f0.w);p = lerp(p0, p1, t);n.x = lerp(f0.x, f1.x, t);n.y = lerp(f0.y, f1.y, t);n.z = lerp(f0.z, f1.z, t);

f0

f1

f0

f1

f0

f1

Page 19: Fluid Surface Rendering in CUDA

CUDA Implementation

Scalar Field: Use density as scalar field

Normals are obtained by:

j

jjS hrrWmr ),()(

0)(

64315),(

322

96rh

hhrWpoly

Density in a position r

Kernel function ρ i,j+1

ρ i+1,j

ρ i,j-1

ρ i-1,jρ i,j

1,,1,,

,1,,1,

,,1,,1

kjikjiz

kjikjiy

kjikjix

n

n

n

Grid

ρρss

Page 20: Fluid Surface Rendering in CUDA

Shading

Use Fresnel Environment Mapping

Use Cube Texture Reflection

Cube Mapping texture acces Refraction

Cube Mapping texture access

)),,(,(

).().()).(1(),( yxT

fluid

sfinal

etstexfetchClerpa

hnkvnbFvnFaC

a = refracted color

b = reflected scene color

T = thickness function

Page 21: Fluid Surface Rendering in CUDA

Results - Particles

Page 22: Fluid Surface Rendering in CUDA

Results - Mesh

Page 23: Fluid Surface Rendering in CUDA

Results - Phong

Page 24: Fluid Surface Rendering in CUDA

Results - Reflection

Page 25: Fluid Surface Rendering in CUDA

Results - Refraction

Page 26: Fluid Surface Rendering in CUDA

Results – Refraction and Reflection Mixed

Page 27: Fluid Surface Rendering in CUDA

Results – Refraction and Reflection Mixed

Page 28: Fluid Surface Rendering in CUDA

Results – Final Rendering

Page 29: Fluid Surface Rendering in CUDA

Results – Final Rendering

Page 30: Fluid Surface Rendering in CUDA

Conclusion

The user was able to render a fluid with physical effects.

CUDA marching cubes proved to be fast.Difficulty in obtaining a scalar field.

Can calculate normals per vertex.

Page 31: Fluid Surface Rendering in CUDA

References

NVIDIA´s Notes on Parallel Marching Cubes Algorithm.

Screen Space Fluid Rendering with Curvature Flow, Simon Green , NVIDIA. Retrieved Jun 25, 2010.

LORENSEN, W. E., AND CLINE, H. E. 1987. Marching cubes: A high resolution 3d surface construction algorithm. SIGGRAPH, Comput. Graph. 21, 4, 163–169.

Real-Time Animation of Water, Takashi Amada.

NVIDIA CUDA Programming Guide. V. 2.0, 2008. Retrieved Mar 29, 2010.