MCPcopy Create free account
hub / github.com/StereoKit/StereoKit / sdf_create_tex

Function sdf_create_tex

StereoKitC/utils/sdf.cpp:66–80  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

64///////////////////////////////////////////
65
66tex_t sdf_create_tex(int32_t width, int32_t height, float (*sdf)(vec2 pt), float scale) {
67 color32 *data = sk_malloc_t(color32, width * height);
68 float center_x = width / 2.0f - 0.5f;
69 float center_y = height / 2.0f - 0.5f;
70 for (int32_t y = 0; y < height; y++) {
71 int32_t yoff = y * width;
72 for (int32_t x = 0; x < width; x++) {
73 float dist = sdf({ x - center_x, y - center_y });
74 float lerp = 1-math_saturate(dist * scale);
75
76 data[x + yoff] = {255,255,255,(uint8_t)(lerp * 255)};
77 }
78 }
79 return tex_create_color32(data, width, height, false);
80}
81
82///////////////////////////////////////////
83

Callers 1

sdf_create_spriteFunction · 0.85

Calls 2

math_saturateFunction · 0.85
tex_create_color32Function · 0.85

Tested by

no test coverage detected