Exemple #1
0
void renderDofAmountTest()
{
    Options opts;
    opts.xRes = 320;
    opts.yRes = 240;
    opts.gridSize = 8;
    opts.clipNear = 0.1;
    opts.superSamp = Imath::V2i(10,10);
    opts.pixelFilter = makeGaussianFilter(Vec2(2.0,2.0));
    opts.fstop = 100;
    opts.focalLength = 20;
    opts.focalDistance = 3;

    Attributes attrs;
    attrs.shadingRate = 1;
    attrs.smoothShading = true;

    Mat4 camToScreen =
        perspectiveProjection(90, opts.clipNear, opts.clipFar) *
        screenWindow(-2.33333, 0.33333, -1, 1);

    // Output variables.
    VarList outVars;
    outVars.push_back(Stdvar::Cs);

    Renderer r(opts, camToScreen, outVars);

    Mat4 wToO = Mat4().setTranslation(Vec3(-0.5,-0.5,-1)) *
                Mat4().setAxisAngle(Vec3(0,0,1), deg2rad(45)) *
                Mat4().setTranslation(Vec3(-1.5, 0, 2));

    const float P[12] = {0, 0, 0,  1, 0, 0,  0, 1, 0,  1, 1, 0};
    {
        const float Cs[3] = {1, 0.7, 0.7};
        r.add(createPatch(P, Cs, wToO), attrs);
    }
    {
        const float Cs[3] = {0.7, 1, 0.7};
        r.add(createPatch(P, Cs, Mat4().setTranslation(Vec3(0,0,1))*wToO), attrs);
    }
    {
        const float Cs[3] = {0.7, 0.7, 1};
        r.add(createPatch(P, Cs, Mat4().setTranslation(Vec3(0,0,2))*wToO), attrs);
    }
    {
        const float Cs[3] = {1, 0.7, 0.7};
        r.add(createPatch(P, Cs, Mat4().setTranslation(Vec3(0,0,5))*wToO), attrs);
    }
    {
        const float Cs[3] = {0.7, 1, 0.7};
        r.add(createPatch(P, Cs, Mat4().setTranslation(Vec3(0,0,25))*wToO), attrs);
    }

    r.render();
}
void peanoclaw::tests::GhostLayerCompositorTest::testInterpolationFromCoarseToFinePatchLeftGhostLayer2D() {
  #if defined(Dim2)
  //Patch-array for lower-left vertex in fine patch
  peanoclaw::Patch patches[TWO_POWER_D];

  //Settings
  int coarseSubdivisionFactor = 2;
  int coarseGhostlayerWidth = 1;
  int fineSubdivisionFactor = 2;
  int fineGhostlayerWidth = 2;
  int unknownsPerSubcell = 1;

  //Setup coarse patch
  tarch::la::Vector<DIMENSIONS, double> coarsePosition;
  assignList(coarsePosition) = 2.0, 1.0;
  patches[1] = createPatch(
    unknownsPerSubcell,
    0,   //Aux fields per subcell
    0,   //Aux fields per subcell
    coarseSubdivisionFactor,
    coarseGhostlayerWidth,
    coarsePosition,
    3.0, //Coarse size
    0,   //Level
    0.0, //Time
    1.0, //Timestep size
    1.0, //Minimal neighbor time
    false   //Overlapped by coarse ghost layer
  );
  patches[3] = patches[1];

  //Setup fine patch
  tarch::la::Vector<DIMENSIONS, double> finePosition;
  assignList(finePosition) = 5.0, 2.0;
  patches[0] = createPatch(
    unknownsPerSubcell,
    0,   //Aux fields per subcell
    0,   //Aux fields per subcell
    fineSubdivisionFactor,
    fineGhostlayerWidth,
    finePosition,
    1.0, //Size
    1,   //Level
    0.0, //Time
    1.0/3.0, //Timestep size
    1.0  //Minimal neighbor time
  );

  //Fill coarse patch
  dfor(index, coarseSubdivisionFactor) {
    tarch::la::Vector<DIMENSIONS, int> subcellIndex;
    subcellIndex(0) = index(1);
    subcellIndex(1) = index(0);
    patches[1].getAccessor().setValueUNew(subcellIndex, 0, 1.0);
  }
Exemple #3
0
//---------------------------------------------------------------------------
const rpatch_t *R_CachePatchNum(int id) {
  const int locks = 1;

  if (!patches)
    I_Error("R_CachePatchNum: Patches not initialized");

#ifdef RANGECHECK
  if (id >= numlumps)
    I_Error("createPatch: %i >= numlumps", id);
#endif

  if (!patches[id].data)
    createPatch(id);

  /* cph - if wasn't locked but now is, tell z_zone to hold it */
  if (!patches[id].locks && locks) {
    Z_ChangeTag(patches[id].data,PU_STATIC);
#ifdef TIMEDIAG
    patches[id].locktic = gametic;
#endif
  }
  patches[id].locks += locks;

#ifdef SIMPLECHECKS
  if (!((patches[id].locks+1) & 0xf))
    lprintf(LO_DEBUG, "R_CachePatchNum: High lock on %8s (%d)\n", 
	    lumpinfo[id].name, patches[id].locks);
#endif

  return &patches[id];
}
//Generates a full patch of value noise. Parameters can be set in constructor.
vector<float> PerlinPatchGenerator::generatePatch(int x, int y)
{
    vector<float> tempPatch;
	vector<float> heightMapPatch;
	int frequency;
	int gradientPoints;
	float amplitude;
    
    //Initiate a start
	heightMapPatch.assign(gridSize*gridSize,0);

    //Position based seed
    int n=x+y*57;
    n=(n<<13)^n;
    int seed=(n*(n*n*60493+19990303)+1376312589)&0x7fffffff;
    srand(seed);

    //Creates a height map for each frequency, and adds them together 
	for(int n = 0; n <= NoF; n = n+1){
        //Each frequency should be a multiple of the previous one  
		frequency = pow(2,n);
		gradientPoints = frequency + 1;
        //Amplitude decreases as frequency increases. Higher frequencies should have smaller inpact on the heightmap  
    	amplitude = 1.0/(float)frequency;

        // Biotope = 2 gives the patch desert like shape
        if(biotope == 2){
            amplitude *= amplitude;
        }
        amplitude *= amplitudeScale;
        
        //Calculate patch for that frequency
		tempPatch = createPatch(frequency,gradientPoints, amplitude);
        //Add the temporary patch together with previous patches
		heightMapPatch = addMatrices(heightMapPatch, tempPatch);
      
	}
	return heightMapPatch;
}
vector<float> PerlinPatchGenerator::generatePatch(int x, int y, int size)
{
    cout << "generatePatch begin\n";
	vector<float> tempPatch;
	vector<float> heightMapPatch;
	int frequency;
	int gradientPoints;
	float amplitude;
    
	heightMapPatch.assign(size*size,0);

	for(int n = 0; n <= 7; n = n+1){ //max value on n: 2^n <= size
		frequency = pow(2,n);
		gradientPoints = frequency + 1;
    	amplitude = 1.0/(float)frequency;

		tempPatch = createPatch(size,frequency,gradientPoints, amplitude);
		heightMapPatch = addMatrices(heightMapPatch, tempPatch, size);
      
	}
      //printMatrix(heightMapPatch,size);
    cout << "generatePatch end\n";
	return heightMapPatch;
}
void peanoclaw::tests::GhostLayerCompositorTest::testTimesteppingVeto2D() {
  #if defined(Dim2)

  for(int vetoIndex = 0; vetoIndex < TWO_POWER_D; vetoIndex++) {

    logDebug("testTimesteppingVeto2D", "testing vetoIndex=" << vetoIndex);

    peanoclaw::Patch patches[TWO_POWER_D];

    for(int i = 0; i < TWO_POWER_D; i++) {
      patches[i] = createPatch(
        3,       //Unknowns per subcell
        0,       //Aux fields per subcell
        0,       //Aux fields per subcell
        16,      //Subdivision factor
        2,       //Ghostlayer width
        0.0,     //Position
        1.0/3.0, //Size
        0,       //Level
        0.0,     //Current time
        1.0,     //Timestep size
        1.0      //Minimal neighbor time
      );
    }
    patches[vetoIndex] =
        createPatch(
            3,       //Unknowns per subcell
            0,       //Aux fields per subcell
            0,       //Aux fields per subcell
            16,      //Subdivision factor
            2,       //Ghostlayer width
            0.0,     //Position
            1.0/3.0, //Size
            0,       //Level
            0.5,     //Current time
            1.0,     //Timestep size
            1.0      //Minimal neighbor time
           );

    for(int i = 0; i < TWO_POWER_D; i++) {
      patches[i].getTimeIntervals().resetMinimalNeighborTimeConstraint();
      validate(patches[i].isValid());
    }

    peanoclaw::tests::NumericsTestStump numerics;
    peanoclaw::interSubgridCommunication::GhostLayerCompositor ghostLayerCompositor
      = peanoclaw::interSubgridCommunication::GhostLayerCompositor(
          patches,
          0,
          numerics,
          false
          );
    ghostLayerCompositor.fillGhostLayersAndUpdateNeighborTimes(-1);

    for(int cellIndex = 0; cellIndex < 4; cellIndex++) {
      if(cellIndex == vetoIndex) {
        validateNumericalEqualsWithParams2(patches[cellIndex].getTimeIntervals().getMinimalNeighborTimeConstraint(), 1.0, vetoIndex, cellIndex);
        validateNumericalEqualsWithParams2(!patches[cellIndex].getTimeIntervals().isBlockedByNeighbors(), false, vetoIndex, cellIndex);
      } else {
        validateNumericalEqualsWithParams2(patches[cellIndex].getTimeIntervals().getMinimalNeighborTimeConstraint(), 1.0, vetoIndex, cellIndex);
        validateNumericalEqualsWithParams2(!patches[cellIndex].getTimeIntervals().isBlockedByNeighbors(), true, vetoIndex, cellIndex);
      }
    }
  }
  #endif
}