DLLEXPORT miBoolean texture_worleynoise3d(
    miColor *result,
    miState *state,
    texture_worleynoise3d_t *param)
{
  worley_context3 *context;
  mi_query(miQ_FUNC_TLS_GET, state, miNULLTAG, &context);
  if (!context) {
    context = mi_mem_allocate( sizeof(worley_context3) );
    mi_query(miQ_FUNC_TLS_SET, state, miNULLTAG, &context);
    context->cache_initialized = 0;
  }
  
  
  miScalar val = worleynoise3d_val(state,param);
  
  if(val < 0) {
    miColor gap = *mi_eval_color(&param->gap);
    result->r = gap.r;
    result->g = gap.g;
    result->b = gap.b;
    result->a = gap.a;
  }
  else {
    miColor *inner = mi_eval_color(&param->inner);
    miColor *outer = mi_eval_color(&param->outer);
    
    grey_to_color(val, inner, outer, result);
  }
  
  return(miTRUE);
}
Example #2
0
extern "C" DLLEXPORT miBoolean mib_photon_basic(
	miColor		*flux,
	miState		*state,
	struct mib_photon_basic *paras)
{
	miColor		rdiff, *spec, *transp, nflux;
	miScalar	ior_frac;
	miVector	dir;
	miRay_type	type;
	miColor		tspec, rspec;

	rdiff   = *mi_eval_color(&paras->diffuse);
	spec    =  mi_eval_color(&paras->specular);
	transp  =  mi_eval_color(&paras->transp);
	tspec.r = spec->r * transp->r;
	tspec.g = spec->g * transp->g;
	tspec.b = spec->b * transp->b;
	rspec.r = spec->r * (1.0 - transp->r);
	rspec.g = spec->g * (1.0 - transp->g);
	rspec.b = spec->b * (1.0 - transp->b);

	if (rdiff.r > 0.0 || rdiff.g > 0.0 || rdiff.b > 0.0)
		mi_store_photon(flux, state);

	type = mi_choose_simple_scatter_type(state, &rdiff, &rspec, 0, &tspec);

	switch(type) {
	  case miPHOTON_REFLECT_SPECULAR:
		nflux.r = flux->r * rspec.r;
		nflux.g = flux->g * rspec.g;
		nflux.b = flux->b * rspec.b;
		mi_reflection_dir_specular(&dir, state);
		return(mi_photon_reflection_specular(&nflux, state, &dir));

	  case miPHOTON_REFLECT_DIFFUSE:
		nflux.r = flux->r * rdiff.r;
		nflux.g = flux->g * rdiff.g;
		nflux.b = flux->b * rdiff.b;
		mi_reflection_dir_diffuse(&dir, state);
		return(mi_photon_reflection_diffuse(&nflux, state, &dir));

	  case miPHOTON_TRANSMIT_SPECULAR:
		nflux.r = flux->r * tspec.r;
		nflux.g = flux->g * tspec.g;
		nflux.b = flux->b * tspec.b;
		ior_frac = *mi_eval_scalar(&paras->ior_frac);
		if (ior_frac == 1.0)
			return(mi_photon_transparent(&nflux, state));

		else if (mi_transmission_dir_specular(&dir, state, 1,ior_frac))
			return(mi_photon_transmission_specular(&nflux, state,
									&dir));
		else
			return(miFALSE);

	  default:
		return(miTRUE);
	}
}
Example #3
0
extern "C" DLLEXPORT miBoolean mib_twosided(
	miColor		*result,
	miState		*state,
	struct mt	*paras)
{
	if (state->inv_normal)
		*result = *mi_eval_color(&paras->back);
	else
		*result = *mi_eval_color(&paras->front);
	return(miTRUE);
}
Example #4
0
extern "C" DLLEXPORT miBoolean mib_dielectric(
	miColor		*result,
	miState		*state,
	struct md	*paras)
{
	miScalar	refract;
	miColor		inp, absorb;
	miVector	dir;
	miScalar	ior;
	double	        dist;
 
        /* check for illegal calls */
	if (state->type == miRAY_SHADOW || state->type == miRAY_DISPLACE)
       		return(miFALSE);
	
	refract = *mi_eval_scalar(&paras->refract);
	if (refract == 0.0)
		*result = *mi_eval_color(&paras->input);
	else {
		ior = *mi_eval_scalar(&paras->ior);
		if (ior==0.0 || ior==1.0)
			mi_trace_transparent(result, state);
		else {
			if (mi_refraction_dir(&dir, state, 1.0, ior))
				mi_trace_refraction(result, state, &dir);
			else {	/* total internal reflection */
				mi_reflection_dir(&dir, state);
				mi_trace_reflection(result, state, &dir);
			}
		}
                dist = state->child ? state->child->dist : 0.0;
		absorb = *mi_eval_color(&paras->absorb);
		if(absorb.r > 0.0f)
			result->r *= (miScalar) exp(log(absorb.r) * dist);
		if(absorb.g > 0.0f)
			result->g *= (miScalar) exp(log(absorb.g) * dist);
		if(absorb.b > 0.0f)
			result->b *= (miScalar) exp(log(absorb.b) * dist);
		if(absorb.a > 0.0f)
			result->a *= (miScalar) exp(log(absorb.a) * dist);

		if (refract < 1.0f) {
			inp = *mi_eval_color(&paras->input);
			result->r = result->r * refract + inp.r * (1-refract);
			result->g = result->g * refract + inp.g * (1-refract);
			result->b = result->b * refract + inp.b * (1-refract);
			result->a = result->a * refract + inp.a * (1-refract);
		}
	}

	return(miTRUE);
}
Example #5
0
extern "C" DLLEXPORT miBoolean mib_reflect(
	miColor		*result,
	miState		*state,
	struct mr	*paras)
{
	miBoolean	ok;
	miBoolean	notrace;
	miColor		*reflect =  mi_eval_color(&paras->reflect);
	miColor		inp;
	miVector	dir;
	miScalar	save_ior;

        /* check for illegal calls */
        if (state->type == miRAY_SHADOW || state->type == miRAY_DISPLACE ) {
		return(miFALSE);
	}

	if (reflect->r == 0.0 && reflect->g == 0.0 &&
	    reflect->b == 0.0 && reflect->a == 0.0) {
		*result = *mi_eval_color(&paras->input);
		return(miTRUE);
	}
	notrace    = *mi_eval_boolean(&paras->notrace);
	save_ior   = state->ior;
	state->ior = state->ior_in;

	mi_reflection_dir(&dir, state);
	ok = miFALSE;
	if (!notrace &&
	    state->reflection_level < state->options->reflection_depth &&
	    state->reflection_level + state->refraction_level <
						state->options->trace_depth)
		ok = mi_trace_reflection(result, state, &dir);

	if (!ok) {
		miTag savevol = state->volume;
		state->volume = 0;
		ok = mi_trace_environment(result, state, &dir) || !notrace;
		state->volume = savevol;
	}

	if (reflect->r != 1.0 || reflect->g != 1.0 ||
	    reflect->b != 1.0 || reflect->a != 1.0) {
		inp = *mi_eval_color(&paras->input);
		result->r = result->r * reflect->r + inp.r * (1 - reflect->r);
		result->g = result->g * reflect->g + inp.g * (1 - reflect->g);
		result->b = result->b * reflect->b + inp.b * (1 - reflect->b);
		result->a = result->a * reflect->a + inp.a * (1 - reflect->a);
	}
	state->ior = save_ior;
	return(ok);
}
Example #6
0
static miBoolean polka_dot(
	miColor		*result,
	miState		*state,
	struct mtp	*paras,
	double		x,
	double		y,
	double		z)
{
	*result = sqrt(x*x + y*y + z*z) < *mi_eval_scalar(&paras->radius)
						? *mi_eval_color(&paras->fg)
						: *mi_eval_color(&paras->bg);

	return(miTRUE);
}
Example #7
0
DLLEXPORT miBoolean nkPass(
	miColor *result,
	miState *state,
	nkPass_t *param)
{
	/*
	 * get parameter values. It is inefficient to do this all at the beginning of
	 * the code. Move the assignments here to where the values are first used.
	 * You may want to use pointers for colors and vectors.
	 */

	miInteger layerNumber = *mi_eval_integer(&param->layerNumber);
	miColor color = *mi_eval_color(&param->color);

	if( !mi_fb_put( state, layerNumber, &color ))
		printf( "Could not save framebuffer %d.\n", layerNumber );

	/*
	 * set shader results. ``+='' etc. is useful for shaders in shader
	 * lists but other shaders may need to simply assign result variables.
	 */

	result->r += color.r;
	result->g += color.g;
	result->b += color.b;
	result->a += color.a;

	return(miTRUE);
}
Example #8
0
extern "C" DLLEXPORT miBoolean mib_volume(
	miColor		*result,	/* in: color at far end, out */
	miState		*state,
	struct mib_volume *paras)
{
	miColor		*color;		/* fog color */
	miScalar	max, fade;	/* max opcity distance, fade factor */

	if (!*mi_eval_boolean(&paras->lightrays) && state->type==miRAY_LIGHT)
		return(miTRUE);				/* ignore light rays?*/

	color =  mi_eval_color (&paras->color);
	max   = *mi_eval_scalar(&paras->max);
	if (state->dist <= 0 ||				/* infinite distance */
	    state->dist >= max) {			/* full-opacity dist */
		fade = 1 - color->a;
		result->r = fade * result->r + color->r;
		result->g = fade * result->g + color->g;
		result->b = fade * result->b + color->b;
		result->a = fade * result->a + color->a;
		return(miTRUE);
	}

	fade = (float)state->dist / max;			/* fade to fog color */
	fade = (1 - fade * fade) * color->a;

	result->r = fade * result->r + (1-fade) * color->r;
	result->g = fade * result->g + (1-fade) * color->g;
	result->b = fade * result->b + (1-fade) * color->b;
	result->a = fade * result->a + (1-fade) * color->a;
	return(miTRUE);
}
Example #9
0
miBoolean contour_shader_widthfromcolor(
	miContour_endpoint	  *result,
	miStdInfo		  *info_near,
	miStdInfo		  *info_far,
	miState			  *state,
	Widthfromcolor_Parameters *paras)
{
	double			  maxcolor;
	miScalar		  min_width;

	/* Contour color given by a parameter */
	result->color = *mi_eval_color(&paras->color);

	/* The contour gets wider when the material color is dark */
	maxcolor = mi_MAX(info_near->color.r, info_near->color.g);
	maxcolor = mi_MAX(info_near->color.b, maxcolor);

	/* Softimage likes to have rgb colors larger than 1.0 */
	if (maxcolor > 1.0)
		maxcolor = 1.0;
	miASSERT(0.0 <= maxcolor && maxcolor <= 1.0);

	min_width = *mi_eval_scalar(&paras->min_width);
	result->width = (*mi_eval_scalar(&paras->max_width) - min_width) *
					(1.0 - maxcolor) + min_width;
	return(miTRUE);
}
Example #10
0
extern "C" DLLEXPORT miBoolean mib_fg_occlusion(
	miColor     *result,
	miState     *state,
	struct mib_fg_occlusion_p *paras)
{
    /* Final gather ray gets a return value of black */
    if (state->type == miRAY_FINALGATHER)
    {
        result->r = result->g = result->b = 0.0;
        result->a = 1.0;
        return miTRUE;
    }
    if (state->options->finalgather)
    {
        miColor color;
        mi_compute_irradiance(&color, state);
        result->r = 1.0-color.a;
        result->g = 1.0-color.a;
        result->b = 1.0-color.a;
        result->a = 1.0;
    }
    else
    {
        *result = *mi_eval_color(&paras->result_when_fg_is_off);
    }

    return miTRUE;
}
Example #11
0
miBoolean contour_shader_curvature(
	miContour_endpoint	  *result,
	miStdInfo		  *info_near,
	miStdInfo		  *info_far,
	miState			  *state,
	Widthfromcolor_Parameters *paras)
{
	double			  d;
	miScalar		  min_width;
	miScalar		  max_width;
	miASSERT(info_near || info_far);

	/* Constant contour color */
	result->color = *mi_eval_color(&paras->color);
	max_width     = *mi_eval_scalar(&paras->max_width);
	min_width     = *mi_eval_scalar(&paras->min_width);

	if ((info_near == NULL) != (info_far == NULL)) {
		/* Max contour width if one point hit background */
		result->width = max_width;

	} else if (fabs(info_near->point.z - info_far->point.z) > 1.0) {
		/* Max contour width if large difference in depth */
		result->width = max_width;
	} else {
		/* Otherwise, the contour width depends on the curvature */
		d = mi_vector_dot(&info_near->normal, &info_far->normal);
		miASSERT(-1.0 <= d && d <= 1.0);
		result->width = min_width + 
				0.5 * (1.0 - d) * (max_width-min_width);
	}
	miASSERT(min_width <= result->width && result->width <= max_width);
	return(miTRUE);
}
Example #12
0
miBoolean contour_shader_widthfromlightdir(
	miContour_endpoint  *result,
	miStdInfo	    *info_near,
	miStdInfo	    *info_far,
	miState		    *state,
	Lightdir_Parameters *paras)
{
	double		    d;
	miVector	    dir;
	miScalar	    max_width;
	miScalar	    min_width;

	/* Contour color given by a parameter */
	result->color = *mi_eval_color(&paras->color);

	/* Normalize light direction (just in case user didn't) */
	dir = *mi_eval_vector(&paras->light_dir);
	mi_vector_normalize(&dir);

	/* The contour gets wider the more the normal differs from the light
	   source direction */
	d = mi_vector_dot(&dir, &info_near->normal);

	min_width     = *mi_eval_scalar(&paras->min_width);
	max_width     = *mi_eval_scalar(&paras->max_width);
	result->width = min_width + 0.5 * (max_width - min_width) * (1.0 - d);

	miASSERT(min_width <= result->width && result->width <= max_width);
	return(miTRUE);
}
Example #13
0
extern "C" DLLEXPORT miBoolean mib_color_spread(
	register miColor  *result,
	miState		  *state,
	struct mib_color_spread *paras)
{
	register int	  i, n = *mi_eval_integer(&paras->num);
	register miScalar r, g, b, a;
	register miScalar weight;
	miColor		  *input;

	input = mi_eval_color(&paras->input);
	r = input->r;
	g = input->g;
	b = input->b;
	a = input->a;
	if (n > 8) n = 8;

	for (i=0; i < n; i++, result++) {
		weight = *mi_eval_scalar(&paras->weight[i]);
		switch(*mi_eval_integer(&paras->mode[i])) {
		  default:
		  case 0:
			result->r = r * weight;
			result->g = g * weight;
			result->b = b * weight;
			result->a = a * weight;
			break;

		  case 1:
			result->r =
			result->g =
			result->b =
			result->a = a * weight;
			break;

		  case 2:
			result->r =
			result->g =
			result->b =
			result->a = (a + r + g)/3 * weight;
			break;

		  case 3:
			result->r =
			result->g =
			result->b =
			result->a = (.299 * r + .587 * g + .114 * b) * weight;
			break;

		  case 4:
			result->r =
			result->g =
			result->b =
			result->a = r * weight;
			break;
		}
	}
	return(miTRUE);
}
Example #14
0
miBoolean contour_shader_framefade(
	miContour_endpoint   *result,
	miStdInfo	     *info_near,
	miStdInfo	     *info_far,
	miState		     *state,
	Framefade_Parameters *paras)
{
	int		     frame = state->camera->frame;
	double		     w1, w2;
	int		     frame1, frame2;

	miASSERT(frame >= 0);

	frame1 = *mi_eval_integer(&paras->frame1);
	frame2 = *mi_eval_integer(&paras->frame2);

	miASSERT(frame1 >= 0 && frame2 >= 0);

	if (frame <= frame1) {		/* before frame1 */
		result->color = *mi_eval_color(&paras->color1);
		result->width = *mi_eval_scalar(&paras->width1);
	} else if (frame2 <= frame) {	/* after frame2 */
		result->color = *mi_eval_color(&paras->color2);
		result->width = *mi_eval_scalar(&paras->width2);
	} else {				/* between frame1 and frame2 */
		/* Weights w1 and w2 depend on frame number */
		miColor color1 = *mi_eval_color(&paras->color1);
		miColor color2 = *mi_eval_color(&paras->color2);

		miASSERT(frame1 < frame2);
		w1 = ((double)frame2 - frame) / (frame2 - frame1);
		miASSERT(0.0 <= w1 && w1 <= 1.0);
		w2 = 1.0 - w1;

		/* Mix of color1 and color2 according to weights */
		result->color.r = w1 * color1.r + w2 * color2.r;
		result->color.g = w1 * color1.g + w2 * color2.g;
		result->color.b = w1 * color1.b + w2 * color2.b;
		result->color.a = w1 * color1.a + w2 * color2.a;

		/* Width depending on weights */
		result->width   = w1 * *mi_eval_scalar(&paras->width1)
				+ w2 * *mi_eval_scalar(&paras->width2);
	}
	return(miTRUE);
}
Example #15
0
extern "C" DLLEXPORT miBoolean mib_lens_stencil(
	miColor*	result,
	miState*	state,
	mibStencil_t*	paras)
{
	miScalar 	f  = *mi_eval_scalar(&paras->floor);
	miScalar 	c  = *mi_eval_scalar(&paras->ceiling);
	miColor  	fc = *mi_eval_color(&paras->floor_color);
	miColor  	cc = *mi_eval_color(&paras->ceil_color);
	miTag    	st = *mi_eval_tag(&paras->stencil);

	miScalar 	s;
	miVector 	coord;

	/* handle default parameter values */
	if (c == 0.0f) {
		c = 1.0f;
	}

	if (!st || f >= c) {
		return mi_trace_eye(result, state, &state->org, &state->dir);
	} 

	coord.x = state->raster_x / state->camera->x_resolution;
	coord.y = state->raster_y / state->camera->y_resolution;
	coord.z = 0.0f;

	mi_lookup_scalar_texture(&s, state, st, &coord);
	s = (s-f)/(c-f);
	if (s < 0.0f) {
		*result = fc;
	} else if ( s > 1.0f) {
		*result = cc;
	} else {
		miColor col = { 0.0, 0.0, 0.0, 1.0};
        	miScalar sn = 1.0f - s;

		(void) mi_trace_eye(&col, state, &state->org, &state->dir);

		result->r = s * col.r + sn * fc.r;
		result->g = s * col.g + sn * fc.g;
		result->b = s * col.b + sn * fc.b;
		result->a =     col.a;
	}
	return miTRUE;
}
Example #16
0
extern "C" DLLEXPORT miBoolean mib_lens_clamp(
	miColor*	result,
	miState*	state,
	mibClamp_t*	paras)
{
	miBoolean 	res;
	miScalar 	f = *mi_eval_scalar(&paras->floor);
	miScalar 	c = *mi_eval_scalar(&paras->ceiling);
	miBoolean	b = *mi_eval_boolean(&paras->luminance);

	if (c == 0.0f) {
		c = 1.0f;
	}
	if (f == c) {
		f = 0.0f;
	}

	res = mi_trace_eye(result, state, &state->org, &state->dir);

	if(b) {
		/* clamp based on luminance. */
		miScalar	lum = mi_luminance(state, result);
	
		if(lum < f) {
			*result = *mi_eval_color(&paras->floor_color);
		} else if (lum > c) {
			*result = *mi_eval_color(&paras->ceil_color);
		} else {
			lum = (lum - f)/(c - f);
			result->r *= lum;
			result->g *= lum;
			result->b *= lum;
		}
	} else {	
		/* clamp based on color components */
		result->r = result->r > f ? 
			(result->r < c ? (result->r-f)/(c-f) : 1) : 0;
		result->g = result->g > f ? 
			(result->g < c ? (result->g-f)/(c-f) : 1) : 0;
		result->b = result->b > f ? 
			(result->b < c ? (result->b-f)/(c-f) : 1) : 0;
	}

	return res;
}
Example #17
0
DLLEXPORT
miBoolean td_color_kernel ( miColor *result, miState *state, struct td_color_kernel *params ){
  
  miVector newPoint = *mi_eval_vector( &params->point );

  state->point = newPoint;

  *result = *mi_eval_color( &params->color );

  return miTRUE;
}
Example #18
0
miBoolean contour_shader_depthfade(
	miContour_endpoint   *result,
	miStdInfo	     *info_near,
	miStdInfo	     *info_far,
	miState		     *state,
	Depthfade_Parameters *paras)
{
	miScalar	     depth = info_near->point.z;
	double		     near_z, far_z, w_near, w_far;

	/* Ensure that near_z and far_z are negative as they should be */
	near_z = -fabs(*mi_eval_scalar(&paras->near_z));
	far_z  = -fabs(*mi_eval_scalar(&paras->far_z));

	if (depth > near_z) {		/* contour is closer than near_z */
		result->color = *mi_eval_color(&paras->near_color);
		result->width = *mi_eval_scalar(&paras->near_width);
	} else if (depth < far_z) {	/* contour is more distant than far_z*/
		result->color = *mi_eval_color(&paras->far_color);
		result->width = *mi_eval_scalar(&paras->far_width);
	} else {			/* contour is betwn near_z and far_z */
		miColor near_color = *mi_eval_color(&paras->near_color);
		miColor far_color  = *mi_eval_color(&paras->far_color);

		/* Weights w_near and w_far depend on depth */
		w_near = (depth - far_z) / (near_z - far_z);
		miASSERT(0.0 <= w_near && w_near <= 1.0);
		w_far = 1.0 - w_near;

		/* Mix of near_color and far_color according to weights */
		result->color.r = w_near * near_color.r + w_far * far_color.r;
		result->color.g = w_near * near_color.g + w_far * far_color.g;
		result->color.b = w_near * near_color.b + w_far * far_color.b;
		result->color.a = w_near * near_color.a + w_far * far_color.a;
		/* Width depending on weights */
		result->width = w_near * *mi_eval_scalar(&paras->near_width) 
			      + w_far  * *mi_eval_scalar(&paras->far_width);
	}
	return(miTRUE);
}
Example #19
0
extern "C" DLLEXPORT miBoolean mib_color_interpolate(
	miColor		*result,
	miState		*state,
	struct mib_color_interpolate *paras)
{
	miInteger	num = *mi_eval_integer(&paras->num);
	miScalar	input;
	miScalar	ominput;
	miScalar	prev = 0;
	miScalar	next = 1;
	int		i;

	if (num < 1) {
		result->r = result->g = result->b = result->a = 0;
		return(miTRUE);
	}
	if (num == 1) {
		*result = *mi_eval_color(&paras->color[0]);
		return(miTRUE);
	}
	if (num > 8)
		num = 8;

	input = *mi_eval_scalar(&paras->input);
	if (input <= 0) {
		*result = *mi_eval_color(&paras->color[0]);
		return(miTRUE);
	}
	if (input >= 1) {
		*result = *mi_eval_color(&paras->color[num-1]);
		return(miTRUE);
	}
	for (i=0; i < num-2; i++) {
		next = *mi_eval_scalar(&paras->weight[i]);
		if (input <= next)
			break;
		prev = next;
		next = 1;
	}
	input	= (input - prev) / (next - prev);
	ominput	= 1 - input;
	if (input == 0)
		*result = *mi_eval_color(&paras->color[i]);
	else if (input == 1)
		*result = *mi_eval_color(&paras->color[i+1]);
	else {
		miColor *pcol = mi_eval_color(&paras->color[i]);
		miColor *ncol = mi_eval_color(&paras->color[i+1]);
		result->r = ominput * pcol->r + input * ncol->r;
		result->g = ominput * pcol->g + input * ncol->g;
		result->b = ominput * pcol->b + input * ncol->b;
		result->a = ominput * pcol->a + input * ncol->a;
	}
	return(miTRUE);
}
Example #20
0
extern "C" DLLEXPORT miBoolean mib_transparency(
    miColor		*result,
    miState		*state,
    struct mt	*paras)
{
    miColor		inp;
    miColor		*transp;

    /* check for illegal calls */
    if (state->type == miRAY_SHADOW || state->type == miRAY_DISPLACE) {
        result->r = result->g = result->b = result->a = 0.0;
        return miTRUE;
    }

    transp = mi_eval_color(&paras->transp);

    if (transp->r == 0.0 && transp->g == 0.0 &&
            transp->b == 0.0 && transp->a == 0.0)
        *result = *mi_eval_color(&paras->input);
    else {
        mi_trace_transparent(result, state);

        if (transp->r != 1.0 || transp->g != 1.0 ||
                transp->b != 1.0 || transp->a != 1.0) {
            inp = *mi_eval_color(&paras->input);
            result->r = result->r * transp->r +
                        inp.r * (1.0 - transp->r);
            result->g = result->g * transp->g +
                        inp.g * (1.0 - transp->g);
            result->b = result->b * transp->b +
                        inp.b * (1.0 - transp->b);
            result->a = result->a * transp->a +
                        inp.a * (1.0 - transp->a);
        }
    }

    return miTRUE;
}
Example #21
0
extern "C" DLLEXPORT miBoolean mib_opacity(
    miColor		*result,
    miState		*state,
    struct mo	*paras)
{
    miColor         inp;
    miColor*        opacity;

    /* check for illegal calls */
    if (state->type == miRAY_SHADOW || state->type == miRAY_DISPLACE) {
        result->r = result->g = result->b = result->a = 0.0;
        return miTRUE;
    }

    opacity = mi_eval_color(&paras->opacity);

    if (opacity->r == 1.0 && opacity->g == 1.0 &&
            opacity->b == 1.0 && opacity->a == 1.0)
        *result = *mi_eval_color(&paras->input);
    else {
        mi_trace_transparent(result, state);

        if (opacity->r != 0.0 || opacity->g != 0.0 ||
                opacity->b != 0.0 || opacity->a != 0.0) {
            inp = *mi_eval_color(&paras->input);
            result->r = result->r * (1.0 - opacity->r) +
                        inp.r * opacity->r;
            result->g = result->g * (1.0 - opacity->g) +
                        inp.g * opacity->g;
            result->b = result->b * (1.0 - opacity->b) +
                        inp.b * opacity->b;
            result->a = result->a * (1.0 - opacity->a) +
                        inp.a * opacity->a;
        }
    }

    return miTRUE;
}
Example #22
0
miBoolean contour_store_function(
	void		*info_void,
	int		*info_size,
	miState		*state,
	miColor		*color)
{
	miState		*s;

	/*
	 * The type of info is unknown to raylib, therefore a void * is passed
	 * and needs to be cast to miStdInfo * here.
	 */
	struct miStdInfo *info = (miStdInfo *) info_void;

	/*
	 * Ray intersection point, normal, material tag, label, triangle index.
	 */
	info->point       = state->point;
	info->normal      = state->normal;
	info->normal_geom = state->normal_geom;
	info->material    = state->material;
	info->label       = state->label;
	info->index       = state->pri_idx;

	/*
	 * Material color at the intersection.  This color is not just the
	 * color of the material (with texture) under a given illumination:
	 * if the material is transparent it also depends on deeper material
	 * colors.
	 */
	info->color = *mi_eval_color(color);

	/*
	 * Compute the refraction level.  Why is state->refraction_level not
	 * what we want?  Because some shaders dont increment it as they
	 * should.
	 */
	info->level = 0;
	for (s=state; s; s=s->parent, info->level++);
	miASSERT(info->level > 0);

	/*
	 * The size of miStdInfo. NOTE: this is obsolete and ignored in
	 * mental ray 3.0 but required for 2.1. In 3.0 the size is derived
	 * from the declaration, which must correctly declare the return type!
	 */
	*info_size = sizeof(miStdInfo);
	return(miTRUE);
}
Example #23
0
extern "C" DLLEXPORT miBoolean MYMR_Alluminum(
		struct MYMR_Alluminum_o *resultStruct ,
		miState *state, 
		struct MYMR_Alluminum_p *paras)
{
	
	//Param values
	miColor *specular = mi_eval_color(&paras->specular);
	miScalar specular_exponent = *mi_eval_scalar(&paras->specular_exponent);
	miColor *diffuse = mi_eval_color(&paras->diffuse);
	miColor *result = mi_eval_color(&resultStruct->result);
	
	//At least it should get the ambient color. I think that somehow ambient should be an ambient light or something....to be studied
	*result = *mi_eval_color(&paras->ambient);
		
	//Do lighting shit
	//Get all the lights
	do_diffuse_and_spec(result,state,diffuse,specular,specular_exponent);
	
	// Do the refraction stuff
	miScalar reflection_factor = *mi_eval_scalar(&paras->reflection_factor);
	miColor *reflection = mi_eval_color(&paras->reflection);
	do_reflections(result,state,reflection,reflection_factor);
	
	// Do the transparency stuff
	//miScalar refraction_factor = *mi_eval_scalar(&paras->refraction_factor);
	//miColor *refraction = mi_eval_color(&paras->refraction);
	//miScalar ior = *mi_eval_scalar(&paras->ior);
	//calculate_ior(state,ior);
	//printf("in:%f out:%f\n",state->ior,state->ior_in);
	//do_refractions(result,state,refraction,refraction_factor);
	
	//printf("\e[33mPost Red: %f\tGreen: %f\tBlue: %f\e[0m\n",result->r,result->g,result->b);

	return miTRUE;
}
Example #24
0
miBoolean contour_shader_layerthinner(
	miContour_endpoint	*result,
	miStdInfo		*info_near,
	miStdInfo		*info_far,
	miState			*state,
	Layerthinner_Parameters *paras)
{
	/* Constant contour color */
	result->color = *mi_eval_color(&paras->color);

	/* Width decreases by factor for each refraction_level */
	result->width = *mi_eval_scalar(&paras->width) *
			pow( (double)(*mi_eval_scalar(&paras->factor)), 
					(double)info_near->level - 1.0);
	return(miTRUE);
}
Example #25
0
miBoolean contour_shader_silhouette(
	miContour_endpoint *result,
	miStdInfo	   *info_near,
	miStdInfo	   *info_far,
	miState		   *state,
	Simple_Parameters  *paras)
{
	if (info_far) {
		result->color.a = 0.0;
		result->width   = 0.0;
	} else {
		result->color   = *mi_eval_color(&paras->color);
		result->width   = *mi_eval_scalar(&paras->width);
	}
	miASSERT(result->color.r >= 0.0 && result->color.g >= 0.0);
	miASSERT(result->color.b >= 0.0 && result->width >= 0.0);

	return(miTRUE);
}
Example #26
0
miBoolean contour_shader_widthfromlight(
	miContour_endpoint *result,
	miStdInfo	   *info_near,
	miStdInfo	   *info_far,
	miState		   *state,
	Light_Parameters   *paras)
{
	miVector	   orgp;	/* light source origin */
	miVector	   dirp;	/* light source direction */
	miVector	   dir;
	double		   d;
	miScalar	   min_width;
	miScalar	   max_width;

	/* Contour color given by a parameter */
	result->color = *mi_eval_color(&paras->color);

	/* Get light origin or direction */
	mi_light_info(*mi_eval_tag(&paras->light), &orgp, &dirp, 0);
	/* Now orgp or dirp is different from the null vector */

	/* Compute direction from light to point */
	if (mi_vector_dot(&orgp, &orgp) > miEPS) {   /* point light source */
		mi_vector_sub(&dir, &info_near->point, &orgp);

	} else {				/* directional light source */
		miASSERT(mi_vector_dot(&dirp, &dirp) > miEPS);
		dir = dirp;
	}
	mi_vector_normalize(&dir);

	/* The contour gets wider the more the normal is pointing in the same
	   direction as the light source */
	d = mi_vector_dot(&dir, &info_near->normal);
	min_width = *mi_eval_scalar(&paras->min_width);
	max_width = *mi_eval_scalar(&paras->max_width);
	result->width = min_width + 0.5 * (max_width - min_width) * (d+1.0);

	miASSERT(min_width <= result->width && result->width <= max_width);
	return(miTRUE);
}
Example #27
0
miBoolean contour_shader_simple(
	miContour_endpoint *result,
	miStdInfo	   *info_near,
	miStdInfo	   *info_far,
	miState		   *state,
	Simple_Parameters  *paras)
{
	miASSERT(paras->color.r >= 0.0 && paras->color.g >= 0.0);
	miASSERT(paras->color.b >= 0.0 && paras->width >= 0.0);

	/*
	 * Contour color given by a parameter
	 */
	result->color = *mi_eval_color(&paras->color);

	/*
	 * Contour width given by a parameter
	 */
	result->width = *mi_eval_scalar(&paras->width);
	return(miTRUE);
}
Example #28
0
extern "C" DLLEXPORT miBoolean mib_ray_marcher(
	miColor		*result,
	miState		*state,
	struct mrm	*p)
{
	struct mrm	pe;
	miScalar	scale;

	result->r = result->g = result->b = result->a = 0.0;

	/*
	 * copy all parameters to a static structure to
	 * avoid all the mi_eval_* calls in the code
	 */
	pe.s        = *mi_eval_tag(&p->s);
	pe.distance = *mi_eval_scalar(&p->distance);
	pe.num      = *mi_eval_integer(&p->num);
	pe.subdiv   = *mi_eval_integer(&p->subdiv);
	pe.contrast = *mi_eval_color(&p->contrast);

	if (pe.num == 0.0)
		if (pe.distance > 0.0)
			pe.num = state->dist / pe.distance;
		else
			pe.num = 4; /* default #samples */
	if (pe.num < 2)
		pe.num = 2;

	/* go! */
	raymarch(result, state, &pe);

	/* normalize result */
	scale = 1.0 / (miScalar)pe.num;
	result->r *= scale;
	result->g *= scale;
	result->b *= scale;
	result->a *= scale;
	return(miTRUE);
}
Example #29
0
miBoolean contour_shader_combi(
	miContour_endpoint *result,
	miStdInfo	   *info_near,
	miStdInfo	   *info_far,
	miState		   *state,
	Combi_Parameters   *paras)
{
	miScalar	   depth = info_near->point.z;
	double		   near_z, far_z, w_near, w_far;
	miVector	   orgp;		/* light source origin */
	miVector	   dirp;		/* light source direction */
	miVector	   dir;
	double		   d;
	double		   factor;
	miTag		   light;

	/* Ensure that near_z and far_z are negative as they should be */
	near_z = -fabs(*mi_eval_scalar(&paras->near_z));
	far_z  = -fabs(*mi_eval_scalar(&paras->far_z));

	if (depth > near_z) {		/* contour is closer than near_z */
		result->color = *mi_eval_color(&paras->near_color);
		result->width = *mi_eval_scalar(&paras->near_width);

	} else if (depth < far_z) {	/* contour is more distant than far_z*/
		result->color = *mi_eval_color(&paras->far_color);
		result->width = *mi_eval_scalar(&paras->far_width);
	} else {			/* contour is betwn near_z and far_z */
		miColor near_color = *mi_eval_color(&paras->near_color);
		miColor far_color  = *mi_eval_color(&paras->far_color);
		/* Weights w_near and w_far depend on depth */
		w_near = (depth - far_z) / (near_z - far_z);
		miASSERT(0.0 <= w_near && w_near <= 1.0);
		w_far = 1.0 - w_near;

		/* Mix of near_color and far_color according to weights */
		result->color.r = w_near * near_color.r + w_far * far_color.r;
		result->color.g = w_near * near_color.g + w_far * far_color.g;
		result->color.b = w_near * near_color.b + w_far * far_color.b;
		result->color.a = w_near * near_color.a + w_far * far_color.a;

		/* Width depending on weights */
		result->width   = w_near * *mi_eval_scalar(&paras->near_width) 
				+ w_far  * *mi_eval_scalar(&paras->far_width);
	}

	/* Width decreases by factor for each refraction_level */
	factor = *mi_eval_scalar(&paras->factor);
	if (factor > miEPS)
		result->width *= pow(factor, (double)info_near->level - 1.0);

	light = *mi_eval_tag(&paras->light);
	if (light) {
		miScalar light_min_factor = 
				*mi_eval_scalar(&paras->light_min_factor);
		/* Get light origin or direction */
		mi_light_info(light, &orgp, &dirp, 0);
		/* Now orgp or dirp is different from the null vector */

		/* Compute direction from light to point */
		if (mi_vector_dot(&orgp, &orgp) > miEPS) /* point light */
			mi_vector_sub(&dir, &info_near->point, &orgp);

		else {				/* directional light source */
			miASSERT(mi_vector_dot(&dirp, &dirp) > miEPS);
			dir = dirp;
		}
		mi_vector_normalize(&dir);

		/* The contour gets wider the more the normal is pointing in
		   the same direction as the light source */
		d = mi_vector_dot(&dir, &info_near->normal);
		result->width *= 0.5 * (d + 1.0) * (1.0 - light_min_factor) +
						light_min_factor;
	}
	miASSERT(result->width <= *mi_eval_scalar(&paras->near_width));
	return(miTRUE);
}
Example #30
0
extern "C" DLLEXPORT miBoolean mib_continue(
    miColor		*result,
    miState		*state,
    struct mc	*paras)
{
    miColor		*inp;
    miColor		*transp;

    /* check for illegal calls */
    if (state->type == miRAY_DISPLACE) {
        result->r = result->g = result->b = result->a = 0.0;
        return miTRUE;
    }

    transp = mi_eval_color(&paras->transp);

    if (state->type == miRAY_SHADOW) {
        /* special case for shadow rays: modulate the result
           color and return miTRUE if there is still some
           transparency, so that intersection finding will
           continue until full occlusion is reached. */

        if (state->options->shadow == 's') {
            /* a surface using the mib_continue shader is
               not meant to contain a volume, so we just
               set the same volume on both sides of the
               surface. */
            state->refraction_volume = state->volume;
            mi_continue_shadow_seg(result, state);
        }

        if (transp->r != 1.0 || transp->g != 1.0 ||
                transp->b != 1.0 || transp->a != 1.0) {
            inp = mi_eval_color(&paras->input);
            result->r = result->r * transp->r +
                        inp->r * (1.0 - transp->r);
            result->g = result->g * transp->g +
                        inp->g * (1.0 - transp->g);
            result->b = result->b * transp->b +
                        inp->b * (1.0 - transp->b);
            result->a = result->a * transp->a +
                        inp->a * (1.0 - transp->a);
        }

        return result->r || result->g || result->b;
    }

    if (transp->r == 0.0 && transp->g == 0.0 &&
            transp->b == 0.0 && transp->a == 0.0)
        *result = *mi_eval_color(&paras->input);
    else {
        mi_trace_continue(result, state);

        if (transp->r != 1.0 || transp->g != 1.0 ||
                transp->b != 1.0 || transp->a != 1.0) {
            inp = mi_eval_color(&paras->input);
            result->r = result->r * transp->r +
                        inp->r * (1.0 - transp->r);
            result->g = result->g * transp->g +
                        inp->g * (1.0 - transp->g);
            result->b = result->b * transp->b +
                        inp->b * (1.0 - transp->b);
            result->a = result->a * transp->a +
                        inp->a * (1.0 - transp->a);
        }
    }

    return miTRUE;
}