OpenCL Procedural Grass and Terrain Example
Last Revision: | Version 1.5, 2011-01-12 Removed the line that caused over-releasing of the "path" object. (Full Revision History) |
Build Requirements: | Mac OS X v10.6 or later |
Runtime Requirements: | Max OS X v10.6 or later |
This example shows how OpenCL can be used to create a procedural field of grass on a generated terrain model which is then rendered with OpenGL. Because OpenGL buffers are shared with OpenCL, the data can remain on the graphics card, thus eliminating the API overhead of creating and submitting the vertices from the host.
All geometry is generated on the compute device, and outputted into a shared OpenGL buffer. The terrain gets generated only within the visible arc covering the camera's view frustum to avoid the need for culling. A page of grass is computed on the surface of the terrain as bezier patches, and flow noise is applied to the angle of the blades to simulate wind. Multiple instances of grass are rendered at jittered offsets to add more grass coverage without having to compute new pages. Finally, a physically based sky shader (via OpenGL) is applied to the background to provide an environment for the grass.
Note that the .cl compute kernel file(s) and shader files (.vert and .frag) are loaded and compiled at runtime. The example source assumes that these files are in the same path as the built executable.
Copyright © 2011 Apple Inc. All Rights Reserved. Terms of Use | Privacy Policy | Updated: 2011-01-12