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

📄 checkerboard.cpp

📁 Ray tracing on PS3, using the acceleration of PPU, No SPE acceleration is used. The code must be com
💻 CPP
📖 第 1 页 / 共 2 页
字号:
/* 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. *//** * checkerboard.cpp holds all the checkerboard related code * @author Russel Ryan * never compile this on its own, it's included from material.cpp just to make things neater */#define CHECKERBOARD_EPSILON 0.01fMATERIAL_SHADER(material_CheckerboardShade) {  dprintf("material_CheckerboardShade\r\n");  vector float _zero = spu_splats(0.0f);    union {    vector unsigned int ids;    struct {      unsigned int id1, id2, id3, id4;    };  };  ids = hp.materialID;    vector float px = spu_madd(rp.dx, hp.t, rp.x0);  vector float py = spu_madd(rp.dy, hp.t, rp.y0);  vector float pz = spu_madd(rp.dz, hp.t, rp.z0);  vector float pw = _zero;  /*  //Filter noise  vector float factor = spu_splats(10.0f);  px = spu_mul(px, factor);  py = spu_mul(py, factor);  pz = spu_mul(pz, factor);  px = floorf4(px);  py = floorf4(py);  pz = floorf4(pz);  px = divf4(px, factor);  py = divf4(py, factor);  pz = divf4(pz, factor);  */     vector float px_temp, py_temp, pz_temp, pw_temp;  vector float px_res, py_res, pz_res;  px_res = py_res = pz_res =  _zero;  vector unsigned int thisID;  vector float matrix[16];  //Do material1's matrix   splat_matrix4x4((vector float*)&matrix, &materials[id1].colorDSRT_r);  xform_vec3_v(&px_temp, &py_temp, &pz_temp, &pw_temp, px, py, pz, (vector float*)&matrix);  thisID = spu_cmpeq(hp.materialID, spu_splats(id1));  px_res = spu_sel(px_res, px_temp, thisID);  py_res = spu_sel(py_res, py_temp, thisID);  pz_res = spu_sel(pz_res, pz_temp, thisID);  //pw_res = spu_sel(pw_res, pw_temp, thisID);  //Do material2's matrix   splat_matrix4x4((vector float*)&matrix, &materials[id2].colorDSRT_r);  xform_vec3_v(&px_temp, &py_temp, &pz_temp, &pw_temp, px, py, pz, (vector float*)&matrix);  thisID = spu_cmpeq(hp.materialID, spu_splats(id2));  px_res = spu_sel(px_res, px_temp, thisID);  py_res = spu_sel(py_res, py_temp, thisID);  pz_res = spu_sel(pz_res, pz_temp, thisID);  //pw_res = spu_sel(pw_res, pw_temp, thisID);  //Do material3's matrix   splat_matrix4x4((vector float*)&matrix, &materials[id3].colorDSRT_r);  xform_vec3_v(&px_temp, &py_temp, &pz_temp, &pw_temp, px, py, pz, (vector float*)&matrix);  thisID = spu_cmpeq(hp.materialID, spu_splats(id3));  px_res = spu_sel(px_res, px_temp, thisID);  py_res = spu_sel(py_res, py_temp, thisID);  pz_res = spu_sel(pz_res, pz_temp, thisID);  //pw_res = spu_sel(pw_res, pw_temp, thisID);  //Do material4's matrix  splat_matrix4x4((vector float*)&matrix, &materials[id4].colorDSRT_r);  xform_vec3_v(&px_temp, &py_temp, &pz_temp, &pw_temp, px, py, pz, (vector float*)&matrix);  thisID = spu_cmpeq(hp.materialID, spu_splats(id4));  px_res = spu_sel(px_res, px_temp, thisID);  py_res = spu_sel(py_res, py_temp, thisID);  pz_res = spu_sel(pz_res, pz_temp, thisID);  //pw_res = spu_sel(pw_res, pw_temp, thisID);    vector float sum = fabsf4(spu_add(floorf4(px_res), spu_add(floorf4(py_res), floorf4(pz_res))));  vector unsigned int type_eq_checker = spu_cmpeq(spu_splats((unsigned int)MATERIAL_CHECKERBOARD), (vector unsigned int){(unsigned int)materials[id1].materialType, (unsigned int)materials[id2].materialType, (unsigned int)materials[id3].materialType, (unsigned int)materials[id4].materialType});  vector unsigned int valid = spu_and(shadeBits, type_eq_checker);      vector unsigned int mat1s = (vector unsigned int){materials[id1].arg1_i, materials[id2].arg1_i, materials[id3].arg1_i, materials[id4].arg1_i};  vector unsigned int mat2s = (vector unsigned int){materials[id1].arg2_i, materials[id2].arg2_i, materials[id3].arg2_i, materials[id4].arg2_i};    sum = fmodf4(sum, spu_splats(2.0f));    vector unsigned int sum_zero = spu_cmpgt(spu_splats(CHECKERBOARD_EPSILON), sum);    HitPacket newhp;  newhp.materialID = spu_sel(mat1s, mat2s, sum_zero);  newhp.materialID = spu_sel(spu_splats((unsigned int)0), newhp.materialID, valid);  newhp.nx = hp.nx;  newhp.ny = hp.ny;  newhp.nz = hp.nz;  newhp.t = hp.t;    //shade and return  materialShade(materials, rgbp, rp, newhp, dirToLight_x, dirToLight_y, dirToLight_z, lightColor_r, lightColor_g, lightColor_b, valid);  //printf("checkerboardShade done\r\n");  return;}MATERIAL_SHADER_DIFFUSE(material_getCheckerboardDiffuseColor) {  vector float _zero = spu_splats(0.0f);    union {    vector unsigned int ids;    struct {      unsigned int id1, id2, id3, id4;    };  };  ids = hp.materialID;    vector float px_temp, py_temp, pz_temp, pw_temp;  vector float px_res, py_res, pz_res;  px_res = py_res = pz_res =  _zero;  vector unsigned int thisID;  vector float matrix[16];  //Do material1's matrix   splat_matrix4x4((vector float*)&matrix, &materials[id1].colorDSRT_r);  xform_vec3_v(&px_temp, &py_temp, &pz_temp, &pw_temp, p_x, p_y, p_z, (vector float*)&matrix);  thisID = spu_cmpeq(hp.materialID, spu_splats(id1));  px_res = spu_sel(px_res, px_temp, thisID);  py_res = spu_sel(py_res, py_temp, thisID);  pz_res = spu_sel(pz_res, pz_temp, thisID);  //pw_res = spu_sel(pw_res, pw_temp, thisID);  //Do material2's matrix   splat_matrix4x4((vector float*)&matrix, &materials[id2].colorDSRT_r);  xform_vec3_v(&px_temp, &py_temp, &pz_temp, &pw_temp, p_x, p_y, p_z, (vector float*)&matrix);  thisID = spu_cmpeq(hp.materialID, spu_splats(id2));  px_res = spu_sel(px_res, px_temp, thisID);  py_res = spu_sel(py_res, py_temp, thisID);  pz_res = spu_sel(pz_res, pz_temp, thisID);  //pw_res = spu_sel(pw_res, pw_temp, thisID);  //Do material3's matrix   splat_matrix4x4((vector float*)&matrix, &materials[id3].colorDSRT_r);  xform_vec3_v(&px_temp, &py_temp, &pz_temp, &pw_temp, p_x, p_y, p_z, (vector float*)&matrix);  thisID = spu_cmpeq(hp.materialID, spu_splats(id3));  px_res = spu_sel(px_res, px_temp, thisID);  py_res = spu_sel(py_res, py_temp, thisID);  pz_res = spu_sel(pz_res, pz_temp, thisID);  //pw_res = spu_sel(pw_res, pw_temp, thisID);  //Do material4's matrix  splat_matrix4x4((vector float*)&matrix, &materials[id4].colorDSRT_r);  xform_vec3_v(&px_temp, &py_temp, &pz_temp, &pw_temp, p_x, p_y, p_z, (vector float*)&matrix);  thisID = spu_cmpeq(hp.materialID, spu_splats(id4));  px_res = spu_sel(px_res, px_temp, thisID);  py_res = spu_sel(py_res, py_temp, thisID);  pz_res = spu_sel(pz_res, pz_temp, thisID);  //pw_res = spu_sel(pw_res, pw_temp, thisID);   vector float sum = fabsf4(spu_add(floorf4(px_res), spu_add(floorf4(py_res), floorf4(pz_res))));  vector unsigned int type_eq_checker = spu_cmpeq(spu_splats((unsigned int)MATERIAL_CHECKERBOARD), (vector unsigned int){(unsigned int)materials[id1].materialType, (unsigned int)materials[id2].materialType, (unsigned int)materials[id3].materialType, (unsigned int)materials[id4].materialType});  vector unsigned int valid = spu_and(shadeBits, type_eq_checker);  vector unsigned int mat1s = (vector unsigned int){materials[id1].arg1_i, materials[id2].arg1_i, materials[id3].arg1_i, materials[id4].arg1_i};  vector unsigned int mat2s = (vector unsigned int){materials[id1].arg2_i, materials[id2].arg2_i, materials[id3].arg2_i, materials[id4].arg2_i};    //vector unsigned int sum_zero = spu_cmpeq(_zero, fmodf4(sum, spu_splats(2.0f)));  vector unsigned int sum_zero = spu_cmpgt(spu_splats(CHECKERBOARD_EPSILON), fmodf4(sum, spu_splats(2.0f)));    HitPacket newhp;  newhp.materialID = spu_sel(mat1s, mat2s, sum_zero);  newhp.materialID = spu_sel(spu_splats((unsigned int)0), newhp.materialID, valid);  newhp.nx = hp.nx;  newhp.ny = hp.ny;  newhp.nz = hp.nz;  newhp.t = hp.t;    material_getDiffuseColor(materials, rgbp, newhp, p_x, p_y, p_z, valid);  //printf("checkerboardDiffuse done\r\n");  return;}MATERIAL_SHADER_REFLECTIVE(material_getCheckerboardReflectiveColor) {  vector float _zero = spu_splats(0.0f);  union {    vector unsigned int ids;    struct {      unsigned int id1, id2, id3, id4;    };  };  ids = hp.materialID;    vector float px_temp, py_temp, pz_temp, pw_temp;

⌨️ 快捷键说明

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