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

📄 blend.cpp

📁 Ray tracing on PS3, using the acceleration of PPU, No SPE acceleration is used. The code must be com
💻 CPP
📖 第 1 页 / 共 3 页
字号:
  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);  union {    vector unsigned int matTypes;    struct {      unsigned int mat1_type;      unsigned int mat2_type;      unsigned int mat3_type;      unsigned int mat4_type;    };  };    matTypes = (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 type_eq_blender = spu_or(spu_cmpeq(spu_splats((unsigned int)MATERIAL_WOOD), matTypes), spu_cmpeq(spu_splats((unsigned int)MATERIAL_MARBLE), matTypes));  vector unsigned int valid = spu_and(shadeBits, type_eq_blender);    union {    vector unsigned int functions;    struct {      material_shader_blendfactor f1;      material_shader_blendfactor f2;      material_shader_blendfactor f3;      material_shader_blendfactor f4;    };     };    functions = (vector unsigned int){							(unsigned int)fp_shader[mat1_type].blendfactor,							(unsigned int)fp_shader[mat2_type].blendfactor,							(unsigned int)fp_shader[mat3_type].blendfactor,							(unsigned int)fp_shader[mat4_type].blendfactor};    vector unsigned int zero_i = spu_splats((unsigned int)0);  vector unsigned int ones_i = spu_splats((unsigned int)1);  union {    vector float blendFactors_v;    struct {      float blendFactor[4];    };  };  union {    vector unsigned int materials_v;    struct {      material *material1;      material *material2;      material *material3;      material *material4;    };  };  material1 = &materials[id1];  material2 = &materials[id2];  material3 = &materials[id3];  material4 = &materials[id4];  blendFactors_v = _zero;    thisID = spu_cmpeq(matTypes, spu_splats(mat1_type));  (*f1)(materials_v, blendFactors_v, px_res, py_res, pz_res, thisID);  functions = spu_sel(functions, spu_splats((unsigned int)material_getBlendFactorDummy), thisID);    thisID = spu_cmpeq(matTypes, spu_splats(mat2_type));  (*f2)(materials_v, blendFactors_v, px_res, py_res, pz_res, thisID);  functions = spu_sel(functions, spu_splats((unsigned int)material_getBlendFactorDummy), thisID);    thisID = spu_cmpeq(matTypes, spu_splats(mat3_type));  (*f3)(materials_v, blendFactors_v, px_res, py_res, pz_res, thisID);  functions = spu_sel(functions, spu_splats((unsigned int)material_getBlendFactorDummy), thisID);  thisID = spu_cmpeq(matTypes, spu_splats(mat4_type));    (*f4)(materials_v, blendFactors_v, px_res, py_res, pz_res, thisID);  //functions = spu_sel(functions, spu_splats((unsigned int)material_getBlendFactorDummy), thisID);    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};    RGBPacket shade1, shade2;  shade1.r = shade2.r = rgbp.r;  shade1.g = shade2.g = rgbp.g;  shade1.b = shade2.b = rgbp.b;  HitPacket newhp;    newhp.nx = hp.nx;  newhp.ny = hp.ny;  newhp.nz = hp.nz;  newhp.t = hp.t;    newhp.materialID = mat1s;  newhp.materialID = spu_sel(spu_splats((unsigned int)0), newhp.materialID, valid);  material_getDiffuseColor(materials, shade1, newhp, p_x, p_y, p_z, valid);    newhp.materialID = mat2s;  newhp.materialID = spu_sel(spu_splats((unsigned int)0), newhp.materialID, valid);  material_getDiffuseColor(materials, shade2, newhp, p_x, p_y, p_z, valid);  // result = (1-t) * v1 + t * v2  lerp_vec3_v(&shade1.r, &shade1.g, &shade1.b, shade2.r, shade2.g, shade2.b, shade1.r, shade1.g, shade1.b, blendFactors_v);  rgbp.r = spu_sel(rgbp.r, shade1.r, valid);  rgbp.g = spu_sel(rgbp.g, shade1.g, valid);  rgbp.b = spu_sel(rgbp.b, shade1.b, valid);  }MATERIAL_SHADER_REFLECTIVE(material_getBlenderReflectiveColor) {  dprintf("material_getBlenderReflectiveColor\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_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);  union {    vector unsigned int matTypes;    struct {      unsigned int mat1_type;      unsigned int mat2_type;      unsigned int mat3_type;      unsigned int mat4_type;    };  };    matTypes = (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 type_eq_blender = spu_or(spu_cmpeq(spu_splats((unsigned int)MATERIAL_WOOD), matTypes), spu_cmpeq(spu_splats((unsigned int)MATERIAL_MARBLE), matTypes));  vector unsigned int valid = spu_and(shadeBits, type_eq_blender);    union {    vector unsigned int functions;    struct {      material_shader_blendfactor f1;      material_shader_blendfactor f2;      material_shader_blendfactor f3;      material_shader_blendfactor f4;    };     };    functions = (vector unsigned int){							(unsigned int)fp_shader[mat1_type].blendfactor,							(unsigned int)fp_shader[mat2_type].blendfactor,							(unsigned int)fp_shader[mat3_type].blendfactor,							(unsigned int)fp_shader[mat4_type].blendfactor};    vector unsigned int zero_i = spu_splats((unsigned int)0);  vector unsigned int ones_i = spu_splats((unsigned int)1);  union {    vector float blendFactors_v;    struct {      float blendFactor[4];    };  };  union {    vector unsigned int materials_v;    struct {      material *material1;      material *material2;      material *material3;      material *material4;    };  };  material1 = &materials[id1];  material2 = &materials[id2];  material3 = &materials[id3];  material4 = &materials[id4];  blendFactors_v = _zero;    thisID = spu_cmpeq(matTypes, spu_splats(mat1_type));  (*f1)(materials_v, blendFactors_v, px_res, py_res, pz_res, thisID);  functions = spu_sel(functions, spu_splats((unsigned int)material_getBlendFactorDummy), thisID);    thisID = spu_cmpeq(matTypes, spu_splats(mat2_type));  (*f2)(materials_v, blendFactors_v, px_res, py_res, pz_res, thisID);  functions = spu_sel(functions, spu_splats((unsigned int)material_getBlendFactorDummy), thisID);    thisID = spu_cmpeq(matTypes, spu_splats(mat3_type));  (*f3)(materials_v, blendFactors_v, px_res, py_res, pz_res, thisID);  functions = spu_sel(functions, spu_splats((unsigned int)material_getBlendFactorDummy), thisID);  thisID = spu_cmpeq(matTypes, spu_splats(mat4_type));    (*f4)(materials_v, blendFactors_v, px_res, py_res, pz_res, thisID);  //functions = spu_sel(functions, spu_splats((unsigned int)material_getBlendFactorDummy), thisID);    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};    RGBPacket shade1, shade2;  shade1.r = shade2.r = rgbp.r;  shade1.g = shade2.g = rgbp.g;  shade1.b = shade2.b = rgbp.b;  HitPacket newhp;    newhp.nx = hp.nx;  newhp.ny = hp.ny;  newhp.nz = hp.nz;  newhp.t = hp.t;    newhp.materialID = mat1s;  newhp.materialID = spu_sel(spu_splats((unsigned int)0), newhp.materialID, valid);  material_getReflectiveColor(materials, shade1, newhp, p_x, p_y, p_z, valid);    newhp.materialID = mat2s;  newhp.materialID = spu_sel(spu_splats((unsigned int)0), newhp.materialID, valid);  material_getReflectiveColor(materials, shade2, newhp, p_x, p_y, p_z, valid);  // result = (1-t) * v1 + t * v2  lerp_vec3_v(&shade1.r, &shade1.g, &shade1.b, shade2.r, shade2.g, shade2.b, shade1.r, shade1.g, shade1.b, blendFactors_v);  rgbp.r = spu_sel(rgbp.r, shade1.r, valid);  rgbp.g = spu_sel(rgbp.g, shade1.g, valid);  rgbp.b = spu_sel(rgbp.b, shade1.b, valid);  }MATERIAL_SHADER_TRANSPARENT(material_getBlenderTransparentColor) {  dprintf("material_getBlenderTransparentColor\r\n");    vector float _zero = spu_splats(0.0f);    union {    vector unsigned int ids;    struct {      unsigned int id1, id2, id3, id4;

⌨️ 快捷键说明

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