Jump to content
How to Install Plugins ×

Texture Smoother


Recommended Posts

Height maps, as used by my Texture Shader plugin, are typically black and white images, where the height corresponds to the intensity. Because there are only 256 intensity levels, the height maps are low precision, which often results in image problems, such as wavy "waterlines." The Texture Shader actually supports 24 bit precision, where the depth is represented by the concatenated red, green, and blue channels. Unfortunately, producing the 24-bit height maps isn't easy. That's the purpose of the Texture Smoother. The Texture Smoother attempts to smooth black-and-white height maps into 24-bit height maps. The method is called "Laplacian smoothing," which amounts to repeatedly replacing each depth with a weighted average of the depths in the immediate neighborhood.


The plugin joins the Texture Shader in the "Effects>Height Map" submenu.


Here is the plugin: TextureSmoother.zip


Here is the user interface:




As the Help menu says:


Texture Smoother smooths a 24-bit height map. Typically, the height map will be originally produced as a gray-scale map, with black pixels representing the lowest values and white pixels the highest. Because there are only 256 different values, the height map is low precision. Texture Smoother applies a smoothing algorithm which modifies each pixel based on nearby pixels. The result is a full-precision 24-bit height map.

The controls are:

Repetitions: Specifies the number of smoothing passes to perform each time the Smooth Texture button is pressed. Increasing the number of repetitions make the texture smoother, but less like the original texture.

Smooth Texture: Initiates the number of smoothing passes specified by Repetitions. Because the texture is not reset when the button is pressed, the button can be repeatedly pressed until the desired smoothness is achieved.

Reset Texture: Resets the texture to its initial state.

Treat Transparent Pixels as Far (Resets texture if changed): Specifies that all transparent pixels are to be treated as if the 24-bit texture value is zero. If this option isn't selected, the actual pixel values are used. Changing the state of this option resets the texture to its initial state.

Don't Move Far Pixels: Specifies that zero-valued pixels are to remain unchanged. This option can be used to prevent smoothing the edge where an object intersects the far plane. The option can be enabled or disabled at any time. This allows a small amount of edge smoothing by performing most, but not all, of the smoothing with the option enabled.

Show Shading (Disable before exiting): Specifies that instead of showing the smoothed texture as a colored image (which is usually not too meaningful), the shaded texture should be shown. To preserve the actual texture for later use, this option must be disabled before exiting. All the controls that follow are used only to control shading, and have no effect of the smoothed texture.

Show All Pixels as Opaque: The transparency of shaded pixels is normally determined by their alpha values. When this option is enabled, all pixels are shown as opaque.

Texture Height Scale: Increases or decreases the texture height.

Ambient Light Intensity: Increases or decreases the intensity of the Ambient Light. Ambient light affects every pixel identically, independent of the gradient.

Directional Light Direction: Sets the direction of the Directional Light. The Directional Light's effect on a pixel is determined by light's direction and the texture's gradient at the pixel. (The control's outer ring currently has no function.)

Directional Light Intensity: Increases or decreases the intensity of the Directional Light. The directional light contributes both diffuse and specular (reflected) light.

Specularity: Determines the shininess of the surface. Increasing this value decreases the diffuse lighting and increases the specular lighting.

Specular Concentration (Exponent): Determines the sharpness of the specular highlights. Higher values produce sharper highlights.


The user interface is slightly unusual in that pressing the Smooth button doesn't start from the beginning image, but instead from the currently smoothed version. I do this because the amount of smoothing required to produce the desired degree of smoothing is quite unpredictable, and over-smoothing can eliminate details. This method allows the user to progressively smooth the texture to the preferred extent.


One very inconvenient feature is that in order to judge the smoothing, the Show Shading option must be enabled; but if the option isn't disabled before exiting the plugin, the result will be the shaded texture, not the texture. Unfortunately, there's currently no (allowed) solution to problem, though there may be in the future. If there is, I'll happily change the plugin to use it.


The Don't Move Far Pixels option is useful for preventing textures, such as the earring texture below, from spreading out. It can sometimes -- or even often -- produce some undesirable wrinkling at the edge, where the object meets the far background. It often helps to first run a few passes with the option disabled, to smooth the edge boundary.


The Treat Transparent Pixels as Far is very useful when the far background is transparent. Most often transparency is represented by "transparent white," which will likely cause problems if this option isn't enabled.


I'll show a couple of examples. First a texture intended to represent a gold earring.


Here is the original texture:



Here is the shaded texture:


As is obvious, the shaded version has waterline anomalies.


Here is the smoothed texture (which required, I believe, 200 smoothing cycles):


Here is the shaded version:



Here is a (low-roughness) Cloud image shaded with the Texture Shader:



Here is the same texture after smoothing (about 25 smoothing passes):





Edited by toe_head2001
Fixed broken Postimg images
  • Upvote 5
Link to comment
Share on other sites

Shochi, I'm not sure why you're not getting the blue color, but I'm pretty sure it's not the Texture Smoother. Perhaps you're trying to use the Texture Smoother to actually draw the shaded image, which is not what it's intended for. The only reason it does any shading is to let you evaluate how well the height map has been smoothed.


Or perhaps you're running the new version of the Texture Shader, and you didn't change the Image source to Clipboard. In the previous version, Clipboard was the default, but in the new version I changed it to White so that the Texture Shader would give a result even if there was no clipboard image.


Or maybe you're trying to smooth the already-shaded image. That's the wrong order of doing it. You need to: 1) create a black-and-white height map (often done by making a black-and white image, then applying blurs to make the sides slope); 2) run the Texture Smoother to smooth the height map (making sure to disable "Show Shading" before exiting!) ; 3) shade the smoothed height map with the Texture Shader.


One thing I'll add is that for the type of height map in your image, which has a relatively flat texture, the Texture Smoother won't give you much advantage, if any. That type of texture works fine as-is with the Texture Shader. The Texture Smoother is intended for "tall" height maps, like the ones in my examples. As a general rule, smoothing the texture won't be necessary unless the Texture Shader's "Texture Height" control is quite high. Or more simply, try the texture without smoothing, and if it has no problems, don't smooth it.

Link to comment
Share on other sites

The smoothing should be done on the texture, not the shaded image. In your example, the Texture Smoother is treating the shaded image as a height map and smoothing it to produce a 24-bit height map (hence the odd colors). Run it on the original black-and-white image instead.


I also suggest you might want to run a small blur on the original texture first. Something like a 2-pixel Gaussian blur. I think it may produce a more interesting shaded image. (As I mentioned previously, I'm not sure that height map will gain much by being smoothed.)

Link to comment
Share on other sites

Yes. The Texture Smoother is for smoothing the height map, not the final image. I think you may want to move the position of the directional light in the Texture Shader. Making the light come from the upper-left generally works well. Or at least I like it.

Link to comment
Share on other sites

  • 2 weeks later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...