Ejemplo n.º 1
0
	inline Float pdfDirection(const DirectionSamplingRecord &dRec,
			const PositionSamplingRecord &pRec) const {
		if (dRec.measure != ESolidAngle)
			return 0.0f;

		Transform invTrafo = m_worldTransform->eval(pRec.time).inverse();
		return importance(invTrafo.transformAffine(pRec.p), invTrafo(dRec.d));
	}
Ejemplo n.º 2
0
	Spectrum eval(const Intersection &its, const Vector &d, Point2 &samplePos) const {
		Transform invTrafo = m_worldTransform->eval(its.time).inverse();
		Point localP = invTrafo.transformAffine(its.p);
		Vector localD = invTrafo(d);

		Float result = importance(localP, localD, &samplePos);

		if (result == 0)
			return Spectrum(0.0f);

		return Spectrum(result * m_aperturePdf / Frame::cosTheta(localD));
	}
Ejemplo n.º 3
0
  HDRILight::HDRILight(const Parms& parms)
    : width(0), height(0), pixels(null)
  {
    local2world = parms.getTransform("local2world",one);
    world2local = rcp(local2world);
    L = parms.getColor("L",one);
    pixels = parms.getImage("image");
    if (pixels == null) pixels = new Image3f(5,5,one);
    width  = (unsigned) pixels->width;
    height = (unsigned) pixels->height;

    Array2D<float> importance(height,width);
    for (size_t y = 0; y < height; y++)
      for (size_t x = 0; x < width; x++)
        importance.set(y, x, sinf(float(pi)*(y+0.5f)*rcp(float(height))) * reduce_add(pixels->get(x,y)));

    distribution = new Distribution2D(importance,width,height);
  }
Ejemplo n.º 4
0
	Spectrum sampleDirect(DirectSamplingRecord &dRec, const Point2 &sample) const {
		const Transform &trafo = m_worldTransform->eval(dRec.time);

		/* Transform the reference point into the local coordinate system */
		Point refP = trafo.inverse().transformAffine(dRec.ref);

		/* Check if it is outside of the clip range */
		if (refP.z < m_nearClip || refP.z > m_farClip) {
			dRec.pdf = 0.0f;
			return Spectrum(0.0f);
		}

		/* Sample a position on the aperture (in local coordinates) */
		Point2 tmp = warp::squareToUniformDiskConcentric(sample)
			* m_apertureRadius;
		Point apertureP(tmp.x, tmp.y, 0);

		/* Compute the normalized direction vector from the
		   aperture position to the reference point */
		Vector localD(refP - apertureP);
		Float dist = localD.length(),
			  invDist = 1.0f / dist;
		localD *= invDist;

		Float value = importance(apertureP, localD, &dRec.uv);
		if (value == 0.0f) {
			dRec.pdf = 0.0f;
			return Spectrum(0.0f);
		}

		dRec.p = trafo.transformAffine(apertureP);
		dRec.d = (dRec.p - dRec.ref) * invDist;
		dRec.dist = dist;
		dRec.n = trafo(Vector(0.0f, 0.0f, 1.0f));
		dRec.pdf = m_aperturePdf * dist*dist/(Frame::cosTheta(localD));
		dRec.measure = ESolidAngle;

		/* intentionally missing a cosine factor wrt. the aperture
		   disk (it is already accounted for in importance()) */
		return Spectrum(value * invDist * invDist);
	}
Ejemplo n.º 5
0
int IA(int player,int depth,int lx,int ly,int w1x,int w1y,int w2x,int w2y,int w3x,int w3y,int w4x,int w4y,int w5x,int w5y)
{
	int count = 0,k;
	t_association pawn[6]={{NULL,{lx,ly}},{NULL,{w1x,w1y}},{NULL,{w2x,w2y}},{NULL,{w3x,w3y}},{NULL,{w4x,w4y}},{NULL,{w5x,w5y}}};
	//printf("mouton %d:%d , loups : %d:%d %d:%d %d:%d %d:%d %d:%d\n",lx,ly,w1x,w1y,w2x,w2y,w3x,w3y,w4x,w4y,w5x,w5y);
	if(game_is_over(pawn))
	{
		if(lamb_won(pawn))
		{
			return importance(depth);
		}
		else
		{
			return (-1 * importance(depth));
		}
	}
	if(depth == 0) return 0;
	if(player == LAMB)
	{
		if(possible_and_free(lx+1,ly+1,pawn) && isnt_too_far(lx+1,ly+1,pawn))
			count += IA(WOLF,depth - 1,lx+1,ly+1,w1x,w1y,w2x,w2y,w3x,w3y,w4x,w4y,w5x,w5y);
		if(possible_and_free(lx+1,ly-1,pawn) && isnt_too_far(lx+1,ly-1,pawn))
			count += IA(WOLF,depth - 1,lx+1,ly-1,w1x,w1y,w2x,w2y,w3x,w3y,w4x,w4y,w5x,w5y);
		if(possible_and_free(lx-1,ly+1,pawn) && isnt_too_far(lx-1,ly+1,pawn))
			count += IA(WOLF,depth - 1,lx-1,ly+1,w1x,w1y,w2x,w2y,w3x,w3y,w4x,w4y,w5x,w5y);
		if(possible_and_free(lx-1,ly-1,pawn) && isnt_too_far(lx-1,ly-1,pawn))
			count += IA(WOLF,depth - 1,lx-1,ly-1,w1x,w1y,w2x,w2y,w3x,w3y,w4x,w4y,w5x,w5y);
	}
	else
	{
		for(k=1;k<6;k++)
		{
			if(possible_and_free(pawn[k].position.x+1,pawn[k].position.y-1,pawn))
			{
				switch(k)
				{
					case 1: count += IA(LAMB,depth - 1,lx,ly,w1x+1,w1y-1,w2x,w2y,w3x,w3y,w4x,w4y,w5x,w5y);
							break;
					case 2: count += IA(LAMB,depth - 1,lx,ly,w1x,w1y,w2x+1,w2y-1,w3x,w3y,w4x,w4y,w5x,w5y);
							break;
					case 3: count += IA(LAMB,depth - 1,lx,ly,w1x,w1y,w2x,w2y,w3x+1,w3y-1,w4x,w4y,w5x,w5y);
							break;
					case 4: count += IA(LAMB,depth - 1,lx,ly,w1x,w1y,w2x,w2y,w3x,w3y,w4x+1,w4y-1,w5x,w5y);
							break;
					case 5: count += IA(LAMB,depth - 1,lx,ly,w1x,w1y,w2x,w2y,w3x,w3y,w4x,w4y,w5x+1,w5y-1);
							break;
				}
			}
			if(possible_and_free(pawn[k].position.x-1,pawn[k].position.y-1,pawn))
			{
				switch(k)
				{
					case 1: count += IA(LAMB,depth - 1,lx,ly,w1x-1,w1y-1,w2x,w2y,w3x,w3y,w4x,w4y,w5x,w5y);
							break;
					case 2: count += IA(LAMB,depth - 1,lx,ly,w1x,w1y,w2x-1,w2y-1,w3x,w3y,w4x,w4y,w5x,w5y);
							break;
					case 3: count += IA(LAMB,depth - 1,lx,ly,w1x,w1y,w2x,w2y,w3x-1,w3y-1,w4x,w4y,w5x,w5y);
							break;
					case 4: count += IA(LAMB,depth - 1,lx,ly,w1x,w1y,w2x,w2y,w3x,w3y,w4x-1,w4y-1,w5x,w5y);
							break;
					case 5: count += IA(LAMB,depth - 1,lx,ly,w1x,w1y,w2x,w2y,w3x,w3y,w4x,w4y,w5x-1,w5y-1);
							break;
				}
			}
		}
	}
	return count;
}