task that renders a single screen tile */
| 167 | |
| 168 | /* task that renders a single screen tile */ |
| 169 | Vec3fa renderPixel(const TutorialData& data, float x, float y, const ISPCCamera& camera, RayStats& stats) |
| 170 | { |
| 171 | /* initialize ray */ |
| 172 | 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); |
| 173 | |
| 174 | /* intersect ray with scene */ |
| 175 | RTCIntersectArguments iargs; |
| 176 | rtcInitIntersectArguments(&iargs); |
| 177 | iargs.feature_mask = (RTCFeatureFlags) (FEATURE_MASK); |
| 178 | |
| 179 | rtcTraversableIntersect1(data.g_traversable,RTCRayHit_(ray),&iargs); |
| 180 | RayStats_addRay(stats); |
| 181 | |
| 182 | /* shade pixels */ |
| 183 | Vec3fa color = Vec3fa(0.0f); |
| 184 | if (ray.geomID != RTC_INVALID_GEOMETRY_ID) |
| 185 | { |
| 186 | /* calculate shading normal in world space */ |
| 187 | Vec3fa Ns = ray.Ng; |
| 188 | if (ray.instID[0] != RTC_INVALID_GEOMETRY_ID) |
| 189 | { |
| 190 | AffineSpace3fa xfm; |
| 191 | rtcGetGeometryTransformFromTraversable(data.g_traversable,ray.instID[0],0.0f,RTC_FORMAT_FLOAT4X4_COLUMN_MAJOR,&xfm); |
| 192 | Ns = xfmNormal(xfm,Ns); |
| 193 | //Ns = xfmVector(data.normal_xfm[ray.instID[0]],Ns); |
| 194 | } |
| 195 | Ns = normalize(Ns); |
| 196 | |
| 197 | /* calculate diffuse color of geometries */ |
| 198 | Vec3fa diffuse = Vec3fa(1,1,1); |
| 199 | if (ray.instID[0] != RTC_INVALID_GEOMETRY_ID) |
| 200 | diffuse = data.colors[4*ray.instID[0]+ray.geomID]; |
| 201 | color = color + diffuse*0.5; |
| 202 | |
| 203 | /* initialize shadow ray */ |
| 204 | Vec3fa lightDir = normalize(Vec3fa(-1,-1,-1)); |
| 205 | Ray shadow(ray.org + ray.tfar*ray.dir, neg(lightDir), 0.001f, inf); |
| 206 | |
| 207 | /* trace shadow ray */ |
| 208 | RTCOccludedArguments sargs; |
| 209 | rtcInitOccludedArguments(&sargs); |
| 210 | sargs.feature_mask = (RTCFeatureFlags) (FEATURE_MASK); |
| 211 | |
| 212 | rtcTraversableOccluded1(data.g_traversable,RTCRay_(shadow),&sargs); |
| 213 | RayStats_addShadowRay(stats); |
| 214 | |
| 215 | /* add light contribution */ |
| 216 | if (shadow.tfar >= 0.0f) |
| 217 | color = color + diffuse*clamp(-dot(lightDir,Ns),0.0f,1.0f); |
| 218 | } |
| 219 | return color; |
| 220 | } |
| 221 | |
| 222 | void renderPixelStandard(const TutorialData& data, |
| 223 | int x, int y, |
no test coverage detected