Exemple #1
0
AColor CellTex::EvalColor(ShadeContext& sc)
	{	
	// Get object point
	Point3 p,dp;
	if (gbufID) sc.SetGBufferID(gbufID);
	xyzGen->GetXYZ(sc,p,dp);
	p += ptOffset;
	p = p/size;
	
	// Eval maps
	Color cellC, div1C, div2C;
	if (useCellMap && subTex[0]) cellC = subTex[0]->EvalColor(sc);
	else cellC = cellCol;
	if (useDiv1Map && subTex[1]) div1C = subTex[1]->EvalColor(sc);
	else div1C = divCol1;
	if (useDiv2Map && subTex[2]) div2C = subTex[2]->EvalColor(sc);
	else div2C = divCol2;

	// Evaluate cell function
	float dist[2];
	int ids[2];
	float u;
	if (type) {
		if (fract) FractalCellFunction(p,iterations,rough,2,dist,ids);
		else CellFunction(p,2,dist,ids);
		u = 1.0f - (dist[1]-dist[0])/spread;		
	} else {
		if (fract) FractalCellFunction(p,iterations,rough,1,dist,ids);
		else CellFunction(p,1,dist,ids);
		u = dist[0]/spread;
		}

	// Vari cell color
	if (var>0.0f) {
		float vr = RandFromCellID(ids[0])*var + varOff;
		cellC.r = cellC.r*vr;
		cellC.g = cellC.g*vr;
		cellC.b = cellC.b*vr;
		cellC.ClampMinMax();		
		}

	if (u<low) return texout->Filter(RGBA(cellC));
	if (u>high) return texout->Filter(RGBA(div2C));
	if (u<mid) {
		u = (u-low)/(midMinuslow);
		return texout->Filter(RGBA(div1C*u + (1.0f-u)*cellC));
	} else {
		u = (u-mid)/(highMinusmid);
		return texout->Filter(RGBA(div2C*u + (1.0f-u)*div1C));
		}
	}
Exemple #2
0
RGBA Noise::EvalColor(ShadeContext& sc) {
	Point3 p,dp;
	if (!sc.doMaps) return black;

	AColor c;
	if (sc.GetCache(this,c)) 
		return c; 

	if (gbufID) sc.SetGBufferID(gbufID);

	//IPoint2 ps = sc.ScreenCoord();
  	UpdateCache(sc.CurTime());  // DS 10/3/00
	xyzGen->GetXYZ(sc,p,dp);
	p /= size;	   
	filter = sc.filterMaps;
	
	float smw;
	float limlev = LimitLevel(dp,smw);
    float d = NoiseFunction(p,limlev,smw);

	RGBA c0 = mapOn[0]&&subTex[0] ? subTex[0]->EvalColor(sc): col[0];
	RGBA c1 = mapOn[1]&&subTex[1] ? subTex[1]->EvalColor(sc): col[1];
	c = texout->Filter((1.0f-d)*c0 + d*c1);
	
	sc.PutCache(this,c); 
	return c;
	}
Exemple #3
0
float Gradient::EvalMono(ShadeContext& sc) {
	if (!sc.doMaps) 
		return 0.0f;
	float f;
	if (sc.GetCache(this,f)) 
		return f; 
	if (gbufID) sc.SetGBufferID(gbufID);
	f = texout->Filter(uvGen->EvalUVMapMono(sc,&mysamp));
	sc.PutCache(this,f); 
	return f;
	}
Exemple #4
0
AColor Gradient::EvalColor(ShadeContext& sc) {
	if (!sc.doMaps) 
		return black;
	AColor c;
	if (sc.GetCache(this,c)) 
		return c; 
	if (gbufID) sc.SetGBufferID(gbufID);
	c = texout->Filter(uvGen->EvalUVMap(sc,&mysamp));
	sc.PutCache(this,c); 
	return c;
	}
Exemple #5
0
Point3 Gradient::EvalNormalPerturb(ShadeContext& sc) 
	{
	Point3 dPdu, dPdv;
	if (!sc.doMaps) return Point3(0,0,0);
	if (gbufID) sc.SetGBufferID(gbufID);
	Point2 dM = uvGen->EvalDeriv(sc,&mysamp);
	uvGen->GetBumpDP(sc,dPdu,dPdv);

#if 0
	// Blinn's algorithm
	Point3 N = sc.Normal();
	Point3 uVec = CrossProd(N,dPdv);
	Point3 vVec = CrossProd(N,dPdu);
	Point3 np = -dM.x*uVec+dM.y*vVec;
#else 
	// Lazy algorithm
	Point3 np = dM.x*dPdu+dM.y*dPdv;
//	return texout->Filter(dM.x*dPdu+dM.y*dPdv);
#endif
	Texmap* sub[3];
	for (int i=0; i<3; i++) 
		sub[i] = mapOn[i]?subTex[i]:NULL;
	if (sub[0]||sub[1]||sub[2]) {
		// d((1-k)*a + k*b ) = dk*(b-a) + k*(db-da) + da
		float a,b,k;
		Point3 da,db;
		Point2 UV, dUV;
		uvGen->GetUV(sc, UV,dUV);
		k = gradFunc(UV.x,UV.y);
		if (k<=center) {	
			k = k/center; 		
			EVALSUBPERTURB(a,da,2);
			EVALSUBPERTURB(b,db,1);
			} 
		else {
			k = (k-center)/(1.0f-center);		
			EVALSUBPERTURB(a,da,1);
			EVALSUBPERTURB(b,db,0);
			}
		np = (b-a)*np + k*(db-da) + da;
		}
	return texout->Filter(np);
	}
Exemple #6
0
Point3 Noise::EvalNormalPerturb(ShadeContext& sc) {
	Point3 p,dp;
	if (!sc.doMaps) return Point3(0,0,0);
	if (gbufID) sc.SetGBufferID(gbufID);
  	UpdateCache(sc.CurTime());  // DS 10/3/00
	xyzGen->GetXYZ(sc,p,dp);
	p /= size;
	filter = sc.filterMaps;
	float smw;
	float limlev = LimitLevel(dp,smw);
	float del,d;
	d = NoiseFunction(p,limlev,smw);
	//del = (dp.x+dp.y+dp.z)/(size*3.0f);
	del = .1f;
	Point3 np;					  
	Point3 M[3];
	xyzGen->GetBumpDP(sc,M);

	np.x = (NoiseFunction(p+del*M[0],limlev,smw) - d)/del;
	np.y = (NoiseFunction(p+del*M[1],limlev,smw) - d)/del;
	np.z = (NoiseFunction(p+del*M[2],limlev,smw) - d)/del;

	np = sc.VectorFromNoScale(np, REF_OBJECT);

	Texmap *sub0 = mapOn[0]?subTex[0]:NULL;
	Texmap *sub1 = mapOn[1]?subTex[1]:NULL;
	if (sub0||sub1) {
		// d((1-k)*a + k*b ) = dk*(b-a) + k*(db-da) + da
		float a,b;
		Point3 da,db;
		if (sub0) { 	a = sub0->EvalMono(sc); 	da = sub0->EvalNormalPerturb(sc);		}
		else {	 a = Intens(col[0]);	 da = Point3(0.0f,0.0f,0.0f);		 }
		if (sub1) { 	b = sub1->EvalMono(sc); 	db = sub1->EvalNormalPerturb(sc);	}
		else {	 b = Intens(col[1]);	 db= Point3(0.0f,0.0f,0.0f);		 }
		np = (b-a)*np + d*(db-da) + da;
		}
	else 
		np *= Intens(col[1])-Intens(col[0]);
	return texout->Filter(np);
	}
Exemple #7
0
float Noise::EvalMono(ShadeContext& sc) {
	Point3 p,dp;
	if (!sc.doMaps) 	return 0.0f;

	float f;
	if (sc.GetCache(this,f)) 
		return f; 

	if (gbufID) sc.SetGBufferID(gbufID);
  	UpdateCache(sc.CurTime());  // DS 10/3/00
	xyzGen->GetXYZ(sc,p,dp);
	p /= size;
	filter = sc.filterMaps;
	float smw;
	float limlev = LimitLevel(dp, smw);
    float d = NoiseFunction(p,limlev,smw);
	float c0 = mapOn[0]&&subTex[0] ? subTex[0]->EvalMono(sc): Intens(col[0]);
	float c1 = mapOn[1]&&subTex[1] ? subTex[1]->EvalMono(sc): Intens(col[1]);
	f = texout->Filter((1.0f-d)*c0 + d*c1);
	sc.PutCache(this,f); 
	return f;
	}
Exemple #8
0
Point3 Output::EvalNormalPerturb(ShadeContext& sc) {
	if (gbufID) sc.SetGBufferID(gbufID);
	return texout->Filter((subTex[0]&&mapOn[0])? subTex[0]->EvalNormalPerturb(sc): Point3(0,0,0));
	}
Exemple #9
0
float Output::EvalMono(ShadeContext& sc) {
	if (gbufID) sc.SetGBufferID(gbufID);
	return texout->Filter((subTex[0]&&mapOn[0])? subTex[0]->EvalMono(sc): 1.0f);
	}
Exemple #10
0
AColor Output::EvalColor(ShadeContext& sc) {
	if (gbufID) sc.SetGBufferID(gbufID);
	return texout->Filter((subTex[0]&&mapOn[0])? subTex[0]->EvalColor(sc): white);
	}
Exemple #11
0
Point3 CellTex::EvalNormalPerturb(ShadeContext& sc)
	{
	Point3 p,dp;
	xyzGen->GetXYZ(sc,p,dp);	
	p += ptOffset;
	Point3 np(0.0f,0.0f,0.0f);
	float dpsq = DotProd(dp,dp);		
	float d = CellFunc(p,dpsq,np,sc.InMtlEditor());

	Texmap* sub0 = (useCellMap && subTex[0])?subTex[0]:NULL; 
	Texmap* sub1 = (useDiv1Map && subTex[1])?subTex[1]:NULL; 
	Texmap* sub2 = (useDiv2Map && subTex[2])?subTex[2]:NULL; 
	if (d<low) {
		if (sub0) 
			np  = sub0->EvalNormalPerturb(sc);
		}
	else 
	if (d>high) {
		if (sub2) 
			np  = sub2->EvalNormalPerturb(sc);
		}
	else {
		Point3 M[3];
		xyzGen->GetBumpDP(sc,M);
		np = Point3( DotProd(np,M[0]),DotProd(np,M[1]),DotProd(np,M[2]));
		if (d<mid) {
			if (sub0||sub1) {
				float a,b;
				Point3 da,db;
				// d((1-k)*a + k*b ) = dk*(b-a) + k*(db-da) + da
				d = (d-low)/(midMinuslow);

				// div1C*u + (1.0f-u)*cellC) ;
				if (sub0) {
					a = sub0->EvalMono(sc);
					da = sub0->EvalNormalPerturb(sc);
					}
				else {
					 a = 1.0f;
					 da = Point3(0.0f,0.0f,0.0f);
					 }
				if (sub1) {
					b = sub1->EvalMono(sc);
					db = sub1->EvalNormalPerturb(sc);
					}
				else {
					 b = 1.0f;
					 db = Point3(0.0f,0.0f,0.0f);
					 }
				np = (b-a)*np + d*(db-da) + da;
				}
			} 
		else {
			if (sub1 || sub2) {
				float a,b;
				Point3 da,db;
				// div2C*u + (1.0f-u)*div1C);
				d = (d-mid)/(highMinusmid);
				if (sub1) {
					a = sub1->EvalMono(sc);
					da = sub1->EvalNormalPerturb(sc);
					}
				else {
					 a = 1.0f;
					 da = Point3(0.0f,0.0f,0.0f);
					 }
				if (sub2) {
					b = sub2->EvalMono(sc);
					db = sub2->EvalNormalPerturb(sc);
					}
				else {
					 b = 1.0f;
					 db = Point3(0.0f,0.0f,0.0f);
					 }
				np = (b-a)*np + d*(db-da)+ da;
				}
			}
		}

//	float d = CellFunc(p,dpsq,np,sc.InMtlEditor());
//	Point3 tmp;
//	float div = type ? -0.1875f : 0.0375f;
//	Point3 DP[3];
//	xyzGen->GetBumpDP(sc,DP);
//	np.x = (CellFunc(p+DP[0],dpsq,tmp,sc.InMtlEditor()) - d)/div;
//	np.y = (CellFunc(p+DP[1],dpsq,tmp,sc.InMtlEditor()) - d)/div;
//	np.z = (CellFunc(p+DP[2],dpsq,tmp,sc.InMtlEditor()) - d)/div;

	if (type) np = np * -0.5f;	
	

	return texout->Filter(sc.VectorFromNoScale(np,REF_OBJECT));
	}