this post was submitted on 19 Jan 2025
37 points (100.0% liked)

gamedev

359 readers
12 users here now

Game Development

Free Resources List

founded 2 years ago
MODERATORS
 

I was trying to process a database of star data and export it to a texture which I could then use in a sky shader (instead of pre-rendering a cube map like a rational person), but Pillow does not seem to work well with color channels greater than 8 bits, so I thought... what if I just inline hundreds of kilobytes of data in an array? This isn't variable data. It doesn't need to be a uniform. It is not like the game is going to run long enough for these stars to move.

I have a feeling this won't work, but I want to see if it will almost work. The shader compiles and runs, though it is not yet processing this data. It takes a pretty long time to compile though. Every time I type in the Godot shader editor the CPU cooling fans spin up to maximum. The editor also seems to really hate text files where lines are 340,000 columns long

Update: It took about five minutes to render one frame, and then Godot crashed.

you are viewing a single comment's thread
view the rest of the comments
[โ€“] Zezzy@hexbear.net 6 points 1 month ago* (last edited 1 month ago) (1 children)

Idk what Pillow is or how it exports, but you could use GDScript to save it as an image with a 32 bit color depth. Then it would run slow just once.

var image := Image.create(width, height, false, Image.FORMAT_RGBF)
for i in range(0, stars_x.size()):
	var color := Color(stars_x[i], stars_y[i], stars_z[i])
	var pixel_coord: Vector2i = get_pixel_coord(i) # however you want
	image.set_pixelv(pixel_coord, color)
image.save_exr("user://my_file.exr") # or save_png, I think both support f32 color components

That's actually not a bad idea. thinkin-lenin

Pillow is basically the official unofficial image processing library for Python. I needed a script to sift through a dataset and sort it by criteria like magnitude (brightness) first before trimming it down (the full data set is like 140MB), so it just made sense to try to spit an image out of there. It's irrelevant though.

No matter how I get this data into the shader, the bottleneck is going to be iterating through this list for each pixel. I got it running with 1024 stars, but it turns into to a slide show at 4K. I'm sure this can be made to work in realtime, but a sky shader is probably not the technique. I might consider particles.

Anyway, it did get me some mediocre visuals