void HiZ::greyRGBA(uint8 **pixels) const { if (UNLIKELY(pixels == NULL)) return; if (UNLIKELY(*pixels == NULL)) return; // Iterate over all pixels, find the tile, find the pixel in the tile and // output a grey scaled pixel uint8 *rgba = *pixels; for (uint32 y = 0; y < this->height; ++y) for (uint32 x = 0; x < this->width; ++x) { const uint32 tileX = x / Tile::width; const uint32 tileY = y / Tile::height; const uint32 tileID = tileX + tileY * this->tileXNum; const Tile &tile = this->tiles[tileID]; const float *zptr = &tile.z[0][0]; const uint32 offsetX = x % Tile::width; const uint32 offsetY = y % Tile::height; const uint32 offset = offsetX + Tile::width * offsetY; const uint32 imageOffset = (x + y * this->width) * 4; const float z = min(zptr[offset] * 32.f, 255.f); PF_ASSERT(imageOffset < 4*this->pixelNum); rgba[imageOffset + 0] = uint8(z); rgba[imageOffset + 1] = uint8(z); rgba[imageOffset + 2] = uint8(z); rgba[imageOffset + 3] = 0xff; } }
// We create packets and directly fill each zBuffer tile. Note that we // really store t values void TaskRayTraceHiZ::run(size_t taskID) { const uint32 taskX = taskID % this->taskXNum; const uint32 taskY = taskID / this->taskXNum; const uint32 startX = taskX * this->width; const uint32 startY = taskY * this->height; const uint32 endX = startX + this->width; const uint32 endY = startY + this->height; uint32 tileY = startY / HiZ::Tile::height; for (uint32 y = startY; y < endY; y += RayPacket::height, ++tileY) { uint32 tileX = startX / HiZ::Tile::width; for (uint32 x = startX; x < endX; x += RayPacket::width, ++tileX) { RayPacket pckt; PacketHit hit; gen.generate(pckt, x, y); intersector->traverse(pckt, hit); ssef zmin(inf), zmax(neg_inf); const uint32 tileID = tileX + tileY * zBuffer->tileXNum; PF_ASSERT(tileID < zBuffer->tileNum); HiZ::Tile &tile = zBuffer->tiles[tileID]; for (uint32 chunkID = 0; chunkID < HiZ::Tile::chunkNum; ++chunkID) { //const ssef t = hit.t[chunkID]; const ssef t = hit.t[chunkID] *dot(sse3f(view.x,view.y,view.z), pckt.dir[chunkID]); tile.z[chunkID] = t; zmin = min(zmin, t); zmax = max(zmax, t); } tile.zmin = reduce_min(zmin)[0]; tile.zmax = reduce_max(zmax)[0]; } } }
void rnContextDelete(RnContext ctx) { if (ctx == NULL) return; PF_ASSERT(ctx == renderer); if (ctx->refDec()) { Lock<MutexSys> lock(rendererMutex); PF_DELETE(renderer); renderer = NULL; } }
void rnFrameSetCamera(RnFrame frame, const float *org, const float *up, const float *view, float fov, float ratio) { PF_ASSERT(frame); frame->setCamera(org, up, view, fov, ratio); }
void RendererDisplayList::add(RendererObj *obj, const float *m) { PF_ASSERT(this->isCompiled() == false); Elem elem; if (m) { elem.isIdentity = 0; elem.model = mat4x4f(m[0], m[1], m[2], m[3], m[4], m[5], m[6], m[7], m[8], m[9], m[10],m[11], m[12],m[13],m[14],m[15]); } else { elem.isIdentity = 1; elem.model = mat4x4f(one); } elem.object = obj; this->objects.push_back(elem); }
int main(int argc, char *argv[]) { int32_t mortonX[n]; int32_t mortonY[n]; for (uint32_t i = 0; i < n; ++i) mortonX[i] = mortonY[i] = -1; for (uint16_t y = 0; y < dim; ++y) for (uint16_t x = 0; x < dim; ++x) { uint32_t z = 0; for (int i = 0; i < sizeof(x) * 8; i++) z |= (x & 1U << i) << i | (y & 1U << i) << (i + 1); mortonX[z] = x; mortonY[z] = y; } #ifndef NDEBUG for (uint32_t i = 0; i < n; ++i) PF_ASSERT(mortonX[i] != -1 && mortonY[i] != -1); #endif /* NDEBUG */ std::cout << "const int32 ALIGNED(16) RTCameraPacketGen::mortonX[] = {" << std::endl; for (uint32_t i = 0; i < n; i += 16) { for (uint32_t j = i; j < i + 16; ++j) std::cout << std::setw(2) << mortonX[j] << ", "; std::cout << std::endl; } std::cout << "};" << std::endl; std::cout << std::endl; std::cout << "const int32 ALIGNED(16) RTCameraPacketGen::mortonY[] = {" << std::endl; for (uint32_t i = 0; i < n; i += 16) { for (uint32_t j = i; j < i + 16; ++j) std::cout << std::setw(2) << mortonY[j] << ", "; std::cout << std::endl; } std::cout << "};" << std::endl; std::cout << std::endl; }
INLINE T& operator [](size_t axis) {PF_ASSERT(axis < 2); return (&x)[axis];}
INLINE const T& operator [](size_t axis) const {PF_ASSERT(axis < 2); return (&x)[axis];}
static void RendererObjectCompile(T *object) { PF_ASSERT(object); object->compile(); }
RnDisplayList rnDisplayListNew(RnContext ctx) { PF_ASSERT(ctx); RnDisplayList list = PF_NEW(RendererDisplayList, *ctx); RendererObjectNew(list); return list; }
/*! Common for all user renderer object deletion */ static void RendererObjectDelete(RendererObject *object) { PF_ASSERT(object); object->externalRefDec(); if (object->refDec()) PF_DELETE(object); }
void rnFrameSetDisplayList(RnFrame frame, RnDisplayList list) { PF_ASSERT(frame); frame->setDisplayList(list); }
RnTask rnFrameDisplay(RnFrame frame) { PF_ASSERT(frame); return frame->display(); }
void rnFrameSetScreenDimension(RnFrame frame, uint32 w, uint32 h) { PF_ASSERT(frame); frame->setScreenDimension(w, h); }
RnFrame rnFrameNew(RnContext ctx) { PF_ASSERT(ctx); RnFrame frame = PF_NEW(RendererFrame, *ctx); RendererObjectNew(frame); return frame; }
INLINE int32& operator []( const size_t index ) { PF_ASSERT(index < 8); return v[index]; }
/*! Common for all user renderer object retains */ static void RendererObjectRetain(RendererObject *object) { PF_ASSERT(object); object->refInc(); object->externalRefInc(); }
void rnObjSetIntersector(RnObj obj, RnIntersector intersector) { PF_ASSERT(obj && obj->isCompiled() == false); obj->intersector = intersector; }