Exemple #1
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
      }
   }
}
Exemple #2
0
// if this function changes, please also check SupportsReShading, PreShade and PostShade
// end - ke/mjm - 03.16.00 - merge reshading code
// [attilas|29.5.2000] if this function changes, please also check EvalColorStdChannel
void Matte::Shade(ShadeContext& sc)
{
   Color c,t, shadowClr;
   float atten;
   float reflA;

   // > 6/15/02 - 11:12am --MQM-- 
   // for renderer prepass, we need to at least call
   // illuminate so that Light Tracer can cache shading
   if ( SHADECONTEXT_IS_PREPASS( sc ) )
   {
      Color    lightCol;
      Point3   L;
      float    NL = 0.0f, diffCoef = 0.0f;
      LightDesc *l = NULL;
      for ( int i = 0;  i < sc.nLights;  i++ )
      {
         l = sc.Light( i );
         if ( NULL != l )
            l->Illuminate( sc, sc.Normal(), lightCol, L, NL, diffCoef );
      }
      return;
   }

#ifdef _DEBUG
   IPoint2 sp = sc.ScreenCoord();
   if ( sp.x == stopX && sp.y == stopY )
      sp.x = stopX;
#endif

   if (gbufID) sc.SetGBufferID(gbufID);
   IllumParams ip( 1, &shadowIllumOutStr);
   IllumParams ipNS(0, NULL);
   ip.ClearInputs(); ip.ClearOutputs();
   ipNS.ClearInputs(); ipNS.ClearOutputs();
   ip.hasComponents = ipNS.hasComponents = HAS_MATTE_MTL; 
   
   // get background color & transparency
   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 = 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;

      ipNS.finalC = ipNS.diffIllumOut = c;
      c *= atten;
      ip.diffIllumOut = c;

      shadowClr *= 1.0f - atten;
      ip.finalC = sc.out.c = c + shadowClr;

      ip.SetUserIllumOutput( 0, shadowClr );

      if (shadowAlpha)
         t *= atten;
   } else {
      sc.out.c  = 
      ipNS.finalC = ipNS.diffIllumOut = ip.finalC = ip.diffIllumOut = c;
   }


   // add the reflections
   if (reflmap && useReflMap) {
      AColor rcol;
      if (reflmap->HandleOwnViewPerturb()) {
         sc.TossCache(reflmap);
         rcol = reflmap->EvalColor(sc);
      } else 
         rcol = sc.EvalEnvironMap(reflmap, sc.ReflectVector());

      Color rc;
      rc = Color(rcol.r,rcol.g,rcol.b)*reflAmt;
      ip.reflIllumOut = ipNS.reflIllumOut = rc;

      if( additiveReflection ) {
         // additive compositing of reflections
         sc.out.c += rc; ip.finalC += rc; ipNS.finalC += rc;
      } else {
         reflA = Intens( rc );
         // over compositing of reflections 
         sc.out.c = (1.0f - reflA) * sc.out.c + rc; 
         ip.finalC = (1.0f - reflA) * ip.finalC + rc;
         ipNS.finalC = (1.0f - reflA) * ipNS.finalC + rc;
      }
   }

   // render elements
   Clamp( t );
   Clamp( reflA );
   ip.finalT = ipNS.finalT = sc.out.t = opaque ? black: additiveReflection? t : Color(reflA,reflA,reflA) ; 
   int nEles = sc.NRenderElements();
   if( nEles != 0 ){
      ip.pShader = ipNS.pShader = NULL; // no shader on matte mtl
      ip.stdIDToChannel = ipNS.stdIDToChannel = NULL;
      ip.pMtl = ipNS.pMtl = this;
      ip.finalAttenuation = ipNS.finalAttenuation = 1.0f;

      for( int i=0; i < nEles; ++i ){
         IRenderElement* pEle = sc.GetRenderElement(i);
         if( pEle->IsEnabled() ){
            MaxRenderElement* pMaxEle = (MaxRenderElement*)pEle->GetInterface( MaxRenderElement::IID );
            if( pEle->ShadowsApplied() )
               pMaxEle->PostIllum( sc, ip );
            else
               pMaxEle->PostIllum( sc, ipNS );
         }
      }
   }

}