コード例 #1
0
ファイル: splat.cpp プロジェクト: vasilenkomike/xray
Point3 Splat::EvalNormalPerturb(ShadeContext& sc) {
    float del, d, f;
    Point3 p, dp, np;

    if (gbufID)
        sc.SetGBufferID(gbufID);

    xyzGen->GetXYZ(sc, p, dp);

    d = splatter(p);
    del = 0.1f;
//	float strength = (abs((int)col[1].r-(int)col[0].r)+
//				abs((int)col[1].g-(int)col[0].g)+
//				abs((int)col[1].b-(int)col[0].b)); ///100.0f; // 756.0f

//	f = strength/del;
    f = 1.0f/del;
    Point3 M[3];
    xyzGen->GetBumpDP(sc,M);
    np.x = f*(splatter(p+del*M[0]) - d);
    np.y = f*(splatter(p+del*M[1]) - d);
    np.z = f*(splatter(p+del*M[2]) - d);

    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 np;
}
コード例 #2
0
ファイル: water.cpp プロジェクト: artemeliy/inf4715
Point3 Water::EvalNormalPerturb(ShadeContext& sc) {
	if (gbufID) 
		sc.SetGBufferID(gbufID);

	Point3 p, dp, np;
	xyzGen->GetXYZ(sc, p, dp);

	VectorWave(p, np);
	Point3 M[3];
	xyzGen->GetBumpDP(sc,M);
	np = Point3( DotProd(np,M[0]),DotProd(np,M[1]),DotProd(np,M[2]));
	return sc.VectorFromNoScale(np,REF_OBJECT);
	}
コード例 #3
0
ファイル: speckle.cpp プロジェクト: innovatelogic/ilogic-vm
Point3 Speckle::EvalNormalPerturb(ShadeContext& sc) {
	float del, d;
	Point3 p, dp;
	Point3 np;

	if (gbufID) 
		sc.SetGBufferID(gbufID);

	xyzGen->GetXYZ(sc, p, dp);
	if (size == 0.0f) 
		size = 0.0001f;
	p *= SCALE_FACTOR/size;

	del = 0.1f;
	d = SpeckleFunc(p);
	Point3 M[3];
	xyzGen->GetBumpDP(sc,M);
    np.x = (SpeckleFunc(p+del*M[0]) - d)/del;
	np.y = (SpeckleFunc(p+del*M[1]) - d)/del;
	np.z = (SpeckleFunc(p+del*M[2]) - 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 np;
}
コード例 #4
0
ファイル: stucco.cpp プロジェクト: 2asoft/xray
Point3 Stucco::EvalNormalPerturb(ShadeContext& sc) {
	float d,k;
	Point3 p, dp, np;

	if (gbufID) 
		sc.SetGBufferID(gbufID);

	xyzGen->GetXYZ(sc, p, dp);

	float scl = compscl(dp, size);
	p /= size;
	d = Func(p, scl);
	k = 0.25f/del;

	Point3 M[3];
	xyzGen->GetBumpDP(sc,M);
	np.x = (Func(p + del*M[0], scl) - d)*k;
	np.y = (Func(p + del*M[1], scl) - d)*k;
	np.z = (Func(p + del*M[2], scl) - d)*k;
	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 np;
}
コード例 #5
0
ファイル: planet.cpp プロジェクト: 2asoft/xray
Point3 Planet::EvalNormalPerturb(ShadeContext& sc) {
	float del,d;
	Point3 p,dp;
	if (!sc.doMaps) return Point3(0,0,0);
	if (gbufID) sc.SetGBufferID(gbufID);
	xyzGen->GetXYZ(sc,p,dp);
	if (size == 0.0f) 
		size = 0.0001f;
	p /= size;
	del = 10.0f;
	d = BumpFunc(p);
	Point3 np;
	Point3 M[3];
	xyzGen->GetBumpDP(sc,M);
    np.x = (BumpFunc(p+del*M[0]) - d)/del;
	np.y = (BumpFunc(p+del*M[1]) - d)/del;
	np.z = (BumpFunc(p+del*M[2]) - d)/del;
	return sc.VectorFromNoScale(np*100.0f,REF_OBJECT);
    }
コード例 #6
0
ファイル: noise.cpp プロジェクト: artemeliy/inf4715
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);
	}
コード例 #7
0
ファイル: BerconNoise.cpp プロジェクト: GeorgeR/BerconMaps
Point3 BerconNoise::EvalNormalPerturb(ShadeContext& sc) {		
	if (!sc.doMaps) return Point3(0,0,0);
	if (gbufID) sc.SetGBufferID(gbufID);

	// UVW and Distortion
	Point3 p, dpdx, dpdy;
	Point3 M[3];
	if (!berconXYZ.get(sc, p, dpdx, dpdy, M)) return Point3(0,0,0);

	if (useDistortion)
		applyDistortion(sc,p);	
	float nSize = (mapOn[4] && subtex[4]) ? subtex[4]->EvalMono(sc)*size : size;
	p /= nSize;
	Noise::alterUVW(p, uvwDist);

	NoiseParams np = EvalParameters(&sc);

	// Vector
	Point3 normal;
	float d = Noise::limitedNoise(p, np);
	if (useCurve) {		
		d = curve->GetControlCurve(0)->GetValue(sc.CurTime(), d);
		normal.x = (curve->GetControlCurve(0)->GetValue(sc.CurTime(), Noise::limitedNoise(p+DELTA*M[0], np)) - d) / DELTA;
		normal.y = (curve->GetControlCurve(0)->GetValue(sc.CurTime(), Noise::limitedNoise(p+DELTA*M[1], np)) - d) / DELTA;
		normal.z = (curve->GetControlCurve(0)->GetValue(sc.CurTime(), Noise::limitedNoise(p+DELTA*M[2], np)) - d) / DELTA;
	} else {
		normal.x = (Noise::limitedNoise(p+DELTA*M[0], np) - d) / DELTA;
		normal.y = (Noise::limitedNoise(p+DELTA*M[1], np) - d) / DELTA;
		normal.z = (Noise::limitedNoise(p+DELTA*M[2], np) - d) / DELTA;
	}	
	normal = -sc.VectorFromNoScale(normal, REF_OBJECT);

	// Eval sub maps
	float f1, f2;
	Point3 v1, v2;
	bool maps = false;
	if (subtex[0]) {
		f1 = subtex[0]->EvalMono(sc);
		v1 = subtex[0]->EvalNormalPerturb(sc);
		maps = true;
	} else {
		f1 = Intens(col[0]);
		v1 = Point3(0.f, 0.f, 0.f);
	}
	if (subtex[1]) {
		f2 = subtex[1]->EvalMono(sc);
		v2 = subtex[1]->EvalNormalPerturb(sc);
		maps = true;
	} else {
		f2 = Intens(col[1]);
		v2 = Point3(0.f, 0.f, 0.f);
	}
	
	// Calculate vector
	if (maps)
		normal = (f2-f1)*normal + d*v2 + (1.f-d)*v1;
	else
		normal *= f2 - f1;

	return texout->Filter(normal); // Does this filter actually do something?
}
コード例 #8
0
ファイル: BerconTile.cpp プロジェクト: Bercon/BerconMaps
Point3 BerconTile::EvalNormalPerturb(ShadeContext& sc) {	
	
	if (!sc.doMaps) return Point3(0,0,0);
	if (gbufID) sc.SetGBufferID(gbufID);

	// Evaulate maps and tiling parameters
	TileParam t	= EvalParameters(sc);

	// UVW, Distortion and size
	Point3 p;
	Point3 M[3];
	berconXYZ.get(sc, p, M);	

	if (useDistortion) p += getDistVector(sc);
	p /= tileSize;

	TilePoint tp =  Tile::draw(p, t);
	if (tp.d < 0) return getNormal(sc, 1);

	Point3 np;
	if (berconXYZ.req()) {		
		TilePoint tp1 = Tile::draw(p + Point3(DELTA,0.f,0.f), t); if (tp1.d < 0) return getNormal(sc, 1);				
		TilePoint tp2 = Tile::draw(p + Point3(0.f,DELTA,0.f), t); if (tp2.d < 0) return getNormal(sc, 1);
		np.x = (tp1.d - tp.d) / DELTA;
		np.y = (tp2.d - tp.d) / DELTA;
		np = M[0]*np.x + M[1]*np.y;
	} else {
		TilePoint tp1 = Tile::draw(p + DELTA*M[0], t); if (tp1.d < 0) return getNormal(sc, 1);				
		TilePoint tp2 = Tile::draw(p + DELTA*M[1], t); if (tp2.d < 0) return getNormal(sc, 1);
		TilePoint tp3 = Tile::draw(p + DELTA*M[2], t); if (tp3.d < 0) return getNormal(sc, 1);	
		np.x = (tp1.d - tp.d) / DELTA;
		np.y = (tp2.d - tp.d) / DELTA;
		np.z = (tp3.d - tp.d) / DELTA;
		np = -sc.VectorFromNoScale(np, REF_OBJECT);
	}
	
	// Eval sub maps
	float f1, f2;
	Point3 v1, v2;

	if (tileParam.mapUV || tileParam.tileID || tileParam.center) { // Then if we map UV coordinates
			
		BerconSC bsc = BerconSC(&sc);			
		if (tileParam.mapUV)
			bsc.setUV1(tp.uvw, uvChan);
		if (tileParam.center)
			bsc.setUV2(tp.center, uvChan2);
		if (tileParam.tileID)
			bsc.setMultiTexture((float)tp.id);

		              f1 = getFloat(bsc, 0);
		if (lockEdge) f2 = getFloat(bsc, 1);
		else		  f2 = getFloat(bsc, 2);

		              v1 = getNormal(bsc, 0);
		if (lockEdge) v2 = getNormal(bsc, 1);
		else		  v2 = getNormal(bsc, 2);
	} else { // And finally just normal eval
		              f1 = getFloat(sc, 0);
		if (lockEdge) f2 = getFloat(sc, 1);
		else		  f2 = getFloat(sc, 2);

		              v1 = getNormal(sc, 0);
		if (lockEdge) v2 = getNormal(sc, 1);
		else		  v2 = getNormal(sc, 2);
	}

	np = (f2-f1)*np + tp.d*v2 + (1.f-tp.d)*v1;
	
	return texout->Filter(np); // Does this filter actually do something?*/
}
コード例 #9
0
ファイル: celltex.cpp プロジェクト: artemeliy/inf4715
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));
	}
コード例 #10
0
ファイル: BerconWood.cpp プロジェクト: GeorgeR/BerconMaps
Point3 BerconWood::EvalNormalPerturb(ShadeContext& sc) {	
	Point3 p,dpdx,dpdy;
	
	if (!sc.doMaps) return Point3(0,0,0);
	if (gbufID) sc.SetGBufferID(gbufID);

	// Evaluate parameters
	WoodParam wp = EvalParameters(sc);
	float grainA = mapOn[19]&&subtex[19]?subtex[19]->EvalMono(sc)*grainAmount:grainAmount;
	float grainF = mapOn[20]&&subtex[20]?subtex[20]->EvalMono(sc)*grainFreq:grainFreq;

	// UVW, Distortion and size
	Point3 M[3];
	berconXYZ.get(sc, p, dpdx, dpdy, M);

	if (useDistortion)
		applyDistortion(sc,p);	
	float wSize = mapOn[5]&&subtex[5]?subtex[5]->EvalMono(sc)*woodSize:woodSize;
	p /= wSize; dpdx /= (wSize / 2.f); dpdy /= (wSize / 2.f);

	// Vectors
	bool grainON = (grainAmount > .001f); 
	Point3 np, nG, gP;
	
	float d = sc.filterMaps? Noise::wood(p, dpdx, dpdy, gP, wp) : Noise::wood(p, gP, wp);
	if (useCurve) d = curve->GetControlCurve(0)->GetValue(sc.CurTime(), d);
	
	float g = grainON ? Fractal::grain(gP, grainA, grainF): 0.f;	
	
	for (int i=0; i<3; i++) {		
		np[i] = sc.filterMaps? Noise::wood(p + DELTA * M[i], dpdx, dpdy, gP, wp) : Noise::wood(p + DELTA * M[i], gP, wp);
		if (useCurve) np[i] = curve->GetControlCurve(0)->GetValue(sc.CurTime(), np[i]);	
		np[i] = (np[i] - d) / DELTA;
		if (grainON) nG[i] = Fractal::grain(gP, grainA, grainF); // gP is updated by wood()
	}

	np = -sc.VectorFromNoScale(np, REF_OBJECT);
	nG = -sc.VectorFromNoScale(nG, REF_OBJECT);

	// Eval sub maps
	float f1, f2, f3;
	Point3 v1, v2, v3;
	bool maps = false;
	if (subtex[0]) {
		f1 = subtex[0]->EvalMono(sc);
		v1 = subtex[0]->EvalNormalPerturb(sc);
		maps = true;
	} else {
		f1 = Intens(col[0]);
		v1 = Point3(0.f, 0.f, 0.f);
	}
	if (subtex[1]) {
		f2 = subtex[1]->EvalMono(sc);
		v2 = subtex[1]->EvalNormalPerturb(sc);
		maps = true;
	} else {
		f2 = Intens(col[1]);
		v2 = Point3(0.f, 0.f, 0.f);
	}
	if (subtex[2]) {
		f3 = subtex[2]->EvalMono(sc);
		v3 = subtex[2]->EvalNormalPerturb(sc);
		maps = true;
	} else {
		f3 = Intens(col[2]);
		v3 = Point3(0.f, 0.f, 0.f);
	}
	
	// Calculate vector	
	if (maps) {
		np = (f2-f1)*np + d*v2 + (1.f-d)*v1;
		if (grainON) {
			float val = d*f1 + (1.f-d)*f2;
			np = (f3-val)*nG + g*v3 + (1.f-g)*np;
		}
	} else {
		np *= f2 - f1;
		if (grainON) {
			float val = d*f1 + (1.f-d)*f2;
			np = (f3-val)*nG + (1.f-g)*np;
		}
	}	

	return texout->Filter(np); // Does this filter actually do something?
}