| 1106 | } |
| 1107 | |
| 1108 | void postIntersectGeometry(const TutorialData& data, const Ray& ray, DifferentialGeometry& dg, ISPCGeometry* geometry, int& materialID) |
| 1109 | { |
| 1110 | if (geometry->type == TRIANGLE_MESH) |
| 1111 | { |
| 1112 | ISPCTriangleMesh* mesh = (ISPCTriangleMesh*) geometry; |
| 1113 | materialID = mesh->geom.materialID; |
| 1114 | |
| 1115 | ISPCTriangle* tri = &mesh->triangles[dg.primID]; |
| 1116 | const Vec3fa p0 = Vec3fa(mesh->positions[0][tri->v0]); |
| 1117 | const Vec3fa p1 = Vec3fa(mesh->positions[0][tri->v1]); |
| 1118 | const Vec3fa p2 = Vec3fa(mesh->positions[0][tri->v2]); |
| 1119 | const Vec3fa e = max(max(abs(p0),abs(p1)),max(abs(p2),abs(ray.org))); |
| 1120 | dg.eps = 32.0f*1.19209e-07f*max(max(e.x,e.y),max(e.z,ray.tfar)); |
| 1121 | |
| 1122 | if (mesh->texcoords) |
| 1123 | { |
| 1124 | ISPCTriangle* tri = &mesh->triangles[dg.primID]; |
| 1125 | const Vec2f st0 = mesh->texcoords[tri->v0]; |
| 1126 | const Vec2f st1 = mesh->texcoords[tri->v1]; |
| 1127 | const Vec2f st2 = mesh->texcoords[tri->v2]; |
| 1128 | const float u = ray.u, v = ray.v, w = 1.0f-ray.u-ray.v; |
| 1129 | const Vec2f st = w*st0 + u*st1 + v*st2; |
| 1130 | dg.u = st.x; |
| 1131 | dg.v = st.y; |
| 1132 | } |
| 1133 | if (mesh->normals) |
| 1134 | { |
| 1135 | if (mesh->numTimeSteps == 1) |
| 1136 | { |
| 1137 | ISPCTriangle* tri = &mesh->triangles[dg.primID]; |
| 1138 | const Vec3fa n0 = Vec3fa(mesh->normals[0][tri->v0]); |
| 1139 | const Vec3fa n1 = Vec3fa(mesh->normals[0][tri->v1]); |
| 1140 | const Vec3fa n2 = Vec3fa(mesh->normals[0][tri->v2]); |
| 1141 | const float u = ray.u, v = ray.v, w = 1.0f-ray.u-ray.v; |
| 1142 | dg.Ns = w*n0 + u*n1 + v*n2; |
| 1143 | } |
| 1144 | else |
| 1145 | { |
| 1146 | ISPCTriangle* tri = &mesh->triangles[dg.primID]; |
| 1147 | float f = mesh->numTimeSteps*ray.time(); |
| 1148 | int itime = clamp((int)floor(f),0,(int)mesh->numTimeSteps-2); |
| 1149 | float t1 = f-itime; |
| 1150 | float t0 = 1.0f-t1; |
| 1151 | const Vec3fa a0 = Vec3fa(mesh->normals[itime+0][tri->v0]); |
| 1152 | const Vec3fa a1 = Vec3fa(mesh->normals[itime+0][tri->v1]); |
| 1153 | const Vec3fa a2 = Vec3fa(mesh->normals[itime+0][tri->v2]); |
| 1154 | const Vec3fa b0 = Vec3fa(mesh->normals[itime+1][tri->v0]); |
| 1155 | const Vec3fa b1 = Vec3fa(mesh->normals[itime+1][tri->v1]); |
| 1156 | const Vec3fa b2 = Vec3fa(mesh->normals[itime+1][tri->v2]); |
| 1157 | const Vec3fa n0 = t0*a0 + t1*b0; |
| 1158 | const Vec3fa n1 = t0*a1 + t1*b1; |
| 1159 | const Vec3fa n2 = t0*a2 + t1*b2; |
| 1160 | const float u = ray.u, v = ray.v, w = 1.0f-ray.u-ray.v; |
| 1161 | dg.Ns = w*n0 + u*n1 + v*n2; |
| 1162 | } |
| 1163 | } |
| 1164 | } |
| 1165 | else if (geometry->type == QUAD_MESH) |
no test coverage detected