void SetParameters(FRHICommandList& RHICmdList, const FPixelShaderRHIParamRef& ShaderRHI, const FRenderingCompositePassContext& Context) const
	{
		{
			// from Separabale.usf: float distanceToProjectionWindow = 1.0 / tan(0.5 * radians(SSSS_FOVY))
			// can be extracted out of projection matrix

			FSceneRenderTargets& SceneContext = FSceneRenderTargets::Get(RHICmdList);

			// Calculate the sssWidth scale (1.0 for a unit plane sitting on the projection window):
			float DistanceToProjectionWindow = Context.View.ViewMatrices.ProjMatrix.M[0][0]; 

			float SSSScaleZ = DistanceToProjectionWindow * GetSubsurfaceRadiusScale();

			// * 0.5f: hacked in 0.5 - -1..1 to 0..1 but why this isn't in demo code?
			float SSSScaleX = SSSScaleZ / SUBSURFACE_KERNEL_SIZE * 0.5f;

			FVector4 ColorScale(SSSScaleX, SSSScaleZ, 0, 0);
			SetShaderValue(Context.RHICmdList, ShaderRHI, SSSParams, ColorScale);
		}

		{
			const IPooledRenderTarget* PooledRT = GetSubsufaceProfileTexture_RT(Context.RHICmdList);

			if(!PooledRT)
			{
				// no subsurface profile was used yet
				PooledRT = GSystemTextures.BlackDummy;
			}

			const FSceneRenderTargetItem& Item = PooledRT->GetRenderTargetItem();

			SetTextureParameter(Context.RHICmdList, ShaderRHI, SSProfilesTexture, Item.ShaderResourceTexture);
		}
	}
Example #2
0
File: shade.cpp Project: RRIE/to3ds
color shade_reflection(ray * incident, vector * hit, vector * N, flt specular) {
  ray specray;
  color col;
  vector R;
 
  VAddS(-2.0 * (incident->d.x * N->x + 
                incident->d.y * N->y + 
                incident->d.z * N->z), N, &incident->d, &R);

  specray.intstruct=incident->intstruct; /* what thread are we   */
  specray.depth=incident->depth - 1;   /* go up a level in recursion depth */
  specray.flags = RT_RAY_REGULAR;      /* infinite ray, to start with */
  specray.serial = incident->serial + 1; /* next serial number */
  specray.mbox = incident->mbox; 
  specray.o=*hit; 
  specray.d=R;			       /* reflect incident ray about normal */
  specray.o=Raypnt(&specray, EPSILON); /* avoid numerical precision bugs */
  specray.maxdist = FHUGE;             /* take any intersection */
  specray.scene=incident->scene;       /* global scenedef info */
  col=trace(&specray);                 /* trace specular reflection ray */ 

  incident->serial = specray.serial;    /* update the serial number */

  ColorScale(&col, specular);

  return col;
}
	void SetParameters(const FRenderingCompositePassContext& Context, float InRadius)
	{
		const FPixelShaderRHIParamRef ShaderRHI = GetPixelShader();

		FGlobalShader::SetParameters(Context.RHICmdList, ShaderRHI, Context.View);
		DeferredParameters.Set(Context.RHICmdList, ShaderRHI, Context.View);
		PostprocessParameter.SetPS(ShaderRHI, Context, TStaticSamplerState<SF_Bilinear,AM_Border,AM_Border,AM_Border>::GetRHI());

		{
			FVector4 ColorScale(InRadius, 0, 0, 0);
			SetShaderValue(Context.RHICmdList, ShaderRHI, NoiseParams, ColorScale);
		}
	}
Example #4
0
	void SetParameters(const FRenderingCompositePassContext& Context)
	{
		const FPixelShaderRHIParamRef ShaderRHI = GetPixelShader();

		const FPostProcessSettings& Settings = Context.View.FinalPostProcessSettings;

		FGlobalShader::SetParameters(Context.RHICmdList, ShaderRHI, Context.View);
		PostprocessParameter.SetPS(ShaderRHI, Context, TStaticSamplerState<SF_Bilinear,AM_Border,AM_Border,AM_Border>::GetRHI());

		{
			FLinearColor Col = FLinearColor::White * Settings.BloomIntensity;
			FVector4 ColorScale(Col.R, Col.G, Col.B, 0);
			SetShaderValue(Context.RHICmdList, ShaderRHI, ColorScale1, ColorScale);
		}
	}
Example #5
0
File: shade.cpp Project: RRIE/to3ds
color shade_transmission(ray * incident, vector * hit, flt trans) {
  ray transray;
  color col;

  transray.intstruct=incident->intstruct; /* what thread are we   */
  transray.depth=incident->depth - 1;    /* go up a level in recursion depth */
  transray.flags = RT_RAY_REGULAR;       /* infinite ray, to start with */
  transray.serial = incident->serial + 1; /* update serial number */
  transray.mbox = incident->mbox;
  transray.o=*hit; 
  transray.d=incident->d;                /* ray continues along incident path */
  transray.o=Raypnt(&transray, EPSILON); /* avoid numerical precision bugs */
  transray.maxdist = FHUGE;              /* take any intersection */
  transray.scene=incident->scene;        /* global scenedef info */
  col=trace(&transray);                  /* trace transmission ray */  

  incident->serial = transray.serial;

  ColorScale(&col, trans);

  return col;
}
Example #6
0
void DivePercentageItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
	Q_UNUSED(option);
	Q_UNUSED(widget);

	if (polygon().isEmpty())
		return;
	painter->save();
	QPen mypen;
	mypen.setWidthF(vAxis->posAtValue(0) - vAxis->posAtValue(4));
	mypen.setCosmetic(false);
	QPolygonF poly = polygon();
	for (int i = 1, modelDataCount = dataModel->rowCount(); i < modelDataCount; i++) {
		if (i < poly.count()) {
			double value = dataModel->index(i, vDataColumn).data().toDouble();
			int cyl = dataModel->index(i, DivePlotDataModel::CYLINDERINDEX).data().toInt();
			int inert = 1000 - get_o2(&displayed_dive.cylinder[cyl].gasmix);
			mypen.setBrush(QBrush(ColorScale(value, inert)));
			painter->setPen(mypen);
			painter->drawLine(poly[i - 1], poly[i]);
		}
	}
	painter->restore();
}
Example #7
0
void DivePercentageItem::paint(QPainter *painter, const QStyleOptionGraphicsItem*, QWidget*)
{
	if (polygon().isEmpty())
		return;
	painter->save();
	QPen mypen;
	mypen.setCapStyle(Qt::FlatCap);
	mypen.setCosmetic(false);
	QPolygonF poly = polygon();
	for (int i = 1, modelDataCount = dataModel->rowCount(); i < modelDataCount; i++) {
		if (i < poly.count()) {
			double value = dataModel->index(i, vDataColumn).data().toDouble();
			struct gasmix gasmix = gasmix_air;
			const struct event *ev = NULL;
			int sec = dataModel->index(i, DivePlotDataModel::TIME).data().toInt();
			gasmix = get_gasmix(&displayed_dive, displayed_dc, sec, &ev, gasmix);
			int inert = 1000 - get_o2(gasmix);
			mypen.setBrush(QBrush(ColorScale(value, inert)));
			painter->setPen(mypen);
			painter->drawLine(poly[i - 1], poly[i]);
		}
	}
	painter->restore();
}
Example #8
0
File: shade.cpp Project: RRIE/to3ds
color shader(ray * incident) {
  color col, diffuse, phongcol; 
  vector N, L, hit;
  ray shadowray;
  flt inten, t, Llen;
  object * obj;
  int numints, i;
  point_light * li;


  numints=closest_intersection(&t, &obj, incident->intstruct);  
		/* find the number of intersections */
                /* and return the closest one.      */

  if (numints < 1) {         
    /* if there weren't any object intersections then return the */
    /* background color for the pixel color.                     */
    return incident->scene->background;
  }

  if (obj->tex->islight) {  /* if the current object is a light, then we  */
    return obj->tex->col;   /* will only use the objects ambient color    */
  }

  RAYPNT(hit, (*incident), t)       /* find the point of intersection from t */ 
  obj->methods->normal(obj, &hit, incident, &N);  /* find the surface normal */

  /* execute the object's texture function */
  col = obj->tex->texfunc(&hit, obj->tex, incident); 

  diffuse.r = 0.0; 
  diffuse.g = 0.0; 
  diffuse.b = 0.0; 
  phongcol = diffuse;

  if ((obj->tex->diffuse > 0.0) || (obj->tex->phong > 0.0)) {  
    for (i=0; i<numlights; i++) {   /* loop for light contributions */
      li=lightlist[i];              /* set li=to the current light  */
      VSUB(li->ctr, hit, L)         /* find the light vector        */

      /* calculate the distance to the light from the hit point */
      Llen = sqrt(L.x*L.x + L.y*L.y + L.z*L.z) + EPSILON;

      L.x /= Llen; /* normalize the light direction vector */
      L.y /= Llen;
      L.z /= Llen;

      VDOT(inten, N, L)             /* light intensity              */

      /* add in diffuse lighting for this light if we're facing it */ 
      if (inten > 0.0) {            
        /* test for a shadow */
        shadowray.intstruct = incident->intstruct;
        shadowray.flags = RT_RAY_SHADOW | RT_RAY_BOUNDED; 
        incident->serial++;
        shadowray.serial = incident->serial;
        shadowray.mbox = incident->mbox;
        shadowray.o   = hit;
        shadowray.d   = L;      
        shadowray.maxdist = Llen;
        shadowray.s   = hit;
        shadowray.e = li->ctr;
        shadowray.scene = incident->scene;
        reset_intersection(incident->intstruct);
        intersect_objects(&shadowray);

        if (!shadow_intersection(incident->intstruct, Llen)) {
          /* XXX now that opacity is in the code, have to be more careful */
          ColorAddS(&diffuse, &li->tex->col, inten);

          /* phong type specular highlights */
          if (obj->tex->phong > 0.0) {
            flt phongval;
            phongval = shade_phong(incident, &hit, &N, &L, obj->tex->phongexp); 
            if (obj->tex->phongtype) 
              ColorAddS(&phongcol, &col, phongval);
            else
              ColorAddS(&phongcol, &(li->tex->col), phongval);
          }
        }
      }  
    } 
  }

  ColorScale(&diffuse, obj->tex->diffuse);

  col.r *= (diffuse.r + obj->tex->ambient); /* do a product of the */
  col.g *= (diffuse.g + obj->tex->ambient); /* diffuse intensity with  */
  col.b *= (diffuse.b + obj->tex->ambient); /* object color + ambient  */

  if (obj->tex->phong > 0.0) {
    ColorAccum(&col, &phongcol);
  }

  /* spawn reflection rays if necessary */
  /* note: this will overwrite the old intersection list */
  if (obj->tex->specular > 0.0) {    
    color specol;
    specol = shade_reflection(incident, &hit, &N, obj->tex->specular);
    ColorAccum(&col, &specol);
  }

  /* spawn transmission rays / refraction */
  /* note: this will overwrite the old intersection list */
  if (obj->tex->opacity < 1.0) {      
    color transcol;
    transcol = shade_transmission(incident, &hit, 1.0 - obj->tex->opacity);
    ColorAccum(&col, &transcol);
  }

  return col;    /* return the color of the shaded pixel... */
}
void EffectFallingPixelsUpdate(int16_t x, int16_t y, systime_t time, void* effectcfg, void* effectdata, struct Effect* next, struct DisplayBuffer* display)
{
    (void) x;
    (void) y;
    (void) next;
    struct EffectFallingPixelsCfg* cfg = (struct EffectFallingPixelsCfg*) effectcfg;
    struct EffectFallingPixelsData* data = (struct EffectFallingPixelsData*) effectdata;

    bool newSpawn = false;
    systime_t diffSpawn = time - data->lastspawn;
    systime_t diffUpdate = time - data->lastupdate;
    if (diffSpawn >= cfg->spawninterval)
    {
        newSpawn = true;
        data->lastspawn += cfg->spawninterval;
    }

    int16_t pixel;
    for (pixel = 0; pixel < 30; pixel++)
    {
        struct EffectFallingPixelHead* pixelHead = &data->pixelHeads[pixel];
        if (pixelHead->active == true)
        {
            pixelHead->time += diffUpdate;
            if (pixelHead->time >= pixelHead->speed)
            {
                pixelHead->time -= pixelHead->speed;
                pixelHead->posY += 1;
                uint16_t pixelNumber = 0;
                if (DisplayCoordToLed(pixelHead->posX, pixelHead->posY, &pixelNumber, display) == true)
                {
                    FadeResetState(cfg->fadeperiod, &data->fadeStates[pixelNumber]);
                    ColorCopy(&pixelHead->color, &data->pixelColors[pixelNumber]);
                }
                else
                {
                    pixelHead->active = false;
                }
            }

        }
        else if (newSpawn == true)
        {
            //spawn a new head
            pixelHead->active = true;

            pixelHead->posX = rand() % display->width;
            pixelHead->posY = 0;

            pixelHead->speed = cfg->speed + rand() % cfg->speedVariance;
            pixelHead->time = 0;

            SetRandomColor(&pixelHead->color, cfg);
            uint16_t pixelNumber = 0;
            DisplayCoordToLed(pixelHead->posX, pixelHead->posY, &pixelNumber, display);
            FadeResetState(cfg->fadeperiod, &data->fadeStates[pixelNumber]);
            ColorCopy(&pixelHead->color, &data->pixelColors[pixelNumber]);

            newSpawn = false;
        }
    }

    int16_t width;
    int16_t height;
    for (width = 0; width < display->width; width++)
    {
        for (height = 0; height < display->height; height++)
        {
            uint16_t pixelNumber = 0;
            DisplayCoordToLed(width, height, &pixelNumber, display);
            float fade = FadeUpdateState(diffUpdate, cfg->fadeperiod, &data->fadeStates[pixelNumber]);
            ColorScale(&data->pixelColors[pixelNumber], fade);
            DisplayDraw(width, height, &data->pixelColors[pixelNumber], display);
        }
    }

    data->lastupdate = time;
}