Beispiel #1
0
void ShadowView::SetShaderConstants()
{
  Property::Index lightCameraProjectionMatrixPropertyIndex = mShadowPlane.RegisterProperty( SHADER_LIGHT_CAMERA_PROJECTION_MATRIX_PROPERTY_NAME, Matrix::IDENTITY );
  Constraint projectionMatrixConstraint = Constraint::New<Dali::Matrix>( mShadowPlane, lightCameraProjectionMatrixPropertyIndex, EqualToConstraint() );
  projectionMatrixConstraint.AddSource( Source( mCameraActor, CameraActor::Property::PROJECTION_MATRIX ) );
  projectionMatrixConstraint.Apply();

  Property::Index lightCameraViewMatrixPropertyIndex = mShadowPlane.RegisterProperty( SHADER_LIGHT_CAMERA_VIEW_MATRIX_PROPERTY_NAME, Matrix::IDENTITY );
  Constraint viewMatrixConstraint = Constraint::New<Dali::Matrix>( mShadowPlane, lightCameraViewMatrixPropertyIndex, EqualToConstraint() );
  viewMatrixConstraint.AddSource( Source( mCameraActor, CameraActor::Property::VIEW_MATRIX ) );
  viewMatrixConstraint.Apply();

  mShadowColorPropertyIndex = mShadowPlane.RegisterProperty( SHADER_SHADOW_COLOR_PROPERTY_NAME, mCachedShadowColor );
}
Beispiel #2
0
void ShadowView::ConstrainCamera()
{
  if( mPointLight && mShadowPlane )
  {
    // Constrain camera to look directly at center of shadow plane. (mPointLight position
    // is under control of application, can't use transform inheritance)

    Constraint cameraOrientationConstraint = Constraint::New<Quaternion> ( mCameraActor, Actor::Property::ORIENTATION, &LookAt );
    cameraOrientationConstraint.AddSource( Source( mShadowPlane, Actor::Property::WORLD_POSITION ) );
    cameraOrientationConstraint.AddSource( Source( mPointLight,  Actor::Property::WORLD_POSITION ) );
    cameraOrientationConstraint.AddSource( Source( mShadowPlane, Actor::Property::WORLD_ORIENTATION ) );
    cameraOrientationConstraint.Apply();

    Constraint pointLightPositionConstraint = Constraint::New<Vector3>( mCameraActor, Actor::Property::POSITION, EqualToConstraint() );
    pointLightPositionConstraint.AddSource( Source( mPointLight, Actor::Property::WORLD_POSITION ) );
    pointLightPositionConstraint.Apply();
  }
}
  /**
   * Invoked upon creation of application
   * @param[in] application The application instance
   */
  void Create( Application& application )
  {
    Stage::GetCurrent().KeyEventSignal().Connect(this, &ExampleController::OnKeyEvent);

    mStageSize = Stage::GetCurrent().GetSize();

    // The Init signal is received once (only) during the Application lifetime

    // Hide the indicator bar
    application.GetWindow().ShowIndicator( Dali::Window::INVISIBLE );

    // Creates a default view with a default tool bar.
    // The view is added to the stage.
    Toolkit::ToolBar toolBar;
    mContent = DemoHelper::CreateView( application,
                                       mView,
                                       toolBar,
                                       BACKGROUND_IMAGE,
                                       TOOLBAR_IMAGE,
                                       APPLICATION_TITLE );

    mContent.SetLeaveRequired(true);
    mContent.TouchSignal().Connect( this, &ExampleController::OnTouched );

    // Create magnifier (controlled by human touch)
    Layer overlay = Layer::New();
    overlay.SetSensitive(false);
    overlay.SetParentOrigin( ParentOrigin::CENTER );
    overlay.SetSize(mStageSize);
    Stage::GetCurrent().Add(overlay);

    mMagnifier = Toolkit::Magnifier::New();
    mMagnifier.SetSourceActor( mView );
    mMagnifier.SetSize( MAGNIFIER_SIZE * mStageSize.width );  // Size of magnifier is in relation to stage width
    mMagnifier.SetProperty( Toolkit::Magnifier::Property::MAGNIFICATION_FACTOR, MAGNIFICATION_FACTOR );
    mMagnifier.SetScale(Vector3::ZERO);
    overlay.Add( mMagnifier );

    // Apply constraint to animate the position of the magnifier.
    Constraint constraint = Constraint::New<Vector3>( mMagnifier, Actor::Property::POSITION, ConfinementConstraint(Vector3( 0.5f, 0.5f, 0.0f ), Vector2::ONE * MAGNIFIER_INDENT, Vector2::ONE * MAGNIFIER_INDENT) );
    constraint.AddSource( LocalSource(Actor::Property::SIZE) );
    constraint.AddSource( LocalSource(Actor::Property::PARENT_ORIGIN) );
    constraint.AddSource( LocalSource(Actor::Property::ANCHOR_POINT) );
    constraint.AddSource( ParentSource(Actor::Property::SIZE) );
    constraint.SetRemoveAction(Constraint::Discard);
    constraint.Apply();

    // Create bouncing magnifier automatically bounces around screen.
    mBouncingMagnifier = Toolkit::Magnifier::New();
    mBouncingMagnifier.SetSourceActor( mView );
    mBouncingMagnifier.SetSize( MAGNIFIER_SIZE * mStageSize.width ); // Size of magnifier is in relation to stage width
    mBouncingMagnifier.SetProperty( Toolkit::Magnifier::Property::MAGNIFICATION_FACTOR, MAGNIFICATION_FACTOR );
    overlay.Add( mBouncingMagnifier );

    mAnimationTimeProperty = mBouncingMagnifier.RegisterProperty("animationTime",  0.0f);
    ContinueAnimation();

    // Apply constraint to animate the position of the magnifier.
    constraint = Constraint::New<Vector3>( mBouncingMagnifier, Actor::Property::POSITION, MagnifierPathConstraint(mStageSize, mStageSize * 0.5f) );
    constraint.AddSource( LocalSource(Actor::Property::SIZE) );
    constraint.AddSource( LocalSource(mAnimationTimeProperty) );
    constraint.Apply();

    // Apply constraint to animate the source of the magnifier.
    constraint = Constraint::New<Vector3>( mBouncingMagnifier, Toolkit::Magnifier::Property::SOURCE_POSITION, MagnifierPathConstraint(mStageSize) );
    constraint.AddSource( LocalSource(Actor::Property::SIZE) );
    constraint.AddSource( LocalSource(mAnimationTimeProperty) );
    constraint.Apply();
  }
Beispiel #4
0
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.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );

  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.SetOrientation(Radian(Degree(180)), Vector3::YAXIS);
  mCameraActor.SetPosition(DEFAULT_LIGHT_POSITION);


  Property::Map customShader;
  customShader[ "vertex-shader" ] = RENDER_SHADOW_VERTEX_SOURCE;
  customShader[ "fragment-shader" ] = RENDER_SHADOW_FRAGMENT_SOURCE;

  customShader[ "subdivide-grid-x" ] = 20;
  customShader[ "subdivide-grid-y" ] = 20;

  customShader[ "hints" ] = "output-is-transparent";

  mShadowRenderShader[ "shader" ] = customShader;

  // 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();
  mBlurRootActor.SetName( "BLUR_ROOT_ACTOR" );

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

  Self().Add(mBlurRootActor);

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

  CustomActor self = Self();
  // Register a property that the user can use to control the blur in the internal object
  mBlurStrengthPropertyIndex = self.RegisterProperty(BLUR_STRENGTH_PROPERTY_NAME, BLUR_STRENGTH_DEFAULT);

  Constraint blurStrengthConstraint = Constraint::New<float>( mBlurFilter.GetHandleForAnimateBlurStrength(), mBlurFilter.GetBlurStrengthPropertyIndex(), EqualToConstraint() );
  blurStrengthConstraint.AddSource( Source( self, mBlurStrengthPropertyIndex) );
  blurStrengthConstraint.Apply();
}
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 );
}