Advertisement Jump to content
Sign in to follow this  

Indirect references in a compute shader

This topic is 1419 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi guys,


I'm trying to make a waterfall particle system for a large hexagonal game board, and I've seen some impressive examples of systems using the compute shader for particle generation and update. This will be my first compute shader algorithm however, and my needs are more complex than available samples.


First let me explain the problem area and the constraints I'm dealing with:


1.)I'm making a large map out of map chunks arranged in a 2D grid. Each map chunk can have many waterfalls or few waterfalls and most will have even no waterfalls at all.


2.)A single waterfall is represented by a line segment that spawns particles, and has no connection to any other waterfall.


3.)I only want to process particles in chunks that are close to the camera. As the camera moves the chosen chunks will change.


If I create fixed length buffers per chunk of this information, I will be wasting a ton of video memory because I might need to store a lot of info per chunk but in most cases very little or none. The problem then is that variable length buffers don't lend themselves well to assigning threads in a compute shader and they don't preserve the grid organization of the overall map.


So I need a scheme that allows me to organize references to variable length data in a grid pattern. I have an idea of how it might be possible, but it's going to require a lot of ugly, error prone math. I plan to dump all the waterfalls in the world into a ByteAdressBuffer and then use another fixed width structured buffer grid with each cell containing the byte offset and structure length and count of the appropriate data for a chunks worth of waterfalls.


So for each thread/particle, I would randomly choose a grid chunk within the appropriate range of the camera, then randomly choose a waterfall from the byte offset and struct count, then load in the waterfall struct with combinations of Load4, Load2 etc.(I guess you need explicit type casting in the hlsl code?) then randomly choose a point on the waterfall for the particle. Yuck!


Is there a cleaner way to achieve this kind of indirection in a compute shader, or is this the only way? Debugging this will be hard for me because I'm still on Windows 7 and VS Express.


EDIT: It occurs to me that since each waterfall uses the same structure, I could just use a structured buffer instead of a byte address buffer and put indices in the grid instead of byte offsets. Hey, I helped myself! Somebody give me an upvote.

Edited by cephalo

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using, you agree to our community Guidelines, Terms of Use, and Privacy Policy. is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!