const BSDF *MetalMaterial::GetBSDF(const DifferentialGeometry &i_dg, size_t i_triangle_index, MemoryPool &i_pool) const { BSDF *p_bsdf = new ( i_pool.Alloc(sizeof(BSDF)) ) BSDF(i_dg); SpectrumCoef_d r, a; if (mp_refractive_index && mp_absorption) { r = mp_refractive_index->Evaluate(i_dg, i_triangle_index); a = mp_absorption->Evaluate(i_dg, i_triangle_index); } else { ASSERT(mp_reflectance); SpectrumCoef_d reflectance = mp_reflectance->Evaluate(i_dg, i_triangle_index); reflectance.Clamp(0.0, 1.0); ApproximateFresnelParameters(reflectance, r, a); } FresnelConductor fresnel(r, a); BxDF *p_bxdf; if (mp_roughness) { typedef Microfacet<FresnelConductor,BlinnDistribution> BlinnMicrofacetMetal; double roughness = MathRoutines::Clamp(mp_roughness->Evaluate(i_dg, i_triangle_index), 0.001, 1.0); BlinnDistribution blinn(1.0/roughness); p_bxdf = new ( i_pool.Alloc(sizeof(BlinnMicrofacetMetal)) ) BlinnMicrofacetMetal(SpectrumCoef_d(1.0), fresnel, blinn); } else { ASSERT(mp_u_roughness && mp_v_roughness); typedef Microfacet<FresnelConductor,AnisotropicDistribution> AnisotropicMicrofacetMetal; double u_roughness = MathRoutines::Clamp(mp_u_roughness->Evaluate(i_dg, i_triangle_index), 0.001, 1.0); double v_roughness = MathRoutines::Clamp(mp_v_roughness->Evaluate(i_dg, i_triangle_index), 0.001, 1.0); AnisotropicDistribution anisotropic(1.0/u_roughness, 1.0/v_roughness); p_bxdf = new ( i_pool.Alloc(sizeof(AnisotropicMicrofacetMetal)) ) AnisotropicMicrofacetMetal(SpectrumCoef_d(1.0), fresnel, anisotropic); } p_bsdf->AddBxDF(p_bxdf); return p_bsdf; }
void exportTerrain::printShadingData(const MFnMesh& theMesh, MString texture) { MObjectArray shaders; MIntArray indices; MPlug tPlug; MPlugArray connections,inConnections; MObject node,shaderObject; MFnDependencyNode dpNode; MStatus status; int i,j; theMesh.getConnectedShaders(0 , shaders, indices); fout << "Shading Data:" << endl; //Will assume that only one shader is used, and therefore only prints //data for the first index; //Assuming only one shader dpNode.setObject( shaders[0] ); dpNode.getConnections(connections); for(i=0;i < connections.length();++i){ connections[i].connectedTo(inConnections,true,true); for(j=0;j<inConnections.length();++j){ node = inConnections[j].node(); dpNode.setObject(node); if(node.hasFn(MFn::kLambert) ){ shaderObject = node; } } } MFnLambertShader shader(shaderObject, &status); if(!status){ status.perror("Unable to create MFnLambertShader!"); return; } //Collect all the data fout << "Diffuse_Color: " << (shader.diffuseCoeff(&status)*(MColor(1.0,1.0,1.0) )*shader.color(&status)) * (MColor(1.0,1.0,1.0) - shader.transparency(&status) )<< endl; fout << "Ambient: " << shader.ambientColor(&status) << endl; fout << "Emmision_Color: " << shader.incandescence(&status) << endl; if(shaderObject.hasFn(MFn::kBlinn) ){ MFnBlinnShader blinn(shaderObject); fout << "Specular_Color: " << blinn.specularColor() << endl; fout << "Shininess: " << blinn.eccentricity() << endl; } else if(shaderObject.hasFn(MFn::kPhong) ){ MFnPhongShader phong(shaderObject); fout << "Specular_Color: " << phong.specularColor() << endl; fout << "Shininess: " << phong.cosPower() << endl; } else{ fout << "Specular_Color: " << MColor() << endl; fout << "Shininess: " << double(0) << endl; } fout << "Texture: " << texture << endl; }