tutorials/viewer/viewer_device.cpp
Vec3fa renderPixelStandard(float x, float y, const ISPCCamera& camera)
{
  /* initialize sampler */
  RandomSampler sampler;
  RandomSampler_init(sampler, (int)x, (int)y, 0);

  /* initialize ray */
  RTCRay ray;
  ray.org = Vec3fa(camera.xfm.p);
  ray.dir = Vec3fa(normalize(x*camera.xfm.l.vx + y*camera.xfm.l.vy + camera.xfm.l.vz));
  ray.tnear = 0.0f;
  ray.tfar = inf;
  ray.geomID = RTC_INVALID_GEOMETRY_ID;
  ray.primID = RTC_INVALID_GEOMETRY_ID;
  ray.mask = -1;
  ray.time = RandomSampler_get1D(sampler);

  /* intersect ray with scene */
  rtcIntersect(g_scene,ray);

  /* shade background black */
  if (ray.geomID == RTC_INVALID_GEOMETRY_ID) {
    return Vec3fa(0.0f);
  }

  /* shade all rays that hit something */
  Vec3fa color = Vec3fa(0.5f);

  /* compute differential geometry */
  DifferentialGeometry dg;
  dg.geomID = ray.geomID;
  dg.primID = ray.primID;
  dg.u = ray.u;
  dg.v = ray.v;
  dg.P  = ray.org+ray.tfar*ray.dir;
  dg.Ng = ray.Ng;
  dg.Ns = ray.Ng;

  if (g_use_smooth_normals)
    if (ray.geomID != RTC_INVALID_GEOMETRY_ID) // FIXME: workaround for ISPC bug, location reached with empty execution mask
  {
    Vec3fa dPdu,dPdv;
    unsigned int geomID = ray.geomID; {
      rtcInterpolate(g_scene,geomID,ray.primID,ray.u,ray.v,RTC_VERTEX_BUFFER0,nullptr,&dPdu.x,&dPdv.x,3);
    }
    dg.Ns = cross(dPdv,dPdu);
  }

  int materialID = postIntersect(ray,dg);
  dg.Ng = face_forward(ray.dir,normalize(dg.Ng));
  dg.Ns = face_forward(ray.dir,normalize(dg.Ns));

  /* shade */
  if (g_ispc_scene->materials[materialID].ty == MATERIAL_OBJ) {
    OBJMaterial* material = (OBJMaterial*) &g_ispc_scene->materials[materialID];
    color = Vec3fa(material->Kd);
  }

  return color*dot(neg(ray.dir),dg.Ns);
}
/* task that renders a single screen tile */
task that renders a single screen tile
task that renders a single screen tile
Vec3fa renderPixelStandard(float x, float y, const ISPCCamera& camera)
{
  RandomSampler sampler;
  RandomSampler_init(sampler, (int)x, (int)y, 0);
  RTCRay ray;
  ray.org = Vec3fa(camera.xfm.p);
  ray.dir = Vec3fa(normalize(x*camera.xfm.l.vx + y*camera.xfm.l.vy + camera.xfm.l.vz));
  ray.tnear = 0.0f;
  ray.tfar = inf;
  ray.geomID = RTC_INVALID_GEOMETRY_ID;
  ray.primID = RTC_INVALID_GEOMETRY_ID;
  ray.mask = -1;
  ray.time = RandomSampler_get1D(sampler);
  rtcIntersect(g_scene,ray);
  if (ray.geomID == RTC_INVALID_GEOMETRY_ID) {
    return Vec3fa(0.0f);
  }
  Vec3fa color = Vec3fa(0.5f);
  DifferentialGeometry dg;
  dg.geomID = ray.geomID;
  dg.primID = ray.primID;
  dg.u = ray.u;
  dg.v = ray.v;
  dg.P  = ray.org+ray.tfar*ray.dir;
  dg.Ng = ray.Ng;
  dg.Ns = ray.Ng;
  if (g_use_smooth_normals)
    if (ray.geomID != RTC_INVALID_GEOMETRY_ID) 
  {
    Vec3fa dPdu,dPdv;
    unsigned int geomID = ray.geomID; {
      rtcInterpolate(g_scene,geomID,ray.primID,ray.u,ray.v,RTC_VERTEX_BUFFER0,nullptr,&dPdu.x,&dPdv.x,3);
    }
    dg.Ns = cross(dPdv,dPdu);
  }
  int materialID = postIntersect(ray,dg);
  dg.Ng = face_forward(ray.dir,normalize(dg.Ng));
  dg.Ns = face_forward(ray.dir,normalize(dg.Ns));
  if (g_ispc_scene->materials[materialID].ty == MATERIAL_OBJ) {
    OBJMaterial* material = (OBJMaterial*) &g_ispc_scene->materials[materialID];
    color = Vec3fa(material->Kd);
  }
  return color*dot(neg(ray.dir),dg.Ns);
}
Vec3fa renderPixelStandard ( float x , float y , const ISPCCamera & camera ) { RandomSampler sampler ; RandomSampler_init ( sampler , ( int ) x , ( int ) y , 0 ) ; RTCRay ray ; ray . org = Vec3fa ( camera . xfm . p ) ; ray . dir = Vec3fa ( normalize ( x * camera . xfm . l . vx + y * camera . xfm . l . vy + camera . xfm . l . vz ) ) ; ray . tnear = 0.0f ; ray . tfar = inf ; ray . geomID = RTC_INVALID_GEOMETRY_ID ; ray . primID = RTC_INVALID_GEOMETRY_ID ; ray . mask = -1 ; ray . time = RandomSampler_get1D ( sampler ) ; rtcIntersect ( g_scene , ray ) ; if ( ray . geomID == RTC_INVALID_GEOMETRY_ID ) { return Vec3fa ( 0.0f ) ; } Vec3fa color = Vec3fa ( 0.5f ) ; DifferentialGeometry dg ; dg . geomID = ray . geomID ; dg . primID = ray . primID ; dg . u = ray . u ; dg . v = ray . v ; dg . P = ray . org + ray . tfar * ray . dir ; dg . Ng = ray . Ng ; dg . Ns = ray . Ng ; if ( g_use_smooth_normals ) if ( ray . geomID != RTC_INVALID_GEOMETRY_ID ) { Vec3fa dPdu , dPdv ; unsigned int geomID = ray . geomID ; { rtcInterpolate ( g_scene , geomID , ray . primID , ray . u , ray . v , RTC_VERTEX_BUFFER0 , nullptr , & dPdu . x , & dPdv . x , 3 ) ; } dg . Ns = cross ( dPdv , dPdu ) ; } int materialID = postIntersect ( ray , dg ) ; dg . Ng = face_forward ( ray . dir , normalize ( dg . Ng ) ) ; dg . Ns = face_forward ( ray . dir , normalize ( dg . Ns ) ) ; if ( g_ispc_scene -> materials [ materialID ] . ty == MATERIAL_OBJ ) { OBJMaterial * material = ( OBJMaterial * ) & g_ispc_scene -> materials [ materialID ] ; color = Vec3fa ( material -> Kd ) ; } return color * dot ( neg ( ray . dir ) , dg . Ns ) ; }
task that renders a single screen tile
task that renders a single screen tile
/* initialize sampler */ /* initialize ray */ /* intersect ray with scene */ /* shade background black */ /* shade all rays that hit something */ /* compute differential geometry */ // FIXME: workaround for ISPC bug, location reached with empty execution mask /* shade */