Beispiel #1
0
void ScatterSky::_getSunColor( ColorF *outColor )
{
   PROFILE_SCOPE( ScatterSky_GetSunColor );

   U32 count = 0;
   ColorF tmpColor( 0, 0, 0 );
   VectorF tmpVec( 0, 0, 0 );

   tmpVec = mLightDir;
   tmpVec.x *= smEarthRadius + smAtmosphereRadius;
   tmpVec.y *= smEarthRadius + smAtmosphereRadius;
   tmpVec.z *= smEarthRadius + smAtmosphereRadius;
   tmpVec.z -= smAtmosphereRadius;

   for ( U32 i = 0; i < 10; i++ )
   {
      _getColor( tmpVec, &tmpColor );
      (*outColor) += tmpColor;
      tmpVec.x += (smEarthRadius * 0.5f) + (smAtmosphereRadius * 0.5f);
      count++;
   }

   if ( count > 0 )
      (*outColor) /= count;
}
size_t LineStripGeometry::addLineStrip(const Core::Array<Vector3f> &vertices,
                                       const Core::Array<Vector3ub> &rgb,
                                       float lineWidth)
{
  if (vertices.empty() || vertices.size() != rgb.size())
    return InvalidIndex;

  size_t result = m_lineStarts.size();
  m_lineStarts.push_back(static_cast<unsigned int>(m_vertices.size()));
  m_lineWidths.push_back(lineWidth);

  Array<Vector3ub>::const_iterator colorIter(rgb.begin());
  Array<Vector3f>::const_iterator vertIter(vertices.begin());
  Array<Vector3f>::const_iterator vertEnd(vertices.end());

  m_vertices.reserve(m_vertices.size() + vertices.size());
  Vector4ub tmpColor(0, 0, 0, m_opacity);
  while (vertIter != vertEnd) {
    tmpColor.head<3>() = *(colorIter++);
    m_vertices.push_back(PackedVertex(*(vertIter++), tmpColor));
  }

  m_dirty = true;
  return result;
}
Beispiel #3
0
void ScatterSky::_getFogColor( ColorF *outColor )
{
   PROFILE_SCOPE( ScatterSky_GetFogColor );

   VectorF scatterPos( 0, 0, 0 );

   F32 sunBrightness = mSkyBrightness;
   mSkyBrightness *= 0.25f;

   F32 yaw = 0, pitch = 0, originalYaw = 0;
   VectorF fwd( 0, 1.0f, 0 );
   MathUtils::getAnglesFromVector( fwd, yaw, pitch );
   originalYaw = yaw;
   pitch = mDegToRad( 10.0f );

   ColorF tmpColor( 0, 0, 0 );

   U32 i = 0;
   for ( i = 0; i < 10; i++ )
   {
      MathUtils::getVectorFromAngles( scatterPos, yaw, pitch );

      scatterPos.x *= smEarthRadius + smAtmosphereRadius;
      scatterPos.y *= smEarthRadius + smAtmosphereRadius;
      scatterPos.z *= smEarthRadius + smAtmosphereRadius;
      scatterPos.y -= smEarthRadius;

      _getColor( scatterPos, &tmpColor );
      (*outColor) += tmpColor;

      if ( i <= 5 )
         yaw += mDegToRad( 5.0f );
      else
      {
         originalYaw += mDegToRad( -5.0f );
         yaw = originalYaw;
      }

      yaw = mFmod( yaw, M_2PI_F );
   }

   if ( i > 0 )
      (*outColor) /= i;

   mSkyBrightness = sunBrightness;
}
Beispiel #4
0
void ScatterSky::_getAmbientColor( ColorF *outColor )
{
   PROFILE_SCOPE( ScatterSky_GetAmbientColor );

   ColorF tmpColor( 0, 0, 0, 0 );
   U32 count = 0;

   // Disable mieScattering for purposes of calculating the ambient color.
   F32 oldMieScattering = mMieScattering;
   mMieScattering = 0.0f;

   for ( U32 i = 0; i < mSkyPoints.size(); i++ )
   {
      Point3F pnt( mSkyPoints[i] );

      _getColor( pnt, &tmpColor );
      (*outColor) += tmpColor;
      count++;
   }

   if ( count > 0 )
      (*outColor) /= count;
   mMieScattering = oldMieScattering;
}
unsigned int MeshGeometry::addVertices(const Core::Array<Vector3f>& v,
                                       const Core::Array<Vector3f>& n,
                                       const Core::Array<Vector3ub>& c)
{
  if (v.size() != n.size() || n.size() != c.size())
    return InvalidIndex;

  size_t result = m_vertices.size();

  Core::Array<Vector3f>::const_iterator vIter = v.begin();
  Core::Array<Vector3f>::const_iterator vEnd = v.end();
  Core::Array<Vector3f>::const_iterator nIter = n.begin();
  Core::Array<Vector3ub>::const_iterator cIter = c.begin();

  Vector4ub tmpColor(0, 0, 0, m_opacity);
  while (vIter != vEnd) {
    tmpColor.head<3>() = *(cIter++);
    m_vertices.push_back(PackedVertex(tmpColor, *(nIter++), *(vIter++)));
  }

  m_dirty = true;

  return static_cast<unsigned int>(result);
}
Beispiel #6
0
void ScatterSky::unpackUpdate(NetConnection *con, BitStream *stream)
{
   Parent::unpackUpdate(con, stream);

   if ( stream->readFlag() ) // TimeMask
   {
      F32 temp = 0;
      stream->read( &temp );
      setAzimuth( temp );

      stream->read( &temp );
      setElevation( temp );
   }

   if ( stream->readFlag() ) // UpdateMask
   {
      stream->read( &mRayleighScattering );
      stream->read( &mRayleighScattering4PI );

      stream->read( &mMieScattering );
      stream->read( &mMieScattering4PI );

      stream->read( &mSunSize );

      stream->read( &mSkyBrightness );

      stream->read( &mMiePhaseAssymetry );

      stream->read( &mSphereInnerRadius );
      stream->read( &mSphereOuterRadius );

      stream->read( &mScale );

      ColorF tmpColor( 0, 0, 0 );

      stream->read( &tmpColor );

      stream->read( &mWavelength4[0] );
      stream->read( &mWavelength4[1] );
      stream->read( &mWavelength4[2] );

      stream->read( &mRayleighScaleDepth );
      stream->read( &mMieScaleDepth );

      stream->read( &mNightColor );
      stream->read( &mNightFogColor );
      stream->read( &mAmbientScale );
      stream->read( &mSunScale );
      stream->read( &mFogScale );
	  F32 colorizeAmt;
      stream->read( &colorizeAmt );

      if(mColorizeAmt != colorizeAmt) {
         mColorizeAmt = colorizeAmt;
         mShader = NULL; //forces shader refresh
      }

      stream->read( &mColorize );


      if ( tmpColor != mWavelength )
      {
         mWavelength = tmpColor;
         mWavelength4[0] = mPow(mWavelength[0], 4.0f);
         mWavelength4[1] = mPow(mWavelength[1], 4.0f);
         mWavelength4[2] = mPow(mWavelength[2], 4.0f);
      }

      stream->read( &mExposure );

      stream->read( &mBrightness );

      mCastShadows = stream->readFlag();

      stream->read( &mFlareScale );

      if ( stream->readFlag() )
      {
         SimObjectId id = stream->readRangedU32( DataBlockObjectIdFirst, DataBlockObjectIdLast );
         LightFlareData *datablock = NULL;

         if ( Sim::findObject( id, datablock ) )
            mFlareData = datablock;
         else
         {
            con->setLastError( "ScatterSky::unpackUpdate() - invalid LightFlareData!" );
            mFlareData = NULL;
         }
      }
      else
         mFlareData = NULL;

      mMoonEnabled = stream->readFlag();
      stream->read( &mMoonMatName );
      stream->read( &mMoonScale );
      stream->read( &mMoonTint );
      mUseNightCubemap = stream->readFlag();
      stream->read( &mNightCubemapName );

      stream->read( &mMoonAzimuth );
      stream->read( &mMoonElevation );

      mLight->unpackExtended( stream );

      if ( isProperlyAdded() )
      {
         mDirty = true;
         _initMoon();
         Sim::findObject( mNightCubemapName, mNightCubemap );
      }
   }
}
void place::displayOutput(
    const Eigen::SparseMatrix<double> &fp,
    const std::vector<Eigen::SparseMatrix<double>> &rSSparseTrimmed,
    const Eigen::MatrixXb &fpDoors,
    const std::vector<std::vector<place::Door>> &pcDoors,
    const std::vector<const place::posInfo *> &minima) {
  const int num = minima.size() < 20 ? minima.size() : 20;
  if (!FLAGS_quietMode) {
    std::cout << "Num minima: " << num << std::endl;
    std::cout << "Press a key to begin displaying placement options"
              << std::endl;
  }
  cv::Mat fpImg = place::sparseToImage(fp);
  cv::Mat tmpColor(fpImg.rows, fpImg.cols, CV_8UC3, cv::Scalar::all(255));

  for (int i = 0; i < tmpColor.rows; ++i) {
    uchar *dst = tmpColor.ptr<uchar>(i);
    const uchar *src = fpImg.ptr<uchar>(i);
    for (int j = 0; j < tmpColor.cols; ++j) {
      if (src[j] != 255) {
        dst[j * 3] = 128;
        dst[j * 3 + 1] = 128;
        dst[j * 3 + 2] = 128;
      }
    }
  }

  for (int j = 0; j < fpDoors.rows(); ++j) {
    uchar *dst = tmpColor.ptr<uchar>(j);
    for (int i = 0; i < fpDoors.cols(); ++i) {
      if (fpDoors(j, i)) {
        dst[i * 3] = 0;
        dst[i * 3 + 1] = 255;
        dst[i * 3 + 2] = 0;
      }
    }
  }

  cv::rectshow(tmpColor);
  const int cutOff = FLAGS_top > 0 ? FLAGS_top : 20;

  int currentCount = 0;
  for (auto &min : minima) {
    const int xOffset = min->x;
    const int yOffset = min->y;
    const Eigen::SparseMatrix<double> &currentScan =
        rSSparseTrimmed[min->rotation];
    auto &doors = pcDoors[min->rotation];

    cv::Mat output(tmpColor.rows, tmpColor.cols, CV_8UC3, cv::Scalar::all(255));
    tmpColor.copyTo(output);
    cv::Mat_<cv::Vec3b> _output = output;

    for (int i = 0; i < currentScan.outerSize(); ++i) {
      for (Eigen::SparseMatrix<double>::InnerIterator it(currentScan, i); it;
           ++it) {
        if (it.row() + yOffset < 0 || it.row() + yOffset >= output.rows)
          continue;
        if (it.col() + xOffset < 0 || it.col() + xOffset >= output.cols)
          continue;

        _output(it.row() + yOffset, it.col() + xOffset)[0] = 0;
        _output(it.row() + yOffset, it.col() + xOffset)[1] = 0;
        _output(it.row() + yOffset, it.col() + xOffset)[2] = 255;
      }
    }

    for (auto &d : doors) {
      auto color = randomColor();
      for (double x = 0; x < d.w; ++x) {
        Eigen::Vector3i index =
            (d.corner + x * d.xAxis + Eigen::Vector3d(min->x, min->y, 0))
                .unaryExpr([](auto v) { return std::round(v); })
                .cast<int>();

        _output(index[1], index[0]) = color;
      }
    }

    if (!FLAGS_quietMode) {
      std::cout << min << std::endl << std::endl;
    }
    cv::rectshow(output);
    ~output;
    if (++currentCount == cutOff)
      break;
  }
}
Beispiel #8
0
  void csVProcStandardProgram::SetupState (const csRenderMesh* mesh,
    csRenderMeshModes& modes,
    const csShaderVariableStack& stack)
  {
    bool skin_updated = false;// @@@ FIXME - time related detection if vertices are not already updated
    if (doVertexSkinning || doNormalSkinning || 
      doTangentSkinning || doBiTangentSkinning)
    {
      skin_updated = UpdateSkinnedVertices (modes, stack);
    }
    if (numLights > 0)
    {
      int lightsActive = 0;
      CS::ShaderVarStringID id;
      id = shaderPlugin->lsvCache.GetDefaultSVId (
        csLightShaderVarCache::varLightCount);
      csShaderVariable* sv;
      if ((stack.GetSize () > id) && ((sv = stack[id]) != 0))
        sv->GetValue (lightsActive);

      iRenderBuffer *vbuf = doVertexSkinning && skin_updated ? 
        modes.buffers->GetRenderBuffer (skinnedPositionOutputBuffer) :
        GetBuffer (positionBuffer, modes, stack);

      iRenderBuffer *nbuf = doNormalSkinning && skin_updated ? 
        modes.buffers->GetRenderBuffer (skinnedNormalOutputBuffer) :
        GetBuffer (normalBuffer, modes, stack);

      iRenderBuffer *cbuf = GetBuffer (colorBuffer, modes, stack);

      if (vbuf == 0 || nbuf == 0) return;

      csReversibleTransform camtrans;
      if ((stack.GetSize () > shaderPlugin->string_world2camera) 
        && ((sv = stack[shaderPlugin->string_world2camera]) != 0))
        sv->GetValue (camtrans);
      csVector3 eyePos (camtrans.GetT2OTranslation ());
      csVector3 eyePosObject (mesh->object2world.Other2This (eyePos));

      bool hasAlpha = cbuf && cbuf->GetComponentCount() >= 4;

      //copy output
      size_t elementCount = vbuf->GetElementCount ();
      csRef<iRenderBuffer> clbuf;
      if (doDiffuse)
      {
        clbuf = csRenderBuffer::CreateRenderBuffer (elementCount, CS_BUF_STREAM,
          CS_BUFCOMP_FLOAT, hasAlpha ? 4 : 3);
        // @@@ FIXME: should probably get rid of the multiple locking/unlocking...
        csRenderBufferLock<float> tmpColor (clbuf);
        memset (tmpColor, 0, sizeof(float) * (hasAlpha?4:3) * elementCount);
      }
      csRef<iRenderBuffer> specBuf;
      if (doSpecular)
      {
        specBuf = csRenderBuffer::CreateRenderBuffer (elementCount, 
          CS_BUF_STREAM, CS_BUFCOMP_FLOAT, 3);
        csRenderBufferLock<float> tmpColor (specBuf);
        memset (tmpColor, 0, sizeof(csColor) * elementCount);
      }
      float shininess = GetParamFloatVal (stack, shininessParam, 0.0f);

      if (lightsActive > 0)
      {
        if (lightMixMode == LIGHTMIXMODE_NONE)
        {
          //only calculate last, other have no effect
          const size_t lightNum = csMin((size_t)lightsActive, numLights)-1;

          if ((disableMask.GetSize() <= lightNum) 
            || !disableMask.IsBitSet (lightNum))
          {
            csLightProperties light (lightNum, shaderPlugin->lsvCache, stack,
              mesh->object2world);
            iVertexLightCalculator *calc = 
              shaderPlugin->GetLightCalculator (light, useAttenuation);
            calc->CalculateLighting (light, eyePosObject, shininess, elementCount, 
              vbuf, nbuf, clbuf, specBuf);
          }
        }
        else
        {
          LightMixmode useMixMode = LIGHTMIXMODE_ADD;
          for (size_t i = 0; i < (csMin((size_t)lightsActive, numLights)); i++)
          {
            if ((disableMask.GetSize() > i) && disableMask.IsBitSet (i))
            {
              useMixMode = lightMixMode;
              continue;
            }

            csLightProperties light (i, shaderPlugin->lsvCache, stack,
              mesh->object2world);
            iVertexLightCalculator *calc = 
              shaderPlugin->GetLightCalculator (light, useAttenuation);

            switch (useMixMode)
            {
            case LIGHTMIXMODE_ADD:
              {
                calc->CalculateLightingAdd (light, eyePosObject, shininess, elementCount, 
                  vbuf, nbuf, clbuf, specBuf);
                break;
              }
            case LIGHTMIXMODE_MUL:
              {
                calc->CalculateLightingMul (light, eyePosObject, shininess, elementCount,
                  vbuf, nbuf, clbuf, specBuf);
                break;
              }
            case LIGHTMIXMODE_NONE:
              break;
            }
            useMixMode = lightMixMode;
          }
        }

      }

      if (doDiffuse && cbuf)
      {
        switch (colorMixMode)
        {
        case LIGHTMIXMODE_NONE:
          if (!hasAlpha) break;
          {
            csVertexListWalker<float> cbufWalker (cbuf, 4);
            csRenderBufferLock<csVector4, iRenderBuffer*> tmpColor (clbuf);
            for (size_t i = 0; i < elementCount; i++)
            {
              const float* c = cbufWalker;
              tmpColor[i].w = c[3];
              ++cbufWalker;
            }
          }
          break;
        case LIGHTMIXMODE_ADD:
          {
            csVertexListWalker<float> cbufWalker (cbuf, 4);
            csRenderBufferLock<csVector4, iRenderBuffer*> tmpColor (clbuf);
            for (size_t i = 0; i < elementCount; i++)
            {
              csVector4& t = tmpColor[i];
              const float* c = cbufWalker;
              for (int j = 0; j < 3; j++)
                t[j] += c[j];
              if (hasAlpha) t[3] = c[3];
              ++cbufWalker;
            }
          }
          break;
        case LIGHTMIXMODE_MUL:
          {
            csVertexListWalker<float> cbufWalker (cbuf, 4);
            csRenderBufferLock<csVector4, iRenderBuffer*> tmpColor (clbuf);
            for (size_t i = 0; i < elementCount; i++)
            {
              csVector4& t = tmpColor[i];
              const float* c = cbufWalker;
              for (int j = 0; j < 3; j++)
                t[j] *= c[j];
              if (hasAlpha) t[3] = c[3];
              ++cbufWalker;
            }
          }
          break;
        default:
          CS_ASSERT (false);
        }
        if (doSpecular && specularOnDiffuse)
        {
	  csRenderBufferLock<csColor> tmpColor (clbuf);
	  csRenderBufferLock<csColor> tmpColor2 (specBuf);
	  for (size_t i = 0; i < elementCount; i++)
	  {
	    tmpColor[i] += tmpColor2[i];
	  }
        }
      }

      float finalLightFactorReal = GetParamFloatVal (stack, finalLightFactor,
	1.0f);
      if (doDiffuse)
      {
	{
	  csRenderBufferLock<csColor> tmpColor (clbuf);
	  for (size_t i = 0; i < elementCount; i++)
	  {
	    tmpColor[i] *= finalLightFactorReal;
	  }
	}
  
	modes.buffers->SetAccessor (modes.buffers->GetAccessor(),
	  modes.buffers->GetAccessorMask() & ~CS_BUFFER_COLOR_MASK);
	modes.buffers->SetRenderBuffer (CS_BUFFER_COLOR, clbuf);
      }
      if (doSpecular && !specularOnDiffuse)
      {
        csRenderBufferLock<csColor> tmpColor (specBuf);
        for (size_t i = 0; i < elementCount; i++)
        {
          tmpColor[i] *= finalLightFactorReal;
        }

        modes.buffers->SetAccessor (modes.buffers->GetAccessor(),
          modes.buffers->GetAccessorMask() & ~(1 << specularOutputBuffer));
        modes.buffers->SetRenderBuffer (specularOutputBuffer, specBuf);
      }
    }
  }
void KTColorPalette::updateColor()
{
	QColor tmpColor(m_nameColor->text());
	tmpColor.setAlpha(m_displayValueColor->alpha());
	setColor(tmpColor);
}