float compute_height_field(int x, int y) { float ht = AVG_GROUND; #if 1 float weight=0; int o; weight = (float) stb_linear_remap(stb_perlin_noise3(x/256.0f,y/256.0f,100,256,256,256), -1.5, 1.5, -4.0f, 5.0f); weight = stb_clamp(weight,0,1); for (o=0; o < 8; ++o) { float scale = (float) (1 << o); float ns = stb_perlin_noise3(x/scale, y/scale, o*2.0f, 256,256,256), heavier; float sign = (ns < 0 ? -1.0f : 1.0f); ns = (float) fabs(ns); heavier = ns*ns*ns*ns*4; ht += scale/2 * stb_lerp(weight, ns, heavier); } #else if (x >= 10 && x <= 50 && y >= 30 && y <= 70) { ht += x; } if (x >= 110 && x <= 150 && y >= 30 && y <= 70) { ht += y; } #endif return ht; }
int main(int argc, char** argv) { enum IrradiantStatus { IRRADIANTSTATUS_BAD, IRRADIANTSTATUS_OK = 2, IRRADIANTSTATUS_GOOD }; char const* name = "Irradiant"; printf("Hello, world from %s", name); if (argc > 1) printf(" and %s", argv[1]); printf("!\n"); for (int i = 0; i < 3; ++i) printf("static_increment: %d\n", static_increment()); if (argc > 3) printf("Sum: %d\n", add(atoi(argv[2]), atoi(argv[3]))); float x = 3.14159, y = 13.37, z = 42.42; printf("Perlin noise at (%f, %f, %f): %f\n", x, y, z, stb_perlin_noise3(x, y, z, 0, 0, 0)); printf("Irradiant status: %d\n", IRRADIANTSTATUS_GOOD); return 0; }
scalar Perlin(Vecf3 const& pos, Veci3 const& wrap) { return stb_perlin_noise3(pos.x(),pos.y(),pos.z(),wrap.x(),wrap.y(),wrap.z()); }