Ejemplo n.º 1
0
void rendering()
{
//Source = http://scala-blitz.github.io/home/documentation/examples//raytracer.html

int width=640,height=480;
vector im[width*height],*pi=im;
double invwidth=1/double(width),invheight=1/double(height);
double f=30,aspectr=width/double(height);
double angle=tan(3.141592653589793*0.5*f/180);

for(int y=0;y<height;y++){
for(int x=0;x<width;x++,pi++) {
double x1=(2*((x+0.5)*invwidth)-1)*angle*aspectr;
double y1=(1-2*((y+0.5)*invheight))*angle;
vector *raydir;
raydir=(vector *)malloc(sizeof(vector));
vec(raydir,x1,y1,-1);
raydir=normalize(raydir);
*pi=tracing(&c,raydir,0);
}
}

std::ofstream o("./raytrace.ppm");
o<<"P6\n"<<width<<" "<<height<<"\n255\n";
for(int i=0;i<width*height;i++){
o<<(char)(min(double(1),im[i].x)*255)<<
   (char)(min(double(1),im[i].y)*255)<<
   (char)(min(double(1),im[i].z)*255);
}
o.close();
}
Ejemplo n.º 2
0
void
WebRenderBridgeParent::CompositeToTarget(gfx::DrawTarget* aTarget, const gfx::IntRect* aRect)
{
  AutoProfilerTracing tracing("Paint", "CompositeToTraget");
  if (mPaused) {
    return;
  }

  const uint32_t maxPendingFrameCount = 1;

  if (!mForceRendering &&
      wr::RenderThread::Get()->GetPendingFrameCount(mApi->GetId()) >= maxPendingFrameCount) {
    // Render thread is busy, try next time.
    ScheduleComposition();
    return;
  }

  bool scheduleComposite = false;
  nsTArray<wr::WrOpacityProperty> opacityArray;
  nsTArray<wr::WrTransformProperty> transformArray;

  mAsyncImageManager->SetCompositionTime(TimeStamp::Now());
  mAsyncImageManager->ApplyAsyncImages(mApi);

  SampleAnimations(opacityArray, transformArray);
  if (!transformArray.IsEmpty() || !opacityArray.IsEmpty()) {
    scheduleComposite = true;
  }

  if (PushAPZStateToWR(transformArray)) {
    scheduleComposite = true;
  }

  wr::RenderThread::Get()->IncPendingFrameCount(mApi->GetId());

#if defined(ENABLE_FRAME_LATENCY_LOG)
  auto startTime = TimeStamp::Now();
  mApi->SetFrameStartTime(startTime);
#endif

  if (!transformArray.IsEmpty() || !opacityArray.IsEmpty()) {
    mApi->GenerateFrame(opacityArray, transformArray);
  } else {
    mApi->GenerateFrame();
  }

  if (!mAsyncImageManager->GetCompositeUntilTime().IsNull()) {
    scheduleComposite = true;
  }

  if (scheduleComposite) {
    ScheduleComposition();
  }
}
Ejemplo n.º 3
0
void
WebRenderBridgeParent::HandleDPEnd(const gfx::IntSize& aSize,
                                 InfallibleTArray<WebRenderParentCommand>&& aCommands,
                                 InfallibleTArray<OpDestroy>&& aToDestroy,
                                 const uint64_t& aFwdTransactionId,
                                 const uint64_t& aTransactionId,
                                 const wr::LayoutSize& aContentSize,
                                 const wr::ByteBuffer& dl,
                                 const wr::BuiltDisplayListDescriptor& dlDesc,
                                 const WebRenderScrollData& aScrollData,
                                 const wr::IdNamespace& aIdNamespace,
                                 const TimeStamp& aFwdTime)
{
  AutoProfilerTracing tracing("Paint", "DPTransaction");
  UpdateFwdTransactionId(aFwdTransactionId);
  AutoClearReadLocks clearLocks(mReadLocks);

  if (mDestroyed) {
    for (const auto& op : aToDestroy) {
      DestroyActor(op);
    }
    return;
  }
  // This ensures that destroy operations are always processed. It is not safe
  // to early-return from RecvDPEnd without doing so.
  AutoWebRenderBridgeParentAsyncMessageSender autoAsyncMessageSender(this, &aToDestroy);

  uint32_t wrEpoch = GetNextWrEpoch();
  ProcessWebRenderCommands(aSize, aCommands, wr::NewEpoch(wrEpoch),
                           aContentSize, dl, dlDesc, aIdNamespace);
  HoldPendingTransactionId(wrEpoch, aTransactionId, aFwdTime);

  mScrollData = aScrollData;
  UpdateAPZ();

  if (mIdNamespace != aIdNamespace) {
    // Pretend we composited since someone is wating for this event,
    // though DisplayList was not pushed to webrender.
    TimeStamp now = TimeStamp::Now();
    mCompositorBridge->DidComposite(wr::AsUint64(mPipelineId), now, now);
  }
}
Ejemplo n.º 4
0
void
ClientLayerManager::ForwardTransaction(bool aScheduleComposite)
{
  AutoProfilerTracing tracing("Paint", "ForwardTransaction");
  TimeStamp start = TimeStamp::Now();

  // Skip the synchronization for buffer since we also skip the painting during
  // device-reset status.
  if (!gfxPlatform::GetPlatform()->DidRenderingDeviceReset()) {
    if (mForwarder->GetSyncObject() &&
        mForwarder->GetSyncObject()->IsSyncObjectValid()) {
      mForwarder->GetSyncObject()->Synchronize();
    }
  }

  mPhase = PHASE_FORWARD;

  mLatestTransactionId = mTransactionIdAllocator->GetTransactionId(!mIsRepeatTransaction);
  TimeStamp transactionStart;
  if (!mTransactionIdAllocator->GetTransactionStart().IsNull()) {
    transactionStart = mTransactionIdAllocator->GetTransactionStart();
  } else {
    transactionStart = mTransactionStart;
  }

  if (gfxPrefs::AlwaysPaint() && XRE_IsContentProcess()) {
    mForwarder->SendPaintTime(mLatestTransactionId, mLastPaintTime);
  }

  // forward this transaction's changeset to our LayerManagerComposite
  bool sent = false;
  bool ok = mForwarder->EndTransaction(
    mRegionToClear, mLatestTransactionId, aScheduleComposite,
    mPaintSequenceNumber, mIsRepeatTransaction, transactionStart,
    &sent);
  if (ok) {
    if (sent) {
      mNeedsComposite = false;
    }
  } else if (HasShadowManager()) {
    NS_WARNING("failed to forward Layers transaction");
  }

  if (!sent) {
    // Clear the transaction id so that it doesn't get returned
    // unless we forwarded to somewhere that doesn't actually
    // have a compositor.
    mTransactionIdAllocator->RevokeTransactionId(mLatestTransactionId);
  }

  mPhase = PHASE_NONE;

  // this may result in Layers being deleted, which results in
  // PLayer::Send__delete__() and DeallocShmem()
  mKeepAlive.Clear();

  TabChild* window = mWidget ? mWidget->GetOwningTabChild() : nullptr;
  if (window) {
    TimeStamp end = TimeStamp::Now();
    window->DidRequestComposite(start, end);
  }
}
Ejemplo n.º 5
0
bool
ClientLayerManager::EndTransactionInternal(DrawPaintedLayerCallback aCallback,
                                           void* aCallbackData,
                                           EndTransactionFlags)
{
  PaintTelemetry::AutoRecord record(PaintTelemetry::Metric::Rasterization);
  AutoProfilerTracing tracing("Paint", "Rasterize");

  Maybe<TimeStamp> startTime;
  if (gfxPrefs::LayersDrawFPS()) {
    startTime = Some(TimeStamp::Now());
  }

#ifdef WIN32
  if (aCallbackData) {
    // Content processes don't get OnPaint called. So update here whenever we
    // may do Thebes drawing.
    gfxDWriteFont::UpdateClearTypeUsage();
  }
#endif

  AUTO_PROFILER_LABEL("ClientLayerManager::EndTransactionInternal", GRAPHICS);

#ifdef MOZ_LAYERS_HAVE_LOG
  MOZ_LAYERS_LOG(("  ----- (beginning paint)"));
  Log();
#endif

  NS_ASSERTION(InConstruction(), "Should be in construction phase");
  mPhase = PHASE_DRAWING;

  ClientLayer* root = ClientLayer::ToClientLayer(GetRoot());

  mTransactionIncomplete = false;

  // Apply pending tree updates before recomputing effective
  // properties.
  GetRoot()->ApplyPendingUpdatesToSubtree();

  mPaintedLayerCallback = aCallback;
  mPaintedLayerCallbackData = aCallbackData;

  GetRoot()->ComputeEffectiveTransforms(Matrix4x4());

  // Skip the painting if the device is in device-reset status.
  if (!gfxPlatform::GetPlatform()->DidRenderingDeviceReset()) {
    if (gfxPrefs::AlwaysPaint() && XRE_IsContentProcess()) {
      TimeStamp start = TimeStamp::Now();
      root->RenderLayer();
      mLastPaintTime = TimeStamp::Now() - start;
    } else {
      root->RenderLayer();
    }
  } else {
    gfxCriticalNote << "LayerManager::EndTransaction skip RenderLayer().";
  }

  if (!mRepeatTransaction && !GetRoot()->GetInvalidRegion().IsEmpty()) {
    GetRoot()->Mutated();
  }

  if (!mIsRepeatTransaction) {
    mAnimationReadyTime = TimeStamp::Now();
    GetRoot()->StartPendingAnimations(mAnimationReadyTime);
  }

  mPaintedLayerCallback = nullptr;
  mPaintedLayerCallbackData = nullptr;

  // Go back to the construction phase if the transaction isn't complete.
  // Layout will update the layer tree and call EndTransaction().
  mPhase = mTransactionIncomplete ? PHASE_CONSTRUCTION : PHASE_NONE;

  NS_ASSERTION(!aCallback || !mTransactionIncomplete,
               "If callback is not null, transaction must be complete");

  if (gfxPlatform::GetPlatform()->DidRenderingDeviceReset()) {
    FrameLayerBuilder::InvalidateAllLayers(this);
  }

  if (startTime) {
    PaintTiming& pt = mForwarder->GetPaintTiming();
    pt.rasterMs() = (TimeStamp::Now() - startTime.value()).ToMilliseconds();
  }

  return !mTransactionIncomplete;
}
Ejemplo n.º 6
0
vector tracing(vector *rayorigin,vector *raydir,int depth){

double tn=IN;
sphere *s=NULL;
double t0=IN,t1=IN;
for(int i=0;i<6;i++){

if(sphere_ray_inter(sp[i],*rayorigin,*raydir,&t0,&t1)){

if(t0<0)t0=t1;

if(t0<tn){

tn=t0;
//if(i==2)printf("\nshan\n");
s=&sp[i];
}
}
}

vector x;
vector z;

vec(&x,2,2,2);
vec(&z,0.5,0.5,0.5);

if(s==NULL)return x;
//else return s->color;

vector color=c;
//printf("%f\n",tn);
//getchar();
vector *tee=vectmult(tn,raydir);
vector *pointhit=vectadd(rayorigin,tee); 
vector *nhit=vectsub(pointhit,&(s->centre));
nhit=normalize(nhit); 

double bias=1e-4;
bool inside=false;

if(dotproduct(raydir,nhit)>0){
nhit=negative(nhit);
inside=true;
}

if((s->transparency>0||s->reflectivity>0)&&depth<maxdepth){

//tee=negative(raydir);

double ratio=-(dotproduct(raydir,nhit));
double fresnel=mixture(pow(1-ratio,3),1,0.1);

double m=dotproduct(raydir,nhit);

//Source : http://www.cs.rpi.edu/~cutler/classes/advancedgraphics/F05/lectures/13_ray_tracing.pdf

tee=vectmult(m*2,nhit);
vector *refldir=vectsub(raydir,tee);
refldir=normalize(refldir);
tee=vectmult(bias,nhit);
tee=vectadd(pointhit,tee);
vector reflection=tracing(tee,refldir,depth+1);
//tee=vectmult(fresnel,&reflection);
//return *tee;

//Source : http://steve.hollasch.net/cgindex/render/refraction.txt

vector refraction=c;
vector *tee1;

if(s->transparency){

double io=1.1,eta=(inside)?io:1/io; 

//tee=negative(nhit);

double cosine=-(dotproduct(nhit,raydir));
double k=1-eta*eta*(1-cosine*cosine);

tee=vectmult((eta*cosine-sqrt(k)),nhit);
tee1=vectmult(eta,raydir);
vector *refrdir=vectadd(tee,tee1);
refrdir=normalize(refrdir);
tee=vectmult(bias,nhit);
tee=vectsub(pointhit,tee);
refraction=tracing(tee,refrdir,depth+1);
//return refraction;
}

tee=vectmult(fresnel,&reflection);
tee1=vectmult(((1-fresnel)*s->transparency),&refraction);
tee=vectadd(tee,tee1);
tee=crossproduct(&(s->color),tee);
color=*tee;
//return *tee;  
}
//return *tee;

else {
 
for(int i=0;i<6;i++){

if(sp[i].emcolor.x>0){
 
vector transmission;

vec(&transmission,1,1,1);
vector *lightdir=vectsub(&(sp[i].centre),pointhit);
lightdir=normalize(lightdir);

for(int j=0;j<6;j++){

if (i != j){

tee=vectmult(bias,nhit);
tee=vectadd(pointhit,tee);
if(sphere_ray_inter(sp[j],*tee,*lightdir,&t0,&t1)){
transmission=c;
break;
}
}
}

tee=crossproduct(&transmission,&(s->color));
tee=crossproduct(&(sp[i].emcolor),tee);
tee=vectmult((max(double(0),dotproduct(nhit,lightdir))),tee);
tee=vectadd(&color,tee);
color=*tee;
}
}
}
  //  return sphere->surfaceColor;

return (*(vectadd(&color,&(s->emcolor))));
}