Exemple #1
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 );
   }
}
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 );
         }
      }
   }

}
Exemple #3
0
//????????????????????????????????????????????????????????????????????????
// The stdID parameter doesn't really have a meaning in this case.
// 
bool Matte::EvalMonoStdChannel
( 
   ShadeContext& sc, // describes context of evaluation
   int stdID,           // must be ID_AM, ect
   float& outVal        // output var
)
{
   switch ( stdID )
   {
      case ID_BU: // Bump (value 8)
      case ID_RR: // Refraction (value 10)
      case ID_DP: // Displacement (value 11)
      case ID_SI: // Self-illumination (value 5)
      case ID_FI: // Filter color (value 7)
         return false;
         break;

      case ID_RL: // Reflection (value 9)
         if ( sc.doMaps &&
                reflmap && 
                useReflMap && 
                reflmap->IsOutputMeaningful(sc) ) 
         {
            if ( reflmap->HandleOwnViewPerturb() ) 
            {
               sc.TossCache(reflmap);
               outVal = reflmap->EvalMono(sc);
            }
            else 
            {
               AColor rcol;
               rcol = sc.EvalEnvironMap( reflmap, sc.ReflectVector() );
               Color rc;
               rc = Color(rcol.r,rcol.g,rcol.b)*reflAmt;
               outVal = Intens(rc);
            }
         }
         else
            return false;
      break;

      case ID_AM: // Ambient (value 0)
         outVal = Intens( GetAmbient() );
         break;
      
      case ID_DI: // Diffuse (value 1)
         outVal = Intens( GetDiffuse() );
         break;
      
      case ID_SP: // Specular (value 2)
         outVal = Intens( GetSpecular() );
         break;
      
      case ID_SH: // Shininess (value 3).  In R3 and later this is called Glossiness.
         outVal = GetShininess();
         break;

      case ID_SS: // Shininess strength (value 4).  In R3 and later this is called Specular Level.
         outVal = GetShinStr();
         break;

      case ID_OP: // Opacity (value 6)
         outVal = GetXParency();
         break;

      default:
         // Should never happen
         //DbgAssert( false );
         return false;
         break;
   }
   return true;
}