Ejemplo n.º 1
0
AColor mrTwoSidedShader::EvalColor(ShadeContext& sc) {

	// Provide a good default for this (for the material editor peview)... 
	// Use the front color for the top half of the screen the the back color 
	// for the bottom half.
	if(m_mainPB != NULL) {
		Point2 screenUV;
		Point2 screenDUV;
		sc.ScreenUV(screenUV, screenDUV);

		// Front map is used for top part of the image
		bool useFront = (screenUV.y > 0.5f);

		TimeValue t = sc.CurTime();
		BOOL mapOn = m_mainPB->GetInt(useFront ? kMainPID_FrontMapOn : kMainPID_BackMapOn, t);
		if(mapOn) {
			Texmap* map = m_mainPB->GetTexmap(useFront ? kMainPID_FrontMap : kMainPID_BackMap, t);
			if(map != NULL) {
				return map->EvalColor(sc);
			}
		}

		// Return the color only
		AColor col = m_mainPB->GetAColor(useFront ? kMainPID_FrontColor : kMainPID_BackColor, t);
		return col;
	}
	
	return AColor(0,0,0);
}
Ejemplo n.º 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;
	}
Ejemplo n.º 3
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;	
}
Ejemplo n.º 4
0
// Seed random number generator		
void BerconGradient::seedRandomGen(ShadeContext& sc) {
	int seed = 1;
	if (previewMatIDMode) {
		seed = sc.mtlNum;
	} else {
		if (p_randMat) { 		
			seed += sc.mtlNum;
		}
		if (p_randObj) {
			int hand = (int)sc.Node()->GetHandle();
			seed += hand*(hand*hand*15731 + 789221);
		}
		if (p_randPar) {
			Object *ob = sc.GetEvalObject();		
			if (ob && ob->IsParticleSystem()) {
				ParticleObject *obj = (ParticleObject*)ob;
				IChkMtlAPI* chkMtlAPI = static_cast<IChkMtlAPI*>(obj->GetInterface(I_NEWMTLINTERFACE));
				if ((chkMtlAPI && chkMtlAPI->SupportsParticleIDbyFace())) {
					int id = chkMtlAPI->GetParticleFromFace(sc.FaceNumber());
					seed += id*(id*id*571 + 789221);
				}			
			}
		}
		if (p_randTile) {
			seed += (int)(sc.UVW(99).z);
		}
	}

	seed *= p_seed;
	srand(seed*(seed*seed*15731 + 789221));	
}
Ejemplo n.º 5
0
void DumMtl::Shade(ShadeContext& sc)
{
	Color lightCol;
	Color diffwk(0.0f,0.0f,0.0f);
	Color specwk(0.0f,0.0f,0.0f);
	Point3 N = sc.Normal();
	Point3	R = sc.ReflectVector();
	LightDesc *l;
	for (int i = 0; i<sc.nLights; i++) {
		l = sc.Light(i);
		register float NL, diffCoef;
		Point3 L;
		if (!l->Illuminate(sc, N, lightCol, L, NL, diffCoef))
			continue;

		// diffuse
		if (l->affectDiffuse)
			diffwk += diffCoef*lightCol;
		// specular
		if (l->affectSpecular) {
			float c = DotProd(L,R);
			if (c>0.0f) {
				c = (float)pow((double)c, (double)phongexp); 
				specwk += c*lightCol*NL;   // multiply by NL to SOFTEN 
			}
		}
	}
	sc.out.t = Color(0.0f,0.0f,0.0f);
	sc.out.c = (.3f*sc.ambientLight + diffwk)*diff + specwk*spec;		
}
Ejemplo n.º 6
0
void StraussShader::AffectReflection(ShadeContext &sc, IllumParams &ip, Color &rClr ) 
{
   float opac = ip.channels[ S_TR ].r;
   float g = ip.channels[ S_GL ].r;
   float m = ip.channels[ S_MT ].r;
   Color Cd = ip.channels[ S_DI ];

   float rn = opac - (1.0f - g * g * g) * opac;

   // the reflection of the reflection vector is just the view vector
   // so dot(v, r) is 1, to any power is still 1
   float a, b;
// NB: this has been transformed for existing in-pointing v
   float NV = Dot( sc.V(), sc.Normal() );
   Point3 R = sc.V() - 2.0f * NV * sc.Normal();
   float NR = Dot( sc.Normal(), R );
      a = (float)acos( NR ) * OneOverHalfPi;
      b = (float)acos( NV ) * OneOverHalfPi;
            
   float fa = F( a );
   float j = fa * G( a ) * G( b );
   float rj = Bound( rn + (rn+kj)*j );
   Color white( 1.0f, 1.0f, 1.0f );

   Color Cs = white + m * (1.0f - fa) * (Cd - white);
   rClr *= Cs * rj * REFL_BRIGHTNESS_ADJUST;
}
Ejemplo n.º 7
0
void plPassMtl::GetInterpVtxValue(int channel, ShadeContext &sc, Point3 &val)
{
    Mesh *mesh = sc.globContext->GetRenderInstance(sc.NodeID())->mesh;
    if (mesh != nil)
    {
        Face *maxFace = &mesh->faces[ sc.FaceNumber() ];
        UVVert *map = mesh->mapVerts(channel);
        if (map != nil)
        {
            Point3 p0 = map[maxFace->getVert( 0 )];
            Point3 p1 = map[maxFace->getVert( 1 )];
            Point3 p2 = map[maxFace->getVert( 2 )];
            Point3 interp = sc.BarycentricCoords();
            val.x = interp.x * p0.x + interp.y * p1.x + interp.z * p2.x;
            val.y = interp.x * p0.y + interp.y * p1.y + interp.z * p2.y;
            val.z = interp.x * p0.z + interp.y * p1.z + interp.z * p2.z;
            return;
        }
    }

    // No value defined... set default.
    if (channel == MAP_SHADING)
        val.x = val.y = val.z = 0.0f;
    else
        val.x = val.y = val.z = 1.0f;
}
Ejemplo n.º 8
0
//????????????????????????????????????????????????????????????????????????
// The submat with a higher index "cover" the ones "below".
// If the first submat taken from the end of the array has amount == 100,
// that's al it matters. Otherwise all until the second consecutive submat
// with amount == 100 matter
//
bool CompositeMat::IsOutputConst
( 
	ShadeContext& sc, // describes context of evaluation
	int stdID				// must be ID_AM, ect
)
{
	Mtl *sm = NULL;
	int numSubMatOn = 0;
	int numConsec = 0;
	bool bIsConst = true;
	Interval iv;

	// Iterate through the submats in reverse order because that is
	// the order of their significance
	for (int i = MAX_NUM_MTLS-1; i >= 0; i--)
	{
		BOOL enabled;
		float amount;
		
		// The first one is always enabled
		if ( i == 0 ) 
			enabled = 1;
		else 
			pblock2->GetValue( compmat_map_on, sc.CurTime(), enabled, iv, i-1 );
		
		if ( enabled )
		{
			pblock2->GetValue( compmat_mtls, sc.CurTime(), sm, iv, i );
			if ( sm != NULL ) 
			{
				numSubMatOn++;

				// All of the first on is always composited
				if ( i == 0 ) 
					amount = 100.f;
				else 
					pblock2->GetValue( compmat_amount, sc.CurTime(), amount, iv, i-1 );
				
				if ( numSubMatOn == 1 && amount == 100.0f )
					return sm->IsOutputConst( sc, stdID );
				else
				{
					if ( amount == 100.0f )
						numConsec++;
					else
						numConsec = 0;
					bool b = sm->IsOutputConst( sc, stdID );
					bIsConst = (bIsConst && b );
					if ( !bIsConst )
						return bIsConst;
					else if ( numConsec == 2 )
						return bIsConst;
				}
			}
		}
	}
	return bIsConst;
}
Ejemplo n.º 9
0
void Matte::PostShade(ShadeContext& sc, IReshadeFragment* pFrag, int& nextTexIndex, IllumParams*)
{
   Color c,t;
   float atten;

   if (!opaque)
      sc.Execute(0x1000); // DS: 6/24/99:use black bg when AA filtering (#192348)

   sc.GetBGColor(c,t,fogBG && !fogObjDepth);
   if (!opaque)
      sc.Execute(0x1001); // DS: 6/24/99:use black bg when AA filtering (#192348)

   if (shadowBG && sc.shadow)
   {
//    sc.shadow = 0;
//    Color col0 = sc.DiffuseIllum();
//    sc.shadow = 1;
//    Color scol = sc.DiffuseIllum();
//    float f = Intens(col0);
//    atten = (f>0.0f)?Intens(scol)/f:1.0f;
//    if (atten>1.0f) atten = 1.0f/atten;
//    atten = amblev+(1.0f-amblev)*atten;
//    sc.out.c = c*atten + (1.0f-atten)*col;
      Color shadowClr;
      atten = IllumShadow( sc, shadowClr );
      atten = amblev + (1.0f-amblev) * atten;

      // key on black user-set shadow clr
      if( gUseLocalShadowClr || col.r != 0.0f || col.g != 0.0f || col.b != 0.0f )
            shadowClr = col;

      c *= atten;
      shadowClr *= 1.0f - atten;

      sc.out.c = c + shadowClr;

      if (shadowAlpha)
         t *= atten;
   } else
      sc.out.c  = c;

   sc.out.t = opaque ? black : t;  
   Clamp(sc.out.t);

   // code for compositing: -1 for opaque , else -2
   sc.out.ior = (opaque) ? -1.0f : -2.0f;
   if( reflmap ){
      if( useReflMap ){
         Color rc = pFrag->GetColorChannel( nextTexIndex++ );
         sc.out.c += rc * reflAmt;
      } else {
         nextTexIndex++;   // skip
      }
   }
}
Ejemplo n.º 10
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;	
}
Ejemplo n.º 11
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;
	}
Ejemplo n.º 12
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;
	}
Ejemplo n.º 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;
}
Ejemplo n.º 14
0
void Matte::PreShade(ShadeContext& sc, IReshadeFragment* pFrag)
{
   // save reflection texture
   if ( reflmap ){
      AColor rcol;
      if (reflmap->HandleOwnViewPerturb()) {
         sc.TossCache(reflmap);
         rcol = reflmap->EvalColor(sc);
      } else 
         rcol = sc.EvalEnvironMap(reflmap, sc.ReflectVector());
      pFrag->AddColorChannel( rcol );
   }
}
Ejemplo n.º 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);
	}
Ejemplo n.º 16
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;
}
Ejemplo n.º 17
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;
}
Ejemplo n.º 18
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;
}
Ejemplo n.º 19
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;
}
Ejemplo n.º 20
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);
}
Ejemplo n.º 21
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);
}
Ejemplo n.º 22
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);
	}
Ejemplo n.º 23
0
bool Plate::IsLocalOutputMeaningful( ShadeContext& sc ) 
{ 
	PlateMap *pmap = FindMap( sc.NodeID() );
	if ( pmap != NULL && sc.globContext == NULL )
			return false;
	return true; 
}
Ejemplo n.º 24
0
void CompositeMat::PreShade(ShadeContext& sc, IReshadeFragment* pFrag)
{
	int i(0);
	Mtl *submtl = NULL;
//	BOOL enabled(FALSE);

	char texLengths[12];

	int lengthChan = pFrag->NTextures();
	pFrag->AddIntChannel(0);
	pFrag->AddIntChannel(0);
	pFrag->AddIntChannel(0);

	int nPrevTex = 3 + lengthChan;

	// preshade any submaterials
	for (i=0; i<MAX_NUM_MTLS; i++)
	{
		pblock2->GetValue(compmat_mtls, sc.CurTime(), submtl, FOREVER, i);
		if (submtl){
			IReshading* pReshading = (IReshading*)(submtl->GetInterface(IID_IReshading));
			if( pReshading ){
				pReshading->PreShade(sc, pFrag);
				int nTex = pFrag->NTextures();
				texLengths[i] = char( nTex - nPrevTex);
				nPrevTex = nTex;
			}
		}
	}
	int* pI = (int*)&texLengths[0];
	pFrag->SetIntChannel( lengthChan++, pI[0] );
	pFrag->SetIntChannel( lengthChan++, pI[1] );
	pFrag->SetIntChannel( lengthChan, pI[2] );

}
Ejemplo n.º 25
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;	
}
Ejemplo n.º 26
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);
}
Ejemplo n.º 27
0
void plPassMtl::Shade(ShadeContext& sc) 
{
    // Get the background color
    Color backColor, backTrans;
    sc.GetBGColor(backColor, backTrans);

    ShadeWithBackground(sc, backColor);
}
Ejemplo n.º 28
0
BOOL DefObjLight::Illuminate(ShadeContext& sc, Point3& normal, Color& color, Point3 &dir, float &dot_nl, float &diffCoef)
{
	dir = Normalize(lightPos-sc.P());
	diffCoef = dot_nl = DotProd(normal, dir);
	color = intensCol;

	return (dot_nl <= 0.0f) ? 0 : 1;
}
Ejemplo n.º 29
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;
	}
Ejemplo n.º 30
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);
    }