locked
Direct2D: Custom source effect RRS feed

  • Question

  • Is it even possible to create a custom source effect (like flood  or turbulence) using Direct2D?

    I have some experience on custom effects, I have created quite a few but they always need at least one input source.

    I wasn't able to find any information on custom source effects at all. Does anyone have any information at all about it?



    • Edited by Kostas_76 Monday, September 19, 2016 1:24 PM
    Monday, September 19, 2016 1:22 PM

Answers

  • Having researched this for you, I have to agree, there is not a lot of information to learn from. Apart from the link that Li posted and the D2DCustomEffects sample, there is nothing else that appears to be helpful.

    It might be worth posting in the Windows Desktop SDK forum and hope to get the attention of someone knowledgeable like Chuck Walbourn.

    Sorry.


    Cheers
    Eddie

    • Proposed as answer by DotNet Wang Tuesday, September 27, 2016 7:25 AM
    • Marked as answer by Xavier Xie-MSFT Tuesday, October 11, 2016 1:45 AM
    Sunday, September 25, 2016 5:54 PM
  • Thanks.
    • Marked as answer by Kostas_76 Thursday, November 24, 2016 12:58 PM
    Sunday, September 25, 2016 6:58 PM

All replies

  • Hi kostas_76,

    thanks for posting here.

    Direct2D ships with a library of effects that perform a variety of common image operations. See the built-in effects topic for the complete list of effects. For functionality that cannot be achieved with the built-in effects, Direct2D allows you to write your own custom effects using standard HLSL. You can use these custom effects alongside the built-in effects that ship with Direct2D.

    For more information, please refer to this document.

    https://msdn.microsoft.com/en-us/library/windows/desktop/jj710194(v=vs.85).aspx

    Hope this could be help of you.

    Best Regards,
    Li Wang


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Friday, September 23, 2016 1:17 AM
  • Thanks Li Wang,

    I am aware of this but it says nothing how to create a custom source effect.

    Thanks anyway.


    Friday, September 23, 2016 11:26 AM
  • I have some experience on custom effects, I have created quite a few but they always need at least one input source.

    That's what an "effect" is. It takes an "input source" and adds an effect to it.

    If you don't what to use an input then it sounds like you want to create an image from scratch.

    Could you describe your intended workflow in more detail to help us better understand your goal?


    Cheers
    Eddie

    Friday, September 23, 2016 3:42 PM
  • Hi Eddie,

    "That's what an "effect" is. It takes an "input source" and adds an effect to it."

    this is not quite true. Here is the link to built in effects: https://msdn.microsoft.com/en-us/library/windows/desktop/hh706316(v=vs.85).aspx

    if you goto ""Source" section you will see these effects: Bitmap source effect, Flood effect, Turbulence effcet. These 3 require no input as source.

    Now about what I am trying to create. I have created a few effects that require no input (for example cellular noise if you are familiar).

    In order to make it work I create a dummy bitmap and I gave it as input. The effects work fine but they don't actually need any input since they don't use it. So there is no real need to give a dummy input. It obviously can be done (see bitmap source, flood, turbulence) but I don't now how and I can not find any information about it at all.

    Thanks for your time.


    Sunday, September 25, 2016 11:48 AM
  • I apologize, you are correct, my reading of the documentation was incomplete.

    When you create your custom effect are you implementing ID2D1Effect or ID2D1EffectImpl?

    Also, what are you including in your metadata string?


    Cheers
    Eddie

    Sunday, September 25, 2016 3:52 PM
  • All needed interfaces (ID2D1Effect, ID2D1EffectImpl, ID2D1DrawTransform...).

    As I said before I have created lots of effects that have sources and they work fine. The problem is the "sourceless" effects.

    I had two plans on how to make it work, unfortunatelly they both failed.

    1. I tried to return 0 to ID2D1Transform's GetInputCount method so the effect does not use any input at all. Unfortunatelly it failed.

    All I get is black for output. There is not much help at msdn's page about it: https://msdn.microsoft.com/en-us/library/windows/desktop/hh404582(v=vs.85).aspx

    2. I tried to create a 2-step graph (like https://msdn.microsoft.com/en-us/library/windows/desktop/jj710194%28v=vs.85%29.aspx?f=255&MSPPError=-2147217396 under: Creating a multi-node transform graph)

    For first node I used built in flood effect (CLSID_D2D1Flood) which requires no source and the second node was my effect. So the whole effect would not need any source since my effect's source would be built in flood and flood needs no input. This was not a complete failure. I got output but with several problems. Actually every time I use the effect it seemed as if pixel shader's texelSpaceInput0 had random range.

    About the metadata I tried to implement several effects fearing that the actual effect's code is the problem. (It isn't). The latest tests are not using any properties at all (so I set no metadata). For the latest tests I use this minimal shader:

    // Test pixel shader
    float4 main(float4 clipSpaceOutput : SV_POSITION,float4 sceneSpaceOutput : SCENE_POSITION, float4 texelSpaceInput0 : TEXCOORD0) : SV_Target
    {
    return float4(texelSpaceInput0.x,texelSpaceInput0.y,0,1);
    }

    *I have tested dozens of different effects (with different shaders and properties each one) and effects that actually work if I use sources for them. I am sure that the problem is not on the effect code. Propably different setup is required for "sourceless" effects.

    Sunday, September 25, 2016 5:44 PM
  • Having researched this for you, I have to agree, there is not a lot of information to learn from. Apart from the link that Li posted and the D2DCustomEffects sample, there is nothing else that appears to be helpful.

    It might be worth posting in the Windows Desktop SDK forum and hope to get the attention of someone knowledgeable like Chuck Walbourn.

    Sorry.


    Cheers
    Eddie

    • Proposed as answer by DotNet Wang Tuesday, September 27, 2016 7:25 AM
    • Marked as answer by Xavier Xie-MSFT Tuesday, October 11, 2016 1:45 AM
    Sunday, September 25, 2016 5:54 PM
  • Thanks.
    • Marked as answer by Kostas_76 Thursday, November 24, 2016 12:58 PM
    Sunday, September 25, 2016 6:58 PM