Example #1
0
void ClipMapBlenderCache::setInterestCenter( const Point2I &origin )
{
   AssertFatal(mClipMapSize != -1, "ClipMapBlenderCache::setInterestCenter - no one set mClipMapSize!");
   
   if (mOpacitySources.size() == 0)
   {
      Con::errorf("ClipMapBlenderCache::setInterestCenter() - tried to set the interest center without any opacity sources");
      return;
   }

   // For each source, scale origin, which is in texels at the
   // most detailed clipmap level, to be in texels at the most detailed
   // level of each source.
   for (U32 i = 0; i < mOpacitySources.size(); i++)
   {
      Point2I opacityOrigin = origin;
      if( mOpacitySources[i]->getMipLevelCount() != ( getBinLog2( mOwningClipMap->mTextureSize ) + 1 ) )
      {
         S32 scaleDelta = mOpacitySources[i]->getMipLevelCount() - 1 - getBinLog2(mOwningClipMap->mTextureSize);
         if(scaleDelta > 0)
         {
            opacityOrigin.x <<= scaleDelta;
            opacityOrigin.y <<= scaleDelta;
         }
         else
         {
            opacityOrigin.x >>= -scaleDelta;
            opacityOrigin.y >>= -scaleDelta;
         }
      }

      mOpacitySources[i]->setInterestCenter(opacityOrigin, mClipMapSize * 2);
   }
bool AtlasClipMapImageSource::isDataAvailable( const U32 mipLevel, const RectI& inRegion ) const
{
   // We need to convert from a mip level to a level in our TOC, potentially scaling.
   U32 baseMips = getBinLog2(mTOC->getTextureChunkSize());
   U32 tocLevel = -1;
   if(mipLevel >= baseMips)
   {
      // In an inner or leaf tile.
      tocLevel = mipLevel - baseMips;
   }
   else
   {
      // It's in our base tile.
      tocLevel = 0;
   }
   
   // We don't scale beyond the depth of the TOC, so simply assert in that
   // case.
   AssertFatal(tocLevel < mTOC->getTreeDepth(), "AtlasClipMapImageSource::isDataAvailable - went beyond depth of tree.");

   // Check all the chunks of all the stubs in the appropriate region...
   RectI r;
   convertToTOCRect(tocLevel, inRegion, r);

   const S32 xStart = mClamp(r.point.x,               0, BIT(tocLevel));
   const S32 xEnd   = mClamp(r.point.x + r.extent.x,  0, BIT(tocLevel));

   const S32 yStart = mClamp(r.point.y,               0, BIT(tocLevel));
   const S32 yEnd   = mClamp(r.point.y + r.extent.y,  0, BIT(tocLevel));

   for(S32 x=xStart; x<xEnd; x++)
   {
      for(S32 y=yStart; y<yEnd; y++)
      {
         AtlasResourceTexStub *arts = mTOC->getResourceStub(mTOC->getStub(tocLevel, Point2I(x,y)));

         if(!arts->hasResource())
            return false;
      }
   }

   return true;
}
Example #3
0
void AbstractClassRep::initialize()
{
   AssertFatal(!initialized, "Duplicate call to AbstractClassRep::initialize()!");
   Vector<AbstractClassRep *> dynamicTable(__FILE__, __LINE__);

   AbstractClassRep *walk;

   // Initialize namespace references...
   for (walk = classLinkList; walk; walk = walk->nextClass)
   {
      walk->mNamespace = Con::lookupNamespace(StringTable->insert(walk->getClassName()));
      walk->mNamespace->mUsage = walk->getDocString();
      walk->mNamespace->mClassRep = walk;
   }

   // Initialize field lists... (and perform other console registration).
   for (walk = classLinkList; walk; walk = walk->nextClass)
   {
      // sg_tempFieldList is used as a staging area for field lists
      // (see addField, addGroup, etc.)
      sg_tempFieldList.setSize(0);

      walk->init();

      // So if we have things in it, copy it over...
      if (sg_tempFieldList.size() != 0)
         walk->mFieldList = sg_tempFieldList;

      // And of course delete it every round.
      sg_tempFieldList.clear();
   }

   // Calculate counts and bit sizes for the various NetClasses.
   for (U32 group = 0; group < NetClassGroupsCount; group++)
   {
      U32 groupMask = 1 << group;

      // Specifically, for each NetClass of each NetGroup...
      for(U32 type = 0; type < NetClassTypesCount; type++)
      {
         // Go through all the classes and find matches...
         for (walk = classLinkList; walk; walk = walk->nextClass)
         {
            if(walk->mClassType == type && walk->mClassGroupMask & groupMask)
               dynamicTable.push_back(walk);
         }

         // Set the count for this NetGroup and NetClass
         NetClassCount[group][type] = dynamicTable.size();
         if(!NetClassCount[group][type])
            continue; // If no classes matched, skip to next.

         // Sort by type and then by name.
         dQsort((void *) &dynamicTable[0], dynamicTable.size(), sizeof(AbstractClassRep *), ACRCompare);

         // Allocate storage in the classTable
         classTable[group][type] = new AbstractClassRep*[NetClassCount[group][type]];

         // Fill this in and assign class ids for this group.
         for(U32 i = 0; i < NetClassCount[group][type];i++)
         {
            classTable[group][type][i] = dynamicTable[i];
            dynamicTable[i]->mClassId[group] = i;
         }

         // And calculate the size of bitfields for this group and type.
         NetClassBitSize[group][type] =
               getBinLog2(getNextPow2(NetClassCount[group][type] + 1));
         AssertFatal(NetClassCount[group][type] < (1 << NetClassBitSize[group][type]), "NetClassBitSize too small!");

         dynamicTable.clear();
      }
   }

   // Ok, we're golden!
   initialized = true;
}
const U32 AtlasClipMapImageSource::getMipLevelCount() const
{
   // We need to return log2(total toc texture size).
   //[rene, 08/06/2008] Plus one! as this is the count, not the max index
   return getBinLog2(mTOC->getTextureChunkSize()) + mTOC->getTreeDepth();
}
Example #5
0
U32 ClipMap::getMipLevel( F32 scale )
{
	return getBinLog2( scale ) + getBinLog2( mClipMapSize );
}
Example #6
0
void ClipMap::initClipStack()
{
   PROFILE_START(ClipMap_initClipStack);

   // Clear out all the levels.
   while(mLevels.size())
   {
      mLevels.last().mDebugTex = NULL;
      mLevels.last().mTex = NULL;
      mLevels.pop_back();
   }

   // What texture profile are we going to be using?
   AssertFatal(mImageCache, "ClipMap::initClipStack - must have image cache by this point.");
   GTextureProfile *texProfile = mImageCache->isRenderToTargetCache() 
                                    ? &ClipMapTextureRTProfile : &ClipMapTextureProfile;

   // Figure out how many clipstack textures we'll have.
   mClipStackDepth = getBinLog2(mTextureSize) - getBinLog2(mClipMapSize) + 1;
   mLevels.setSize(mClipStackDepth);

   // Print a little report on our allocation.
   Con::printf("Allocating a %d px clipmap for a %dpx source texture.", mClipMapSize, mTextureSize);
   Con::printf("   - %d base clipstack entries, + 1 cap.", mClipStackDepth - 1);

   U32 baseTexSize = (mClipMapSize * mClipMapSize * 4);
   Con::printf("   - Using approximately %fMB of texture memory.", 
      (F32(baseTexSize * mClipStackDepth) * 1.33) / (1024.0*1024.0));

   // First do our base textures - they are not mipped.
   // We rely on auto-mipmapping, but if the device/card doesn't support it, we should just not ask for it.
   U32 numMips = GRAPHIC->getCardProfiler()->queryProfile("autoMipMapLevel", true) ? 0 : 1;
   for(S32 i=0; i<mClipStackDepth; i++)
   {
      mLevels[i].mScale = (F32)BIT(mClipStackDepth - (1 + i));
      mLevels[i].mTex.set(mClipMapSize, mClipMapSize, GFormatR8G8B8X8, texProfile, avar("%s() - mLevels[%d].mTex (line %d)", __FUNCTION__, i, __LINE__), numMips);
   }

   // Some stuff can get skipped once we're set up.
   if(mTexCallbackHandle != -1)
      return;

   // Don't forget to allocate our debug textures...

   for(S32 i=0; i<mClipStackDepth; i++)
      mLevels[i].initDebugTexture(i);

   GAtlasVert2* vert = NULL;

   if (GRAPHIC->getPixelShaderVersion() > 0)
   {   
      // Do shader lookup for 2,3,4 level shaders.
      for(S32 i=2; i<5; i++)
      {
         // Init materials
         const String matname = String::ToString("AtlasMaterial%d", i);
         const U32 arrayOffset = i-1;
         mClipmapMat[arrayOffset] = MaterialManager::get()->createMatInstance(matname, (GVertexFlags)getGVertFlags(vert));
         if (!mClipmapMat[arrayOffset])
         {
            Con::errorf("Could not find material: %s", matname.c_str());
            continue;
         }
         else
         {
            if (mMapInfoConst.getElementSize() == 0)
               mMapInfoConst.setCapacity(4, mClipmapMat[arrayOffset]->getMaterialParameters()->getAlignmentValue(GSCT_Float4));
         }
         BaseMatInstance* matParams = mClipmapMat[arrayOffset];
         mMorphTSC[arrayOffset] = matParams->getMaterialParameterHandle("$morphT");
         mMapInfoTC[arrayOffset] = matParams->getMaterialParameterHandle("$mapInfo");
         mDiffuseMap0TC[arrayOffset] = matParams->getMaterialParameterHandle("$diffuseMap0");
         mDiffuseMap1TC[arrayOffset] = matParams->getMaterialParameterHandle("$diffuseMap1");
         mDiffuseMap2TC[arrayOffset] = matParams->getMaterialParameterHandle("$diffuseMap2");
         mDiffuseMap3TC[arrayOffset] = matParams->getMaterialParameterHandle("$diffuseMap3");
      }
   } else {
      mClipmapMatBasePassFF = MaterialManager::get()->createMatInstance("AtlasMaterialFFBasePass", (GVertexFlags)getGVertFlags(vert));
      mClipmapMatAddPassFF = MaterialManager::get()->createMatInstance("AtlasMaterialFFAddPass", (GVertexFlags)getGVertFlags(vert));
   }
   
   // Grab a callback from the texture manager to deal with zombification.
   GRAPHIC->getTextureManager()->registerTexCallback(texCB, this, mTexCallbackHandle);

   // Ok, everything is ready to go.
   PROFILE_END();
}
      }

      return true;
   }
};

ConsoleFunction(atlasGenerateGeometryFromHeightfield, void, 6, 6, 
                "(atlasOutFile, inHeightfield, hfSize, gridSpacing, patchSize) - generate terrain geometry "
                "to atlasOutFile based on the heightfield.")
{
   const U32 hfSize = dAtoi(argv[3]);
   const F32 gridSpacing = dAtof(argv[4]);
   const U32 tileSize = dAtoi(argv[5]);

   // Caculate treeDepth...
   const S32 treeDepth = getBinLog2(hfSize/tileSize)+1;

   Con::errorf("***************************************************************");
   Con::errorf("");
   Con::errorf("BE AWARE - THIS FUNCTION IS STILL IN DEVELOPMENT AND WILL NOT GIVE USEFUL RESULTS.");
   Con::errorf("PLEASE USE THE atlasOldGenerateChunkFileFromRaw16 method AND importOldAtlasCHU");
   Con::errorf("TO GENERATE GEOMETRY FOR NOW.");
   Con::errorf("");
   Con::errorf("Now generating geometry...");
   Con::errorf("");
   Con::errorf("***************************************************************");

   Con::printf("atlasGenerateGeometryFromHeightfield - Preparing...");

   // Ok, we now have a live atlas file.
   AtlasFile af;
Example #8
0
//-----------------------------------------------------------------------------
// Verve
// Copyright (C) - Violent Tulip
//-----------------------------------------------------------------------------

#include "VPathNode.h"
#include "VPath.h"

#include "core/stream/bitStream.h"
#include "core/strings/stringUnit.h"
#include "sim/netConnection.h"

//-----------------------------------------------------------------------------

static U32 gOrientationTypeBits = getBinLog2( getNextPow2( VPathNode::k_OrientationTypeSize ) );

//-----------------------------------------------------------------------------

VPathNode::VPathNode( void ) :
        mPath( NULL ),
        mLocalPosition( Point3F( 0.f, 0.f, 0.f ) ),
        mLocalRotation( QuatF( 0.f, 0.f, 0.f, 1.f ) ),
        mWorldPosition( Point3F( 0.f, 0.f, 0.f ) ),
        mWorldRotation( QuatF( 0.f, 0.f, 0.f, 1.f ) ),
        mWeight( 10.f ),
        mLength( 0.f )
{
    // Init.
    mOrientationMode.Type   = k_OrientationFree;
    mOrientationMode.Point  = Point3F::Zero;
Example #9
0
void ProcessedShaderMaterial::_setShaderConstants(SceneRenderState * state, const SceneData &sgData, U32 pass)
{
   PROFILE_SCOPE( ProcessedShaderMaterial_SetShaderConstants );

   GFXShaderConstBuffer* shaderConsts = _getShaderConstBuffer(pass);
   ShaderConstHandles* handles = _getShaderConstHandles(pass);
   U32 stageNum = getStageFromPass(pass);

   // First we do all the constants which are not
   // controlled via the material... we have to
   // set these all the time as they could change.

   if ( handles->mFogDataSC->isValid() )
   {
      Point3F fogData;
      fogData.x = sgData.fogDensity;
      fogData.y = sgData.fogDensityOffset;
      fogData.z = sgData.fogHeightFalloff;     
      shaderConsts->set( handles->mFogDataSC, fogData );
   }

   shaderConsts->setSafe(handles->mFogColorSC, sgData.fogColor);

   if( handles->mOneOverFarplane->isValid() )
   {
      const F32 &invfp = 1.0f / state->getFarPlane();
      Point4F oneOverFP(invfp, invfp, invfp, invfp);
      shaderConsts->set( handles->mOneOverFarplane, oneOverFP );
   }

   shaderConsts->setSafe( handles->mAccumTimeSC, MATMGR->getTotalTime() );

   // If the shader constants have not been lost then
   // they contain the content from a previous render pass.
   //
   // In this case we can skip updating the material constants
   // which do not change frame to frame.
   //
   // NOTE: This assumes we're not animating material parameters
   // in a way that doesn't cause a shader reload... this isn't
   // being done now, but it could change in the future.
   // 
   if ( !shaderConsts->wasLost() )
      return;

   shaderConsts->setSafe(handles->mSpecularColorSC, mMaterial->mSpecular[stageNum]);   
   shaderConsts->setSafe(handles->mSpecularPowerSC, mMaterial->mSpecularPower[stageNum]);

   shaderConsts->setSafe(handles->mParallaxInfoSC, mMaterial->mParallaxScale[stageNum]);   
   shaderConsts->setSafe(handles->mMinnaertConstantSC, mMaterial->mMinnaertConstant[stageNum]);

   if ( handles->mSubSurfaceParamsSC->isValid() )
   {
      Point4F subSurfParams;
      dMemcpy( &subSurfParams, &mMaterial->mSubSurfaceColor[stageNum], sizeof(ColorF) );
      subSurfParams.w = mMaterial->mSubSurfaceRolloff[stageNum];
      shaderConsts->set(handles->mSubSurfaceParamsSC, subSurfParams);
   }

   if ( handles->mRTSizeSC->isValid() )
   {
      const Point2I &resolution = GFX->getActiveRenderTarget()->getSize();
      Point2F pixelShaderConstantData;

      pixelShaderConstantData.x = resolution.x;
      pixelShaderConstantData.y = resolution.y;

      shaderConsts->set( handles->mRTSizeSC, pixelShaderConstantData );
   }

   if ( handles->mOneOverRTSizeSC->isValid() )
   {
      const Point2I &resolution = GFX->getActiveRenderTarget()->getSize();
      Point2F oneOverTargetSize( 1.0f / (F32)resolution.x, 1.0f / (F32)resolution.y );

      shaderConsts->set( handles->mOneOverRTSizeSC, oneOverTargetSize );
   }

   // set detail scale
   shaderConsts->setSafe(handles->mDetailScaleSC, mMaterial->mDetailScale[stageNum]);
   shaderConsts->setSafe(handles->mDetailBumpStrength, mMaterial->mDetailNormalMapStrength[stageNum]);

   // MFT_ImposterVert
   if ( handles->mImposterUVs->isValid() )
   {
      U32 uvCount = getMin( mMaterial->mImposterUVs.size(), 64 ); // See imposter.hlsl   
      AlignedArray<Point4F> imposterUVs( uvCount, sizeof( Point4F ), (U8*)mMaterial->mImposterUVs.address(), false );
      shaderConsts->set( handles->mImposterUVs, imposterUVs );
   }
   shaderConsts->setSafe( handles->mImposterLimits, mMaterial->mImposterLimits );

   // Diffuse
   shaderConsts->setSafe(handles->mDiffuseColorSC, mMaterial->mDiffuse[stageNum]);

   shaderConsts->setSafe( handles->mAlphaTestValueSC, mClampF( (F32)mMaterial->mAlphaRef / 255.0f, 0.0f, 1.0f ) );      

   if(handles->mDiffuseAtlasParamsSC)
   {
      Point4F atlasParams(1.0f / mMaterial->mCellLayout[stageNum].x, // 1 / num_horizontal
         1.0f / mMaterial->mCellLayout[stageNum].y, // 1 / num_vertical
         mMaterial->mCellSize[stageNum],            // tile size in pixels
         getBinLog2(mMaterial->mCellSize[stageNum]) );    // pow of 2 of tile size in pixels 2^9 = 512, 2^10=1024 etc
      shaderConsts->setSafe(handles->mDiffuseAtlasParamsSC, atlasParams);
   }

   if(handles->mBumpAtlasParamsSC)
   {
      Point4F atlasParams(1.0f / mMaterial->mCellLayout[stageNum].x, // 1 / num_horizontal
         1.0f / mMaterial->mCellLayout[stageNum].y, // 1 / num_vertical
         mMaterial->mCellSize[stageNum],            // tile size in pixels
         getBinLog2(mMaterial->mCellSize[stageNum]) );    // pow of 2 of tile size in pixels 2^9 = 512, 2^10=1024 etc
      shaderConsts->setSafe(handles->mBumpAtlasParamsSC, atlasParams);
   }

   if(handles->mDiffuseAtlasTileSC)
   {
      // Sanity check the wrap flags
      //AssertWarn(mMaterial->mTextureAddressModeU == mMaterial->mTextureAddressModeV, "Addresing mode mismatch, texture atlasing will be confused");
      Point4F atlasTileParams( mMaterial->mCellIndex[stageNum].x, // Tile co-ordinate, ie: [0, 3]
         mMaterial->mCellIndex[stageNum].y, 
         0.0f, 0.0f ); // TODO: Wrap mode flags?
      shaderConsts->setSafe(handles->mDiffuseAtlasTileSC, atlasTileParams);
   }

   if(handles->mBumpAtlasTileSC)
   {
      // Sanity check the wrap flags
      //AssertWarn(mMaterial->mTextureAddressModeU == mMaterial->mTextureAddressModeV, "Addresing mode mismatch, texture atlasing will be confused");
      Point4F atlasTileParams( mMaterial->mCellIndex[stageNum].x, // Tile co-ordinate, ie: [0, 3]
         mMaterial->mCellIndex[stageNum].y, 
         0.0f, 0.0f ); // TODO: Wrap mode flags?
      shaderConsts->setSafe(handles->mBumpAtlasTileSC, atlasTileParams);
   }
}
Example #10
0
// Copyright (C) GarageGames.com, Inc.
//-----------------------------------------------------------------------------

#include "core/strings/stringFunctions.h"

#include "atlas/resource/atlasResourceTexTOC.h"


ConsoleFunction(atlasGenerateTextureTOCFromTiles, void, 5, 5, "(leafCount, tileMask, outFile, outFormat) - "
                "Generate a texture TOC from a set of tiles. leafCount is the size of the grid "
                "of tiles on a side. tileMask is the path for the tiles (no extension) with %d "
                "for x and y, ie, 'demo/alpha/Alpha1_x%dy%d'. outFile is the file to output a "
                "new .atlas file to.")
{
   U32 leafSize = dAtoi(argv[1]);
   U32 treeDepth = getBinLog2(leafSize) + 1;
   const char *tileMask = argv[2];
   const char *filePath = argv[3];
   U32 outFormat = dAtoi(argv[4]);

   if(!isPow2(leafSize))
   {
      Con::errorf("atlasGenerateTextureTOCFromTiles - leafSize is not a power of 2!");
      return;
   }

   Con::printf("atlasGenerateTextureTOCFromTiles - Initializing atlas file '%s'...", filePath );

   // Allocate a new AtlasFile.
   AtlasFile af;