Manual: TextureUtils Normal Maps

Documentation and discussion for Draconus Texture Utils available in the Unity Asset Store.
snlehton
Crew
Crew
Posts: 16
Joined: Tue Nov 04, 2014 1:59 pm

Manual: TextureUtils Normal Maps

Postby snlehton » Tue Nov 11, 2014 2:33 pm

Manual: TextureUtils Normal Maps
TextureUtils: Slicing | Pixel Operations |Normal Maps | Misc
AtlasGenerator | PSDReader |API Scripting Reference

GenerateNormalMapFromLitMaps (API ➔)

This function generates a normal map from two lit grayscale textures (only red channel is used).

First texture is lit from the left. The intensity of the pixel in the source texture is basically dot product between the surface normal and light coming from left. Dot product values -1...1 are normalized to range 0...1, and that's why gray means that the normal is horizontally facing the view (dot product value 0 gets normalized to 0.5). The dot product is not clamped, and that's why the image contains black color as well which could be considered as black light coming from the right. Same applies to the second, top lit texture.

normalmap_explained.png
normalmap_explained.png (13.82 KiB) Viewed 642 times


These two images are combined to form the normal map. See the details of the algorithm in the source code of TextureUtils.GenerateNormalMapFromLitMaps

Code: Select all

Texture2D normalMap = TextureUtils.GenerateNormalMapFromLitMaps(textureNormalLeft, textureNormalTop);

normalmap_helloworld.png
normalmap_helloworld.png (64.49 KiB) Viewed 642 times


GenerateNormalMapFromHeightMap (API ➔)

This function generates a normal map from a height map texture. Only red channel is used.

For each pixel in the heightmap, values surrounding (left, right, up, down) pixels are read, and both horizontal and vertical deltas are calculated, multiplied with the depth parameter. These deltas are then used to form the normal vector for this particular pixel.

Due to the nature of this algorithm, it's impossible to generate sharp and accurate normal maps. The height map based are useful for situations where subtle normal maps are needed, and they're great for augmenting normal maps calculated by other means (such as from lit maps above).

Code: Select all

Texture2D normalMap = TextureUtils.GenerateNormalMapFromHeightMap(heightmap);


FIGURE HERE

CombineNormalMaps (API ➔)

CombineNormalMaps takes two normal maps, a base and a modifier, and combines them to form a new normal map. The algorithm processes each pixel in the base normal map by taking the base normal and rotating it by the modifier normal. The resulting normal map is calculated using spherical interpolation between the original base normal and the new, modified base normal.

CombineNormalMaps can be used to augment normal maps with other normal maps (for details, dents, bumpiness...).

This function has following properties:
  • Using identity normal map as a modifier (all normals pointing towards the view) equals to the base normal map (no effect): CombineNormalMaps(baseNormalMap, identityNormalMap, xxx) = baseNormalMap;
  • Using identity normal map as a base with blend 1.0 (100%) equals to the modifier normal map: CombineNormalMaps(identityNormalMap, modifierNormalMap, 1.0f) = modifierNormalMap;

combinenmap.jpg
combinenmap.jpg (94.73 KiB) Viewed 642 times



Code: Select all

Texture2D normalMap = TextureUtils.CombineNormalMaps(baseTexture, normalMapFromHeightmap, 1.0f);



====================================================================================
TextureUtils: Slicing | Pixel Operations |Normal Maps | Misc
AtlasGenerator | PSDReader |API Scripting Reference

Return to “DTU - Draconus Texture Utils”

Who is online

Users browsing this forum: No registered users and 1 guest