BRL-CAD
sh_light.c File Reference
#include "common.h"
#include <stddef.h>
#include <stdio.h>
#include <string.h>
#include <math.h>
#include "bu/parallel.h"
#include "vmath.h"
#include "raytrace.h"
#include "optical.h"
#include "plot3.h"
#include "light.h"
#include "photonmap.h"
Include dependency graph for sh_light.c:

Go to the source code of this file.

Data Structures

struct  light_obs_stuff
 

Macros

#define LIGHT_O(m)   bu_offsetof(struct light_specific, m)
 
#define VF_SEEN   1
 
#define VF_BACKFACE   2
 

Functions

HIDDEN void aim_set (const struct bu_structparse *, const char *, void *, const char *, void *)
 
HIDDEN void light_cvt_visible (const struct bu_structparse *, const char *, void *, const char *, void *)
 
HIDDEN void light_pt_set (const struct bu_structparse *, const char *, void *, const char *, void *)
 
HIDDEN int light_setup (struct region *rp, struct bu_vls *matparm, void **dpp, const struct mfuncs *mfp, struct rt_i *rtip)
 
HIDDEN int light_render (struct application *ap, const struct partition *pp, struct shadework *swp, void *dp)
 
HIDDEN void light_print (register struct region *rp, void *dp)
 
HIDDEN void light_free (void *cp)
 
HIDDEN void light_pt_allocate (register struct light_specific *lsp)
 
void light_gen_sample_pts (struct application *upap, struct light_specific *lsp)
 
HIDDEN int light_setup (register struct region *rp, struct bu_vls *matparm, void **dpp, const struct mfuncs *mfp, struct rt_i *rtip)
 
int light_init (struct application *ap)
 
void light_cleanup (void)
 
int light_hit (struct application *ap, struct partition *PartHeadp, struct seg *finished_segs)
 
int light_miss (register struct application *ap)
 
void light_obs (struct application *ap, struct shadework *swp, int have)
 
void light_maker (int num, mat_t v2m)
 

Variables

struct light_specific LightHead
 
struct mfuncs light_mfuncs []
 
struct bu_structparse light_print_tab []
 
struct bu_structparse light_parse []
 

Detailed Description

Implement simple isotropic light sources as a material property.

Definition in file sh_light.c.

Macro Definition Documentation

#define LIGHT_O (   m)    bu_offsetof(struct light_specific, m)

Definition at line 46 of file sh_light.c.

Referenced by light_cvt_visible().

#define VF_SEEN   1

Definition at line 1279 of file sh_light.c.

#define VF_BACKFACE   2

Definition at line 1280 of file sh_light.c.

Function Documentation

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

This routine is called by bu_struct_parse() if the "aim" qualifier is encountered, and causes lt_exaim to be set.

Definition at line 147 of file sh_light.c.

References rdebug, RDEBUG_LIGHT, and VPRINT.

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

light_cvt_visible()

Convert "visible" flag to "invisible" variable

Definition at line 167 of file sh_light.c.

References bu_log(), LIGHT_O, rdebug, RDEBUG_LIGHT, and bu_structparse::sp_offset.

Here is the call graph for this function:

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

create a set of light point samples for specified pt/pn arguments (for points and points with normals respectively)

Definition at line 222 of file sh_light.c.

References bu_log(), BU_STR_EQUAL, light_pt_allocate(), rdebug, RDEBUG_LIGHT, and bu_structparse::sp_offset.

Here is the call graph for this function:

HIDDEN int light_setup ( struct region rp,
struct bu_vls matparm,
void **  dpp,
const struct mfuncs *  mfp,
struct rt_i rtip 
)
HIDDEN int light_render ( struct application ap,
const struct partition pp,
struct shadework *  swp,
void *  dp 
)

If we have a direct view of the light, return its color. A cosine term is needed in the shading of the light source, to make it have dimension and shape. However, just a simple cosine of the angle between the normal and the direction vector leads to a pretty dim looking light. Therefore, a cos/2 + 0.5 term is used when the viewer is within the beam, and a cos/2 term when the beam points away.

Definition at line 262 of file sh_light.c.

References application::a_ray, application::a_x, application::a_y, bn_tabdata_scale(), bu_log(), PM_Activated, partition::pt_regionp, xray::r_dir, rdebug, RDEBUG_LIGHT, region::reg_name, and rt_spect_black_body().

Here is the call graph for this function:

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

Definition at line 565 of file sh_light.c.

References bu_struct_print(), and region::reg_name.

Referenced by light_setup().

Here is the call graph for this function:

void light_free ( void *  cp)

Definition at line 572 of file sh_light.c.

References bu_free(), and BU_LIST_DEQUEUE.

Referenced by light_cleanup(), and light_setup().

Here is the call graph for this function:

HIDDEN void light_pt_allocate ( register struct light_specific *  lsp)

ensure that there are sufficient light samples, allocate more if necessary in batches.

Definition at line 198 of file sh_light.c.

References bu_calloc(), bu_free(), and bu_realloc().

Referenced by light_pt_set().

Here is the call graph for this function:

void light_gen_sample_pts ( struct application upap,
struct light_specific *  lsp 
)

Generate a set of sample points on the surface of the light with surface normals. calling during shader init to generate samples for all lights.

Definition at line 492 of file sh_light.c.

References application::a_hit, application::a_logoverlap, application::a_miss, application::a_onehit, application::a_rt_i, application::a_uptr, bu_log(), memset(), rdebug, RDEBUG_LIGHT, rt_bound_tree(), rt_shootray(), V3ARGS, and Z.

Referenced by light_init().

Here is the call graph for this function:

HIDDEN int light_setup ( register struct region rp,
struct bu_vls matparm,
void **  dpp,
const struct mfuncs *  mfp,
struct rt_i rtip 
)
int light_init ( struct application ap)

Special routine called by view_2init() to determine the relative intensities of each light source.

Because of the limited dynamic range of RGB space (0..255), the strategy used here is a bit risky. We find the brightest single light source in the model, and assume that the energy from multiple lights will not shine on a single location in such a way as to add up to an overload condition. We then account for the effect of ambient light, because it always adds its contribution. Even here we only expect 50% of the ambient intensity, to keep the pictures reasonably bright.

Definition at line 748 of file sh_light.c.

References AmbientIntensity, BU_LIST_FOR, BU_LIST_INIT, BU_LIST_IS_INITIALIZED, bu_log(), light_gen_sample_pts(), LightHead, R_DEBUG, V3ARGS, and Z.

Here is the call graph for this function:

void light_cleanup ( void  )

Called from view_end(). Take care of releasing storage for any lights which will not be cleaned up by mlib_free(): implicitly created lights, because they have no associated region, and invisible lights, because their region was destroyed.

Definition at line 838 of file sh_light.c.

References BU_LIST_FOR, BU_LIST_INIT, BU_LIST_IS_INITIALIZED, BU_LIST_PREV, light_free(), LightHead, and REGION_NULL.

Here is the call graph for this function:

int light_hit ( struct application ap,
struct partition PartHeadp,
struct seg finished_segs 
)

A light visibility test ray hit something. Determine what this means.

Input -

a_color[] contains the fraction of a the light that will be propagated back along the ray, so far. If this gets too small, recursion through lots of glass ought to stop.

Output -

a_color[] contains the fraction of light that can be seen. RGB transmissions are separately indicated, to allow simplistic colored glass (with apologies to Roy Hall).

a_spectrum is used in place of a_color for multispectral renderings.

These shadow functions return a boolean "light_visible".

This is a simplified algorithm, and could be improved. Reflected light can't be dealt with at all.

Would also be nice to return an actual energy level, rather than a boolean, which could account for distance, etc.

FIXME: Bogus with Air. We should check to see if it is the same surface.

Since the light visibility ray started at the surface of a solid, it is likely that the solid will be the first partition on the list, with pt_outhit->hit_dist being roughly zero. Don't start using partitions until pt_inhit->hit_dist is slightly larger than zero, i.e., that the partition is not including the start point.

The outhit distance needs to be checked too, so that if the partition is heading through the solid toward the light e.g. (-1, +50), then the fact that the light is obscured will not be missed.

Definition at line 887 of file sh_light.c.

References application::a_color, application::a_cumlen, application::a_level, application::a_purpose, application::a_ray, application::a_refrac_index, application::a_return, application::a_rt_i, application::a_spectrum, application::a_uptr, application::a_user, application::a_uvec, application::a_vvec, application::a_x, application::a_y, BN_CK_TABDATA, BN_GET_TABDATA, bn_pr_tabdata(), bn_tabdata_constval(), bn_tabdata_copy(), bn_tabdata_dup(), bn_tabdata_free(), bn_tabdata_get_constval(), bn_tabdata_mul(), BN_TABDATA_NULL, bn_tabdata_scale(), BU_CK_LIST_HEAD, BU_LIST_FOR, bu_log(), bn_tol::dist, hit::hit_dist, seg::l, LightHead, memset(), out, partition::pt_forw, partition::pt_inhit, partition::pt_outhit, partition::pt_regionp, xray::r_dir, xray::r_pt, rdebug, RDEBUG_LIGHT, region::reg_aircode, region::reg_mfuncs, region::reg_name, region::reg_transmit, RT_CK_PT, RT_CK_PT_HD, rt_pr_partitions(), rt_shootray(), rt_i::rti_tol, spectrum, V3ARGS, viewshade(), and VSETALL.

Here is the call graph for this function:

int light_miss ( register struct application ap)

If there is no explicit light solid in the model, we will always "miss" the light, so return light_visible = TRUE.

Definition at line 1254 of file sh_light.c.

References application::a_color, application::a_level, application::a_ray, application::a_uptr, application::a_x, application::a_y, bu_log(), xray::r_dir, xray::r_pt, rdebug, RDEBUG_LIGHT, V3ARGS, and VSETALL.

Here is the call graph for this function:

void light_obs ( struct application ap,
struct shadework *  swp,
int  have 
)

Determine the visibility of each light source in the scene from a particular location. It is up to the caller to apply sw_lightfract[] to lp_color, etc.

Sets swp: sw_tolight[] sw_intensity[] or msw_intensity[] sw_visible[] sw_lightfract[]

References ap: a_resource a_rti_i->rti_tol a_rbeam a_diverge

Definition at line 1621 of file sh_light.c.

References light_obs_stuff::ap, BN_CK_TABDATA, bn_vec_ortho(), bu_calloc(), bu_free(), BU_LIST_FOR, bu_log(), light_obs_stuff::inten, light_obs_stuff::iter, light_obs_stuff::light_x, light_obs_stuff::light_y, LightHead, light_obs_stuff::lsp, memset(), light_obs_stuff::rand_idx, rdebug, RDEBUG_LIGHT, RT_CK_AP, light_obs_stuff::swp, and light_obs_stuff::to_light_center.

Referenced by phong_render(), scloud_render(), shade_inputs(), and toon_render().

Here is the call graph for this function:

void light_maker ( int  num,
mat_t  v2m 
)

Special hook called by view_2init to build 1 or 3 debugging lights.

Definition at line 1767 of file sh_light.c.

References BN_GET_TABDATA, bn_tabdata_scale(), BU_GET, BU_LIST_INIT, BU_LIST_INIT_MAGIC, BU_LIST_INSERT, BU_LIST_IS_INITIALIZED, bu_log(), bu_strdup, LIGHT_MAGIC, LightHead, rdebug, RDEBUG_LIGHT, REGION_NULL, rt_spect_reflectance_rgb(), spectrum, V3ARGS, and VSET.

Here is the call graph for this function:

Variable Documentation

struct light_specific LightHead

Heads linked list of lights

Definition at line 50 of file sh_light.c.

Referenced by EmitPhotonsRandom(), light_cleanup(), light_hit(), light_init(), light_maker(), light_obs(), light_setup(), and viewshade().

struct bu_structparse light_print_tab[]
Initial value:
= {
{"%f", 1, "bright", LIGHT_O(lt_intensity), BU_STRUCTPARSE_FUNC_NULL, NULL, NULL },
{"%f", 1, "angle", LIGHT_O(lt_angle), BU_STRUCTPARSE_FUNC_NULL, NULL, NULL },
{"%f", 1, "fract", LIGHT_O(lt_fraction), BU_STRUCTPARSE_FUNC_NULL, NULL, NULL },
{"%f", 3, "target", LIGHT_O(lt_target), aim_set, NULL, NULL },
{"%d", 1, "shadows", LIGHT_O(lt_shadows), BU_STRUCTPARSE_FUNC_NULL, NULL, NULL },
{"%d", 1, "infinite", LIGHT_O(lt_infinite), BU_STRUCTPARSE_FUNC_NULL, NULL, NULL },
{"%d", 1, "visible", LIGHT_O(lt_visible), BU_STRUCTPARSE_FUNC_NULL, NULL, NULL },
{"%d", 1, "invisible", LIGHT_O(lt_invisible), BU_STRUCTPARSE_FUNC_NULL, NULL, NULL },
{"", 0, (char *)0, 0, BU_STRUCTPARSE_FUNC_NULL, NULL, NULL }
}
HIDDEN void aim_set(const struct bu_structparse *, const char *, void *, const char *, void *)
Definition: sh_light.c:147
#define BU_STRUCTPARSE_FUNC_NULL
Definition: parse.h:153
#define LIGHT_O(m)
Definition: sh_light.c:46

for printing out light values

Definition at line 72 of file sh_light.c.

struct bu_structparse light_parse[]

for actually parsing light values

Definition at line 86 of file sh_light.c.