Exemplo n.º 1
0
void LightmapPostProcess::ApplyScaleClampFunction (csColor* colors, size_t numColors,
        float scaleValue, float maxValue)
{
    for (uint i = 0; i < numColors; i++)
    {
        csColor &c = colors[i];
        c.red = csClamp (c.red * scaleValue, maxValue, 0.0f);
        c.green = csClamp (c.green * scaleValue, maxValue, 0.0f);
        c.blue = csClamp (c.blue * scaleValue, maxValue, 0.0f);
    }
}
Exemplo n.º 2
0
  csString TUI::GetProgressBar (uint percent) const
  {
    csString result;

    percent = csClamp(percent, 100u, 0u);

    result.SetCapacity (73);
    //Draw a progess bar being in total 73+2 characters wide
    //|========== =--------- ---------- ---------- ---------- ---------- ---------- ---|
    
    result.Append ('|');

    uint numDone = (73*percent) / 100;
    uint numToDo = (73*(100-percent)) / 100;

    if(numDone + numToDo < 73) numToDo++;

    for(uint i = 0; i < numDone; ++i)
    {
      result.Append ('=');
    }

    for(uint i = 0; i < numToDo; ++i)
    {
      result.Append ('-');
    }

    result.Append ('|');

    return result;
  }
Exemplo n.º 3
0
 LayerSampler (int basemap_w, int basemap_h, MaterialLayer* layer)
  : textureScale (layer->texture_scale)
 {
   float layer_needed_x = float (basemap_w) / textureScale.x;
   float layer_needed_y = float (basemap_h) / textureScale.y;
   iImage* layerImage = layer->GetImage();
   int mip_x = csFindNearestPowerOf2 (
     int (ceil (layerImage->GetWidth() / layer_needed_x)));
   int mip_y = csFindNearestPowerOf2 (
     int (ceil (layerImage->GetHeight() / layer_needed_y)));
   int mip = csMax (
     csClamp (csLog2 (mip_x), csLog2 (layerImage->GetWidth()), 0),
     csClamp (csLog2 (mip_y), csLog2 (layerImage->GetHeight()), 0));
   img = GetImageMip (layerImage, mip);
   img_w = img->GetWidth();
   img_h = img->GetHeight();
 }
Exemplo n.º 4
0
void csMeshGeneratorGeometry::SetWindSpeed (float speed)
{
  wind_speed = csClamp (speed, FLT_MAX, 0.0f);

  for (size_t g = 0; g < factories.GetSize (); ++g)
  {
    csVector2 maxOffset = wind_direction * wind_speed;
    factories[g].windDataVar->SetValue (csVector3(maxOffset.x, maxOffset.y, wind_bias));
  }
}
Exemplo n.º 5
0
void Lightmap::SaveLightmap (const csString& fname, bool gray)
{
    ScopedSwapLock<Lightmap> l (*this);

    filename = fname;
    //write it out

    csRef<iImage> img;
    void* data;
    const size_t pixelArraySize = width*height;

    if (gray)
    {
        // first we downsample to LDR gray values
        data = cs_malloc (pixelArraySize);
        uint8* pixelData = (uint8*)data;
        for (uint i = 0; i < pixelArraySize; i++)
        {
            csColor &c = colorArray[i];
            // make sure we don't oversaturate below
            float f = csClamp (c.Luminance(), 1.0f, 0.0f);
            pixelData[i] = (uint) (f * 255.0f);
        }
        // make an image
        csRGBpixel* gray = new csRGBpixel[256];
        for (int v = 0; v < 256; v++) gray[v].Set (v, v, v);
        img.AttachNew (new csImageMemory (width, height, pixelData, false,
                                          CS_IMGFMT_PALETTED8, gray));
    }
    else
    {
        // first we downsample to LDR csRGBpixel RGBA
        data = cs_malloc (pixelArraySize * sizeof (csRGBpixel));
        csRGBpixel *pixelData = (csRGBpixel*)data;
        for (uint i = 0; i < pixelArraySize; i++)
        {
            csColor &c = colorArray[i];
            c.Clamp (1.0f,1.0f,1.0f); //just make sure we don't oversaturate below
            pixelData[i].red = (uint) (c.red * 255.0f);
            pixelData[i].green = (uint) (c.green * 255.0f);
            pixelData[i].blue = (uint) (c.blue * 255.0f);
        }
        // make an image
        img.AttachNew (new csImageMemory (width, height, pixelData, false));
    }

    csRef<iDataBuffer> imgData = globalLighter->imageIO->Save (img, "image/png");
    csRef<iFile> file = globalLighter->vfs->Open (fname, VFS_FILE_WRITE);
    if (file)
    {
        file->Write (imgData->GetData (), imgData->GetSize ());
        file->Flush ();
    }
    cs_free (data);
}