DLLEXPORT void domeAFL_FOV_Stereo_init( miState *state, struct dsDomeAFL_FOV_Stereo *params, miBoolean *inst_init_req) { if (!params) { // version output mi_info(_VER_); *inst_init_req = miTRUE; } else { fov_angle = *mi_eval_scalar(¶ms->FOV_Angle); viewport_offset = *mi_eval_vector(¶ms->View_Offset); camera = *mi_eval_integer(¶ms->Camera); dome_radius = *mi_eval_scalar(¶ms->Dome_Radius); dome_tilt = *mi_eval_scalar(¶ms->Dome_Tilt); cameras_separation = *mi_eval_scalar(¶ms->Cameras_Separation); dome_tilt_compensation = *mi_eval_boolean(¶ms->Dome_Tilt_Compensation); vertical_mode = *mi_eval_boolean(¶ms->Vertical_Mode); //mi_info("II-> fov=%f,cam=%i,rad=%f,tilt=%f,sep=%f,comp=%i,vert=%i",fov_angle,camera,dome_radius,dome_tilt,cameras_separation,dome_tilt_compensation,vertical_mode); // Convert input angles from degrees to radians... fov_angle = (miScalar)(fov_angle*M_PI/180.0); dome_tilt = (miScalar)(dome_tilt*M_PI/180.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(¶s->color); /* Normalize light direction (just in case user didn't) */ dir = *mi_eval_vector(¶s->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(¶s->min_width); max_width = *mi_eval_scalar(¶s->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); }
extern "C" DLLEXPORT miBoolean mib_texture_polkasphere( miColor *result, miState *state, struct mtp *paras) { miVector *x; x = mi_eval_vector(¶s->coord); return(polka_dot(result, state, paras, x->x, x->y, x->z)); }
extern "C" DLLEXPORT miBoolean mib_texture_filter_lookup( miColor *result, miState *state, struct mib_texture_filter_lookup *paras) { miTag tex = *mi_eval_tag(¶s->tex); miVector *coord; miUint space; miTag remap; miVector p[3], t[3]; miMatrix ST; miTexfilter ell_opt; miScalar disc_r; if (!tex) { result->r = result->g = result->b = result->a = 0; return(miFALSE); } coord = mi_eval_vector(¶s->coord); space = *mi_eval_integer(¶s->space); disc_r = *mi_eval_scalar(¶s->disc_r); if (disc_r <= 0) disc_r = DISC_R; if (state->reflection_level == 0 && mi_texture_filter_project(p, t, state, disc_r, space) && (remap = *mi_eval_tag(¶s->remap))) { mi_call_shader_x((miColor*)&t[0], miSHADER_TEXTURE, state, remap, &t[0]); mi_call_shader_x((miColor*)&t[1], miSHADER_TEXTURE, state, remap, &t[1]); mi_call_shader_x((miColor*)&t[2], miSHADER_TEXTURE, state, remap, &t[2]); if (mi_texture_filter_transform(ST, p, t)) { ell_opt.eccmax = *mi_eval_scalar(¶s->eccmax); ell_opt.max_minor = *mi_eval_scalar(¶s->maxminor); ell_opt.bilinear = *mi_eval_boolean(¶s->bilinear); ell_opt.circle_radius = CIRCLE_R; /* * when no bump-mapping is used, coord and ST[..] * are identical. for bump mapping, the projection * matrix is calculated for the current raster * position, the ellipse is translated to the * bump position */ ST[2*4+0] = coord->x; ST[2*4+1] = coord->y; if (mi_lookup_filter_color_texture(result, state, tex, &ell_opt, ST)) return(miTRUE); } } /* fallback to standard pyramid or nonfiltered texture lookup */ return(mi_lookup_color_texture(result, state, tex, coord)); }
DLLEXPORT miBoolean td_color_kernel ( miColor *result, miState *state, struct td_color_kernel *params ){ miVector newPoint = *mi_eval_vector( ¶ms->point ); state->point = newPoint; *result = *mi_eval_color( ¶ms->color ); return miTRUE; }
DLLEXPORT miBoolean td_scalar_kernel ( miScalar *result, miState *state, struct td_scalar_kernel *params ){ miVector newPoint = *mi_eval_vector( ¶ms->point ); state->point = newPoint; *result = *mi_eval_scalar( ¶ms->value ); return miTRUE; }
extern "C" DLLEXPORT miBoolean mib_texture_lookup( miColor *result, miState *state, struct mib_texture_lookup *paras) { miTag tex = *mi_eval_tag(¶s->tex); miVector *coord = mi_eval_vector(¶s->coord); if (tex && coord->x >= 0 && coord->x < 1 && coord->y >= 0 && coord->y < 1 && mi_lookup_color_texture(result, state, tex, coord)) return(miTRUE); result->r = result->g = result->b = result->a = 0; return(miFALSE); }
DLLEXPORT miBoolean domeAFL_FOV( miColor *result, miState *state, register struct dsDomeAFL_FOV *params) { miScalar fov_angle_deg = *mi_eval_scalar(¶ms->FOV_Angle); miGeoScalar fov_angle_rad; miVector viewpt_offset = *mi_eval_vector(¶ms->View_Offset); miVector ray; miGeoScalar x, y, r, phi, theta; /* normalize image coordinates btwn [-1,1]... */ /* [ah] Rotate the cartesian axis 90 deg CW */ x = -2.0*state->raster_y/state->camera->y_resolution+1.0; y = 2.0*state->raster_x/state->camera->x_resolution-1.0; /* Calcaulate the radius value */ r = MI_SQRT( ( x * x ) + ( y * y ) ); if ( r < 1.0 ) { /* Calculate phi... */ if ( (r > -EPSILON) && (r < EPSILON) ) { phi = 0.0; } else { phi = atan2(x,y); // [rz] using atan2 instead of original if-then formula } /* Convert FOV angle of fisheye from degrees to radians... */ fov_angle_rad = fov_angle_deg * M_PI / 180.0; /* Calculate theta... */ theta = r * ( fov_angle_rad / 2.0 ); /* Calculate Ray direction vector... */ ray.x = (float)(sin(theta) * cos(phi)); ray.y = (float)(-sin(theta) * sin(phi)); /* -Z is Look At Direction*/ ray.z = (float)(-cos(theta)); /* Account for view offset... */ /* Offset is added to y & z components because they are negative values...*/ ray.x = ray.x - viewpt_offset.x; ray.y = ray.y + viewpt_offset.y; /* Add because MR uses -Z as Look At */ ray.z = ray.z + viewpt_offset.z; /* Flip the ray direction about the y-axis */ if(*mi_eval_boolean(¶ms->Flip_Ray_X)) { ray.x = (-ray.x); } /* Flip the ray direction about the x-axis */ if(*mi_eval_boolean(¶ms->Flip_Ray_Y)) { ray.y = (-ray.y); } /* Convert ray from camera space */ mi_vector_from_camera(state, &ray, &ray); /* Trace new ray... */ return(mi_trace_eye(result, state, &state->org, &ray)); } else { /* Set the return colors to Black */ result->r = result->g = result->b = result->a = 0; return(miFALSE); } } /* end of dome_FOV_AFL() */
DLLEXPORT miBoolean domeAFL_WxH( miColor *result, miState *state, register struct dsDomeAFL_WxH *params) { miScalar diameter = *mi_eval_scalar(¶ms->Diameter); miScalar height = *mi_eval_scalar(¶ms->Height); miGeoScalar fov; /* Field-of-View of specified dome */ miGeoScalar radius; /* Radius of dome being subtended */ /* Does this need to be a pointer? */ miVector viewpt_offset = *mi_eval_vector(¶ms->View_Offset); miVector ray; miGeoScalar x, y, r, phi, theta; /* normalize image coordinates btwn [-1,1]... */ x = (2.0 * state->raster_x) / state->camera->x_resolution - 1.0; y = (2.0 * state->raster_y) / state->camera->y_resolution - 1.0; /* Calculate FOV for given Diameter & height of dome... */ /* Equations obtained from: */ /* http://mathforum.org/dr.math/faq/faq.circle.segment.html#8 */ radius = ((diameter * diameter) + (4 * height * height)) / (8 * height); fov = 2 * asin(diameter / (2 * radius)); /* Calcaulate the radius value */ r = MI_SQRT( ( x * x ) + ( y * y ) ); if ( r < 1.0 ) { /* Calculate phi... */ if ( (r > -EPSILON) && (r < EPSILON) ) { phi = 0.0; } else { phi = atan2(x,y); // [rz] using atan2 instead of original if-then formula } /* Calculate theta... */ theta = r * ( fov / 2.0 ); /* Calculate Ray direction vector... */ ray.x = (float)(sin(theta) * cos(phi)); ray.y = (float)(-sin(theta) * sin(phi)); /* -Z is Look At Direction*/ ray.z = (float)(-cos(theta)); /* Account for view offset... */ /* Offset is added to y & z components because they are negative values...*/ ray.x = ray.x - viewpt_offset.x; ray.y = ray.y + viewpt_offset.y; /* Add because MR uses -Z as Look At */ ray.z = ray.z + viewpt_offset.z; // Flip the ray direction about the y-axis if(*mi_eval_boolean(¶ms->Flip_Ray_X)) { ray.x = (-ray.x); } /* Flip the ray direction about the x-axis */ if(*mi_eval_boolean(¶ms->Flip_Ray_Y)) { ray.y = (-ray.y); } /* Convert ray from camera space */ mi_vector_from_camera(state, &ray, &ray); /* Trace new ray... */ return(mi_trace_eye(result, state, &state->org, &ray)); } else { /* Set return color to Black */ result->r = result->g = result->b = result->a = 0; return(miFALSE); } } /* end of domeAFL_WxH() */