1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89
|
#include <stdio.h>
#include <math.h>
#include <sipp.h>
#include <geometric.h>
#include <noise.h>
/* A reasonably nice brown color */
static Color land = {0.28125, 0.1875, 0.09375};
/* Oceans are usually blue */
static Color sea = {0.0, 0.0, 1.0};
/* And Clouds are white */
static Color cloud = {1.0, 1.0, 1.0};
/*
* This was designed to work with a unit sphere.
*
* Thanks to Jon Buller jonb@vector.dallas.tx.us
*/
double
turb(size, scale_factor, loc)
int size;
double scale_factor;
Vector loc;
{
double cur_scale, result;
int cur;
result = noise(&loc);
cur_scale = 1.0;
cur = 1;
while (cur < size) {
cur <<= 1;
cur_scale = cur_scale * scale_factor;
loc.x *= 2.0;
loc.y *= 2.0;
loc.z *= 2.0;
result += noise(&loc) * cur_scale;
}
return result;
}
extern bool noise_ready;
void
planet_shader(pos, normal, texture, view_vec, lights, sd, color, opacity)
Vector *pos;
Vector *normal;
Vector *texture;
Vector *view_vec;
Lightsource *lights;
Surf_desc *sd;
Color *color;
Color *opacity;
{
Vector tmp;
double amt;
if (!noise_ready) {
noise_init();
}
VecCopy(tmp, *texture);
if (turb(430, 0.7, tmp) > 0.15)
sd->color = land;
else
sd->color = sea;
VecScalMul(tmp, 12.0, tmp)
amt = turb(18, 0.6, tmp);
if (amt > -0.25) {
amt += 0.25;
sd->color.red += amt * (cloud.red - sd->color.red);
sd->color.grn += amt * (cloud.grn - sd->color.grn);
sd->color.blu += amt * (cloud.blu - sd->color.blu);
}
basic_shader(pos, normal, texture, view_vec, lights, sd,
color, opacity);
}
|