I'm trying to draw sphere galaxy mentioned in this tutorial: http://martindevans.me/game-development/2016/01/14/Procedural-Generation-For-Dummies-Galaxies/

Here is an image for reference:

enter image description here

Basically, it is just a (3D normally-distributed) set of small (few pixels) spheres.

I believe if I draw it using some primitives (like circle) it would be very slow (drawing thousand of circles every frame would be too expensive even in pure opengl). So I've decided to write a small shader for that purpose. It should be pretty simple, but I don't even know where to start.

I'm completely new to shader programming. I know how to run shader program, the basic terms, etc, so, for example, I can draw a circle on a screen with given radius, nothing more.

Can you, please, tell me where to start? I've searched shadertoy, but can't find any suitable example. I believe it should be pretty easy to write this, may be I'm just missing some conceptions.

Thanks in advance.

  • 2
    \$\begingroup\$ The tutorial you link to doesn't use a special shader for this. It does exactly what you propose "would be very slow": plotting each star as its own independent primitive, and it seems to run fine on my several-years-old phone. So you might be optimizing prematurely here. If you want to proceed with a shader-based approach, can you outline at least a little about the strategy you want to use? (eg. will this be rendered as an image effect on a quad, or on particular shaped geometry? Does it need to support motion/a moving perspective? Etc. \$\endgroup\$ – DMGregory Jan 14 '18 at 18:40
  • \$\begingroup\$ @DMGregory, sorry for a delay: the library I'm using (SFML) only provides a 2D primitives. I can probably achieve that using particles system, but then particles will be just pixels (points) where I want it to be a small primites (e.g. spheres, having several pixels radius). I also can imagine doing that in pure opengl, but I'm not sure how to apply post-processing then for each primitive in a group. \$\endgroup\$ – despero Jan 15 '18 at 19:18
  • \$\begingroup\$ Regarding to shaders:I want jsut generate (with normal distribution) a set of small bright circles ("stars") so they create an irregular sphere. Later, I'll render this as a rectangle on top of my window. Take a look at this example: shadertoy.com/view/llSGR1 It is very similar to what I want to achieve. \$\endgroup\$ – despero Jan 15 '18 at 19:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.