Exemple #1
0
// --- Methods inherited from Texmap ---
RGBA Water::EvalColor(ShadeContext& sc) {
	float d;
	float q[3];
	Point3 p, dp;

	if (gbufID) 
		sc.SetGBufferID(gbufID);

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

	q[0] = p.x;
	q[1] = p.y;
	q[2] = p.z;
	d = ScalarWave(q);
	if (d>1.0f) d = 1.0f;

	// If we have sub-texmaps and they are enabled, get the colors from 
	// the sub-texmaps, otherwise get them from the color swatch
	RGBA c0 = (mapOn[0]&&subTex[0]) ? subTex[0]->EvalColor(sc): col[0];
	RGBA c1 = (mapOn[1]&&subTex[1]) ? subTex[1]->EvalColor(sc): col[1];

	Col24 c;
	Col24 col1 = Col24FromColor(c0);
	Col24 col2 = Col24FromColor(c1);

	lerp_color(&c, &col1, &col2, d);
	return ColorFromCol24(c);
	}
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
// --- Methods inherited from Texmap ---
RGBA Smoke::EvalColor(ShadeContext& sc) {
	float d;
	Point3 p, dp;

	if (gbufID) 
		sc.SetGBufferID(gbufID);

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

	if (size == 0.0f) 
		size = 1.0f;

	d = SmokeFunc(p/size, iter);

	// If we have sub-texmaps and they are enabled, get the colors from 
	// the sub-texmaps, otherwise get them from the color swatch
	RGBA c0 = (mapOn[0]&&subTex[0]) ? subTex[0]->EvalColor(sc): col[0];
	RGBA c1 = (mapOn[1]&&subTex[1]) ? subTex[1]->EvalColor(sc): col[1];

	Col24 c;
	Col24 col1 = Col24FromColor(c0);
	Col24 col2 = Col24FromColor(c1);

	lerp_color(&c, &col1, &col2, d);
	return ColorFromCol24(c);
}
Exemple #4
0
// --- Methods inherited from Texmap ---
RGBA Stucco::EvalColor(ShadeContext& sc) {
	float f;
	Point3 p, dp;

	if (gbufID) 
		sc.SetGBufferID(gbufID);

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

	if (size == 0.0f) 
		size = 0.0001f;
	p /= size;

	float scl = compscl(dp, size);
	f = Func(p, scl);

	// If we have sub-texmaps and they are enabled, get the colors from 
	// the sub-texmaps, otherwise get them from the color swatch
	RGBA c0 = (mapOn[0]&&subTex[0]) ? subTex[0]->EvalColor(sc): col[0];
	RGBA c1 = (mapOn[1]&&subTex[1]) ? subTex[1]->EvalColor(sc): col[1];

	Col24 c;
	Col24 col1 = Col24FromColor(c0);
	Col24 col2 = Col24FromColor(c1);

	lerp_color(&c, &col1, &col2, f);
	return ColorFromCol24(c);
}
Exemple #5
0
// --- Methods inherited from Texmap ---
RGBA Speckle::EvalColor(ShadeContext& sc) {
	// After being evaluated, if a map or material has a non-zero gbufID, 
	// it should call ShadeContext::SetGBuffer() to store it into 
	// the shade context.
	if (gbufID) 
		sc.SetGBufferID(gbufID);

	// Use the XYZGen instance to get a transformed point from the
	// ShadeContext.
	Point3 p, dp;
	xyzGen->GetXYZ(sc, p, dp);
	if (size == 0.0f) 
		size = 0.0001f;
	p *= SCALE_FACTOR/size;

	float d = SpeckleFunc(p);
	if (d>1.0f) d = 1.0f;

	// If we have sub-texmaps and they are enabled, get the colors from 
	// the sub-texmaps, otherwise get them from the color swatch
	RGBA c0 = (mapOn[0]&&subTex[0]) ? subTex[0]->EvalColor(sc): col[0];
	RGBA c1 = (mapOn[1]&&subTex[1]) ? subTex[1]->EvalColor(sc): col[1];

	// Composite the colors together and return the result.
	return (1.0f-d)*c0 + d*c1;
}
Exemple #6
0
AColor BerconNoise::EvalColor(ShadeContext& sc) {
	if (!sc.doMaps) return black;
	
	AColor c;
	if (sc.GetCache(this,c)) 
		return c; 	
	if (gbufID) sc.SetGBufferID(gbufID);

	// UVW and Distortion
	Point3 p, dpdx, dpdy, dp;	
	if(!berconXYZ.get(sc, p, dpdx, dpdy)) return AColor(0,0,0,0);

	if (useDistortion)
		applyDistortion(sc,p);	
	float nSize = (mapOn[4] && subtex[4]) ? subtex[4]->EvalMono(sc)*size : size;
	p /= nSize; dpdx /= nSize; dpdy /= nSize;
	
	Noise::alterUVW(p, uvwDist);
	NoiseParams np = EvalParameters(&sc);
		
	// Caluclate noise function
	float d = sc.filterMaps ? Noise::limitedNoise(p, dpdx, dpdy, np) : Noise::limitedNoise(p, np);	
	if (useCurve)
		d = curve->GetControlCurve(0)->GetValue(sc.CurTime(), d);

	// Get colors
	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.f-d)*c0 + d*c1);

	// Cache
	sc.PutCache(this,c); 
	return c;	
}
Exemple #7
0
float Mask::EvalMono(ShadeContext& sc) {
	if (gbufID) sc.SetGBufferID(gbufID);
	float m = 1.0f;
	if (subTex[1]&&mapOn[1]) {
		m = subTex[1]->EvalMono(sc);
		if (invertMask) m = 1.0f-m;
		}
	float c0 = subTex[0]&&mapOn[0]? subTex[0]->EvalMono(sc): 1.0f;
	return m*c0;
	}
Exemple #8
0
Point3 Mask::EvalNormalPerturb(ShadeContext& sc) {
	if (gbufID) sc.SetGBufferID(gbufID);
	float m = 1.0f;
	if (subTex[1]&&mapOn[1]) {
		m = subTex[1]->EvalMono(sc);
		if (invertMask) m = 1.0f-m;
		}
	Point3 p0  = subTex[0]&&mapOn[0]? subTex[0]->EvalNormalPerturb(sc): Point3(0.0f,0.0f,0.0f);
	return m*p0;
	}
Exemple #9
0
AColor BerconTile::EvalColor(ShadeContext& sc) {	
	Point3 p;	
	if (!sc.doMaps) return black;

	// If we've already evalutated the color at this point we'll use it and stop here
	AColor c;
	if (sc.GetCache(this,c)) 
		return c; 	
	if (gbufID) sc.SetGBufferID(gbufID);

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

	// UVW, Distortion and size
	berconXYZ.get(sc,p);
	if (useDistortion) p += getDistVector(sc);
	p /= tileSize;

	// Caluclate tiling	
	TilePoint tp = Tile::draw(p, t);

	// Calculate color	
	if (tp.d < -.5f) // First check if we are on edge		
		c = mapOn[1]&&subtex[1]?subtex[1]->EvalColor(sc): col[1];
	else {
		RGBA c1, c2;

		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);

			              c1 = getColor(bsc, 0);
			if (lockEdge) c2 = getColor(bsc, 1);
			else          c2 = getColor(bsc, 2);
		
		} else { // Normal eval
			              c1 = getColor(sc, 0);
			if (lockEdge) c2 = getColor(sc, 1);
			else		  c2 = getColor(sc, 2);
		}
		c = (1.0f-tp.d)*c2 + tp.d*c1;
	}

	c = texout->Filter(c);

	// Cache
	sc.PutCache(this,c); 
	return c;	
}
Exemple #10
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 #11
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 #12
0
// --- Methods inherited from Texmap ---
RGBA Planet::EvalColor(ShadeContext& sc) {
	float d, x, y, z;
	RGBA color;

	// After being evaluated, if a map or material has a non-zero gbufID, 
	// it should call ShadeContext::SetGBuffer() to store it into 
	// the shade context.
	if (gbufID) 
		sc.SetGBufferID(gbufID);

	// Use the XYZGen instance to get a transformed point from the
	// ShadeContext.
	Point3 p, dp;
	xyzGen->GetXYZ(sc, p, dp);

	if (size == 0.0f) 
		size = 0.0001f;
	x = p.x/size;
	y = p.y/size;
	z = p.z/size;
	d = NoiseFunc(x, y, z);
	if (d < land) {
		float frac;
		int index;

		d = d/land*3.0f;
		index = (int)d;
		frac = d-(float)index;
		if (index < 2)
			color = (1.0f-frac)*col[index]+frac*col[index+1];
		else {
			if (blend)
				color = (1.0f-frac)*col[2]+frac*col[3];
			else
				color = col[2];
			}
		}
	else {
		float divfac, frac;
		int index;
		
		divfac = 1.0f-land;
		if (divfac==0.0) divfac = .000001f;
		d = (d-land)/divfac*5;
		index = (int)d;
		frac = d-(float)index;
		if (index < 4)
			color = (1.0f-frac)*col[index+3]+frac*col[index+4];
		else
			color = col[7];
		}
	return color;
	}
Exemple #13
0
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;
}
Exemple #14
0
AColor UVtex::EvalColor(ShadeContext& sc) {
	if (gbufID) sc.SetGBufferID(gbufID);

#if MAX_RELEASE > 3100
	Point3 uvw;
	if (uvChannel < 0)
	{
		if (sc.InMtlEditor())
		{
			Point2 a, b;
			sc.ScreenUV(a, b);
			uvw = Point3(a.x, a.y, 0.0f);
		} else if (sc.globContext != NULL && sc.NodeID() >= 0)
		{
			RenderInstance* ri = sc.globContext->GetRenderInstance(sc.NodeID());
			Mesh* m = ri->mesh;
			if (m->mapSupport(uvChannel))
			{
				Point3 bc = sc.BarycentricCoords();
				int i = sc.FaceNumber();

				UVVert* v = m->mapVerts(uvChannel);
				TVFace* f = m->mapFaces(uvChannel);

				uvw =	v[f[i].t[0]] * bc.x +
						v[f[i].t[1]] * bc.y +
						v[f[i].t[2]] * bc.z;
			} else {
				uvw = Point3(0.0,0.0,0.0);
			}
		} else {
			uvw = Point3(0.0,0.0,0.0);
		}
	} else {
		uvw = sc.UVW(uvChannel);
	}
#else
	Point3 uvw = sc.UVW(uvChannel);
#endif

	if (clampUVW) {
		uvw.x = Clamp(uvw.x);
		uvw.y = Clamp(uvw.y);
		uvw.z = Clamp(uvw.z);
	} else {
		uvw.x = mod(uvw.x, 1.0000001f);
		uvw.y = mod(uvw.y, 1.0000001f);
		uvw.z = mod(uvw.z, 1.0000001f);
	}

	return EvalUVtex(uvw);
}
Exemple #15
0
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);
	}
Exemple #16
0
AColor Mask::EvalColor(ShadeContext& sc) {
	if (gbufID) sc.SetGBufferID(gbufID);
	float m = 1.0f;
	if (subTex[1]&&mapOn[1]) {
		m = subTex[1]->EvalMono(sc);
		if (invertMask) m = 1.0f-m;
		}
	AColor c0 = subTex[0]&&mapOn[0]? subTex[0]->EvalColor(sc): white;
	if(m==1.0f)   
		return c0;
	else 
		return m*c0;
	}
Exemple #17
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 #18
0
AColor plLayerTex::EvalColor(ShadeContext& sc)
{
    if (!sc.doMaps)
        return AColor(0.0f, 0.0f, 0.0f, 1.0f);

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

    if (gbufID)
        sc.SetGBufferID(gbufID);

    //
    // Evaluate the Bitmap
    //
    if (fBitmapPB->GetInt(kBmpUseBitmap) && fBM)
    {
        plBMSampler mysamp(this, fBM);
        color = fUVGen->EvalUVMap(sc, &mysamp, FALSE);
        // We'd like to pass TRUE and actually filter the image, but that seems to be
        // tripping an odd crash in Max internals. *shrug*
    }
    else
        color.White();

    // Invert color if specified
    if (fBitmapPB->GetInt(kBmpInvertColor))
    {
        color.r = 1.0f - color.r;
        color.g = 1.0f - color.g;
        color.b = 1.0f - color.b;
    }
    // Discard color if specified
    if (fBitmapPB->GetInt(kBmpDiscardColor))
        color.r = color.g = color.b = 1.0f;

    // Invert alpha if specified
    if (fBitmapPB->GetInt(kBmpInvertAlpha))
        color.a = 1.0f - color.a;
    // Discard alpha if specified
    if (fBitmapPB->GetInt(kBmpDiscardAlpha))
        color.a = 1.0f;

    // If RGB output is set to alpha, show RGB as grayscale of the alpha
    if (fBitmapPB->GetInt(kBmpRGBOutput) == 1)
        color = AColor(color.a, color.a, color.a, 1.0f);

    sc.PutCache(this, color);
    return color;
}
Exemple #19
0
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;
}
Exemple #20
0
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;
}
Exemple #21
0
AColor BerconWood::EvalColor(ShadeContext& sc) {
	Point3 p,dpdx,dpdy;
	if (!sc.doMaps) return black;

	// If we've already evalutated the color at this point we'll use it and stop here
	AColor c;
	if (sc.GetCache(this,c)) 
		return c; 	
	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
	berconXYZ.get(sc,p,dpdx,dpdy);
	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);
		
	// Caluclate wood function and grain
	Point3 gP;
	
	float d = sc.filterMaps? Noise::wood(p, dpdx, dpdy, gP, wp) : Noise::wood(p, gP, wp);

	float g = (grainAmount > .001f) ? Fractal::grain(gP, grainA, grainF): 0.f;	

	// Get colors
	RGBA c0 = mapOn[0]&&subtex[0] ? subtex[0]->EvalColor(sc): col[0];
	RGBA c1 = mapOn[1]&&subtex[1] ? subtex[1]->EvalColor(sc): col[1];
	RGBA c2 = lockGrain ? c1: (mapOn[2]&&subtex[2] ? subtex[2]->EvalColor(sc): col[2]);
	
	// Apply curves
	if (useCurve)
		d = curve->GetControlCurve(0)->GetValue(sc.CurTime(), d);

	// Calculate color
	c = (1.0f-d)*c0 + d*c1;
	c = (1.0f-g)*c + g*c2;
	c = texout->Filter(c);

	// Cache
	sc.PutCache(this,c); 
	return c;	
}
Exemple #22
0
AColor Composite::EvalColor(ShadeContext& sc) {	
	AColor c;
	if (sc.GetCache(this,c)) 
		return c; 
	if (gbufID) sc.SetGBufferID(gbufID);
	AColor res(0,0,0);	
	for (int i=0; i<subTex.Count(); i++) {
//		int on;
		Interval iv;
//		pblock->GetValue(comptex_ons,0,on,iv,i);

		if (!subTex[i]||!mapOn[i]) continue;
//		if (!subTex[i]||!on) continue;
		res = CompOver(subTex[i]->EvalColor(sc),res);
		}
	sc.PutCache(this,res); 
	return res;
	}
Exemple #23
0
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);
    }
Exemple #24
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 #25
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 #26
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 #27
0
// #################### // Color \\ ####################
AColor BerconGradient::EvalColor(ShadeContext& sc) {
	// Initialize returned color
	AColor res(0.0f,0.0f,0.0f,0.0f);
	if (!sc.doMaps) return res;

	// Use cache
	if (sc.GetCache(this,res)) 
		return res; 	
	if (gbufID) sc.SetGBufferID(gbufID);		
	
	// Function type
	float d;
	if (p_type == 0) {// UVW
		Point3 p;
		if (!berconXYZ.get(sc, p)) return res;
		d = getGradientValueUVW(p);
	} else { // Others
		d = getGradientValue(sc);
	}		 

	// Distortion
	if (p_disOn && p_distex) d += (1.f - p_distex->EvalMono(sc) * 2.f) * p_disStr;

	// Limit range
	if (!limitRange(d)) return res;

	// Curve
	if (p_curveOn) d = curve->GetControlCurve(0)->GetValue(sc.CurTime(), d);		

	// Get color from gradient
	res = gradient->getColor(p_reverse?1.f-d:d, sc);

	// Output
	res = texout->Filter(res);

	// Shading ready, return results
	sc.PutCache(this,res);
	return res;
}
Exemple #28
0
RGBA Wood::EvalColor(ShadeContext& sc) 
{
	Point3	p,dp;
	RGBA	c;
	if (!sc.doMaps) return black;
	if (gbufID) sc.SetGBufferID(gbufID);
	
	xyzGen->GetXYZ(sc,p,dp);
	if (size==0.0f) size=.0001f;
//	p *= FACT/size;

	float d = WoodFunc(p);
	
	if (d<=.0005f) 
		return  (mapOn[0]&&subTex[0]) ? subTex[0]->EvalColor(sc): col[0];
	else 
		if (d>=.9995) 
			return  (mapOn[1]&&subTex[1]) ? subTex[1]->EvalColor(sc): col[1];
	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 = (1.0f-d)*c0 + d*c1;
	return c;
}
Exemple #29
0
Point3 Composite::EvalNormalPerturb(ShadeContext& sc) 
	{
	Point3 p(0,0,0);
	if (gbufID) sc.SetGBufferID(gbufID);
    BOOL c = FALSE;
	for (int i=0; i<subTex.Count(); i++) {
//		int on;
		Interval iv;
//		pblock->GetValue(comptex_ons,0,on,iv,i);
		if (!subTex[i]||!mapOn[i]) continue;
//		if (!subTex[i]||!on) continue;
		Point3 d = subTex[i]->EvalNormalPerturb(sc);
		if (!c) {
			p = d;
			c = 1;
			}	
		else {
			// composite perturbations using alpha -- DS 4/4/97
			AColor col = subTex[i]->EvalColor(sc);
			p = (1.0f-col.a)*p + d;
			}
		}
	return p;	
	}
Exemple #30
0
void plPassMtl::ShadeWithBackground(ShadeContext &sc, Color background, bool useVtxAlpha /* = true */)
{
#if 1

    // old
#if 0
    Color lightCol,rescol, diffIllum0;
    RGBA mval;
    Point3 N0,P;
    BOOL bumped = FALSE;
    int i;

    if (gbufID) 
        sc.SetGBufferID(gbufID);
    
    if (sc.mode == SCMODE_SHADOW) {
        float opac = 0.0;
        for (i=0; i < NumSubTexmaps(); i++)     {
            if (SubTexmapOn(i)) {
                hsMaxLayerBase *hsmLay = (hsMaxLayerBase *)GetSubTexmap(i);
                opac += hsmLay->GetOpacity(t);
            }
        }
        
        float f = 1.0f - opac;
        sc.out.t = Color(f,f,f);
        return;
    }
    
    N0 = sc.Normal();
    P = sc.P();
#endif

    TimeValue t = sc.CurTime();
    Color color(0, 0, 0);
    float alpha = 0.0;

    // Evaluate Base layer
    Texmap *map = fLayersPB->GetTexmap(kPassLayBase);
    if (map && ( map->ClassID() == LAYER_TEX_CLASS_ID 
                || map->ClassID() == STATIC_ENV_LAYER_CLASS_ID ) )
    {
        plLayerTex *layer = (plLayerTex*)map;
        AColor evalColor = layer->EvalColor(sc);

        color = evalColor;
        alpha = evalColor.a;
    }

    // Evaluate Top layer, if it's on
    if (fLayersPB->GetInt(kPassLayTopOn))
    {
        Texmap *map = fLayersPB->GetTexmap(kPassLayTop);
        if (map && ( map->ClassID() == LAYER_TEX_CLASS_ID 
                    || map->ClassID() == STATIC_ENV_LAYER_CLASS_ID 
                    || map->ClassID() == ANGLE_ATTEN_LAYER_CLASS_ID) )
        {
            plPlasmaMAXLayer *layer = (plPlasmaMAXLayer*)map;
            AColor evalColor = layer->EvalColor(sc);

            // Blend layers
            if( !layer->DiscardColor() )
            {
                int blendType = fLayersPB->GetInt(kPassLayBlend);
                switch (blendType)
                {
                case kBlendAdd:
                    color += evalColor * evalColor.a;
                    break;
                case kBlendAlpha:
                    color = (1.0f - evalColor.a) * color + evalColor.a * evalColor;
                    break;
                case kBlendMult:
                    color *= evalColor;
                    break;
                default:    // No blend...
                    color = evalColor;
                    break;
                }
            }
            if( !layer->DiscardAlpha() )
            {
                int alphaType = fLayersPB->GetInt(kPassLayOutputBlend);
                switch( alphaType )
                {
                case kAlphaMultiply:
                    alpha *= evalColor.a;
                    break;
                case kAlphaAdd:
                    alpha += evalColor.a;
                    break;
                case kAlphaDiscard:
                default:
                    break;
                }
            }
        }
    }

#if 1
    AColor black;
    black.Black();
    AColor white;
    white.White();


    SIllumParams ip;
    if (fBasicPB->GetInt(kPassBasEmissive))
    {
        // Emissive objects don't get shaded
        ip.diffIllum = fBasicPB->GetColor(kPassBasColorAmb, t) * color;
        ip.diffIllum.ClampMinMax();
        ip.specIllum = black;
    }
    else
    {
        //
        // Shading setup
        //

        // Setup the parameters for the shader
        ip.amb = fBasicPB->GetColor(kPassBasColorAmb, t);
        ip.diff = fBasicPB->GetColor(kPassBasColor, t) * color;
        ip.diffIllum = black;
        ip.specIllum = black;
        ip.N = sc.Normal();
        ip.V = sc.V();


        //
        // Specularity
        //
        if (fBasicPB->GetInt(kPassBasUseSpec, t))
        {
            ip.sh_str = 1.f;
            ip.spec = fBasicPB->GetColor( kPassBasSpecColor, t );
            ip.ph_exp = (float)pow(2.0f,float(fBasicPB->GetInt(kPassBasShine, t)) / 10.0f);
            ip.shine = float(fBasicPB->GetInt(kPassBasShine, t)) / 100.0f;
        }
        else
        {
            ip.spec = black;
            ip.sh_str = 0;
            ip.ph_exp = 0;
            ip.shine = 0;
        }
        ip.softThresh = 0;

        //

        // Do the shading
        Shader *myShader = GetShader(SHADER_BLINN);
        myShader->Illum(sc, ip);

        // Override shader parameters
        if (fAdvPB->GetInt(kPBAdvNoShade))
        {
            ip.diffIllum = black;
            ip.specIllum = black;
        }
        if (fAdvPB->GetInt(kPBAdvWhite))
        {
            ip.diffIllum = white;
            ip.specIllum = black;
        }

        ip.specIllum.ClampMinMax();
        ip.diffIllum = ip.amb * sc.ambientLight + ip.diff * ip.diffIllum;
        ip.diffIllum.ClampMinMax();
    }

//  AColor returnColor = AColor(opac * ip.diffIllum + ip.specIllum, opac)
#endif

    // Get opacity and combine with alpha
    float opac = float(fBasicPB->GetInt(kPassBasOpacity, t)) / 100.0f;
    alpha *= opac;

    float vtxAlpha = 1.0f;
    if (useVtxAlpha && GetOutputBlend() == plPassMtlBase::kBlendAlpha)
    {
        Point3 p;
        GetInterpVtxValue(MAP_ALPHA, sc, p);
        vtxAlpha = p.x;
    }
    alpha *= vtxAlpha;

    // MAX will do the additive/alpha/no blending for us based on what Requirements()
    // we tell it. However, since MAX's formula is bgnd*sc.out.t + sc.out.c,
    // we have to multiply our output color by the alpha.
    // If we ever need a more complicated blending function, you can request the
    // background color via Requirements() (otherwise it's just black) and then do
    // the blending yourself; however, if the transparency isn't set, the shadows
    // will be opaque, so be careful.
    Color outC = ip.diffIllum + ip.specIllum;

    sc.out.c = ( outC * alpha );
    sc.out.t = Color( 1.f - alpha, 1.f - alpha, 1.f - alpha );

#endif
}