





































Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
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
1 / 45
This page cannot be seen from the preview
Don't miss anything!






































๎ (^) Vertex processor ๎ (^) Fragment processor
๎ (^) Particles are point primitives ๎ (^) Can use vertex attributes to store particle state ๎
๎ (^) gl_Vertex does not change
FBO
๎
VP FP Texture
FBO
๎ (^) 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
๎
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
๎ (^) 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; }
๎ (^) Slow GPU-CPU copy ๎
๎ (^) Fast GPU-GPU copy
๎ (^) Look up position in texture during vertex processing
๎
๎ (^) 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);
๎ (^) 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);
๎ (^) In shader model 3.0 (GeForce 6 Series and newer) ๎
๎ (^) 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));
๎
๎ (^) OpenGL: render view-aligned quadrilateral ๎ (^) FP : Read particle position from โoldโ texture ๎ (^) FP : Write particle position to โnewโ texture
๎ (^) VP : Read gl_Position from โnewโ texture ๎ (^) FP : Render particles ๎
๎ (^) Water and fluid simulation ๎ (^) Surface waves ๎ (^) Sine waves ๎ (^) Modified sine waves ๎ (^) Gerstner waves ๎
๎ (^) Fresnel's Law ๎ (^) Snell's Law ๎ (^) Lambert-Beer Law ๎ (^) Caustics
๎ (^) 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.
๎ ๎ (^) A : amplitude ๎ (^) w: frequency ๎ (^) D : direction crest travels in x-y plane ๎ (^) phi: speed ๎ (^) Simple to compute tangent, bitangent, normal
i = 1 n Ai sin ๎ wi Di โ
x
๎๎ i t ๎