Пример #1
0
//=================================================================================
void ThreadFunc (STimer& timer)
{
    // each thread grabs a pixel at a time and renders it
    size_t pixelIndex = ++g_currentPixelIndex;
    bool firstThread = pixelIndex == 0;
    int lastPercent = -1;
    while (pixelIndex < c_numPixels)
    {
        float jitterX = JITTER_AA() ? RandomFloat() : 0.5f;
        float jitterY = JITTER_AA() ? RandomFloat() : 0.5f;

        // get the current pixel's UV coordinate and memory location
        size_t x = pixelIndex % c_imageWidth;
        size_t y = pixelIndex / c_imageWidth;
        float u = ((float)x + jitterX) / (float)c_imageWidth;
        float v = ((float)y + jitterY) / (float)c_imageHeight;
        TPixelRGBF32& pixel = g_pixels[pixelIndex];

        // render the pixel by taking multiple samples and incrementally averaging them
        for (size_t i = 0; i < c_samplesPerPixel; ++i)
        {
            TPixelRGBF32 sample;
            RenderPixel(u, v, sample);
            pixel += (sample - pixel) / float(i + 1.0f);
        }

        // move to next pixel
        pixelIndex = ++g_currentPixelIndex;

        // report our progress (from a single thread only)
        if (firstThread)
            timer.ReportProgress(pixelIndex, c_numPixels);
    }
}
Пример #2
0
bool RenderThread::render(int x, int y, int red, int green, int blue) {
    if ( RenderCanvas::STOPPED == canvas->getState() )
        return false;

    pixels.push_back(RenderPixel(x, y, red, green, blue));
    if (timer->Time() - lastUpdateTime > 250)
        NotifyCanvas();

    TestDestroy();
    return true;
}
Пример #3
0
/**********************************************************
 * 
 * RenderSpan
 * 
 * parameters IN:
 * 	int y
 *	EdgeBox ** edgeBox1
 *	EdgeBox ** edgeBox2
 * 
 *********************************************************/
void RenderSpan (int y, EdgeBox ** edgeBox1, EdgeBox ** edgeBox2)
{
  	EdgeBox * tempEdgeBox;
  	int       x, z;
  	double    dz, di;
  	MyVector    dw;

 	if ((*edgeBox1)->x > (*edgeBox2)->x) {
  	  	tempEdgeBox = *edgeBox1;
		*edgeBox1 = *edgeBox2;
  	  	*edgeBox2 = tempEdgeBox;
  	}

  	int x1 = (int)(*edgeBox1)->x;
  	int x2 = (int)(*edgeBox2)->x;
  	if (x1 != x2) {
  	  	int dx = x2 - x1;

		double currZ = (*edgeBox1)->z;
		double currI = (*edgeBox1)->i;
		MyVector currW = (*edgeBox1)->w;

  	  	dz = ((*edgeBox2)->z - currZ) / dx;
  	  	di = ((*edgeBox2)->i - currI) / dx;

  	  	dw.SetX( ((*edgeBox2)->w.GetX() - currW.GetX()) / dx);
  	  	dw.SetY( ((*edgeBox2)->w.GetY() - currW.GetY()) / dx);
  	  	dw.SetZ( ((*edgeBox2)->w.GetZ() - currW.GetZ()) / dx);

  	  	for (x = x1; x <= x2 - 1; x++) {
			z = (int)currZ;
			if (z < zBufferAt[x][y]) {
			    zBufferAt[x][y] = z;
  	  	    	RenderPixel (x, y, currI, currW);
  	  	  	}

  	  	  	currZ += dz;
			currI += di;

  	  	  	currW.SetX( currW.GetX() + dw.GetX());
  	  	  	currW.SetY( currW.GetY() + dw.GetY());
  	  	  	currW.SetZ( currW.GetZ() + dw.GetZ());
		}
  	}
}
Пример #4
0
void InnerGlowStyle::operator() (Pixels destPixels, Pixels maskPixels)
{
  if (!active)
    return;

  SharedTable <Colour> table;
  
  if (reverse)
    table = colours.withReversedStops().createLookupTable ();
  else
    table = colours.createLookupTable ();

#if 1
  // Anti-Aliased
  //
  DistanceTransform::Meijster::calculateAntiAliased (
    RenderPixelAntiAliased (
      destPixels,
      opacity,
      choke,
      size,
      table),
    GetMask (maskPixels),
    maskPixels.getWidth (),
    maskPixels.getHeight (),
    DistanceTransform::Meijster::EuclideanMetric ());
#else
  // Regular
  //
  DistanceTransform::Meijster::calculate (
    RenderPixel (
      destPixels,
      opacity,
      choke,
      size,
      table),
    TestMask (maskPixels),
    maskPixels.getWidth (),
    maskPixels.getHeight (),
    DistanceTransform::Meijster::EuclideanMetric ());
#endif
}
void UpdateGraphics(void)
{
	RenderBackground();

	RenderPixel(401, 300, 0x0000000F);
	RenderPixel(402, 300, 0x0000000F);
	RenderPixel(403, 300, 0x0000000F);
	RenderPixel(404, 300, 0x0000000F);

	RenderPixel(401, 301, 0x0000000F);
	RenderPixel(402, 301, 0x0000000F);
	RenderPixel(403, 301, 0x0000000F);
	RenderPixel(404, 301, 0x0000000F);

	RenderPixel(401, 302, 0x0000000F);
	RenderPixel(402, 302, 0x0000000F);
	RenderPixel(403, 302, 0x0000000F);
	RenderPixel(404, 302, 0x0000000F);

	RenderPixel(401, 303, 0x0000000F);
	RenderPixel(402, 303, 0x0000000F);
	RenderPixel(403, 303, 0x0000000F);
	RenderPixel(404, 303, 0x0000000F);	
}
Пример #6
0
UINT ClientThreadFunction(void* param)
{
  SClientThreadParam * cp = (SClientThreadParam*) param; 
  ASSERT( AfxIsValidAddress(param, sizeof (SClientThreadParam) ) );
  
  CEvent& p_process_params_event = cp->process_params_event; //wait 
  CCriticalSection& params_cs = cp->params_cs; 

  TRY{
    while(1){
      if ( cp->bShouldExit )
        return 0; //we should stop

      BOOL ret = p_process_params_event.Lock(); //we wait here for access to thread params

      if ( cp->bShouldExit )
        return 0; //we should stop

      if( !ret ){
        ASSERT( 0 ); //very strange
        break; //we terminate this thread
      }

      params_cs.Lock(); //we enter critical section and don't allow
                        //main thread modify most params data members

      COLORREF* data = cp->data;
      CEnvironment* scene = cp->scene;
      CCamera* camera = cp->camera;
      int line_number = cp->line_number;
      HWND hwnd_main = cp->hwnd_main;

      ASSERT(data);
      ASSERT(scene);
      ASSERT(camera);
  
      int  imgWidth, imgHeight;
      camera->GetWidth( imgWidth );
      camera->GetHeight( imgHeight );

      ASSERT( line_number >=0 && line_number < imgHeight );

      CSimpleTracerSettings settings;
      settings.m_defaultDepth = 10;
      settings.m_shadeA = 0.08;
      settings.m_shadeB = 0.08;
      settings.m_shadeC = 0.08;
      settings.m_shadeRoD = 1;
      settings.m_shadeRoReflected = 1;
      settings.m_shadeRoRefracted = 1;

      SimpleTracer	tracer( settings );

      Medium			medium; //base medium - vacuum
      medium.Betta = 0;
      medium.nRefr = 1;
      CVector	color;

      for( int i = 0; i < imgWidth; i ++){      
        if ( cp->bShouldStop || cp->bShouldExit ) //if the main thread have set
                              //this variable to true we should stop rendering
          break;

        RenderPixel( *scene, medium, *camera, tracer, i, line_number, color);

        BYTE c_red =   (BYTE) (color.x*255.0);
        BYTE c_green = (BYTE) (color.y*255.0);
        BYTE c_blue =  (BYTE) (color.z*255.0);

        data[i] = RGB(c_blue, c_green, c_red); //Exactly this order!
      
      };

      params_cs.Unlock(); //leave critical section and allow for params modifications
      
      if(!cp->bShouldStop){ //main thread said us to stop, so we 
                        //probably haven't finished the image line
        ::PostMessage(hwnd_main, WM_CLIENT_LINE_RENDERED, 0, 0 );
        
      }
    }
  }
  CATCH_ALL(e){
    ErrorMessageFromException( e, TRUE ); //Show message box with error description
    AfxAbort(); //don't know how to recover, close the application
  }
  END_CATCH_ALL

  return 0;
}