Пример #1
0
Scene* scene_box(const Box* box) {
	Plane rightPlane = (Plane){(Vec3){1,0,0},(FPType)-0.5 * box->lenX};
	Plane leftPlane = (Plane){(Vec3){-1,0,0},(FPType)-0.5 * box->lenX};
	Plane backPlane = (Plane){(Vec3){0,1,0},(FPType)-0.5 * box->lenY};
	Plane frontPlane = (Plane){(Vec3){0,-1,0},(FPType)-0.5 * box->lenY};
	Plane topPlane = (Plane){(Vec3){0,0,1},(FPType)-0.5 * box->lenZ};
	Plane bottomPlane = (Plane){(Vec3){0,0,-1},(FPType)-0.5 * box->lenZ};
	return scene_from_space(
		scene_intersect(
			scene_intersect(
				scene_half_space(&rightPlane),
				scene_half_space(&leftPlane)
			),
			scene_intersect(
				scene_intersect(
					scene_half_space(&backPlane),
					scene_half_space(&frontPlane)
				),
				scene_intersect(
					scene_half_space(&topPlane),
					scene_half_space(&bottomPlane)
				)
			)
		),
		&box->axes
	);
}
Пример #2
0
bool OSLRenderServices::trace(TraceOpt &options, OSL::ShaderGlobals *sg,
	const OSL::Vec3 &P, const OSL::Vec3 &dPdx,
	const OSL::Vec3 &dPdy, const OSL::Vec3 &R,
	const OSL::Vec3 &dRdx, const OSL::Vec3 &dRdy)
{
	/* todo: options.shader support, maybe options.traceset */
	ShaderData *sd = (ShaderData *)(sg->renderstate);

	/* setup ray */
	Ray ray;

	ray.P = TO_FLOAT3(P);
	ray.D = TO_FLOAT3(R);
	ray.t = (options.maxdist == 1.0e30)? FLT_MAX: options.maxdist - options.mindist;
	ray.time = sd->time;

	if(options.mindist == 0.0f) {
		/* avoid self-intersections */
		if(ray.P == sd->P) {
			bool transmit = (dot(sd->Ng, ray.D) < 0.0f);
			ray.P = ray_offset(sd->P, (transmit)? -sd->Ng: sd->Ng);
		}
	}
	else {
		/* offset for minimum distance */
		ray.P += options.mindist*ray.D;
	}

	/* ray differentials */
	ray.dP.dx = TO_FLOAT3(dPdx);
	ray.dP.dy = TO_FLOAT3(dPdy);
	ray.dD.dx = TO_FLOAT3(dRdx);
	ray.dD.dy = TO_FLOAT3(dRdy);

	/* allocate trace data */
	OSLTraceData *tracedata = (OSLTraceData*)sg->tracedata;
	tracedata->ray = ray;
	tracedata->setup = false;
	tracedata->init = true;

	/* raytrace */
#ifdef __HAIR__
	return scene_intersect(sd->osl_globals, &ray, ~0, &tracedata->isect, NULL, 0.0f, 0.0f);
#else
	return scene_intersect(sd->osl_globals, &ray, ~0, &tracedata->isect);
#endif
}
Пример #3
0
static void	get_lum(double *col, t_scene *s, t_intersect *inter, int m)
{
  t_vec3	l;
  t_vec3	r;
  double	ln;
  int		i;
  double	is;
  double	id;
  double	dist;
  double	rv;
  double	tmp;
  t_ray		ray;
  t_intersect	shadow;

  i = -1;
  if (s->lights[m].light.type == DIRECTIONNAL)
    {
      while (++i < 3)
	{
	  ln = dot_vec3(inter->norm, s->lights[m].light.dir);
	  col[i] =  MAX(ln, 0) * s->lights[m].light.color.argb[i] / 255.0 *
	    s->lights[m].light.power;
	}
      return ;
    }
  l = sub_vec3(s->lights[m].pos, inter->pos);
  dist = vec3_len(l);
  l = div_vec3(l, dist);
  dist -= s->lights[m].light.radius;
  ln = dot_vec3(l, inter->norm);
  ln = MAX(ln, 0.0);
  r = vec3_normalize(sub_vec3(mult_vec3(inter->norm, 2 * ln), l));
  is = s->lights[m].light.power / dist;
  id = s->lights[m].light.radius * is;
  rv = -dot_vec3(r, inter->dir);
  rv = MAX(rv, 0.0);
  ray.pos = add_vec3(inter->pos, mult_vec3(inter->norm, 0.00001));
  ray.dir = l;
  ray.env = NULL;
  scene_intersect(s, &ray, &shadow);
  if (shadow.dist < dist - 0.0001)
    return ;
  while (++i < 3)
    {
      tmp = inter->mat->diffuse * MAX(ln, 0) * id *
      	s->lights[m].light.color.argb[i] / 255.0;
      col[i] += MAX(tmp, 0);
      tmp = inter->mat->specular * pow(rv, inter->mat->shininess)
	* is * s->lights[m].light.color.argb[i] / 255.0;
      col[i] += MAX(tmp, 0);
    }
}
Пример #4
0
bool OSLRenderServices::trace(TraceOpt &options,
                              OSL::ShaderGlobals *sg,
                              const OSL::Vec3 &P,
                              const OSL::Vec3 &dPdx,
                              const OSL::Vec3 &dPdy,
                              const OSL::Vec3 &R,
                              const OSL::Vec3 &dRdx,
                              const OSL::Vec3 &dRdy)
{
  /* todo: options.shader support, maybe options.traceset */
  ShaderData *sd = (ShaderData *)(sg->renderstate);

  /* setup ray */
  Ray ray;

  ray.P = TO_FLOAT3(P);
  ray.D = TO_FLOAT3(R);
  ray.t = (options.maxdist == 1.0e30f) ? FLT_MAX : options.maxdist - options.mindist;
  ray.time = sd->time;

  if (options.mindist == 0.0f) {
    /* avoid self-intersections */
    if (ray.P == sd->P) {
      bool transmit = (dot(sd->Ng, ray.D) < 0.0f);
      ray.P = ray_offset(sd->P, (transmit) ? -sd->Ng : sd->Ng);
    }
  }
  else {
    /* offset for minimum distance */
    ray.P += options.mindist * ray.D;
  }

  /* ray differentials */
  ray.dP.dx = TO_FLOAT3(dPdx);
  ray.dP.dy = TO_FLOAT3(dPdy);
  ray.dD.dx = TO_FLOAT3(dRdx);
  ray.dD.dy = TO_FLOAT3(dRdy);

  /* allocate trace data */
  OSLTraceData *tracedata = (OSLTraceData *)sg->tracedata;
  tracedata->ray = ray;
  tracedata->setup = false;
  tracedata->init = true;
  tracedata->sd.osl_globals = sd->osl_globals;

  /* Raytrace, leaving out shadow opaque to avoid early exit. */
  uint visibility = PATH_RAY_ALL_VISIBILITY - PATH_RAY_SHADOW_OPAQUE;
  return scene_intersect(sd->osl_globals, ray, visibility, &tracedata->isect);
}