Пример #1
0
void ScatterSky::_getColor( const Point3F &pos, ColorF *outColor )
{
   PROFILE_SCOPE( ScatterSky_GetColor );

   F32 scaleOverScaleDepth = mScale / mRayleighScaleDepth;
   F32 rayleighBrightness = mRayleighScattering * mSkyBrightness;
   F32 mieBrightness = mMieScattering * mSkyBrightness;

   Point3F invWaveLength(  1.0f / mWavelength4[0],
                           1.0f / mWavelength4[1],
                           1.0f / mWavelength4[2] );

   Point3F v3Pos = pos / 6378000.0f;
   v3Pos.z += mSphereInnerRadius;

   Point3F newCamPos( 0, 0, smViewerHeight );

   VectorF v3Ray = v3Pos - newCamPos;
   F32 fFar = v3Ray.len();
   v3Ray / fFar;
   v3Ray.normalizeSafe();

   Point3F v3Start = newCamPos;
   F32 fDepth = mExp( scaleOverScaleDepth * (mSphereInnerRadius - smViewerHeight ) );
   F32 fStartAngle = mDot( v3Ray, v3Start );

   F32 fStartOffset = fDepth * _vernierScale( fStartAngle );

   F32 fSampleLength = fFar / 2.0f;
   F32 fScaledLength = fSampleLength * mScale;
   VectorF v3SampleRay = v3Ray * fSampleLength;
   Point3F v3SamplePoint = v3Start + v3SampleRay * 0.5f;

   Point3F v3FrontColor( 0, 0, 0 );
   for ( U32 i = 0; i < 2; i++ )
   {
      F32 fHeight = v3SamplePoint.len();
      F32 fDepth = mExp( scaleOverScaleDepth * (mSphereInnerRadius - smViewerHeight) );
      F32 fLightAngle = mDot( mLightDir, v3SamplePoint ) / fHeight;
      F32 fCameraAngle = mDot( v3Ray, v3SamplePoint ) / fHeight;

      F32 fScatter = (fStartOffset + fDepth * ( _vernierScale( fLightAngle ) - _vernierScale( fCameraAngle ) ));
      Point3F v3Attenuate( 0, 0, 0 );

      F32 tmp = mExp( -fScatter * (invWaveLength[0] * mRayleighScattering4PI + mMieScattering4PI) );
      v3Attenuate.x = tmp;

      tmp = mExp( -fScatter * (invWaveLength[1] * mRayleighScattering4PI + mMieScattering4PI) );
      v3Attenuate.y = tmp;

      tmp = mExp( -fScatter * (invWaveLength[2] * mRayleighScattering4PI + mMieScattering4PI) );
      v3Attenuate.z = tmp;

      v3FrontColor += v3Attenuate * (fDepth * fScaledLength);
      v3SamplePoint += v3SampleRay;
   }

   Point3F mieColor = v3FrontColor * mieBrightness;
   Point3F rayleighColor = v3FrontColor * (invWaveLength * rayleighBrightness);
   Point3F v3Direction = newCamPos - v3Pos;
   v3Direction.normalize();

   F32 fCos = mDot( mLightDir, v3Direction ) / v3Direction.len();
   F32 fCos2 = fCos * fCos;

   F32 g = -0.991f;
   F32 g2 = g * g;
   F32 miePhase = _getMiePhase( fCos, fCos2, g, g2 );

   Point3F color = rayleighColor + (miePhase * mieColor);
   ColorF tmp( color.x, color.y, color.z, color.y );

   Point3F expColor( 0, 0, 0 );
   expColor.x = 1.0f - exp(-mExposure * color.x);
   expColor.y = 1.0f - exp(-mExposure * color.y);
   expColor.z = 1.0f - exp(-mExposure * color.z);

   tmp.set( expColor.x, expColor.y, expColor.z, 1.0f );

   if ( !tmp.isValidColor() )
   {
      F32 len = expColor.len();
      if ( len > 0 )
         expColor /= len;
   }

   outColor->set( expColor.x, expColor.y, expColor.z, 1.0f );
}
Пример #2
0
void GuiVehicleControl::onMouseMove(const GuiEvent &evt)
{
	// Contribute mouse position to MoveManager::*Speed variables
	// Dead zone (mMouseDeadZone), with the rest contributing
	// mContributePitch, mContributeYaw, and mContriuteRoll.
	// (Mouse position normalized to 0.0->1.0)

	  // Calculate useful vectors (squared)
	Point2I realPos = globalToLocalCoord(evt.mousePoint);
	Point2F normalizedPos((F32)realPos.x / (F32)mBounds.extent.x,
                         (F32)realPos.y / (F32)mBounds.extent.y);
	Point2F centerPos(normalizedPos.x - 0.5, normalizedPos.y - 0.5);
   
	if (mCurveMode == 1) {
		normalizedPos.x = mCurveCoeff * (F32)(normalizedPos.x*normalizedPos.x);
		normalizedPos.y = mCurveCoeff * (F32)(normalizedPos.y*normalizedPos.y);
	} else if (mCurveMode == 2) {
		normalizedPos.x = mCurveCoeff * mExp((F32)mLog((F32)normalizedPos.x));
		normalizedPos.y = mCurveCoeff * mExp((F32)mLog((F32)normalizedPos.y));
	} else {
		normalizedPos *= mCurveCoeff;
	}
   
	//Con::printf("real =[%d,%d], normal=[%f,%f], center=[%f,%f]", realPos.x, realPos.y, normalizedPos.x, normalizedPos.y, centerPos.x, centerPos.y);

	// Send directly to *Speed variables
	// TODO: factor in sensitivity?
	// centerPos is used, expressed in the range -0.5,0.5

	// Pitch goes from up -> down,but needs to be converted to 0-1 range
	MoveManager::mPitchSpeed = centerPos.y * 2;
   	
	// Calculate YAW - must be in dead zone
	F32 absX = mFabs(centerPos.x);
	if (absX < mMouseDeadZone) {
		// Calculate in range (0.0-1.0) in dead zone
		MoveManager::mYawSpeed = absX * (1.0 / mMouseDeadZone);
		if (centerPos.x < 0.0f) MoveManager::mYawSpeed = -MoveManager::mYawSpeed;
	} else {
		MoveManager::mYawSpeed = 0;
	}
   	
	// Calculate ROLL
	if (absX > mMouseDeadZone)
	{
		// Negate dead zone and determine percentage outside dead zone
		// (0.5-mMouseDeadZone)
		MoveManager::mRollSpeed = (absX - mMouseDeadZone) * ( 1.0 / (0.5-mMouseDeadZone) );
		if (centerPos.x < 0.0f) MoveManager::mRollSpeed = -MoveManager::mRollSpeed;
	} else {
		MoveManager::mRollSpeed = 0;
	}

	// Calculate X and Y axis
	if (!mUseRightAxis) {
		MoveManager::mXAxis_L = centerPos.x;
		MoveManager::mYAxis_L = centerPos.y;
	} else {
		MoveManager::mXAxis_R = centerPos.x;
		MoveManager::mYAxis_R = centerPos.y;
	}