Skip to main content

Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
TagsGame Engines
(1 edit)

Ok, now that I can look at your code, here is how to improve your shader and your experience.

First, there are 2 areas to improve in your effect:

  1.  Internal to the shader: your shader code alone.
  2. External to the shader: Ways to improve quality and performance that would require you to change the one (application/engine) invoking your shader.

Starting with Internal only improvements (the easier one):

You have to define a shader version at the beginning :

#version 150

I think 1.5 would be enough for your effect, (I know http://editor.thebookofshaders.com/ does not work with #version, it seems a limitation on their end) but this is important to tell the developer using your shader what GL version your shader needs in order to to run. (you can leave it commented out to make your life easier, but you must indicate it)

Use "in" for function parameters that are read only, they work like C++ const& so it's a small optimization:

vec2 normalizedCoordinates(in vec2 fragCoords)

Use pre-processor defines for consts, I know that is another limitation of the online shader editor you used to create your shader, but keep in mind that if someone is going to use that shader in their game , it will not be using the http://editor.thebookofshaders.com/ compiler, you can keep the global float until you decide your values and then you should make sure they are #defines before you wrap it up.

// instead of:
//float intensity = 0.5;
// use
#define INTENSITY 0.5

Use descriptive names for everything, ( the only exception are heavily optimized equations, in which would require you to explain what you did). So this applies to things like:

... vec3(0.985, 0.786, 0.002) * glow(st, .2), smoothstep( .280, 1.678, ellipse) / intensity)

The vec3(0.985, 0.786, 0.002) should be a #define with a proper name tag so we know what it means.

Lastly, this is more personal, but since you plan to sell code, then I suggest you do new-line after function declaration, makes your code easier to read, specially when you have to deal with large code:

float circle(float radius, vec2 st) 
{     
    ... 
}

Now about external improvements:

These ones would require you to make changes to your shader AND whatever is invoking your shader, so testing it in http://editor.thebookofshaders.com/ online compiler is out of the question here, you will need your own engine/application to do these.

All previous optimizations are like ants close to these one: Your shader is a screen space effect, so it needs a quad to be rendered so your pixel shader can fill in ALL pixels, however the black hole and all its components are not occupying the whole screen, so all pixels outside of the effect itself are just uselessly taking performance.

So you can start rendering a sphere or even better, a impostor circle (one that always faces the camera), and apply the effect onto that surface only. For that you will also need a vertex shader.

From that point, your pixel shader may have some internal optimizations as well, for instance, this function can die:

vec2 normalizedCoordinates(vec2 fragCoords) {     return fragCoords / u_resolution.xy; }

As it only normalizes the screen UVs, whereas your circle should send the pre-normalized tex. coords to your vertex shader up to the pixel shader for you. This means you will not guide the effect via gl_FragCoord, you will use:

in vec2 texCoord;

As a global, indicating a varying coming from your vertex shader.

The glow in your black hole can be applied to the edges of your circle, but the elliptical bloom you do may have to be rasterized as well, You can do it using the same formula to bake your circle, you simply distort it to make an ellipse. 

These of course will have to be combined using blending, so you will need to take advantage of your alpha channel.

Keep in mind that these optimizations are for games, i.e., real time rendering.

Takeaway:

The effect is good, but it's green, there's lots of room for improvement both on quality and performance. Do not reflect your work with the ones out there, respect your learning curve and keep improving, eventually you will surpass them.