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 90 91 92 93 94
|
/**
** sipp - SImple Polygon Processor
**
** A general 3d graphic package
**
** Copyright Equivalent Software HB 1992
**
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation; either version 1, or any later version.
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
** You can receive a copy of the GNU General Public License from the
** Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
**/
/**
** marble.c - Marble shader: simulates marble using noise & turbulence
**/
#include <math.h>
#include <stdio.h>
#include <sipp.h>
#include <noise.h>
#include <shaders.h>
#include <geometric.h>
extern bool noise_ready;
static void
marble _ANSI_ARGS_((Vector *p,
Color *color,
Marble_desc *md));
static void
marble(p, color, md)
Vector *p;
Color *color;
Marble_desc *md;
{
double x, t;
x = p->x + turbulence(p, 7) * 5;
x = sin(x);
if (x > -0.1 && x < 0.1) {
color->red = md->strip.red;
color->grn = md->strip.grn;
color->blu = md->strip.blu;
} else if (x > -0.9 && x < 0.9){
/* You are not supposed to understand this... */
t = 7.0 / 6.0 - 1.0 / (6.25 * fabs(x) + 0.375);
color->red = md->strip.red + t * (md->base.red - md->strip.red);
color->grn = md->strip.grn + t * (md->base.grn - md->strip.grn);
color->blu = md->strip.blu + t * (md->base.blu - md->strip.blu);
} else {
color->red = md->base.red;
color->grn = md->base.grn;
color->blu = md->base.blu;
}
}
void
marble_shader(pos, normal, texture, view_vec, lights, md, color, opacity)
Vector *pos;
Vector *normal;
Vector *texture;
Vector *view_vec;
Lightsource *lights;
Marble_desc *md;
Color *color;
Color *opacity;
{
Vector tmp;
Surf_desc surface;
if (!noise_ready) {
noise_init();
}
VecScalMul(tmp, md->scale, *texture);
marble(&tmp, &surface.color, md);
surface.ambient = md->ambient;
surface.specular = md->specular;
surface.c3 = md->c3;
surface.opacity = md->opacity;
basic_shader(pos, normal, texture, view_vec, lights, &surface,
color, opacity);
}
|