// fakefur.cc* // Source Code Copyright /* * lrt source code Copyright(c) 1998-2002 Matt Pharr and Greg Humphreys * All Rights Reserved. * For non-commercial use only. * No warranty, express or implied, for this software. */ #include "lrt.h" #include "materials.h" // FakeFur Class Declarations class FakeFur : public Material { public: // FakeFur Interface ~FakeFur(); FakeFur(Texture *kd, Texture *ks, Texture *d, Texture *disp) : Material(disp) { Kd = kd; Ks = ks; D = d; //Stex = stex; } BSDF *getBSDF(const Surf *surf) const; private: // FakeFur Private Data Texture *Kd, *Ks; Texture *D; //Texture *Stex; }; // FakeFur Method Definitions FakeFur::~FakeFur() { delete Kd; delete Ks; delete D; //delete Stex; } BSDF *FakeFur::getBSDF(const Surf *surf) const { Spectrum kd = Kd->evaluate(surf->dgShading); Spectrum ks = Ks->evaluate(surf->dgShading); Float d = D->evaluate(surf->dgShading); //Float x = (float)rand()/(float)RAND_MAX; //Float y = (float)rand()/(float)RAND_MAX; //Float z = (float)rand()/(float)RAND_MAX; //x = .5 + .5 * x; //y = .5 + .1 * y; //cout << kd << "kd "; ///cout << "shade" << surf->dgShading.N << endl; //cout << surf->dgShading.S << endl; //cout << surf->dgShading.T << endl; //cout << surf->dgGeom.N << endl; //cout << surf->dgGeom.S << endl; //cout << surf->dgGeom.T << endl; Float *skin = new Float[3]; skin[0] = .77; skin[1] = .66; skin[2] = .78; Spectrum skincol(skin); Float reflect = .8; Float transmit = .2; Float length = 1.5; Float baseRadius = .2; Float tipRadius = 0.; Float hairarea = (length * (baseRadius+tipRadius)) / 2.0; BSDF *ret = new BSDF(surf->dgShading, surf->dgGeom); //cout << "S " << surf->dgShading.S << " WtoL s " << ret->WorldToLocal(surf->dgShading.S) << endl; //cout << "T " << surf->dgShading.T << " WtoL s " << ret->WorldToLocal(surf->dgShading.T) << endl; //Vector Ns(surf->dgShading.N); //cout << "N " << surf->dgShading.N << " WtoL s " << ret->WorldToLocal(Ns) << endl; Vector N(0.,0.,1.); Vector T(1., 0., 0.); //T = ret->WorldToLocal(T); T = ret->WorldToLocal(surf->dgShading.S); BRDF *furBRDF = new FurBRDF(kd, ks, T, N, d, skincol, reflect, transmit, hairarea); ret->add(furBRDF); return ret; } extern "C" Reference CreateMaterial(const Transform &xform, const ParamSet &geomParams, const ParamSet &surfaceParams, const Spectrum &color, Texture *displace) { SURF_TEX_F(Kd, 1.); SURF_TEX_F(Ks, 1.); //SURF_TEX_F(roughness, 0.1); SURF_TEX_S(Cs, color); SURF_TEX_S(specularcolor, 1.); SURF_TEX_F(D, 1.); //SURF_TEX_S(Stex, 1.); string tex = geomParams.findOneString("texturename", surfaceParams.findOneString("texturename", "")); Texture *kd = new ScaleTexture(Kd, Cs); Texture *ks = new ScaleTexture(Ks, specularcolor); if (tex != "") { kd = new ScaleTexture(Kd, new ImageTexture(new IdentityMapping2D, tex)); ks = new ScaleTexture(Ks, new ImageTexture(new IdentityMapping2D, tex)); } return new FakeFur(kd, ks, D, displace); }