task that renders a single screen tile */
| 350 | |
| 351 | /* task that renders a single screen tile */ |
| 352 | Vec3fa renderPixel(const TutorialData& data, float x, float y, const ISPCCamera& camera, RayStats& stats) |
| 353 | { |
| 354 | /* initialize ray */ |
| 355 | Ray ray(Vec3fa(camera.xfm.p), Vec3fa(normalize(x*camera.xfm.l.vx + y*camera.xfm.l.vy + camera.xfm.l.vz)), 0.0f, inf); |
| 356 | |
| 357 | /* intersect ray with scene */ |
| 358 | rtcIntersect1(data.scene,RTCRayHit_(ray)); |
| 359 | RayStats_addRay(stats); |
| 360 | |
| 361 | /* shade pixels */ |
| 362 | Vec3fa color = Vec3fa(0.0f); |
| 363 | if (ray.geomID != RTC_INVALID_GEOMETRY_ID) |
| 364 | { |
| 365 | /* interpolate diffuse color */ |
| 366 | Vec3fa diffuse = Vec3fa(1.0f,0.0f,0.0f); |
| 367 | if (ray.geomID > 0) |
| 368 | { |
| 369 | auto geomID = ray.geomID; { |
| 370 | rtcInterpolate0(rtcGetGeometry(data.scene,geomID),ray.primID,ray.u,ray.v,RTC_BUFFER_TYPE_VERTEX_ATTRIBUTE,0,&diffuse.x,3); |
| 371 | } |
| 372 | //return diffuse; |
| 373 | diffuse = 0.5f*diffuse; |
| 374 | } |
| 375 | |
| 376 | /* calculate smooth shading normal */ |
| 377 | Vec3fa Ng = ray.Ng; |
| 378 | /*if (ray.geomID == 2 || ray.geomID == 3) { |
| 379 | Vec3fa dPdu,dPdv; |
| 380 | auto geomID = ray.geomID; { |
| 381 | rtcInterpolate1(rtcGetGeometry(data.scene,geomID),ray.primID,ray.u,ray.v,RTC_BUFFER_TYPE_VERTEX,0,nullptr,&dPdu.x,&dPdv.x,3); |
| 382 | } |
| 383 | //return dPdu; |
| 384 | Ng = cross(dPdu,dPdv); |
| 385 | }*/ |
| 386 | Ng = normalize(Ng); |
| 387 | color = color + diffuse*0.5f; |
| 388 | Vec3fa lightDir = normalize(Vec3fa(-1,-1,-1)); |
| 389 | |
| 390 | /* initialize shadow ray */ |
| 391 | Ray shadow(ray.org + ray.tfar*ray.dir, neg(lightDir), 0.001f, inf); |
| 392 | |
| 393 | /* trace shadow ray */ |
| 394 | rtcOccluded1(data.scene,RTCRay_(shadow)); |
| 395 | RayStats_addShadowRay(stats); |
| 396 | |
| 397 | /* add light contribution */ |
| 398 | if (shadow.tfar >= 0.0f) { |
| 399 | Vec3fa r = normalize(reflect(ray.dir,Ng)); |
| 400 | float s = pow(clamp(dot(r,lightDir),0.0f,1.0f),10.0f); |
| 401 | float d = clamp(-dot(lightDir,Ng),0.0f,1.0f); |
| 402 | color = color + diffuse*d + 0.5f*Vec3fa(s); |
| 403 | } |
| 404 | } |
| 405 | return color; |
| 406 | } |
| 407 | |
| 408 | void renderPixelStandard(const TutorialData& data, |
| 409 | int x, int y, |
no test coverage detected