Example #1
0
	bool bExecute( const shaderreg *i_pInput, vector4 &io_vColor, float32 &io_fDepth )
	{
		#ifdef VISUALIZE_RATE_OF_CHANGE
		vector4 vDdx, vDdy; GetDerivatives( 0, vDdx, vDdy );
		io_vColor.r = (*(vector2 *)&vDdx).length() * 100;
		io_vColor.g = (*(vector2 *)&vDdy).length() * 100;
		io_vColor.b = 0;
		io_vColor.a = 1;
		return true;
		#endif

		vector4 vRainbowFilm;
		SampleTexture( vRainbowFilm, 0, i_pInput[0].x, i_pInput[0].y, 0.0f );

		const float32 fFresnel = 1.0f - fabsf( i_pInput[2].x );

		vector4 vReflectionEnv;
		SampleTexture( vReflectionEnv, 1, i_pInput[1].x, i_pInput[1].y, i_pInput[1].z );

		float32 fAlpha = fSaturate( 4.0f * ( vReflectionEnv.a * vReflectionEnv.a - 0.75f ) );
		const vector4 vBaseEnvColor = ( vRainbowFilm * vReflectionEnv * 2.0f ).saturate();

		vector4 vColor;
		vVector4Lerp( vColor, vBaseEnvColor, vReflectionEnv, fAlpha );

		fAlpha += 0.6f * fFresnel + 0.1f;

		vVector4Lerp( io_vColor, io_vColor, vColor, fSaturate( fAlpha ) );
		return true;
	}
Example #2
0
	inline const C3DFLOAT32 FilterWidth() const
	{
		C3DVECTOR4 kDdx, kDdy;
		GetDerivatives(0, kDdx, kDdy);
		C3DFLOAT32 fChangeX = (*(C3DVECTOR2*)&kDdx).Length();
		C3DFLOAT32 fChangeY = (*(C3DVECTOR2*)&kDdy).Length();
		return MaxF(fChangeX, fChangeY);
	}
Example #3
0
void SplineSeg3<D> :: Project (const Point<D> point, Point<D> & point_on_curve, double & t) const
{
  double t_old = -1;

  if(proj_latest_t > 0. && proj_latest_t < 1.)
    t = proj_latest_t;
  else
    t = 0.5;
	
  Point<D> phi;
  Vec<D> phip,phipp,phimp;
    
  int i=0;

  while(t > -0.5 && t < 1.5 && i<20 && fabs(t-t_old) > 1e-15 )
    {
      GetDerivatives(t,phi,phip,phipp);
	
      t_old = t;

      phimp = phi-point;

      //t = min2(max2(t-(phip*phimp)/(phipp*phimp + phip*phip),0.),1.);
      t -= (phip*phimp)/(phipp*phimp + phip*phip);

      i++;
    }
    
  //if(i<10 && t > 0. && t < 1.)
  if(i<20 && t > -0.4 && t < 1.4)
    {
      if(t < 0)
	{
	  t = 0.;
	}
      if(t > 1)
	{
	  t = 1.;
	}

      point_on_curve = GetPoint(t);
	
      double dist = Dist(point,point_on_curve);
	
      phi = GetPoint(0);
      double auxdist = Dist(phi,point);
      if(auxdist < dist)
	{
	  t = 0.;
	  point_on_curve = phi;
	  dist = auxdist;
	}
      phi = GetPoint(1);
      auxdist = Dist(phi,point);
      if(auxdist < dist)
	{
	  t = 1.;
	  point_on_curve = phi;
	  dist = auxdist;
	}
    }
  else
    {
      double t0 = 0;
      double t1 = 0.5;
      double t2 = 1.;

      double d0,d1,d2;

	
      //(*testout) << "newtonersatz" << endl;
      while(t2-t0 > 1e-8)
	{
	    
	  phi = GetPoint(t0); d0 = Dist(phi,point);
	  phi = GetPoint(t1); d1 = Dist(phi,point);
	  phi = GetPoint(t2); d2 = Dist(phi,point);

	  double a = (2.*d0 - 4.*d1 +2.*d2)/pow(t2-t0,2);

	  if(a <= 0)
	    {
	      if(d0 < d2)
		t2 -= 0.3*(t2-t0);
	      else
		t0 += 0.3*(t2-t0);

	      t1 = 0.5*(t2+t0);
	    }
	  else
	    {
	      double b = (d1-d0-a*(t1*t1-t0*t0))/(t1-t0);

	      double auxt1 = -0.5*b/a;

	      if(auxt1 < t0)
		{
		  t2 -= 0.4*(t2-t0);
		  t0 = max2(0.,t0-0.1*(t2-t0));
		}
	      else if (auxt1 > t2)
		{
		  t0 += 0.4*(t2-t0);
		  t2 = min2(1.,t2+0.1*(t2-t0));
		}
	      else
		{
		  t1 = auxt1;
		  auxt1 = 0.25*(t2-t0);
		  t0 = max2(0.,t1-auxt1);
		  t2 = min2(1.,t1+auxt1);
		}
		
	      t1 = 0.5*(t2+t0);
	    }  

	}

	
      phi = GetPoint(t0); d0 = Dist(phi,point);
      phi = GetPoint(t1); d1 = Dist(phi,point);
      phi = GetPoint(t2); d2 = Dist(phi,point);

      double mind = d0;
      t = t0;
      if(d1 < mind)
	{
	  t = t1;
	  mind = d1;
	}
      if(d2 < mind)
	{
	  t = t2;
	  mind = d2;
	}

      point_on_curve = GetPoint(t);
    }
  //(*testout) << " latest_t " << proj_latest_t << " t " << t << endl;

  proj_latest_t = t;
}