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

📄 checkerboard.cpp

📁 Ray tracing on PS3, using the acceleration of PPU, No SPE acceleration is used. The code must be com
💻 CPP
📖 第 1 页 / 共 2 页
字号:
  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_getReflectiveColor(materials, rgbp, newhp, p_x, p_y, p_z, valid);  //printf("checkerboardReflective done\r\n");  return;}MATERIAL_SHADER_TRANSPARENT(material_getCheckerboardTransparentColor) {  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_getTransparentColor(materials, rgbp, newhp, p_x, p_y, p_z, valid);  //printf("checkerboardTransparentColor done\r\n");  return;}MATERIAL_SHADER_REFRACTIVE(material_getCheckerboardRefractiveIndex) {  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_getRefractiveIndex(materials, rindices, newhp, p_x, p_y, p_z, valid);  //printf("getCheckerboardRefractiveIndex done\r\n");  return;}

⌨️ 快捷键说明

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