Wolfram Function Repository
Instant-use add-on functions for the Wolfram Language
Function Repository Resource:
Generate a normal texture from height data
ResourceFunction["NormalTexture"][data] gives the normal texture for the height data data. | |
ResourceFunction["NormalTexture"][data, s] gives the normal texture with relative strength s. | |
ResourceFunction["NormalTexture"][data, s, r] uses a kernel radius of r. | |
ResourceFunction["NormalTexture"][data, {sx, sy}, {rx, ry}] uses separate strengths and radii for the horizontal and vertical directions. |
"Sobel" | binomial generalizations of the Sobel edge-detection kernels |
"Gaussian" | standardized Gaussian derivative kernel |
"ShenCastan" | first-order derivatives of exponentials |
{0, 1} | the {x,y,z} values of each normal are rescaled from {-1,1} to {0,1} |
{-1, 1} | no rescaling is applied |
{min, max} | values are rescaled from {-1, 1} to {min,max} |
Normal texture from a grayscale image:
In[1]:= |
|
Out[1]= |
|
Normal texture from array data:
In[2]:= |
|
Out[2]= |
|
Normal texture from a height map (CC0 source):
In[3]:= |
|
Out[3]= |
|
Apply the normal texture to a polygon (MaterialShading requires Wolfram Language 12.3):
In[4]:= |
|
Out[4]= |
|
Use elevation data of real world locations:
In[5]:= |
|
Out[5]= |
|
Use textures:
In[6]:= |
|
Out[6]= |
|
In[7]:= |
|
Out[7]= |
|
Use graphics:
In[8]:= |
|
Out[8]= |
|
In[9]:= |
|
Out[9]= |
|
Create normal textures with varying strengths:
In[10]:= |
|
Out[10]= |
|
Use different vertical and horizontal strengths:
In[11]:= |
|
Out[11]= |
|
Negative strength values reverse the normal direction:
In[12]:= |
|
Out[12]= |
|
Create normal textures using increasing radii:
In[13]:= |
|
Out[13]= |
|
Use different vertical and horizontal radii:
In[14]:= |
|
Out[14]= |
|
Compute the horizontal and vertical derivatives using the default Sobel method:
In[15]:= |
|
Out[15]= |
|
Use the Gaussian method:
In[16]:= |
|
Out[16]= |
|
Use custom kernels for computing the derivatives:
In[17]:= |
|
Out[17]= |
|
Compare different methods with increasing kernel radii:
In[18]:= |
|
Out[18]= |
|
By default, a "Fixed" padding is used when convolving the input image:
In[19]:= |
|
Out[19]= |
|
Pad with one:
In[20]:= |
|
Out[20]= |
|
No padding results in a smaller image:
In[21]:= |
|
Out[21]= |
|
By default, the channels in the output are rescaled to be between 0 and 1:
In[22]:= |
|
Out[22]= |
|
Use the range -1 to 1 to leave the normal vectors unscaled:
In[23]:= |
|
Out[23]= |
|
In[24]:= |
|
Out[24]= |
|
NormalTexture produces normal textures compatible with MaterialShading (requires Wolfram Language 12.3):
In[25]:= |
|
Out[25]= |
|
The red and green channels of the normal texture correspond to the horizontal and vertical derivatives of the input image:
In[26]:= |
|
Out[26]= |
|
In[27]:= |
|
Out[27]= |
|
In[28]:= |
|
Out[28]= |
|
NormalTexture calculates derivatives similarly to GradientFilter:
In[29]:= |
|
Out[29]= |
|
By default, the components of each normal vector are rescaled, causing them to no longer be unit length vectors:
In[30]:= |
|
Out[30]= |
|
Use an output range of -1 to 1 to leave the normal vectors unscaled and unit length:
In[31]:= |
|
Out[31]= |
|
Create a normal texture for the Earth:
In[32]:= |
|
Out[32]= |
|
Apply it to the unit sphere to simulate Earth's terrain (MaterialShading requires Wolfram Language 12.3):
In[33]:= |
|
Out[33]= |
|
Visualize the normal directions across the implied surface:
In[34]:= |
|
Out[34]= |
|
This work is licensed under a Creative Commons Attribution 4.0 International License