void SpreadFilter::Enable()
{
  mCameraActor = CameraActor::New();
  mCameraActor.SetParentOrigin(ParentOrigin::CENTER);

  // create actor to render input with applied emboss effect
  mActorForInput = ImageActor::New( mInputImage );
  mActorForInput.SetParentOrigin( ParentOrigin::CENTER );
  mActorForInput.ApplyConstraint( Constraint::New<Vector3>( Actor::SIZE, ParentSource( Actor::SIZE ), EqualToConstraint() ) );
  mActorForInput.ScaleBy( Vector3(1.0f, -1.0f, 1.0f) );

  // create internal offscreen for result of horizontal pass
  mImageForHorz = FrameBufferImage::New( mTargetSize.width, mTargetSize.height, mPixelFormat, Image::Unused );

  // create an actor to render mImageForHorz for vertical blur pass
  mActorForHorz = ImageActor::New( mImageForHorz );
  mActorForHorz.SetParentOrigin( ParentOrigin::CENTER );
  mActorForHorz.ApplyConstraint( Constraint::New<Vector3>( Actor::SIZE, ParentSource( Actor::SIZE ), EqualToConstraint() ) );
  mActorForHorz.ScaleBy( Vector3(1.0f, -1.0f, 1.0f) );

  mRootActor.Add( mActorForInput );
  mRootActor.Add( mActorForHorz );
  mRootActor.Add( mCameraActor );

  std::ostringstream fragmentSource;
  if( mDebugRender )
  {
    fragmentSource << "#define DEBUG_RENDER\n";
  }
  fragmentSource << SPREAD_FRAGMENT_SOURCE;

  mShaderForHorz = ShaderEffect::New( "", fragmentSource.str() );
  mActorForInput.SetShaderEffect( mShaderForHorz );
  mShaderForHorz.SetUniform( "uSpread", mSpread );
  mShaderForHorz.SetUniform( "uTexScale", Vector2( 1.0f / mTargetSize.width, 0.0f ) );

  mShaderForVert = ShaderEffect::New( "", fragmentSource.str() );
  mActorForHorz.SetShaderEffect( mShaderForVert );
  mShaderForVert.SetUniform( "uSpread", mSpread );
  mShaderForVert.SetUniform( "uTexScale", Vector2( 0.0f, 1.0f / mTargetSize.height ) );

  SetupCamera();
  CreateRenderTasks();
}
void ShadowView::OnInitialize()
{
    // root actor to parent all user added actors. Used as source actor for shadow render task.
    mChildrenRoot.SetPositionInheritanceMode( Dali::USE_PARENT_POSITION );
    mChildrenRoot.ApplyConstraint(Constraint::New<Vector3>( Actor::SIZE, ParentSource( Actor::SIZE ), EqualToConstraint() ));

    Vector2 stageSize = Stage::GetCurrent().GetSize();
    mCameraActor = CameraActor::New(stageSize);

    mCameraActor.SetParentOrigin( ParentOrigin::CENTER );

    // Target is constrained to point at the shadow plane origin
    mCameraActor.SetNearClippingPlane( 1.0f );
    mCameraActor.SetType( Dali::Camera::FREE_LOOK ); // Camera orientation constrained to point at shadow plane world position
    mCameraActor.SetRotation(Radian(Degree(180)), Vector3::YAXIS);
    mCameraActor.SetPosition(DEFAULT_LIGHT_POSITION);

    mShadowRenderShader = ShaderEffect::New( RENDER_SHADOW_VERTEX_SOURCE, RENDER_SHADOW_FRAGMENT_SOURCE,
                          Dali::GeometryType( GEOMETRY_TYPE_IMAGE ),
                          ShaderEffect::GeometryHints( ShaderEffect::HINT_GRID | ShaderEffect::HINT_BLENDING ));

    // Create render targets needed for rendering from light's point of view
    mSceneFromLightRenderTarget = FrameBufferImage::New( stageSize.width, stageSize.height, Pixel::RGBA8888 );

    mOutputImage = FrameBufferImage::New( stageSize.width * 0.5f, stageSize.height * 0.5f, Pixel::RGBA8888 );

    //////////////////////////////////////////////////////
    // Connect to actor tree

    Self().Add( mChildrenRoot );
    Stage::GetCurrent().Add( mCameraActor );

    mBlurFilter.SetRefreshOnDemand(false);
    mBlurFilter.SetInputImage(mSceneFromLightRenderTarget);
    mBlurFilter.SetOutputImage(mOutputImage);
    mBlurFilter.SetSize(stageSize * 0.5f);
    mBlurFilter.SetPixelFormat(Pixel::RGBA8888);

    mBlurRootActor = Actor::New();

    // Turn off inheritance to ensure filter renders properly
    mBlurRootActor.SetPositionInheritanceMode(USE_PARENT_POSITION);
    mBlurRootActor.SetInheritRotation(false);
    mBlurRootActor.SetInheritScale(false);
    mBlurRootActor.SetColorMode(USE_OWN_COLOR);

    Self().Add(mBlurRootActor);

    mBlurFilter.SetRootActor(mBlurRootActor);
    mBlurFilter.SetBackgroundColor(Vector4::ZERO);

    SetShaderConstants();
}
void ImageView::Initialize()
{
  Actor self = Self();
  // Register property that represents the level of detail.
  mPropertyDetail = self.RegisterProperty(Toolkit::ImageView::DETAIL_PROPERTY_NAME, 0.0f);

  // Create an empty image actor, filling the entire size of this ImageView.
  Image emptyImage;
  mImageActor = ImageActor::New( emptyImage );
  self.Add( mImageActor );
  mImageActor.ApplyConstraint( Constraint::New<Vector3>( Actor::SIZE, ParentSource( Actor::SIZE ), EqualToConstraint() ) );
  mImageActor.SetParentOrigin( ParentOrigin::CENTER );
}
Exemple #4
0
void View::SetBackground( ImageActor backgroundImage )
{
  // Create background layer if doesn't exist.

  if( !mBackgroundLayer )
  {
    mBackgroundLayer = Layer::New();

    mBackgroundLayer.SetPositionInheritanceMode( Dali::USE_PARENT_POSITION );
    mBackgroundLayer.ApplyConstraint( Constraint::New<Vector3>( Actor::SIZE, ParentSource( Actor::SIZE ), EqualToConstraint() ) );

    // Add background layer to custom actor.
    Self().Add( mBackgroundLayer );

    // Drop the background layer

    DALI_ASSERT_ALWAYS( mBackgroundLayer.OnStage() ); // We need to be on-stage to drop the layer
    mBackgroundLayer.LowerToBottom();
  }
  else
  {
    // It removes the old background
    if( 0 < mBackgroundLayer.GetChildCount() )
    {
      mBackgroundLayer.Remove( mBackgroundLayer.GetChildAt(0) );
    }
  }

  backgroundImage.SetPositionInheritanceMode( Dali::USE_PARENT_POSITION );
  Constraint constraint = Constraint::New<Vector3>(
      Actor::SCALE,
      LocalSource( Actor::SIZE ),
      ParentSource( Actor::SIZE ),
      ScaleToFillXYKeepAspectRatioConstraint() );
  backgroundImage.ApplyConstraint( constraint );
  mBackgroundLayer.Add( backgroundImage );
}
void GaussianBlurView::OnInitialize()
{
    // root actor to parent all user added actors, needed to allow us to set that subtree as exclusive for our child render task
    mChildrenRoot.SetParentOrigin(ParentOrigin::CENTER);

    //////////////////////////////////////////////////////
    // Create shaders

    // horiz
    std::ostringstream horizFragmentShaderStringStream;
    horizFragmentShaderStringStream << "#define NUM_SAMPLES " << mNumSamples << "\n";
    horizFragmentShaderStringStream << GAUSSIAN_BLUR_FRAGMENT_SOURCE;
    mHorizBlurShader = ShaderEffect::New( "", horizFragmentShaderStringStream.str() );
    // vert
    std::ostringstream vertFragmentShaderStringStream;
    vertFragmentShaderStringStream << "#define NUM_SAMPLES " << mNumSamples << "\n";
    vertFragmentShaderStringStream << GAUSSIAN_BLUR_FRAGMENT_SOURCE;
    mVertBlurShader = ShaderEffect::New( "", vertFragmentShaderStringStream.str() );


    //////////////////////////////////////////////////////
    // Create actors

    // Create an ImageActor for performing a horizontal blur on the texture
    mImageActorHorizBlur = ImageActor::New();
    mImageActorHorizBlur.SetParentOrigin(ParentOrigin::CENTER);
    mImageActorHorizBlur.ScaleBy( Vector3(1.0f, -1.0f, 1.0f) ); // FIXME
    mImageActorHorizBlur.SetShaderEffect( mHorizBlurShader );

    // Create an ImageActor for performing a vertical blur on the texture
    mImageActorVertBlur = ImageActor::New();
    mImageActorVertBlur.SetParentOrigin(ParentOrigin::CENTER);
    mImageActorVertBlur.ScaleBy( Vector3(1.0f, -1.0f, 1.0f) ); // FIXME
    mImageActorVertBlur.SetShaderEffect( mVertBlurShader );

    // Register a property that the user can control to fade the blur in / out via the GaussianBlurView object
    mBlurStrengthPropertyIndex = Self().RegisterProperty(GAUSSIAN_BLUR_VIEW_STRENGTH_PROPERTY_NAME, GAUSSIAN_BLUR_VIEW_DEFAULT_BLUR_STRENGTH);

    // Create an ImageActor for compositing the blur and the original child actors render
    if(!mBlurUserImage)
    {
        mImageActorComposite = ImageActor::New();
        mImageActorComposite.SetParentOrigin(ParentOrigin::CENTER);
        mImageActorComposite.ScaleBy( Vector3(1.0f, -1.0f, 1.0f) ); // FIXME
        mImageActorComposite.SetOpacity(GAUSSIAN_BLUR_VIEW_DEFAULT_BLUR_STRENGTH); // ensure alpha is enabled for this object and set default value

        Constraint blurStrengthConstraint = Constraint::New<float>( mImageActorComposite, Actor::Property::COLOR_ALPHA, EqualToConstraint());
        blurStrengthConstraint.AddSource( ParentSource(mBlurStrengthPropertyIndex) );
        blurStrengthConstraint.Apply();

        // Create an ImageActor for holding final result, i.e. the blurred image. This will get rendered to screen later, via default / user render task
        mTargetActor = ImageActor::New();
        mTargetActor.SetParentOrigin(ParentOrigin::CENTER);
        mTargetActor.ScaleBy( Vector3(1.0f, -1.0f, 1.0f) ); // FIXME


        //////////////////////////////////////////////////////
        // Create cameras for the renders corresponding to the view size
        mRenderFullSizeCamera = CameraActor::New();
        mRenderFullSizeCamera.SetParentOrigin(ParentOrigin::CENTER);


        //////////////////////////////////////////////////////
        // Connect to actor tree
        Self().Add( mImageActorComposite );
        Self().Add( mTargetActor );
        Self().Add( mRenderFullSizeCamera );
    }


    //////////////////////////////////////////////////////
    // Create camera for the renders corresponding to the (potentially downsampled) render targets' size
    mRenderDownsampledCamera = CameraActor::New();
    mRenderDownsampledCamera.SetParentOrigin(ParentOrigin::CENTER);


    //////////////////////////////////////////////////////
    // Connect to actor tree
    Self().Add( mChildrenRoot );
    Self().Add( mImageActorHorizBlur );
    Self().Add( mImageActorVertBlur );
    Self().Add( mRenderDownsampledCamera );
}