GPU Particles: Simulation and Rendering Techniques, Study notes of Computer Science

Various techniques for simulating and rendering particles on the gpu. It covers particle simulation on both the vertex and fragment processors, the use of fbos for ping-ponging buffers, and methods for copying data from gpu to cpu and back for render-to-vertex buffer mechanisms. The document also touches upon water simulation and rendering, including reflections, refractions, and caustics.

Typology: Study notes

Pre 2010

Uploaded on 07/31/2009

koofers-user-6g3
koofers-user-6g3 ๐Ÿ‡บ๐Ÿ‡ธ

9 documents

1 / 45

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Particles on the GPU
๎€ŠParticle simulation
๎€ŠVertex processor
๎€ŠFragment processor
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22
pf23
pf24
pf25
pf26
pf27
pf28
pf29
pf2a
pf2b
pf2c
pf2d

Partial preview of the text

Download GPU Particles: Simulation and Rendering Techniques and more Study notes Computer Science in PDF only on Docsity!

Particles on the GPU

๎€Š Particle simulation

๎€Š (^) Vertex processor ๎€Š (^) Fragment processor

Particle simulation on the vertex processor

๎€Š Most intuitive approach

๎€Š (^) Particles are point primitives ๎€Š (^) Can use vertex attributes to store particle state ๎€Š

No write access to memory

๎€Š (^) gl_Vertex does not change

๎€Š Geometry shader can write to memory...

FBO

Ping-ponging buffers

No simultaneous read-write access to texture memory

๎€Š Cannot do this:

๎€Š

Can't read from texture attached to currently bound FBO.

๎€Š Can't render to a texture currently bound to

GL_TEXTURE_2D

VP FP Texture

FBO

Ping-ponging buffers

No simultaneous read-write access to texture memory

๎€Š (^) No error, but results of the read are undefined ๎€Š (^) Use ping-ponging ๎€Š (^) Drawbacks: ๎€Š (^) storage requirements double ๎€Š (^) Overhead of swapping VP FP Tex 2 Tex 1 FBO VP FP Tex 1 Tex 2 Even iterations Odd iterations

Updating particle positions

๎€Š Particle state stored in texels of a FP texture

๎€Š

We want to only update each particle once per frame

๎€Š Need a 1-1 correspondence between texels and fragments

Draw a view aligned textured quadrilateral

glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(0.0f, 1.0f, 0.0f, 1.0f, 0.0f, 1.0f); glViewport(0, 0, TexSizeU, TexSizeV); glBegin(GL_QUADS); glTexCoord2f(0.0, 0.0); glVertex2f(0.0, 0.0); glTexCoord2f(1.0, 0.0); glVertex2f(1.0, 0.0); glTexCoord2f(1.0, 1.0); glVertex2f(1.0, 1.0); glTexCoord2f(0.0, 1.0); glVertex2f(0.0, 1.0); glEnd();

Particle simulation on the fragment processor

๎€Š In fragment shader

๎€Š (^) Read attributes ๎€Š (^) Update attributes ๎€Š (^) Write attributes to FBO attached textures. uniform sampler2D Pos2D; uniform sampler2D Vel2D; uniform float StepSize; uniform mat4 ScaleBiasP; uniform mat4 ScaleBiasV; void main() { vec4 pos0 = ScaleBiasPtexture2D(Pos2D, gl_TexCoord[0].st); vec4 vel0 = ScaleBiasVtexture2D(Dir2D, gl_TexCoord[0].st); vec4 vel1 = UpdateVelocity(vel0); vec4 pos1 = pos0 + StepSize*vel1; gl_FragData[0] = pos1; gl_FragData[1] = vel1; }

Render-to-vertex buffer

๎€Š Approach one: glReadPixels()

๎€Š (^) Slow GPU-CPU copy ๎€Š

Approach two: Pixel buffer objects (PBO)

๎€Š (^) Fast GPU-GPU copy

๎€Š Approach three: Vertex Texture Fetch

๎€Š (^) Look up position in texture during vertex processing

Render-to-vertex buffer : Approach 1

๎€Š Copy from GPU-CPU,

๎€Š

Then copy from CPU-GPU

๎€Š Slowest - don't need to do this anymore

๎€Š (^) glReadBuffer(GL_COLOR_ATTACHMENTn_EXT); ๎€Š (^) glReadPixels(0, 0, w, h, format, type, &data); ๎€Š (^) glBindBuffer(GL_ARRAY_BUFFER, vbo_id); ๎€Š (^) glBufferData(GL_ARRAY_BUFFER, size, &data, GL_STREAM_DRAW);

Render-to-vertex buffer : Approach 2

๎€Š Fast GPU-GPU copy using PBO

๎€Š (^) glReadBuffer(GL_COLOR_ATTACHMENTn_EXT); ๎€Š (^) glBindBuffer(GL_PIXEL_PACK_BUFFER_EXT, vbo_id); ๎€Š (^) glReadPixels(0, 0, w, h, format, type, 0); ๎€Š (^) glBindBuffer(GL_PIXEL_PACK_BUFFER_EXT, 0);

Render-to-vertex buffer : Approach 3

๎€Š Vertex texture fetch (VTF)

๎€Š (^) In shader model 3.0 (GeForce 6 Series and newer) ๎€Š

Set up

๎€Š (^) Create a VBO for 2D points ๎€Š (^) Set point locations to be texture coordinates const int w = 256; const int h = 256; float data = new float[2wh]; for(int i=0; i<w; i++) for(int j=0; j<h; j++) { data[2(ih+j)] = (float)i/w; data[2(ih+j)+1] = (float)j/h; } glBindBuffer(GL_ARRAY_BUFFER, vbo_id); glBufferData(GL_ARRAY_BUFFER, wh2sizeof(float), data, GL_STATIC_DRAW); glVertexPointer(2, GL_FLOAT, 0, BUFFER_OFFSET(0));

GPU Particles Overview

๎€Š Init: FBO, โ€œoldโ€ and โ€œnewโ€ floating point textures for particle

attributes, VBO

๎€Š

Pass 1 : Compute positions

๎€Š (^) OpenGL: render view-aligned quadrilateral ๎€Š (^) FP : Read particle position from โ€œoldโ€ texture ๎€Š (^) FP : Write particle position to โ€œnewโ€ texture

๎€Š Pass 2: Render particles

๎€Š (^) VP : Read gl_Position from โ€œnewโ€ texture ๎€Š (^) FP : Render particles ๎€Š

Swap โ€œoldโ€, โ€œnewโ€ texture IDs

๎€Š Goto Pass 1

Water simulation and rendering

๎€Š Water simulation / animation

๎€Š (^) Water and fluid simulation ๎€Š (^) Surface waves ๎€Š (^) Sine waves ๎€Š (^) Modified sine waves ๎€Š (^) Gerstner waves ๎€Š

Water rendering

๎€Š (^) Fresnel's Law ๎€Š (^) Snell's Law ๎€Š (^) Lambert-Beer Law ๎€Š (^) Caustics

Water animation

๎€Š Water surface = mesh displaced by height map

๎€Š (^) No splashes ๎€Š (^) Simple model for real-time water ๎€Š (^) No FFT M. Finch, Effective Water Simulation from Physical Models, GPU Gems,

J. Guardado, Rendering Water Caustics, GPU Gems, 2004. (online http://developer.download.nvidia.com/books/HTML/gpugems/gpugems_ch01.html) Hinsinger, D. and Neyret, F. and Cani, M.P., Interactive animation of ocean waves, Proceedings of the 2002 ACM SIGGRAPH/Eurographics symposium on Computer animation, pp. 161-166, 2002. Tessendorf, J., Simulating ocean water, Siggraph Course Notes, 1999.

Waves

๎€Š Sum of sine waves

๎€Š ๎€Š (^) A : amplitude ๎€Š (^) w: frequency ๎€Š (^) D : direction crest travels in x-y plane ๎€Š (^) phi: speed ๎€Š (^) Simple to compute tangent, bitangent, normal

H ๎‚ž x , y ,t ๎‚Ÿ=โˆ‘

i = 1 n Ai sin ๎‚ž wi Di โ‹…

[

x

y ]

๎‚ƒ๎ƒ‹ i t ๎‚Ÿ