void FilterTurbulence::render_cairo(FilterSlot &slot)
{
    cairo_surface_t *input = slot.getcairo(_input);
    cairo_surface_t *out = ink_cairo_surface_create_same_size(input, CAIRO_CONTENT_COLOR_ALPHA);

    if (!gen->ready()) {
        Geom::Point ta(fTileX, fTileY);
        Geom::Point tb(fTileX + fTileWidth, fTileY + fTileHeight);
        gen->init(seed, Geom::Rect(ta, tb),
            Geom::Point(XbaseFrequency, YbaseFrequency), stitchTiles,
            type == TURBULENCE_FRACTALNOISE, numOctaves);
    }

    Geom::Affine unit_trans = slot.get_units().get_matrix_primitiveunits2pb().inverse();
    Geom::Rect slot_area = slot.get_slot_area();
    double x0 = slot_area.min()[Geom::X];
    double y0 = slot_area.min()[Geom::Y];

    ink_cairo_surface_synthesize(out, Turbulence(*gen, unit_trans, x0, y0));

    cairo_surface_mark_dirty(out);

    slot.set(_output, out);
    cairo_surface_destroy(out);
}
Vector BitmapData::Output(BaseShader *chn, ChannelData *cd)
{
	if (!shader) return 1.0;

	Vector uv=cd->p;

	if (noise>0.0)
	{
		Real    scl = 5.0*scale;
		Vector  res = Vector(Turbulence(uv*scl,octaves,TRUE),Turbulence((uv+Vector(0.34,13.0,2.43))*scl,octaves,TRUE),0.0);
		cd->p.x  = Mix(uv.x,res.x,noise);
		cd->p.y  = Mix(uv.y,res.y,noise);
	}

	Vector res=shader->Sample(cd);
	cd->p=uv;

	return res;
}
void WoodMaterial::color_texture (Vector3D& v)
{
  float X = v.x, Y = v.y, Z = v.z;  
  float x=scale*X, y=scale*Y, z=scale*Z;         // scale the texture coordinates
   
  x *= 0.08f;                    // Get some noise values. Drag out the texture in
  float chaos = Turbulence(x,y,z,0.01f) * 0.5; // the direction of the stem of the 
  float val2 = Noise(x,y,z);             // fictive tree. The pattern should vary
                                                    //  less along that direction

  float tx,ty,tz;           // Make the pattern "semi"-periodic so it looks as if
  if (z > 0.0) {                      // a new board is used at regular intervals
    tz = floor((z + boardsize*0.5) / boardsize);
    z -= tz * boardsize;
  } else {
    tz = floor((boardsize*0.5 - z) / boardsize);
    z += tz * boardsize;
  }
  if (y > 0.0) {
    ty = floor((y + boardsize*0.5) / boardsize);
    y -= ty * boardsize;
  } else {
    ty = floor((boardsize*0.5 - y) / boardsize);
    y += ty * boardsize;
  }

  tx = 0;                            // Skew the "stem" so the "cylinders" aren't 
  float skewoff = Noise(tx,ty,tz);               // perfectly symmetric about the  
  z -= (0.05 + 0.03*skewoff) * (X*scale - 2.0);     // x-axis. Skew the different
  y -= (0.05 + 0.03*skewoff) * (X*scale - 2.0);   // "logs" slightly differently.
    
  float rad = ::hypot(y,z) + chaos; // Calculate distance from middle of "stem" and
  float val = rad - floor(rad);   //  distort this distance with turbulence value

  if (val < 0.1) {	    // Choose a color dependent on the distorted distance
    v.x = base.red;
    v.y = base.green;
    v.z = base.blue;
  } else if (val < 0.9) {
    float t = 1.0 - pow(val / 0.8 - 0.1, 6.0);
    v.x = ring.red   + t * (base.red   - ring.red);
    v.y = ring.green + t * (base.green - ring.green);
    v.z = ring.blue  + t * (base.blue  - ring.blue);
  } else {
    v.x = ring.red;
    v.y = ring.green;
    v.z = ring.blue;
  }
  
  if (val2 < 0.01 && val2 > 0.0) {   // Add a little extra "noise" so the pattern 
   v.x = ring.red;                      // doesn't get too regular. this could be 
   v.y = ring.green;               // small cracks,or other anomalies in the wood
   v.z = ring.blue;
  }
}
Exemple #4
0
/*************
 * DESCRIPTION:   this is the work function
 * INPUT:         info     info structure
 *                params   pointer to user texture parameters
 *                patch    pointer to patch structure
 *                v        hit position - relative to texture axis
 * OUTPUT:        -
 *************/
static void SAVEDS texture_work(CLOUDS_INFO *info, DIALOG_DATA *params, TEXTURE_PATCH *patch, VECTOR *v)
{
	VECTOR p;
	float t;

	VecScale(params->frequency, v, &p);
	t = params->amplitude * Turbulence(&p, params->octaves, info->hashTable);
	if(t < 0.f)
		t = 0.f;

	patch->density = t;
}
Exemple #5
0
void noise_serial(float x0, float y0, float x1, float y1,
                  int width, int height, float output[])
{
    float dx = (x1 - x0) / width;
    float dy = (y1 - y0) / height;

    for (int j = 0; j < height; j++) {
        for (int i = 0; i < width; ++i) {
            float x = x0 + i * dx;
            float y = y0 + j * dy;

            int index = (j * width + i);
            output[index] = Turbulence(x, y, 0.6f, 8);
        }
    }
}
void MarbleMaterial::color_texture (Vector3D& v)
{
  float X = v.x*scale, Y = v.y*scale, Z = v.z*scale, x , t;
  x = X + Turbulence(X,Y,Z,0.01f) * 5;
  x = sin(x);
  if (x > -0.1 && x < 0.1) {
    v.x = strip.red;
    v.y = strip.green;
    v.z = strip.blue;
  } else if (x > -0.9 && x < 0.9){
    t = 7.0 / 6.0 - 1.0 / (6.25 * fabs(x) + 0.375);
    v.x = strip.red   + t * (base.red   - strip.red);
    v.y = strip.green + t * (base.green - strip.green);
    v.z = strip.blue  + t * (base.blue  - strip.blue);
  } else {
    v.x = base.red;         
    v.y = base.green;
    v.z = base.blue;
  }
}
static DBL constant_fog(RAY *Ray, DBL Depth, DBL  Width, FOG *Fog, COLOUR Colour)
{
  DBL k;
  VECTOR P;

  if (Fog->Turb != NULL)
  {
    Depth += Width / 2.0;

    VEvaluateRay(P, Ray->Initial, Depth, Ray->Direction);

    VEvaluateEq(P, Fog->Turb->Turbulence);

    /* The further away the less influence turbulence has. */

    k = exp(-Width / Fog->Distance);

    Width *= 1.0 - k * min(1.0, Turbulence(P, Fog->Turb, NULL)*Fog->Turb_Depth);
  }

  Assign_Colour(Colour, Fog->Colour);

  return (exp(-Width / Fog->Distance));
}
Exemple #8
0
Vector SDKGradientClass::Output(BaseShader *sh, ChannelData *sd)
{
	Vector p=sd->p;
	Real	 r=0.0,angle,xx,yy;

	if (gdata.turbulence>0.0)
	{
		Vector	res;
		Real		scl=5.0*gdata.scale,tt=sd->t*gdata.freq*0.3;

		res = Vector(Turbulence(p*scl,tt,gdata.octaves,TRUE),Turbulence((p+Vector(0.34,13.0,2.43))*scl,tt,gdata.octaves,TRUE),0.0);

		if (gdata.absolute)
		{
			p.x  = Mix(p.x,res.x,gdata.turbulence);
			p.y  = Mix(p.y,res.y,gdata.turbulence);
		}
		else
		{
			p.x += (res.x-0.5)*gdata.turbulence;
			p.y += (res.y-0.5)*gdata.turbulence;
		}
	}

	// rotation
	p.x -= 0.5;
	p.y -= 0.5;

	xx = gdata.ca*p.x-gdata.sa*p.y + 0.5;
	yy = gdata.sa*p.x+gdata.ca*p.y + 0.5;

	p.x = xx;
	p.y = yy;

	if (gdata.mode<=SDKGRADIENTSHADER_MODE_CORNER && gdata.cycle && (sd->texflag&TEX_TILE))
	{
		if (sd->texflag & TEX_MIRROR)
		{
			p.x = Modulo(p.x,RCO 2.0);
			if (p.x>=1.0) p.x=2.0-p.x;

			p.y = Modulo(p.y,RCO 2.0);
			if (p.y>= 1.0) p.y=2.0-p.y;
		}
		else
		{
			p.x = Modulo(p.x, RCO 1.0);
			p.y = Modulo(p.y, RCO 1.0);
		}
	}

	switch (gdata.mode)
	{
		case SDKGRADIENTSHADER_MODE_U:
			r = p.x; 
			break;

		case SDKGRADIENTSHADER_MODE_V:
			r = 1.0-p.y; 
			break;

		case SDKGRADIENTSHADER_MODE_DIAGONAL:
			r = (p.x+p.y)*0.5; 
			break;

		case SDKGRADIENTSHADER_MODE_RADIAL:
			p.x-=0.5;
			p.y-=0.5;
			if (p.x==0.0) p.x=0.00001;

			angle = ATan(p.y/p.x);
			if (p.x<0.0) angle+=pi;
			if (angle<0.0) angle+=pi2;
			r = angle/pi2;
			break;

		case SDKGRADIENTSHADER_MODE_CIRCULAR:
			p.x-=0.5;
			p.y-=0.5;
			r = Sqrt(p.x*p.x+p.y*p.y)*2.0;
			break;

		case SDKGRADIENTSHADER_MODE_BOX:
			p.x = Abs(p.x - 0.5);
			p.y = Abs(p.y - 0.5);
			r   = FMax(p.x,p.y)*2.0;
			break;

		case SDKGRADIENTSHADER_MODE_STAR:
			p.x = Abs(p.x - 0.5)-0.5;
			p.y = Abs(p.y - 0.5)-0.5;
			r   = Sqrt(p.x*p.x+p.y*p.y) * 1.4142;
			break;

		case SDKGRADIENTSHADER_MODE_CORNER:
		{
			Real		cx;
			Vector	ca,cb;

			cx = FCut01(p.x);
			ca = Mix(gdata.c[0],gdata.c[1],cx);
			cb = Mix(gdata.c[2],gdata.c[3],cx);

			return Mix(ca,cb,FCut01(p.y));
			break;
		}
	}

	return gdata.gradient->CalcGradientPixel(FCut01(r));
}
Exemple #9
0
	T Evaluate(const DifferentialGeometry &dg) const {
		Vector dpdx, dpdy;
		Point P = mapping->Map(dg, &dpdx, &dpdy);
		return Turbulence(P, dpdx, dpdy, omega, octaves);
	}
static DBL ground_fog(RAY *Ray, DBL Depth, DBL  Width, FOG *Fog, COLOUR Colour)
{
  DBL fog_density, delta;
  DBL start, end;
  DBL y1, y2, k;
  VECTOR P, P1, P2;

  /* Get start point. */

  VEvaluateRay(P1, Ray->Initial, Depth, Ray->Direction);

  /* Get end point. */

  VLinComb2(P2, 1.0, P1, Width, Ray->Direction);

  /*
   * Could preform transfomation here to translate Start and End
   * points into ground fog space.
   */

  VDot(y1, P1, Fog->Up);
  VDot(y2, P2, Fog->Up);

  start = (y1 - Fog->Offset) / Fog->Alt;
  end   = (y2 - Fog->Offset) / Fog->Alt;

  /* Get integral along y-axis from start to end. */

  if (start <= 0.0)
  {
    if (end <= 0.0)
    {
      fog_density = 1.0;
    }
    else
    {
      fog_density = (atan(end) - start) / (end - start);
    }
  }
  else
  {
    if (end <= 0.0)
    {
      fog_density = (atan(start) - end) / (start - end);
    }
    else
    {
      delta = start - end;

      if (fabs(delta) > EPSILON)
      {
        fog_density = (atan(start) - atan(end)) / delta;
      }
      else
      {
        fog_density = 1.0 / (Sqr(start) + 1.0);
      }
    }
  }

  /* Apply turbulence. */

  if (Fog->Turb != NULL)
  {
    VHalf(P, P1, P2);

    VEvaluateEq(P, Fog->Turb->Turbulence);

    /* The further away the less influence turbulence has. */

    k = exp(-Width / Fog->Distance);

    Width *= 1.0 - k * min(1.0, Turbulence(P, Fog->Turb, NULL)*Fog->Turb_Depth);
  }

  Assign_Colour(Colour, Fog->Colour);

  return (exp(-Width * fog_density / Fog->Distance));
}