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

📄 brdf.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 R2 = (vector float){mat1->arg2_f, mat2->arg2_f, mat3->arg2_f, mat4->arg2_f};  R2 = spu_mul(R2, R2);    vector float result;  vector float _pi = spu_splats(3.14159f);  vector float highbit = spu_splats((float)0x80000000);  vector float _one = spu_splats(1.0f);  vector float tmp = spu_mul(R2, HN2);  tmp = spu_mul(tmp, HN2);  tmp = spu_re(tmp);  vector float tangent2 = spu_mul(spu_sub(_one, HN2), spu_re(HN2)); //(1-HN2) / HN2, approximate tan2theta  //vector float D = expf4(spu_mul(spu_xor(tangent2, highbit), spu_re(R2)));    vector float D = spu_mul(spu_splats(-1.0f), tangent2);//spu_xor(tangent2, highbit);  D = spu_mul(D, spu_re(R2));  D = expf4(D);  D = spu_mul(D, tmp);  tmp = spu_mul(spu_splats(2.0f), HN);  tmp = spu_mul(tmp, spu_re(HV));  tmp = spu_mul(tmp, fminf4(VN, NL_v));  vector float G = fminf4(_one, tmp);  vector float S = (vector float){mat1->arg1_f, mat2->arg1_f, mat3->arg1_f, mat4->arg1_f};  tmp = spu_re(spu_add(S, _one));  S = spu_sub(S, _one);  S = spu_mul(tmp, S);  S = spu_mul(S, S);    spec9Exponent exp;  set_spec_exponent9(&exp, 5);    tmp = spec9_v(spu_sub(_one, HV), &exp);  tmp = spu_mul(tmp, spu_sub(_one, S));  S = spu_add(S, tmp);    //return D*G*S/(3.14159f * NL * VN);    result = spu_mul(NL_v, VN);  result = spu_mul(result, _pi);  result = spu_re(result);  tmp = spu_mul(D,G);  tmp = spu_mul(tmp, S);  result = spu_mul(tmp, result);  specularCoefficients = spu_sel(specularCoefficients, result, shadeBits);  /*  float HN = dot_product3(normal, halfangle);  float VN = dot_product3(v, normal);  float HV = dot_product3(v, halfangle);  //precompute values  float HN2 = HN * HN;  float R2 = mat.arg2_f * mat.arg2_f; //roughness * roughness    float tangent2 = (1.0f - HN2) / HN2; //approximation  float D = 1.0f / (R2 * HN2 * HN2) * expf(-tangent2/R2);  float G = fminf(1.0f, 2.0f*HN*fminf(VN,NL)/HV);  float S = (mat.arg1_f-1.0f) / (mat.arg1_f+1.0f);  S = S*S;  //do the pow with the fast library method  spec9Exponent exp;  set_spec_exponent9(&exp, 5); //arg1_i is exponent for phong materials  S = S + (1.0f-S)*spec9(1.0f-HV, &exp);    return D*G*S/(3.14159f*NL*VN);  */}MATERIAL_SHADER_DIFFUSE(material_getBRDFDiffuseColor) {    dprintf("materialgetBRDFDiffuseColor\r\n");    union{    vector unsigned int mats;    struct {      material* mat1;      material* mat2;      material* mat3;      material* mat4;    };  };  //mats = spu_splats((unsigned int)materials);    //mats = spu_add(mats, (vector unsigned int){  //		   spu_extract(hp.materialID,0)*(unsigned int)sizeof(material),  //		   spu_extract(hp.materialID,1)*(unsigned int)sizeof(material),  //		   spu_extract(hp.materialID,2)*(unsigned int)sizeof(material),  //		   spu_extract(hp.materialID,3)*(unsigned int)sizeof(material)});    //mats = spu_add( mats, spu_mul(hp.materialID, spu_splats((unsigned int)sizeof(material))));  mat1 = &materials[hp.materialID1];  mat2 = &materials[hp.materialID2];  mat3 = &materials[hp.materialID3];  mat4 = &materials[hp.materialID4];    vector float tmp;  vector unsigned char tag1 = (vector unsigned char)    {0x00, 0x01, 0x02, 0x03, 0x10, 0x11, 0x12, 0x13, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80};  vector unsigned char tag2 = (vector unsigned char)    {0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00, 0x01, 0x02, 0x03, 0x10, 0x11, 0x12, 0x13};  vector float diffuse_r, diffuse_g, diffuse_b;    tmp = spu_shuffle(mat1->colorDSRT_r, mat2->colorDSRT_r, tag1);  diffuse_r = spu_shuffle(mat3->colorDSRT_r, mat4->colorDSRT_r, tag2);  diffuse_r = spu_or(tmp, diffuse_r);  tmp = spu_shuffle(mat1->colorDSRT_g, mat2->colorDSRT_g, tag1);  diffuse_g = spu_shuffle(mat3->colorDSRT_g, mat4->colorDSRT_g, tag2);  diffuse_g = spu_or(tmp, diffuse_g);  tmp = spu_shuffle(mat1->colorDSRT_b, mat2->colorDSRT_b, tag1);  diffuse_b = spu_shuffle(mat3->colorDSRT_b, mat4->colorDSRT_b, tag2);  diffuse_b = spu_or(tmp, diffuse_b);  rgbp.r = spu_sel(rgbp.r, diffuse_r, shadeBits);  rgbp.g = spu_sel(rgbp.g, diffuse_g, shadeBits);  rgbp.b = spu_sel(rgbp.b, diffuse_b, shadeBits);  }MATERIAL_SHADER_REFLECTIVE(material_getBRDFReflectiveColor) {    dprintf("materialgetBRDFReflectiveColor\r\n");    union{    vector unsigned int mats;    struct {      material* mat1;      material* mat2;      material* mat3;      material* mat4;    };  };  //mats = spu_splats((unsigned int)materials);  //TODO: FOR THE LOVE OF GOD TRY AND FIX THIS  //mats = spu_add(mats, (vector unsigned int){  //  		   spu_extract(hp.materialID,0)*(unsigned int)sizeof(material),  //  		   spu_extract(hp.materialID,1)*(unsigned int)sizeof(material),  //  		   spu_extract(hp.materialID,2)*(unsigned int)sizeof(material),  //  		   spu_extract(hp.materialID,3)*(unsigned int)sizeof(material)});  mat1 = &materials[hp.materialID1];  mat2 = &materials[hp.materialID2];  mat3 = &materials[hp.materialID3];  mat4 = &materials[hp.materialID4];   vector float tmp;  vector unsigned char tag1 = (vector unsigned char)    {0x08, 0x09, 0x0A, 0x0B, 0x18, 0x19, 0x1A, 0x1B, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80};  vector unsigned char tag2 = (vector unsigned char)    {0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x08, 0x09, 0x0A, 0x0B, 0x18, 0x19, 0x1A, 0x1B};  vector float reflective_r, reflective_g, reflective_b;    tmp = spu_shuffle(mat1->colorDSRT_r, mat2->colorDSRT_r, tag1);  reflective_r = spu_shuffle(mat3->colorDSRT_r, mat4->colorDSRT_r, tag2);  reflective_r = spu_or(tmp, reflective_r);  tmp = spu_shuffle(mat1->colorDSRT_g, mat2->colorDSRT_g, tag1);  reflective_g = spu_shuffle(mat3->colorDSRT_g, mat4->colorDSRT_g, tag2);  reflective_g = spu_or(tmp, reflective_g);  tmp = spu_shuffle(mat1->colorDSRT_b, mat2->colorDSRT_b, tag1);  reflective_b = spu_shuffle(mat3->colorDSRT_b, mat4->colorDSRT_b, tag2);  reflective_b = spu_or(tmp, reflective_b);  rgbp.r = spu_sel(rgbp.r, reflective_r, shadeBits);  rgbp.g = spu_sel(rgbp.g, reflective_g, shadeBits);  rgbp.b = spu_sel(rgbp.b, reflective_b, shadeBits);  }MATERIAL_SHADER_TRANSPARENT(material_getBRDFTransparentColor) {    dprintf("materialgetBRDFTransparentColor\r\n");    union{    vector unsigned int mats;    struct {      material* mat1;      material* mat2;      material* mat3;      material* mat4;    };  };  //mats = spu_splats((unsigned int)materials);  //mats = spu_add(mats, (vector unsigned int){  //		   spu_extract(hp.materialID,0)*(unsigned int)sizeof(material),  //		   spu_extract(hp.materialID,1)*(unsigned int)sizeof(material),  //		   spu_extract(hp.materialID,2)*(unsigned int)sizeof(material),  //		   spu_extract(hp.materialID,3)*(unsigned int)sizeof(material)});  //PRINT_VECTOR_INT("mats", mats);  mat1 = &materials[hp.materialID1];  mat2 = &materials[hp.materialID2];  mat3 = &materials[hp.materialID3];  mat4 = &materials[hp.materialID4];  vector float tmp;  vector unsigned char tag1 = (vector unsigned char)    {0x0C, 0x0D, 0x0E, 0x0F, 0x1C, 0x1D, 0x1E, 0x1F, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80};  vector unsigned char tag2 = (vector unsigned char)    {0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x0C, 0x0D, 0x0E, 0x0F, 0x1C, 0x1D, 0x1E, 0x1F};  vector float transparent_r, transparent_g, transparent_b;    tmp = spu_shuffle(mat1->colorDSRT_r, mat2->colorDSRT_r, tag1);  transparent_r = spu_shuffle(mat3->colorDSRT_r, mat4->colorDSRT_r, tag2);  transparent_r = spu_or(tmp, transparent_r);  tmp = spu_shuffle(mat1->colorDSRT_g, mat2->colorDSRT_g, tag1);  transparent_g = spu_shuffle(mat3->colorDSRT_g, mat4->colorDSRT_g, tag2);  transparent_g = spu_or(tmp, transparent_g);  tmp = spu_shuffle(mat1->colorDSRT_b, mat2->colorDSRT_b, tag1);  transparent_b = spu_shuffle(mat3->colorDSRT_b, mat4->colorDSRT_b, tag2);  transparent_b = spu_or(tmp, transparent_b);  rgbp.r = spu_sel(rgbp.r, transparent_r, shadeBits);  rgbp.g = spu_sel(rgbp.g, transparent_g, shadeBits);  rgbp.b = spu_sel(rgbp.b, transparent_b, shadeBits);  }MATERIAL_SHADER_REFRACTIVE(material_getBRDFRefractiveIndex) {    dprintf("materialgetBRDFRefractiveIndex\r\n");    union {    vector unsigned int mats;    struct {      material* mat1;      material* mat2;      material* mat3;      material* mat4;    };  };  //mats = spu_splats((unsigned int)materials);   //mats = spu_add(mats, (vector unsigned int){  //		   spu_extract(hp.materialID,0)*(unsigned int)sizeof(material),  //		   spu_extract(hp.materialID,1)*(unsigned int)sizeof(material),  //		   spu_extract(hp.materialID,2)*(unsigned int)sizeof(material),  //		   spu_extract(hp.materialID,3)*(unsigned int)sizeof(material)});  //PRINT_VECTOR_INT("mats", mats);    mat1 = &materials[hp.materialID1];  mat2 = &materials[hp.materialID2];  mat3 = &materials[hp.materialID3];  mat4 = &materials[hp.materialID4];    vector unsigned char tag1 = (vector unsigned char)    {0x00, 0x01, 0x02, 0x03, 0x10, 0x11, 0x12, 0x13, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80};  vector unsigned char tag2 = (vector unsigned char)    {0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00, 0x01, 0x02, 0x03, 0x10, 0x11, 0x12, 0x13};    vector float tmp;  vector float indices;  tmp = spu_shuffle(mat1->argf_v, mat2->argf_v, tag1);  indices = spu_shuffle(mat3->argf_v, mat4->argf_v, tag2);  indices = spu_or(tmp, indices);  rindices = spu_sel(rindices, indices, shadeBits);  }

⌨️ 快捷键说明

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