⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 triangle.h

📁 Ray tracing on PS3, using the acceleration of PPU, No SPE acceleration is used. The code must be com
💻 H
字号:
/* Copyright (c) 2007 Massachusetts Institute of Technology * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in * the Software without restriction, including without limitation the rights to * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of * the Software, and to permit persons to whom the Software is furnished to do so, * subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *//** * triangle.h - blue-steel Triangle class * @author Brian Sweatt * * Includes methods for intersecting a RayPacket with a triangle and getting the bounding box of a triangle on the SPU * As well as methods for translating and rotating the triangle from the PPU */#ifndef _TRIANGLE_H_#define _TRIANGLE_H_extern "C" {#include <libvector.h>#include <normalize3.h>#include <cross_product3.h>#include <cross_product3_v.h>#include <dot_product3.h>#include <dot_product3_v.h>#include <simdmath/isgreaterequalf4.h>#include <simdmath/fminf4.h>#include <simdmath/fmaxf4.h>#include <simdmath/recipf4.h>}#include "raypacket.h"#include "hitpacket.h"class Triangle {private:  vector float m_a;  vector float m_ab;  vector float m_ac;  vector float m_n;    // Rather than kicking storage space up another 16 bytes, we should just pack the material id   // in the normal or something  uint32_t m_materialID;    uint32_t pad1, pad2, pad3;		public:  /**   * Constructor: Takes the coordinates for the vertices, as well as the material ID of the shader   * @param a Vertex a   * @param b Vertex b   * @param c Vertex c   * @param m The integer offset in the material array of the material used to shade this triangle   */  Triangle(const vector float &a, const vector float &b, const vector float &c, 	   const uint32_t &m);  ~Triangle() {} ;#ifdef __SPU__  //void intersectPacket(const RayPacket r, HitPacket &h, float tmin);    /**   * SIMDized implementation of the Moller-Trumbore triangle intersection test   * @param r The packet of rays to check for intersection   * @param h The record that will be filled with the details of the resulting intersection   * @param tmin The minimum hit time that will be accepted as a true collision (the near clipping plane)   */  inline void intersectPacket(const RayPacket r, HitPacket &h, float tmin)  {      vector float tvecx, tvecy, tvecz, pvecx, pvecy, pvecz, qvecx, qvecy, qvecz;    vector float det, inv_det, t, u, v, tmin_v = spu_splats(tmin), one_v = spu_splats(1.0f), zero_v = spu_splats(0.0f);    vector unsigned char splat0 =      (vector unsigned char){0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3};    vector unsigned char splat1 =      (vector unsigned char){4, 5, 6, 7, 4, 5, 6, 7, 4, 5, 6, 7, 4, 5, 6, 7};    vector unsigned char splat2 =      (vector unsigned char){8, 9,10,11, 8, 9,10,11, 8, 9,10,11, 8, 9,10,11};    vector float m_acx = spu_shuffle(m_ac, m_ac, splat0);    vector float m_acy = spu_shuffle(m_ac, m_ac, splat1);    vector float m_acz = spu_shuffle(m_ac, m_ac, splat2);    vector float m_abx = spu_shuffle(m_ab, m_ab, splat0);    vector float m_aby = spu_shuffle(m_ab, m_ab, splat1);    vector float m_abz = spu_shuffle(m_ab, m_ab, splat2);    vector float m_ax = spu_shuffle(m_a, m_a, splat0);    vector float m_ay = spu_shuffle(m_a, m_a, splat1);    vector float m_az = spu_shuffle(m_a, m_a, splat2);    _cross_product3_v(&pvecx, &pvecy, &pvecz, r.dx, r.dy, r.dz, m_acx, m_acy, m_acz);    vector float m_nx = spu_shuffle(m_n, m_n, splat0);    vector float m_ny = spu_shuffle(m_n, m_n, splat1);    vector float m_nz = spu_shuffle(m_n, m_n, splat2);    det = _dot_product3_v(m_abx, m_aby, m_abz, pvecx, pvecy, pvecz);    inv_det = _recipf4(det);    tvecx = spu_sub(r.x0, m_ax);    tvecy = spu_sub(r.y0, m_ay);    tvecz = spu_sub(r.z0, m_az);    u = spu_mul(inv_det, _dot_product3_v(tvecx, tvecy, tvecz, pvecx, pvecy, pvecz));    _cross_product3_v(&qvecx, &qvecy, &qvecz, tvecx, tvecy, tvecz, m_abx, m_aby, m_abz);    v = spu_mul(inv_det, _dot_product3_v(r.dx, r.dy, r.dz, qvecx, qvecy, qvecz));    t = spu_mul(inv_det, _dot_product3_v(m_acx, m_acy, m_acz, qvecx, qvecy, qvecz));    vector unsigned int ugt0 = _isgreaterequalf4(u, zero_v);    vector float uPlusv = spu_add(u,v);    vector unsigned int vgt0 = _isgreaterequalf4(v, zero_v);    vector unsigned int oldgtnew = spu_cmpgt(h.t, t);    vector unsigned int uPlusvlt1 = _isgreaterequalf4(one_v, uPlusv);    vector unsigned int newgttmin = spu_cmpgt(t, tmin_v);    ugt0 = spu_and(ugt0, vgt0);      oldgtnew = spu_and(oldgtnew, uPlusvlt1);    ugt0 = spu_and(ugt0, newgttmin);    vector unsigned int valid = spu_and(oldgtnew, ugt0);    h.t = spu_sel(h.t, t, valid);    h.nx = spu_sel(h.nx, m_nx, valid);    h.ny = spu_sel(h.ny, m_ny, valid);    h.nz = spu_sel(h.nz, m_nz, valid);    h.materialID = spu_sel(h.materialID, spu_splats(m_materialID), valid);        return;}    vector float getBoundingBoxMin();  vector float getBoundingBoxMax();#else  void rotate(float rad, const vector float &center, const vector float &axis);#endif  void translate(vector float dir);  };#endif

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -