Ejemplo n.º 1
0
void AtlasClipMapBatcher::renderDetail( SceneGraphData& sgData )
{
   PROFILE_SCOPE(AtlasClipMapBatcher_renderDetail);

   if( !mDetailMat )
      return;

   if( mFixedFunction )
   {
      MatrixF detailTexMatrix( true );
      detailTexMatrix.scale( Point3F( mDetailMapTextureMultiply, 
                                      mDetailMapTextureMultiply, 0.0f ) );

      GFX->setTextureMatrix( 0, detailTexMatrix );
   }
   else
   {
      Point3F detailConst(
         mDetailMapFadeStartDistance,
         1.f / (mDetailMapFadeEndDistance - mDetailMapFadeStartDistance), 
         mDetailMapTextureMultiply);
      F32 brightnessScale = 1.0;

      MaterialParameters* params = mDetailMat->getMaterialParameters();
      params->set( mDetDataSC, detailConst );
      params->set( mBrightnessScaleSC, brightnessScale );
   }

   GFX->setTexture( 0, mObject->mDetailTex );

   // And render all the detailed chunks - all for now.
   for(S32 i=0; i<mDetailList.size(); i++)
   {
      // Grab the render note.
      const RenderNote *rn = mDetailList[i];

      // And draw it.
      while( mDetailMat->setupPass( mState, sgData ) )
         rn->chunk->render();
   }
}
Ejemplo n.º 2
0
void WaterPlane::setShaderParams( SceneRenderState *state, BaseMatInstance* mat, const WaterMatParams& paramHandles)
{
   // Set variables that will be assigned to shader consts within WaterCommon
   // before calling Parent::setShaderParams

   mUndulateMaxDist = mGridElementSize * mGridSizeMinusOne * 0.5f;

   Parent::setShaderParams( state, mat, paramHandles );   

   // Now set the rest of the shader consts that are either unique to this
   // class or that WaterObject leaves to us to handle...    

   MaterialParameters* matParams = mat->getMaterialParameters();

   // set vertex shader constants
   //-----------------------------------   
   matParams->setSafe(paramHandles.mGridElementSizeSC, (F32)mGridElementSize);
   //matParams->setSafe( paramHandles.mReflectTexSizeSC, mReflectTexSize );
   if ( paramHandles.mModelMatSC->isValid() )
      matParams->set(paramHandles.mModelMatSC, getRenderTransform(), GFXSCT_Float4x4);

   // set pixel shader constants
   //-----------------------------------

   ColorF c( mWaterFogData.color );
   matParams->setSafe( paramHandles.mBaseColorSC, c );   
   
   // By default we need to show a true reflection is fullReflect is enabled and
   // we are above water.
   F32 reflect = mPlaneReflector.isEnabled() && !isUnderwater( state->getCameraPosition() );
   
   // If we were occluded the last frame a query was fetched ( not necessarily last frame )
   // and we weren't updated last frame... we don't have a valid texture to show
   // so use the cubemap / fake reflection color this frame.
   if ( mPlaneReflector.lastUpdateMs != REFLECTMGR->getLastUpdateMs() && mPlaneReflector.isOccluded() )
      reflect = false;

   //Point4F reflectParams( getRenderPosition().z, mReflectMinDist, mReflectMaxDist, reflect );
   Point4F reflectParams( getRenderPosition().z, 0.0f, 1000.0f, !reflect );
   
   // TODO: This is a hack... why is this broken... check after
   // we merge advanced lighting with trunk!
   //
   reflectParams.z = 0.0f;
   matParams->setSafe( paramHandles.mReflectParamsSC, reflectParams );

   VectorF reflectNorm( 0, 0, 1 );
   matParams->setSafe(paramHandles.mReflectNormalSC, reflectNorm ); 
}
void AdvancedLightBinManager::LightMaterialInfo::setViewParameters(  const F32 _zNear, 
                                                                     const F32 _zFar, 
                                                                     const Point3F &_eyePos, 
                                                                     const PlaneF &_farPlane,
                                                                     const PlaneF &_vsFarPlane)
{
   MaterialParameters *matParams = matInstance->getMaterialParameters();

   matParams->setSafe( farPlane, *((const Point4F *)&_farPlane) );

   matParams->setSafe( vsFarPlane, *((const Point4F *)&_vsFarPlane) );

   if ( negFarPlaneDotEye->isValid() )
   {
      // -dot( farPlane, eyePos )
      const F32 negFarPlaneDotEyeVal = -( mDot( *((const Point3F *)&_farPlane), _eyePos ) + _farPlane.d );
      matParams->set( negFarPlaneDotEye, negFarPlaneDotEyeVal );
   }

   matParams->setSafe( zNearFarInvNearFar, Point4F( _zNear, _zFar, 1.0f / _zNear, 1.0f / _zFar ) );
}
Ejemplo n.º 4
0
BaseMatInstance* ClipMap::getMaterialAndTextures( U32 level1, U32 level2, U32 level3/*=-1*/, U32 level4/*=-1*/, bool doTerrainRenderHack )
{
   // Figure out how many layers we have.
   U32 levelCount = 2;
   if(level3 != -1) levelCount++;
   if(level4 != -1) levelCount++;

   GRAPHIC->clearSamplerOverrides();   

   mMapInfoConst.setSize(levelCount);
   // Set up constants, bind textures.
   for(S32 i=0; i<levelCount; i++)
   {
      U32 curLevel = -1;
      switch(i)
      {
      case 0: curLevel = level1; break;
      case 1: curLevel = level2; break;
      case 2: curLevel = level3; break;
      case 3: curLevel = level4; break;
      }

      AssertFatal(curLevel != -1, "ClipMap::bindShaderAndTextures - tried to draw an unspecified layer!");
      AssertFatal(curLevel < mLevels.size(), "ClipMap::bindShaderAndTextures - out of range level specified!");

      // Grab references to relevant data.
      Point4F &pt = mMapInfoConst[i];
      ClipMap::ClipStackEntry &cse = mLevels[curLevel];

      // Bind debug or real textures, depending on flag.
      if(smDebugTextures)
         GRAPHIC->setTexture(i, cse.mDebugTex);
      else
         GRAPHIC->setTexture(i, cse.mTex);

      // Note the offset and center for this level as well.
      pt.x = cse.mClipCenter.x * cse.mScale;
      pt.y = cse.mClipCenter.y * cse.mScale;
      pt.z = cse.mScale;
      pt.w = 0.f;

      if (doTerrainRenderHack && TerrainRender::mCurrentBlock && !TerrainRender::mCurrentBlock->isTiling())
      {
         // At scale 1.0 we can clamp the UV edges avoiding edge bleed between terrain blocks
         if (cse.mScale == 1.0f)
         {            
            GRAPHIC->setSamplerAddressModeOverride(i, true, GAddressClamp);
         }

         // Ideally, we want to clamp at scale 2.0 as well.
         // however, we can't clamp as the shader is scaling the UV coords
         // edge bleed is caused by mipmaps wrapping, so let's bias the mipmap selection
         // out a little bit, this is only necessary for level 2 of the clip map
         if (cse.mScale == 2.0f)
         {
            
            GRAPHIC->setSamplerMipLODBiasOverride(i, true, -1.0f);
         }
         else
         {
            GRAPHIC->setSamplerMipLODBiasOverride(i, true, 0.0f);
         }
      }

   }

   S32 idx = levelCount - 1;
   BaseMatInstance* ret = mClipmapMat[idx];
   MaterialParameters* params = ret->getMaterialParameters();
   
   // We do not use the morph target in the shader, but
   // we also cannot assume it will be cleared for us.     
   params->set(mMorphTSC[idx], 0.0f);   

   // Set all the constants in one go.   
   params->set(mMapInfoTC[idx], mMapInfoConst);
   
   params->set(mDiffuseMap0TC[idx], (S32)0);
   params->set(mDiffuseMap1TC[idx], (S32)1);
   params->set(mDiffuseMap2TC[idx], (S32)2);
   params->set(mDiffuseMap3TC[idx], (S32)3);

   
   GRAPHIC->updateStates(true);
   
   // Ok - all bound!
   return ret;
}