Help with explosion shader alpha

Godot Version

4.2

I’m following a tutorial for a an explosion shader from Godot 3, but I’m trying to adapt it to Godot 4. I’m using a fractal noise textures output and multiplying it by a float which i change, with the expectation that when the float is increased, the alpha should fill in the transparency 100%. However, it never seems to fill in completely, and instead seems to affect the luminance of the model, and I can see a new brighter fractal pattern applied. Any idea what I’m doing wrong?

Thanks


Let’s take a look at what your shader does currently.

As a first step, you’re multiplying the noise texture by a floating-point number. Because the noise texture’s values is in the range of [0, 1], the brighter pixels become brighter while the dark pixels remain dark (e.g. 0 * 6.604 = 0). It is for this reason that holes are present in your shader; the pixels remain at a value near zero.

A side-effect of multiplying the noise texture by a number is that the brighter pixels ventures outside the expected value range for the alpha channel ([0, 1]). If I recall correctly, this can create visual artefacts (in your case, the altered luminance) and must be fixed via a clamping operation or similar.

Depending on the effect you wish to achieve, you should alter your shader in the following manner.

Alpha Cutout

If your goal is to produce a bitmask (a black and white texture, no grey values) for means of showing/hiding the object, you should perform a threshold operation on your noise texture. You can do this with the Step node.

Alpha Cutout Example

Smooth Mask

If your goal is to produce a smooth transition from opaque to transparent, the method is somewhat the same:

  1. Use the SmoothStep node instead of the Step node
  2. Define a blend-value which expands the interpolation range for the SmoothStep node
    2.1 edge0 = threshold - (blend / 2.0)
    2.2 edge1 = threshold + (blend / 2.0)
Smooth Mask Example

As a final note, remember that the operations you perform in a fragment shader apply to all the pixels of a texture/object. It may help to write down the operations you’re doing (in the form of functions or equations). Visual shader programming is sometimes hard to assess at a glance.

1 Like

Thanks so much for your thorough response! The step node worked perfectly