int ray_color(t_ray *ray, t_env *e) { double spot_dist; int color; t_list *lst; t_ray light; if (!ray->obj) return (COLOR_BACKGROUND); if (!e->scene->spot) return (ray->obj->param.color); /* Si le damier est voulue; */ //color = damier_color(ray); color = color_scale(ray->obj->param.color, ray->obj->param.ambiant); lst = e->scene->spot; while (lst) { init_light_ray(&light, ray, lst->content); ray_intersect(&light, e); spot_dist = 0; if (light.obj) spot_dist = mat_dist(&LST_CONTENT(lst, t_spot*)->position, &ray->intersection); if (!light.obj || spot_dist < light.dist) color = color_add(color, get_spot(ray, &light, lst->content)); lst = lst->next; } //if(ray->obj && ray->obj->param.type == PLANE) // color = damier_color(ray); return (color); }
main(int argc, char **argv) { Prim *o; Color c; int u, v; Ray r; Inode *l; o = sphere_instance(&sphere_funcs); init_sdl(); s = scene_read(); init_render(); for (v = s->view->sc.ll.y; v < s->view->sc.ur.y; v += 1) { for (u = s->view->sc.ll.x; u < s->view->sc.ur.x; u += 1) { r = ray_unit(ray_transform(ray_view(u, v), mclip)); if ((l = ray_intersect(s->objs, r)) != NULL) c = point_tshade(ray_point(r, l->t), l->n, s->view->center, rc, l->m, o); else c = bgcolor; inode_free(l); img_putc(s->img, u, v, col_dpymap(c)); } } img_write(s->img,"stdout",0); exit(0); }
Color ray_shade(int level, Real w, Ray v, RContext *rc, Object *ol) { Inode *i = ray_intersect(ol, v); if (i != NULL) { Light *l; Real wf; Material *m = i->m; Vector3 p = ray_point(v, i->t); Cone recv = cone_make(p, i->n, PIOVER2); Color c = c_mult(m->c, c_scale(m->ka, ambient(rc))); rc->p = p; for (l = rc->l; l != NULL; l = l->next) if ((*l->transport)(l, recv, rc) && (wf = shadow(l, p, ol)) > RAY_WF_MIN) c = c_add(c, c_mult(m->c, c_scale(wf * m->kd * v3_dot(l->outdir,i->n), l->outcol))); if (level++ < MAX_RAY_LEVEL) { if ((wf = w * m->ks) > RAY_WF_MIN) { Ray r = ray_make(p, reflect_dir(v.d, i->n)); c = c_add(c, c_mult(m->s, c_scale(m->ks, ray_shade(level, wf, r, rc, ol)))); } if ((wf = w * m->kt) > RAY_WF_MIN) { Ray t = ray_make(p, refract_dir(v.d, i->n, (i->enter)? 1/m->ir: m->ir)); if (v3_sqrnorm(t.d) > 0) { c = c_add(c, c_mult(m->s, c_scale(m->kt, ray_shade(level, wf, t, rc, ol)))); } } } inode_free(i); return c; } else { return BG_COLOR; } }
// Doc in parent void SoVRMLGroup::rayPick(SoRayPickAction * action) { if (this->pickCulling.getValue() == OFF || !PRIVATE(this)->bboxcache || !PRIVATE(this)->bboxcache->isValid(action->getState()) || !action->hasWorldSpaceRay() || ray_intersect(action, PRIVATE(this)->bboxcache->getProjectedBox())) { SoVRMLGroup::doAction(action); } }
Real shadow(Light *l, Vector3 p, Object *ol) { Real t, kt; Inode *i; Vector3 d; if (l->type == LIGHT_AMBIENT) return 1.0; d = (l->type == LIGHT_DISTANT)? l->dir : v3_sub(l->loc, p); if ((i = ray_intersect(ol, ray_make(p, d))) == NULL) return 1.0; t = i->t; kt = i->m->kt; inode_free(i); if (l->type == LIGHT_DISTANT && t > RAY_EPS) return kt; else if (l->type != LIGHT_DISTANT && t > RAY_EPS && t < 1) return kt; else return 1.0; }