BRL-CAD
sh_wood.c File Reference
#include "common.h"
#include <stddef.h>
#include <stdio.h>
#include <ctype.h>
#include <math.h>
#include "vmath.h"
#include "raytrace.h"
#include "optical.h"
Include dependency graph for sh_wood.c:

Go to the source code of this file.

Data Structures

struct  wood_specific
 

Macros

#define WOOD_NULL   ((struct wood_specific *)0)
 
#define WOOD_O(m)   bu_offsetof(struct wood_specific, m)
 
#define EXPLICIT_VERTEX   1
 
#define EXPLICIT_DIRECTION   2
 
#define IPOINTS   10 /* undithered number of points */
 
#define TPOINTS   20 /* Dithering space */
 

Functions

HIDDEN int wood_setup (register struct region *rp, struct bu_vls *matparm, void **dpp, const struct mfuncs *mfp, struct rt_i *rtip)
 
HIDDEN int wood_render (struct application *ap, const struct partition *partp, struct shadework *swp, void *dp)
 
HIDDEN void wood_print (register struct region *rp, void *dp)
 
HIDDEN void wood_free (void *cp)
 
HIDDEN void wood_V_set (const struct bu_structparse *, const char *, void *, const char *, void *)
 
HIDDEN void wood_D_set (const struct bu_structparse *, const char *, void *, const char *, void *)
 
HIDDEN void wood_setup_2 (struct wood_specific *)
 
HIDDEN double wood_noise (double x, double y, double z, struct wood_specific *wd)
 
HIDDEN double wood_turb (double x, double y, double z, struct wood_specific *wd)
 

Variables

fastf_t turb_table [20][20][20]
 
struct mfuncs wood_mfuncs []
 
struct bu_structparse wood_parse []
 

Detailed Description

Simple wood-grain texture

Author - Bill Laut, Gull Island Consultants, Inc.

"Where Credit is Due" Authors - Tom DiGiacinto - For his linearly-interpolated noise function as found in the "sh_marble.c" routine.

Description - This module implements a simple concentric ring abstraction that fairly simulates the ring pattern of wood. The placement of the rings within the combination is controlled through two MATPARM entries which centers the rings and specifies their direction. The actual rings themselves are formed on a plane perpendicular to the direction cosines, from the sine of the product of the outward distance and a MATPARM coefficient.

The dithering mechanism is a slight enhancement upon the 3-D noise table which Tom DiGiacinto used in "sh_marble." In my case, the access is still limited to 10x10x10, but the table itself is expanded to 20x20x20. There is a MATPARM "dither" field which is used to "dither the dither." I.e., the "dither" parameter is a coefficient which is summed into Tom's interpolation routine, thereby allowing each wood-shaded combination to have a different noise pattern, and prevents all similar combinations from looking alike. The "dither" field is initialized with the "bn_rand0to1" routine before calling the parser, so default values can be used. However, (obviously) the user can override the defaults if desired.

The MATPARM fields for this shader are:

     id = n         Multi-region identification number
     o{verlay} = n  # of dithered overlay rings to circumscribe
     lt{_rgb} = R/G/B       The RGB color for the wood between the rings.
     dk{_rgb} = R/G/B       The RGB color of the rings.
     s{pacing} = n  Space in mm between rings
     p{hase} = n            Controls thickness of the rings
     qd = n         Degree of dithered "bleed" on edges of rings
     qp = n         Degree of undithered "bleed" on ring edges
     dd = n         Amount of 3-D dither applied to vertex
     dz = n         Amount of Z-axis vertex dither
     di{ther} = a/b/c       Starting point of dither within noise table
     de{pth} = f            Amount of dither to add to sine
     r{otation} = a/b/c     3-D rotation of rings' vertex
     V = X/Y/Z              Vertex of rings' center
     D = X/Y/Z              XYZ of where rings' center is aimed at

Source - Gull Island Consultants, Inc. P.O. Box 627 Muskegon, MI 49440

Definition in file sh_wood.c.

Macro Definition Documentation

#define WOOD_NULL   ((struct wood_specific *)0)

Definition at line 147 of file sh_wood.c.

Referenced by wood_free(), and wood_setup().

#define WOOD_O (   m)    bu_offsetof(struct wood_specific, m)

Definition at line 148 of file sh_wood.c.

#define EXPLICIT_VERTEX   1

Definition at line 150 of file sh_wood.c.

Referenced by wood_setup(), wood_setup_2(), and wood_V_set().

#define EXPLICIT_DIRECTION   2

Definition at line 151 of file sh_wood.c.

Referenced by wood_D_set(), and wood_setup().

#define IPOINTS   10 /* undithered number of points */

Definition at line 205 of file sh_wood.c.

Referenced by wood_noise().

#define TPOINTS   20 /* Dithering space */

Definition at line 206 of file sh_wood.c.

Function Documentation

HIDDEN int wood_render ( struct application ap,
const struct partition partp,
struct shadework *  swp,
void *  dp 
)

Definition at line 574 of file sh_wood.c.

References A, wood_specific::b_max, wood_specific::b_min, C, wood_specific::depth, wood_specific::dir, wood_specific::dither, wood_specific::dk_rgb, wood_specific::lt_rgb, M_PI, wood_specific::phase, wood_specific::qd, wood_specific::qp, wood_specific::spacing, wood_specific::vertex, wood_turb(), X, Y, and Z.

Here is the call graph for this function:

HIDDEN void wood_print ( register struct region rp,
void *  dp 
)

Definition at line 458 of file sh_wood.c.

References bu_struct_print(), region::reg_name, and region::reg_udata.

Here is the call graph for this function:

HIDDEN void wood_free ( void *  cp)

Definition at line 470 of file sh_wood.c.

References BU_PUT, wood_specific::forw, and WOOD_NULL.

HIDDEN void wood_V_set ( const struct bu_structparse sdp,
const char *  name,
void *  base,
const char *  value,
void *  data 
)

Definition at line 215 of file sh_wood.c.

References EXPLICIT_VERTEX, and wood_specific::flags.

HIDDEN void wood_D_set ( const struct bu_structparse sdp,
const char *  name,
void *  base,
const char *  value,
void *  data 
)

Definition at line 229 of file sh_wood.c.

References EXPLICIT_DIRECTION, and wood_specific::flags.

HIDDEN void wood_setup_2 ( struct wood_specific wd)

Definition at line 411 of file sh_wood.c.

References wood_specific::b_max, wood_specific::b_min, bn_mat_angles(), bn_rand0to1, wood_specific::D, wood_specific::dd, wood_specific::dir, wood_specific::dz, EXPLICIT_VERTEX, wood_specific::flags, resource::re_randptr, wood_specific::rot, rt_uniresource, wood_specific::V, V3ARGS, and wood_specific::vertex.

Referenced by wood_setup().

Here is the call graph for this function:

HIDDEN double wood_noise ( double  x,
double  y,
double  z,
struct wood_specific wd 
)

Definition at line 505 of file sh_wood.c.

References IPOINTS, wood_specific::scale, and turb_table.

Referenced by wood_turb().

HIDDEN double wood_turb ( double  x,
double  y,
double  z,
struct wood_specific wd 
)

Definition at line 538 of file sh_wood.c.

References bn_rand_half, wood_specific::dither, wood_specific::jitter, wood_specific::ns, resource::re_randptr, rt_uniresource, wood_noise(), X, Y, and Z.

Referenced by wood_render().

Here is the call graph for this function:

Variable Documentation

fastf_t turb_table[20][20][20]

Definition at line 21 of file turb.c.

Referenced by wood_noise().

struct mfuncs wood_mfuncs[]
Initial value:
= {
{MF_MAGIC, "wood", 0, MFI_HIT|MFI_UV|MFI_NORMAL, 0, wood_setup, wood_render, wood_print, wood_free},
{MF_MAGIC, "w", 0, MFI_HIT|MFI_UV|MFI_NORMAL, 0, wood_setup, wood_render, wood_print, wood_free},
{0, (char *)0, 0, 0, 0, 0, 0, 0, 0}
}
HIDDEN void wood_print(register struct region *rp, void *dp)
Definition: sh_wood.c:458
#define MF_MAGIC
Definition: magic.h:205
HIDDEN void wood_free(void *cp)
Definition: sh_wood.c:470
HIDDEN int wood_setup(register struct region *rp, struct bu_vls *matparm, void **dpp, const struct mfuncs *mfp, struct rt_i *rtip)
Definition: sh_wood.c:243
HIDDEN int wood_render(struct application *ap, const struct partition *partp, struct shadework *swp, void *dp)
Definition: sh_wood.c:574

Definition at line 100 of file sh_wood.c.

Referenced by optical_shader_init().

struct bu_structparse wood_parse[]

Definition at line 163 of file sh_wood.c.