← Back to context

Comment by nonameiguess

4 months ago

I'm not a game dev, but what's a straightforward way of adjusting some channel of a pixel at coordinate X,Y without indexing the underlying raster array? Iterators are fine when you want to perform some operation on every item in a collection but that is far from the only thing you ever might want to do with a collection.

Game dev here. If you’re concerned about performance the only answer to this is a pixel shader, as anything else involves either cpu based rendering or a texture copy back and forth.

  • A compute shader could update some subset of pixels in a texture. It's on the programmer to prevent race conditions though. However that would again involve explicit indexing.

    In general I think GP is correct. There is some subset of problems that absolutely requires indexing to express efficiently.

    • You can manipulate texture coordinate derivatives in order to just sample a subset of the whole texture on a pixel shader and only shade those pixels (basically the same as mipmapping, but you can have the "window" wherever you want really).

      This is something you can't do on a compute shader, given you don't have access to the built-in derivative methods (building your own won't be cheaper either).

      Still, if you want those changes to persist, a compute shader would be the way to go. You _can_ do it using a pixel shader but it really is less clean and more hacky.

      4 replies →

    • You're right - I should have just said "shader" and left it at that.

      > There is some subset of problems that absolutely requires indexing to express efficiently.

      Sure. But it's almost certainly quicker to run a shader over them, and ignore the values you don't want to operate on than it is to copy the data back, modify it in a safe bounds checked array in rust, and then copy it again.

      1 reply →