rendering countless blades of waving grass

24
Rendering Countless Blades of Waving Grass Jeff Schmidt CS 680

Upload: rufus

Post on 23-Feb-2016

27 views

Category:

Documents


0 download

DESCRIPTION

Jeff Schmidt CS 680. Rendering Countless Blades of Waving Grass. Project Problem. Nature scenes are a prevalent topic in computer graphics (for example, computer games) - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: Rendering Countless Blades of Waving Grass

Rendering Countless Blades of Waving Grass

Jeff SchmidtCS 680

Page 2: Rendering Countless Blades of Waving Grass

Project Problem

Nature scenes are a prevalent topic in computer graphics (for example, computer games)

In addition, to realistic trees and flowing water effects, we want to render a high-quality grass effect in real-time that looks realistic from all angles

Page 3: Rendering Countless Blades of Waving Grass

Project Problem

In general, grass needs to cover a vast amount of the scene. This makes modeling each individual blade of grass with polygons unrealistic

A simple, flat grass texture will only look realistic from certain angles

Page 4: Rendering Countless Blades of Waving Grass

Solution

We create a “star” organization of quads and cover them with grass textures

Page 5: Rendering Countless Blades of Waving Grass

Solution

The star formation gives us the same effect no matter which side of the grass object we are viewing

Page 6: Rendering Countless Blades of Waving Grass

SolutionFinally, we want to simulate a wind

effect to make the grass feel more realistic

To simulate the blowing of grass, we shift the upper vertices of our grass object

Page 7: Rendering Countless Blades of Waving Grass

My implementation

I have implemented both a CPU only and a GPU version of the program

I use OpenGL/GLUT for rendering

I used the GPU to speed up various tasks

Page 8: Rendering Countless Blades of Waving Grass

My implementation

I have been running my project on double/float

CPU: Intel(R) Xeon(R) CPU GPU: GeForce GTX 580

Timings were taken using cudaEvent’s

No compiler flags

Page 9: Rendering Countless Blades of Waving Grass

Where I use the GPU – Texture Loading

For the grass texture, I use .ppm files for their simple r, g, b, r, g, b,… file format

However, ppm files do not support an alpha channel

Solution: Pick a color that does not appear in any textures and fill the background with it. Then parse the texture file, and fill in alpha values where you used the “transparent” color

Page 10: Rendering Countless Blades of Waving Grass

Where I use the GPU – Texture Loading

Each (r, g, b) triple is independent, therefore, splitting it amongst threads is simple

We only read each r, g, b value once, and we only write each alpha value once

Therefore, I used zero-copy host memory to eliminate copying the texture from the CPU to the GPU and back

Page 11: Rendering Countless Blades of Waving Grass

Where I use the GPU – Texture Loading

Experiment ran with varying texture sizes. GPU version has 64 blocks, 64 threads

100 200 300 400 5000

100200300400500600700800900

Timings

Texture dimensions

Time (ms)

CPU

GPU

Page 12: Rendering Countless Blades of Waving Grass

Where I use the GPU – Texture Loading

100 200 300 400 5000

0.2

0.4

0.6

0.8

1

1.2

1.4

1.6

GPU - Speedup

Texture dimensions

Speedup

Page 13: Rendering Countless Blades of Waving Grass

Where I use the GPU – Scene InitializationAgain, each grass object is

independent of one another, therefore, each thread can create it’s own set of grass objects in parallel

Each grass object has an initial position that is perturbed by some random value, which gives slightly non-uniform distribution

PROBLEM: Creating a random number on the GPU

Page 14: Rendering Countless Blades of Waving Grass

Where I use the GPU – Scene Initialization

To generate random numbers, I create an array on the host filled with random numbers

Then I place the array in texture memory

Each block/thread indexes into the texture to retrieve the desired random numbers

Page 15: Rendering Countless Blades of Waving Grass

Where I use the GPU – Scene InitializationExperiment ran with varying numbers of grass

objects. GPU version has 64 blocks, 64 threads

10000 20000 30000 40000 500000

102030405060708090

100

Timings

Number of Grass Objects

Time (ms)

CPU

GPU

Page 16: Rendering Countless Blades of Waving Grass

Where I use the GPU – Scene Initialization

10000 20000 30000 40000 500001.351.4

1.451.5

1.551.6

1.651.7

1.751.8

1.85

GPU - Speedup

Number of Grass Objects

Speedup

Page 17: Rendering Countless Blades of Waving Grass

Where I use the GPU – Wind Simulation

Create random wind vectors crossing the viewing area

Calculate vector to shift the grass objects by measuring their distance from wind vector

After the wind blows, “spring” back towards resting position

Include some slight randomness, so that all grass doesn’t move exactly the same speed/direction

Page 18: Rendering Countless Blades of Waving Grass

Where I use GPU – Wind Simulation

Unfortunately, due to time, I was unable to simulate wind

Instead, my grass objects wave randomly

Page 19: Rendering Countless Blades of Waving Grass

Where I use the GPU – Wind Simulation My “wind” simulation actually runs

slower on the GPU version, due to creating the texture of random numbers and copying them to the GPU

For this reason, I did not include any timings

For a more in-depth wind simulation, the GPU version would likely out-perform the CPU

Page 20: Rendering Countless Blades of Waving Grass

Lessons Learned

Strategies to get random numbers from the GPU: Store them in a texture generated by the

host Implement a simple psuedo-random

number generator that runs on the GPU (example: linear congruential generators)

Page 21: Rendering Countless Blades of Waving Grass

Lessons Learned

I got to implement some new (for me) CUDA features Zero-copy host memory – used for

updating my textures with transparency Texture memory – used for storing

random numbers and passing them to the GPU

Use __host__ __device__ for functions you want on both the CPU and GPU

Page 22: Rendering Countless Blades of Waving Grass

Future Improvements

I would have liked to use CUDA’s interoperability features with OpenGL to have the GPU render the scene without going through the CPU

I would have liked to explore CUDA streams for overlapping of GPU calculations and memory copying

Page 23: Rendering Countless Blades of Waving Grass

Future Improvements

Due to time constraints, I was unable to implement wind simulation. I would have liked to use a real simulation formula and better grass textures to make the scene look more realistic

Page 24: Rendering Countless Blades of Waving Grass

A screenshot