Skip to content

Bug in GLSL code for examples/Topics/Shaders/Nebula  #20

Open
@pjfordham

Description

Issue description

When you run this example, opaque black regions occasionally appear in the visualization. This appears to be caused by the surface3 function returning values larger than 1.0 due to the way it sums various different frequencies of noise. When the value is larger than 1.0 the calculated color can end up negative which results in the opaque black sections.

URL(s) of affected page(s)

Proposed fix

float surface3 ( vec3 coord, float frequency ) {

float n = 0.0;	
	
n += (0.5     + 0.00625) * abs( cnoise4( coord * frequency ) );
n += (0.25    + 0.00625) * abs( cnoise4( coord * frequency * 2.0 ) );
n += (0.125   + 0.00625) * abs( cnoise4( coord * frequency * 4.0 ) );
n += (0.0625  + 0.00625) * abs( cnoise4( coord * frequency * 8.0 ) );
n += (0.03125 + 0.00625) * abs( cnoise4( coord * frequency * 16.0 ) );

return n;
}

This suggested new version of surface3 ensures that the return value is never greater than 1 by weighting the noise frequencies more appropriately. I have reduced the main weighting of each frequency by half and added back a small extra bit to ensure the total of all the weights is 1, while maintaining approximately the same intended distribution.

The result is a little more nebula heavy than the original so more tweaking might be needed by those with a better eye for graphic design than me.

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions