task that renders a single screen tile */
| 556 | |
| 557 | /* task that renders a single screen tile */ |
| 558 | void renderPixelStandard(const TutorialData& data, |
| 559 | int x, int y, |
| 560 | int* pixels, |
| 561 | const unsigned int width, |
| 562 | const unsigned int height, |
| 563 | const float time, |
| 564 | const ISPCCamera& camera, RayStats& stats) |
| 565 | { |
| 566 | /* initialize ray */ |
| 567 | 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); |
| 568 | |
| 569 | /* intersect ray with scene */ |
| 570 | RTCIntersectArguments iargs; |
| 571 | rtcInitIntersectArguments(&iargs); |
| 572 | iargs.feature_mask = (RTCFeatureFlags) (FEATURE_MASK); |
| 573 | rtcTraversableIntersect1(data.g_traversable,RTCRayHit_(ray),&iargs); |
| 574 | RayStats_addRay(stats); |
| 575 | |
| 576 | /* shade pixels */ |
| 577 | Vec3fa color = Vec3fa(0.0f); |
| 578 | if (ray.geomID != RTC_INVALID_GEOMETRY_ID) |
| 579 | { |
| 580 | Vec3fa diffuse = ray.geomID != 0 ? Vec3fa(0.9f,0.6f,0.5f) : Vec3fa(0.8f,0.0f,0.0f); |
| 581 | color = color + diffuse*0.5f; |
| 582 | Vec3fa lightDir = normalize(Vec3fa(-1,-1,-1)); |
| 583 | Vec3fa Ng = normalize(ray.Ng); |
| 584 | |
| 585 | if (ray.geomID == 1) |
| 586 | { |
| 587 | unsigned int startVertexID = data.gmesh.egrids[ray.primID].startVertexID; |
| 588 | int width = data.gmesh.egrids[ray.primID].width; |
| 589 | int height = data.gmesh.egrids[ray.primID].height; |
| 590 | unsigned int stride = data.gmesh.egrids[ray.primID].stride; |
| 591 | float U = ray.u*(width-1); |
| 592 | float V = ray.v*(height-1); |
| 593 | int x = min((int)floor(U),width -2); |
| 594 | int y = min((int)floor(V),height-2); |
| 595 | float u = U-x; |
| 596 | float v = V-y; |
| 597 | Vec3fa N00 = data.gmesh.normals[startVertexID+(y+0)*stride+(x+0)]; |
| 598 | Vec3fa N01 = data.gmesh.normals[startVertexID+(y+0)*stride+(x+1)]; |
| 599 | Vec3fa N10 = data.gmesh.normals[startVertexID+(y+1)*stride+(x+0)]; |
| 600 | Vec3fa N11 = data.gmesh.normals[startVertexID+(y+1)*stride+(x+1)]; |
| 601 | Vec3fa N0 = mylerp(u,N00,N01); |
| 602 | Vec3fa N1 = mylerp(u,N10,N11); |
| 603 | Ng = normalize(mylerp(v,N0,N1)); |
| 604 | //return Ng; |
| 605 | } |
| 606 | |
| 607 | /* initialize shadow ray */ |
| 608 | Ray shadow(ray.org + ray.tfar*ray.dir, neg(lightDir), 0.001f, inf, 0.0f); |
| 609 | |
| 610 | /* trace shadow ray */ |
| 611 | RTCOccludedArguments sargs; |
| 612 | rtcInitOccludedArguments(&sargs); |
| 613 | sargs.feature_mask = (RTCFeatureFlags) (FEATURE_MASK); |
| 614 | rtcTraversableOccluded1(data.g_traversable,RTCRay_(shadow),&sargs); |
| 615 | RayStats_addShadowRay(stats); |
no test coverage detected