So, I recently delved into Texturing and Modeling: A Procedural Approach and started writing my first procedural textures in GLSL. Which gives me most of the headaches, although this is the topic of smoothing . Obviously, this is done in simple cases, such as very regular patterns (analytical averaging using integration) or spectral synthesis (frequency clamp), but whenever this is something else, none of the methods work.
I have the following code, which is only part of the texture of the procedure tree (tree):
vec4 TreeTexCompute(in vec2 sp) { const float holeFrequency = 1.0; const vec2 holeThreshold = vec2(0.6, 0.85); vec2 vfw = fwidth(sp); float fw = max(vfw.x, vfw.y); float holeNyquist = 0.5 * holeFrequency * (1.0 / fw); // Upper bound for the frequencies in the function to compute 'hole' below float holeHighestFreq = 1.0 / (0.5 * (holeThreshold.y-holeThreshold.x)); // Spawn a hole where gnoise has its "maximum" values float hole = smoothstep(holeThreshold.x, holeThreshold.y, gnoise(vec3(sp*holeFrequency, -3.75))*0.5 + 0.5); // Gradually fade out the hole as we approach the nyquist frequency float t = mix(hole, 0.0, smoothstep(0.5*holeNyquist, holeNyquist, holeHighestFreq)); return vec4(t, t, t, 1.0); }
What he does is accidentally put small “holes”, passing the output of Perlin-style gradient noise ( float gnoise(vec3) ) to the smoothstep function, creating bright spots only around the maximum gnoise values. Smoothing is performed by gradually decreasing this value to black as we approach the Nyquist frequency. However, it seems that attenuation is happening too soon. . The camera should basically touch the surface of the texture to see all the holes. This does not seem correct, and when I turn off the attenuation, I do not see any overlap until I go further.
So what am I doing wrong? For some time I was thinking about my frequency calculations and could not find anything bad with them. The Nyquist frequency is half the sampling frequency, and the highest frequency (indeed, the upper limit) of the function used to calculate the “hole” is determined by the maximum frequency gnoise (which, it seems to me, is about 2.0) and smoothstep (what if I understand correctly, roughly corresponds to its ramp width).
And by the way: What would you say is the preferred way to smooth out such a texture of randomly placed holes? Fading them out completely is the only thing I could think of, but it’s not, they seem very satisfactory. Supersampling I assume this is just a hack and doesn’t really solve the problem. I use similar methods for delivering compressed gradient noise in the smoothstep function to generate many other features of the wood texture, including large cracks, so for this I really need good smoothing.