//#ifndef OPENGL_RENDERER /// do the lighting using the deferred shading system, uses GBuffer and lighting in screen space is done is a post step void TSRLightingManager::RenderAllLightsPassesDeferred( TSRGBufferPass* _pGBuffer, TSRSceneWorldInterface* _pWorld ) { /// set the gbuffer component to start doing the lighting TSRGlobalConstants.m_DiffuseTexture.Set( _pGBuffer->m_pColorTarget ); TSRGlobalConstants.m_SpecularTexture.Set( _pGBuffer->m_pSpecularTarget ); TSRGlobalConstants.m_NormalTexture.Set( _pGBuffer->m_pNormalTarget ); TSRGlobalConstants.m_DepthTexture.Set( _pGBuffer->m_pDepthTarget ); /// set the inverse view projection matrix TSRMatrix4 viewProj; const TSRMatrix4& view = _pWorld->GetMainCamera()->GetViewMatrix(); const TSRMatrix4& proj = _pWorld->GetMainCamera()->GetProjectionMatrix(); TSRMaterial whiteMaterial; TSRGlobalConstants.SetMaterial( whiteMaterial ); _pWorld->GetMainCamera()->ComputeViewProjMatrix( viewProj ); TSRMatrix4 invViewProj; Matrix4Inverse( viewProj, invViewProj ); _pGBuffer->m_InverseViewProjection.Set( invViewProj ); TSRMatrix4 invView; TSRMatrix4 invProj; Matrix4Inverse( view, invView ); _pGBuffer->m_InverseView.Set( invView ); _pGBuffer->m_CameraView.Set( view ); Matrix4Inverse( proj, invProj ); _pGBuffer->m_InverseProjection.Set( invProj ); Graphics()->SetDepthStencilState( Graphics()->m_DepthTestDisabledWriteDisabled ); if ( m_SceneLightsContext.GetDirectionalLightsCount() > 0 ) { TSRGlobalConstants.SetLight( 0, *m_SceneLightsContext.m_DirectionalLights[ 0 ] ); TSRImmediateDraw::RenderFullScreenQuad( ( m_EffectsDisabledMask & TWISTER_SHADER_FLAG_SHADOWMAP ) ? m_pMainLightShader : m_pMainLightAndShadowShader ); } Graphics()->SetBlendState( Graphics()->m_BlendAdditiveColor ); /// additional directional lights.. for ( unsigned int i = 1; i < m_SceneLightsContext.GetDirectionalLightsCount(); i++ ) { TSRGlobalConstants.SetLight( 0, *m_SceneLightsContext.m_DirectionalLights[ i ] ); TSRImmediateDraw::RenderFullScreenQuad( m_pDirectionalLightShader ); } TSRVector3& vCameraSide = _pWorld->GetMainCamera()->m_Side; TSRVector3& vCameraUp = _pWorld->GetMainCamera()->m_Up; TSRVector3& vCameraFwd = _pWorld->GetMainCamera()->m_Fwd; /// point lights TSRVector3 vCameraPosition = _pWorld->GetMainCamera()->m_Loc; m_pPointLightShader->Activate(); for ( unsigned int i = 0; i < m_SceneLightsContext.GetPointLightsCount(); i++ ) { PointLightData& currLight = *m_SceneLightsContext.m_PointLights[ i ]; TSRGlobalConstants.SetLight( 0, currLight ); TSRVector3& vLightPosition = ( TSRVector3& ) currLight.m_Position; float fRadius = currLight.m_Radius.x; TSRGlobalConstants.PushMatrix(); TSRGlobalConstants.Translate( vLightPosition.x, vLightPosition.y, vLightPosition.z ); //TSRImmediateDraw::BillBoardCircle( vCameraSide, vCameraUp, vCameraFwd, fRadius * 1.1f ); TSRVector3 vCameraToLightDirection = vLightPosition - _pWorld->GetMainCamera()->m_Loc; vCameraToLightDirection.Normalize(); if ( vCameraToLightDirection.Dot( vCameraFwd ) < 0.0f ) { Graphics()->SetRasterizerState( Graphics()->m_FillDoubleSidedState ); TSRDebugDraw::RenderSphere( fRadius, m_pPointLightShader ); Graphics()->SetRasterizerState( Graphics()->m_FillSolidState ); } else { TSRImmediateDraw::BillBoardCircle( vCameraSide, vCameraUp, vCameraFwd, fRadius * 1.1f ); } TSRGlobalConstants.PopMatrix(); } /// spot lights.. for ( unsigned int i = 0; i < m_SceneLightsContext.GetSpotLightsCount(); i++ ) { SpotLightData& currSpot = *m_SceneLightsContext.m_SpotLights[ i ]; TSRGlobalConstants.SetLight( 0, currSpot ); /*Vector4& Position = currSpot.m_Position; TSRGlobalConstants.PushMatrix(); TSRGlobalConstants.Translate( Position.x, Position.y, Position.z ); Vector3 direction = currSpot.m_Direction; float angle = acosf( currSpot.m_SpotAngles.y ); float length = 1000.0f * cosf( angle ); float radius = 1000.0f * sinf( angle ); m_pSpotLightShader->Activate(); // TSRDebugDraw::RenderCone( length, radius, direction ); TSRGlobalConstants.PopMatrix(); //*/ TSRImmediateDraw::RenderFullScreenQuad( m_pSpotLightShader ); } //*/ // Graphics()->SetDepthStencilState( Graphics()->m_DefaultDepthStencilState ); /// this sets the light, so that the blended stuff coming later would have the first lights context used SetShaderConstants( m_SceneLightsContext ); }
void GaussianBlurView::AllocateResources() { // size of render targets etc is based on the size of this actor, ignoring z if(mTargetSize != mLastSize) { mLastSize = mTargetSize; // get size of downsampled render targets mDownsampledWidth = mTargetSize.width * mDownsampleWidthScale; mDownsampledHeight = mTargetSize.height * mDownsampleHeightScale; // Create and place a camera for the renders corresponding to the (potentially downsampled) render targets' size mRenderDownsampledCamera.SetFieldOfView(ARBITRARY_FIELD_OF_VIEW); // TODO: how do we pick a reasonable value for near clip? Needs to relate to normal camera the user renders with, but we don't have a handle on it mRenderDownsampledCamera.SetNearClippingPlane(1.0f); mRenderDownsampledCamera.SetAspectRatio(mDownsampledWidth / mDownsampledHeight); mRenderDownsampledCamera.SetType(Dali::Camera::FREE_LOOK); // camera orientation based solely on actor mRenderDownsampledCamera.SetPosition(0.0f, 0.0f, ((mDownsampledHeight * 0.5f) / tanf(ARBITRARY_FIELD_OF_VIEW * 0.5f))); // setup for normal operation if(!mBlurUserImage) { // Create and place a camera for the children render, corresponding to its render target size mRenderFullSizeCamera.SetFieldOfView(ARBITRARY_FIELD_OF_VIEW); // TODO: how do we pick a reasonable value for near clip? Needs to relate to normal camera the user renders with, but we don't have a handle on it mRenderFullSizeCamera.SetNearClippingPlane(1.0f); mRenderFullSizeCamera.SetAspectRatio(mTargetSize.width / mTargetSize.height); mRenderFullSizeCamera.SetType(Dali::Camera::FREE_LOOK); // camera orientation based solely on actor float cameraPosConstraintScale = 0.5f / tanf(ARBITRARY_FIELD_OF_VIEW * 0.5f); mRenderFullSizeCamera.SetPosition(0.0f, 0.0f, mTargetSize.height * cameraPosConstraintScale); // create offscreen buffer of new size to render our child actors to mRenderTargetForRenderingChildren = FrameBufferImage::New( mTargetSize.width, mTargetSize.height, mPixelFormat, Dali::Image::UNUSED ); // Set ImageActor for performing a horizontal blur on the texture mImageActorHorizBlur.SetImage( mRenderTargetForRenderingChildren ); // Create offscreen buffer for vert blur pass mRenderTarget1 = FrameBufferImage::New( mDownsampledWidth, mDownsampledHeight, mPixelFormat, Dali::Image::UNUSED ); // use the completed blur in the first buffer and composite with the original child actors render mImageActorComposite.SetImage( mRenderTarget1 ); // set up target actor for rendering result, i.e. the blurred image mTargetActor.SetImage(mRenderTargetForRenderingChildren); } // Create offscreen buffer for horiz blur pass mRenderTarget2 = FrameBufferImage::New( mDownsampledWidth, mDownsampledHeight, mPixelFormat, Dali::Image::UNUSED ); // size needs to match render target mImageActorHorizBlur.SetSize(mDownsampledWidth, mDownsampledHeight); // size needs to match render target mImageActorVertBlur.SetImage( mRenderTarget2 ); mImageActorVertBlur.SetSize(mDownsampledWidth, mDownsampledHeight); // set gaussian blur up for new sized render targets SetShaderConstants(); } }