📄 material.cpp
字号:
((*fp_shader[materials[id].materialType].diffuse) (materials, rgbp, hp, p_x, p_y, p_z, res_v)); dprintf("getDiffuse: calling fourth material's function.\r\n"); } */ return;}MATERIAL_SHADER_REFLECTIVE(material_getReflectiveColorDummy) { dprintf("material_getReflectiveColorDummy\r\n");}MATERIAL_SHADER_REFLECTIVE(material_getReflectiveColor) { dprintf("material_getReflectiveColor\r\n"); union { vector unsigned int functions; struct { material_shader_reflective f1; material_shader_reflective f2; material_shader_reflective f3; material_shader_reflective f4; }; }; union { vector unsigned int matTypes; struct { unsigned int mat1_type, mat2_type, mat3_type, mat4_type; }; }; matTypes = (vector unsigned int) {materials[hp.materialID1].materialType, materials[hp.materialID2].materialType, materials[hp.materialID3].materialType, materials[hp.materialID4].materialType}; vector unsigned int dummy = spu_splats((unsigned int)material_getReflectiveColorDummy); functions = (vector unsigned int){ (unsigned int)fp_shader[mat1_type].reflective, (unsigned int)fp_shader[mat2_type].reflective, (unsigned int)fp_shader[mat3_type].reflective, (unsigned int)fp_shader[mat4_type].reflective}; vector unsigned int thisID; thisID = spu_cmpeq(matTypes, spu_splats(mat1_type)); (*f1)(materials, rgbp, hp, p_x, p_y, p_z, spu_and(shadeBits, thisID)); functions = spu_sel(functions, dummy, thisID); thisID = spu_cmpeq(matTypes, spu_splats(mat2_type)); (*f2)(materials, rgbp, hp, p_x, p_y, p_z, spu_and(shadeBits, thisID)); functions = spu_sel(functions, dummy, thisID); thisID = spu_cmpeq(matTypes, spu_splats(mat3_type)); (*f3)(materials, rgbp, hp, p_x, p_y, p_z, spu_and(shadeBits, thisID)); functions = spu_sel(functions, dummy, thisID); thisID = spu_cmpeq(matTypes, spu_splats(mat4_type)); (*f4)(materials, rgbp, hp, p_x, p_y, p_z, spu_and(shadeBits, thisID)); functions = spu_sel(functions, dummy, thisID); /* unsigned int i=0; union { vector unsigned int res_v; struct { unsigned int res_i[4]; }; }; //MAJOR TODO : MAKE IT SO IT DOESN'T CALL F'ING FUNCTIONS WITH SHADEBITS == 0 //STUPID TRICK TO GET AROUND LOOPING AND SUCH //IDEA: make a dummy function that does nothing, remove branching. Do spu_ bitmagic to spu_sel the function pointer to call // between the real one and the dummy one. That way we call unconditionally. unsigned int prevID[3] = { 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF }; //call material 1's reflective, set bits so that it shades anything else with material1's id unsigned int id = spu_extract(hp.materialID, 0); res_v = spu_cmpeq(hp.materialID, spu_splats(id)); res_v = spu_and(shadeBits, res_v); ((*fp_shader[materials[id].materialType].reflective) (materials, rgbp, hp, p_x, p_y, p_z, res_v)); prevID[0] = id; dprintf("getReflective: calling first material's function.\r\n"); //this is the style fix we need id = spu_extract(hp.materialID, 1); res_v = spu_cmpeq(hp.materialID, spu_slqwbyte(hp.materialID, 8)); res_v = spu_shuffle(res_v, res_v, (vector unsigned char){0x00, 0x01, 0x02, 0x03, 0x00, 0x01, 0x02, 0x03, 0x00, 0x01, 0x02, 0x03, 0x00, 0x01, 0x02, 0x03}); material_shader_reflective fp = (material_shader_reflective)spu_extract(spu_sel(spu_splats((unsigned int)fp_shader[materials[id].materialType].reflective), spu_splats((unsigned int)material_getReflectiveColorDummy), res_v), 0); ((*fp) (materials, rgbp, hp, p_x, p_y, p_z, res_v)); //call material 2's shader, don't call if it's already been called, set bits so that it shades anything else with material1's id //id = spu_extract(hp.materialID, 1); //if(id != prevID[0]) { // res_v = spu_cmpeq(hp.materialID, spu_splats(id)); // res_v = spu_and(shadeBits, res_v); // ((*fp_shader[materials[id].materialType].diffuse) (materials, rgbp, hp, p_x, p_y, p_z, res_v)); // prevID[1] = id; // dprintf("getDiffuse: calling second material's function.\r\n"); // } //call material 3's shader, don't call if it's already been called, set bits so that it shades anything else with material1's id id = spu_extract(hp.materialID, 2); if(id != prevID[0] && id != prevID[1]) { res_v = spu_cmpeq(hp.materialID, spu_splats(id)); res_v = spu_and(shadeBits, res_v); ((*fp_shader[materials[id].materialType].reflective) (materials, rgbp, hp, p_x, p_y, p_z, res_v)); prevID[2] = id; dprintf("getReflective: calling third material's function.\r\n"); } //call material 4's shader, don't call if it's already been called, set bits so that it shades anything else with material1's id id = spu_extract(hp.materialID, 3); if(id != prevID[0] && id != prevID[1] && id != prevID[2]) { res_v = spu_cmpeq(hp.materialID, spu_splats(id)); res_v = spu_and(shadeBits, res_v); ((*fp_shader[materials[id].materialType].reflective) (materials, rgbp, hp, p_x, p_y, p_z, res_v)); dprintf("getReflective: calling fourth material's function.\r\n"); } */ return;}MATERIAL_SHADER_TRANSPARENT(material_getTransparentColorDummy) { dprintf("material_getTransparentColorDummy\r\n");}MATERIAL_SHADER_TRANSPARENT(material_getTransparentColor) { dprintf("material_getTransparentColor\r\n"); union { vector unsigned int functions; struct { material_shader_transparent f1; material_shader_transparent f2; material_shader_transparent f3; material_shader_transparent f4; }; }; union { vector unsigned int matTypes; struct { unsigned int mat1_type, mat2_type, mat3_type, mat4_type; }; }; matTypes = (vector unsigned int) {materials[hp.materialID1].materialType, materials[hp.materialID2].materialType, materials[hp.materialID3].materialType, materials[hp.materialID4].materialType}; vector unsigned int dummy = spu_splats((unsigned int)material_getTransparentColorDummy); functions = (vector unsigned int){ (unsigned int)fp_shader[mat1_type].transparent, (unsigned int)fp_shader[mat2_type].transparent, (unsigned int)fp_shader[mat3_type].transparent, (unsigned int)fp_shader[mat4_type].transparent}; vector unsigned int thisID; thisID = spu_cmpeq(matTypes, spu_splats(mat1_type)); (*f1)(materials, rgbp, hp, p_x, p_y, p_z, spu_and(shadeBits, thisID)); functions = spu_sel(functions, dummy, thisID); thisID = spu_cmpeq(matTypes, spu_splats(mat2_type)); (*f2)(materials, rgbp, hp, p_x, p_y, p_z, spu_and(shadeBits, thisID)); functions = spu_sel(functions, dummy, thisID); thisID = spu_cmpeq(matTypes, spu_splats(mat3_type)); (*f3)(materials, rgbp, hp, p_x, p_y, p_z, spu_and(shadeBits, thisID)); functions = spu_sel(functions, dummy, thisID); thisID = spu_cmpeq(matTypes, spu_splats(mat4_type)); (*f4)(materials, rgbp, hp, p_x, p_y, p_z, spu_and(shadeBits, thisID)); functions = spu_sel(functions, dummy, thisID); /* unsigned int i=0; union { vector unsigned int res_v; struct { unsigned int res_i[4]; }; }; dprintf("material_getTransparentColor\r\n"); //MAJOR TODO : MAKE IT SO IT DOESN'T CALL F'ING FUNCTIONS WITH SHADEBITS == 0 //STUPID TRICK TO GET AROUND LOOPING AND SUCH //IDEA: make a dummy function that does nothing, remove branching. Do spu_ bitmagic to spu_sel the function pointer to call // between the real one and the dummy one. That way we call unconditionally. unsigned int prevID[3] = { 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF }; //call material 1's reflective, set bits so that it shades anything else with material1's id unsigned int id = spu_extract(hp.materialID, 0); res_v = spu_cmpeq(hp.materialID, spu_splats(id)); res_v = spu_and(shadeBits, res_v); ((*fp_shader[materials[id].materialType].transparent) (materials, rgbp, hp, p_x, p_y, p_z, res_v)); prevID[0] = id; dprintf("getTransparent: calling first material's function.\r\n"); //this is the style fix we need id = spu_extract(hp.materialID, 1); res_v = spu_cmpeq(hp.materialID, spu_slqwbyte(hp.materialID, 8)); res_v = spu_shuffle(res_v, res_v, (vector unsigned char){0x00, 0x01, 0x02, 0x03, 0x00, 0x01, 0x02, 0x03, 0x00, 0x01, 0x02, 0x03, 0x00, 0x01, 0x02, 0x03}); material_shader_transparent fp = (material_shader_transparent)spu_extract(spu_sel(spu_splats((unsigned int)fp_shader[materials[id].materialType].transparent), spu_splats((unsigned int)material_getTransparentColorDummy), res_v), 0); ((*fp) (materials, rgbp, hp, p_x, p_y, p_z, res_v)); //call material 2's shader, don't call if it's already been called, set bits so that it shades anything else with material1's id //id = spu_extract(hp.materialID, 1); //if(id != prevID[0]) { // res_v = spu_cmpeq(hp.materialID, spu_splats(id)); // res_v = spu_and(shadeBits, res_v); // ((*fp_shader[materials[id].materialType].diffuse) (materials, rgbp, hp, p_x, p_y, p_z, res_v)); // prevID[1] = id; // dprintf("getDiffuse: calling second material's function.\r\n"); //} //call material 3's shader, don't call if it's already been called, set bits so that it shades anything else with material1's id id = spu_extract(hp.materialID, 2); if(id != prevID[0] && id != prevID[1]) { res_v = spu_cmpeq(hp.materialID, spu_splats(id)); res_v = spu_and(shadeBits, res_v); ((*fp_shader[materials[id].materialType].transparent) (materials, rgbp, hp, p_x, p_y, p_z, res_v)); prevID[2] = id; dprintf("getTransparent: calling third material's function.\r\n"); } //call material 4's shader, don't call if it's already been called, set bits so that it shades anything else with material1's id id = spu_extract(hp.materialID, 3); if(id != prevID[0] && id != prevID[1] && id != prevID[2]) { res_v = spu_cmpeq(hp.materialID, spu_splats(id)); res_v = spu_and(shadeBits, res_v); ((*fp_shader[materials[id].materialType].transparent) (materials, rgbp, hp, p_x, p_y, p_z, res_v)); dprintf("getTransparent: calling fourth material's function.\r\n"); } */ return;}MATERIAL_SHADER_REFRACTIVE(material_getRefractiveIndexDummy) { dprintf("material_getRefractiveIndexColorDummy\r\n");}MATERIAL_SHADER_REFRACTIVE(material_getRefractiveIndex) { union { vector unsigned int functions; struct { material_shader_refractive f1; material_shader_refractive f2; material_shader_refractive f3; material_shader_refractive f4; }; }; union { vector unsigned int matTypes; struct { unsigned int mat1_type, mat2_type, mat3_type, mat4_type; }; }; matTypes = (vector unsigned int) {materials[hp.materialID1].materialType, materials[hp.materialID2].materialType, materials[hp.materialID3].materialType, materials[hp.materialID4].materialType}; vector unsigned int dummy = spu_splats((unsigned int)material_getRefractiveIndexDummy); functions = (vector unsigned int){ (unsigned int)fp_shader[mat1_type].refractive, (unsigned int)fp_shader[mat2_type].refractive, (unsigned int)fp_shader[mat3_type].refractive, (unsigned int)fp_shader[mat4_type].refractive}; vector unsigned int thisID; thisID = spu_cmpeq(matTypes, spu_splats(mat1_type)); (*f1)(materials, rindices, hp, p_x, p_y, p_z, spu_and(shadeBits, thisID)); functions = spu_sel(functions, dummy, thisID); thisID = spu_cmpeq(matTypes, spu_splats(mat2_type)); (*f2)(materials, rindices, hp, p_x, p_y, p_z, spu_and(shadeBits, thisID)); functions = spu_sel(functions, dummy, thisID); thisID = spu_cmpeq(matTypes, spu_splats(mat3_type)); (*f3)(materials, rindices, hp, p_x, p_y, p_z, spu_and(shadeBits, thisID)); functions = spu_sel(functions, dummy, thisID); thisID = spu_cmpeq(matTypes, spu_splats(mat4_type)); (*f4)(materials, rindices, hp, p_x, p_y, p_z, spu_and(shadeBits, thisID)); functions = spu_sel(functions, dummy, thisID); /* unsigned int i=0; union { vector unsigned int res_v; struct { unsigned int res_i[4]; }; }; dprintf("material_getRefractiveIndex\r\n"); //MAJOR TODO : MAKE IT SO IT DOESN'T CALL F'ING FUNCTIONS WITH SHADEBITS == 0 //STUPID TRICK TO GET AROUND LOOPING AND SUCH //IDEA: make a dummy function that does nothing, remove branching. Do spu_ bitmagic to spu_sel the function pointer to call // between the real one and the dummy one. That way we call unconditionally. unsigned int prevID[3] = { 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF }; //call material 1's reflective, set bits so that it shades anything else with material1's id unsigned int id = spu_extract(hp.materialID, 0); res_v = spu_cmpeq(hp.materialID, spu_splats(id)); res_v = spu_and(shadeBits, res_v); ((*fp_shader[materials[id].materialType].refractive) (materials, rindices, hp, p_x, p_y, p_z, res_v)); prevID[0] = id; dprintf("getRefractive: calling first material's function.\r\n"); //this is the style fix we need id = spu_extract(hp.materialID, 1); res_v = spu_cmpeq(hp.materialID, spu_slqwbyte(hp.materialID, 8)); res_v = spu_shuffle(res_v, res_v, (vector unsigned char){0x00, 0x01, 0x02, 0x03, 0x00, 0x01, 0x02, 0x03, 0x00, 0x01, 0x02, 0x03, 0x00, 0x01, 0x02, 0x03}); material_shader_refractive fp = (material_shader_refractive)spu_extract(spu_sel(spu_splats((unsigned int)fp_shader[materials[id].materialType].refractive), spu_splats((unsigned int)material_getRefractiveIndexDummy), res_v), 0); ((*fp) (materials, rindices, hp, p_x, p_y, p_z, res_v)); //call material 2's shader, don't call if it's already been called, set bits so that it shades anything else with material1's id //id = spu_extract(hp.materialID, 1); //if(id != prevID[0]) { // res_v = spu_cmpeq(hp.materialID, spu_splats(id)); // res_v = spu_and(shadeBits, res_v); // ((*fp_shader[materials[id].materialType].diffuse) (materials, rgbp, hp, p_x, p_y, p_z, res_v)); // prevID[1] = id; // dprintf("getDiffuse: calling second material's function.\r\n"); //} //call material 3's shader, don't call if it's already been called, set bits so that it shades anything else with material1's id id = spu_extract(hp.materialID, 2); if(id != prevID[0] && id != prevID[1]) { res_v = spu_cmpeq(hp.materialID, spu_splats(id)); res_v = spu_and(shadeBits, res_v); ((*fp_shader[materials[id].materialType].refractive) (materials, rindices, hp, p_x, p_y, p_z, res_v)); prevID[2] = id; dprintf("getRefractive: calling third material's function.\r\n"); } //call material 4's shader, don't call if it's already been called, set bits so that it shades anything else with material1's id id = spu_extract(hp.materialID, 3); if(id != prevID[0] && id != prevID[1] && id != prevID[2]) { res_v = spu_cmpeq(hp.materialID, spu_splats(id)); res_v = spu_and(shadeBits, res_v); ((*fp_shader[materials[id].materialType].refractive) (materials, rindices, hp, p_x, p_y, p_z, res_v)); dprintf("getRefractive: calling fourth material's function.\r\n"); } */ return;}#include "brdf.cpp"#include "checkerboard.cpp"#include "blend.cpp"#include "bump.cpp"
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -