コード例 #1
0
ファイル: Light.cpp プロジェクト: ArchyInf/HPL1Engine
	void iLight::UpdateLight(float afTimeStep)
	{	
		/////////////////////////////////////////////
		// Fade
		if(mfFadeTime>0)
		{
			//Log("Fading: %f / %f\n",afTimeStep,mfFadeTime);
			
			mfFarAttenuation += mfRadiusAdd*afTimeStep;
			mDiffuseColor.r += mColAdd.r*afTimeStep;
			mDiffuseColor.g += mColAdd.g*afTimeStep;
			mDiffuseColor.b += mColAdd.b*afTimeStep;
			mDiffuseColor.a += mColAdd.a*afTimeStep;
			SetDiffuseColor(mDiffuseColor);

			mfFadeTime-=afTimeStep;
			
			//Set the dest values.
			if(mfFadeTime<=0)
			{
				mfFadeTime =0;
				SetDiffuseColor(mDestCol);
				mfFarAttenuation = mfDestRadius;
			}
		}

		/////////////////////////////////////////////
		// Flickering
		if(mbFlickering && mfFadeTime<=0)
		{	
			//////////////////////
			//On
			if(mbFlickerOn)
			{
				if(mfFlickerTime >= mfFlickerStateLength)
				{
					mbFlickerOn = false;
					if(!mbFlickerFade)
					{
						SetDiffuseColor(mFlickerOffColor);
						mfFarAttenuation = mfFlickerOffRadius;
					}
					else
					{
						FadeTo(mFlickerOffColor,mfFlickerOffRadius,mfFlickerOffFadeLength);
					}
					//Sound
					if(msFlickerOffSound!=""){
						cSoundEntity *pSound = mpWorld3D->CreateSoundEntity("FlickerOff",
							msFlickerOffSound,true);
						if(pSound) pSound->SetPosition(GetLightPosition());
					}

					OnFlickerOff();
                   
					mfFlickerTime =0;
					mfFlickerStateLength = cMath::RandRectf(mfFlickerOffMinLength,mfFlickerOffMaxLength);
				}
			}
			//////////////////////
			//Off
			else 
			{
				if(mfFlickerTime >= mfFlickerStateLength)
				{
					mbFlickerOn = true;
					if(!mbFlickerFade)
					{
						SetDiffuseColor(mFlickerOnColor);
						mfFarAttenuation = mfFlickerOnRadius;
					}
					else
					{
						FadeTo(mFlickerOnColor,mfFlickerOnRadius,mfFlickerOnFadeLength);
					}
					if(msFlickerOnSound!=""){
						cSoundEntity *pSound = mpWorld3D->CreateSoundEntity("FlickerOn",
															msFlickerOnSound,true);
						if(pSound) pSound->SetPosition(GetLightPosition());
					}

					OnFlickerOn();
					
					mfFlickerTime =0;
					mfFlickerStateLength = cMath::RandRectf(mfFlickerOnMinLength,mfFlickerOnMaxLength);
				}
			}

			mfFlickerTime += afTimeStep;
		}

		/*Log("Time: %f Length: %f FadeTime: %f Color: (%f %f %f %f)\n",mfFlickerTime, mfFlickerStateLength,
											mfFadeTime,
											mDiffuseColor.r,mDiffuseColor.g,
											mDiffuseColor.b,mDiffuseColor.a);*/
	}
コード例 #2
0
void CGodRaysEffect::Render( int x, int y, int w, int h )
{
	CMatRenderContextPtr pRenderContext( materials );

	// Save off the current render target and put the occlusion
	// mask on the top of the rt stack.
	pRenderContext->PushRenderTargetAndViewport( m_OcclusionMask );

		// Create the god rays rendering view.
		CViewRender* pViewRender = CViewRender::GetMainView();
		CRefPtr<CGodRaysView> pGodRaysView = new CGodRaysView( pViewRender );

		// Set the sun instance.
		pGodRaysView->m_pSun = m_pSun;

		// Draw the occlusion mask.
		pViewRender->AddViewToScene( pGodRaysView );

	// Restore original render targets.
	pRenderContext->PopRenderTargetAndViewport();
	
	// Now, downsample the occlusion mask. Start by setting the quarter
	// sized render target as the texture to render to.
	pRenderContext->PushRenderTargetAndViewport( m_SmallRT0 );
	
		// Get the dimensions of the god rays texture.
		ITexture* pMaskTexture = m_OcclusionMask;
		const int nSrcWidth = pMaskTexture->GetActualWidth();
		const int nSrcHeight = pMaskTexture->GetActualHeight();
		const int nQtrWidth = nSrcWidth / 4;
		const int nQtrHeight = nSrcHeight / 4;

		// Blit the data from the occlusion mask texture to the quarter sized one
		// and use the downsample shader to do it with.
		pRenderContext->DrawScreenSpaceRectangle(
			m_DownsampleMaterial,
			0, 0,
			nQtrWidth, nQtrHeight,
			0, 0, 
			nSrcWidth - 2, nSrcHeight - 2,
			nSrcWidth, nSrcHeight );
	
	// Restore the original render target.
	pRenderContext->PopRenderTargetAndViewport();

	Vector vLightPos;
	GetLightPosition( vLightPos );
	if( SetMaterialParms( vLightPos ) )
	{
		// Apply godrays on _rt_SmallFB0 -> _rt_SmallFB1.
		pRenderContext->PushRenderTargetAndViewport( m_SmallRT1 );

		pRenderContext->DrawScreenSpaceRectangle(
			m_GodRaysMaterial,
			0, 0, 
			nQtrWidth, nQtrHeight,
			0, 0, 
			nQtrWidth - 2, nQtrHeight - 2,
			nQtrWidth, nQtrHeight );

		pRenderContext->PopRenderTargetAndViewport();

		// Now blur _rt_SmallFB1 -> _rt_SmallFB0.
		pRenderContext->PushRenderTargetAndViewport( m_SmallRT0 );

		pRenderContext->DrawScreenSpaceRectangle(
			m_BlurYMaterial,
			0, 0, 
			nQtrWidth, nQtrHeight,
			0, 0, 
			nQtrWidth - 2, nQtrHeight - 2,
			nQtrWidth, nQtrHeight );

		pRenderContext->PopRenderTargetAndViewport();

		// Now blur _rt_SmallFB0 -> _rt_SmallFB1.
		pRenderContext->PushRenderTargetAndViewport( m_SmallRT1 );

		pRenderContext->DrawScreenSpaceRectangle(
			m_BlurXMaterial,
			0, 0, 
			nQtrWidth, nQtrHeight,
			0, 0, 
			nQtrWidth - 2, nQtrHeight - 2,
			nQtrWidth, nQtrHeight );

		// Restore old render target and viewport.
		pRenderContext->PopRenderTargetAndViewport();

		// This forces the framebuffer to update with the latest scene.
		UpdateScreenEffectTexture( 0, x, y, w, h, true );

		// Now combine the godrays results with the main frame buffer.
		pRenderContext->DrawScreenSpaceQuad( m_GodRaysCombineMaterial );
	}

	// Release the render context.
	pRenderContext->Release();
}