A very simple normal map generator written as a single header library.
Features:
- Convert color buffer to greyscale using either lightness, average or luminance methods(with SSE/AVX versions available)
- Convert greyscale buffer to a normal map with gaussian blur pre-filtering
typedef enum
{
sinm_greyscale_none,
sinm_greyscale_lightness,
sinm_greyscale_average,
sinm_greyscale_luminance,
sinm_greyscale_count,
} sinm_greyscale_type;
void sinm_greyscale(const uint32_t *in, uint32_t *out, int32_t w, int32_t h, sinm_greyscale_type type);
uint32_t *sinm_normal_map(const uint32_t *in, int32_t w, int32_t h, float scale, float blurRadius, sinm_greyscale_type greyscaleType);
#define SI_NORMALMAP_IMPLEMENTATION
#include "si_normalmap.h"
int main()
{
uint32_t *image = //...load pixels from some image;
uint32_t *nm = sinm_normal_map(image, imageWidth, imageHeight, 1.0f, 2.0f, sinm_greyscale_average);
//... write normalmap to a file
return 0;
}
Input:
Output:
Comparison of lighting without and with normal map(and a second "detail" normal map)