Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

LinearGradientBrush horizontal vs. vertical

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    LinearGradientBrush horizontal vs. vertical

    Experimenting with SharpDX.Direct2D1.LinearGradientBrush, as described in this thread http://ninjatrader.com/support/forum...ad.php?t=83447 I find that horizontal gradients make smooth transitions, whereas vertical ones do not.
    The jagged gradient is most apparent when the opacity is less than 100%. The attached image displays the problem.
    Attached Files

    #2
    Hello,

    Thank you for the image.

    I would be interested to see how the drawing is being done in this case.

    Is this one rectangle being colored or multiple rectangles in this image?

    If there are multiple rectangles, this may be able to be explained. If there is a single rectangle in both cases, I would like to see the code to draw one rectangle in the same manor to test. If you could provide a sample that simply draws a single rectangle with the gradient you are using for the image I would be happy to take a look into this.


    I look forward to being of further assistance.
    JesseNinjaTrader Customer Service

    Comment


      #3
      Originally posted by NinjaTrader_Jesse View Post
      Is this one rectangle being colored or multiple rectangles in this image?
      If there are multiple rectangles, this may be able to be explained.
      In the jagged gradient, there are two rectangles. For example, in the 13:03 bar, the top rectangle is between 2170.50 and 2171.00 and the bottom rectangle is between 2170.50 and 2170.00. The top gradient should be from white to green, while the bottom one should be from white to red.

      I experimented with a single rectangle instead of two and the gradient is smooth. The attached image shows this.

      So, is there a problem using gradients with more than one rectangle to fill?
      Attached Files

      Comment


        #4
        Hello,

        Thank you for the reply.

        This is interesting, I was kind of expecting either one rectangle or a few for each notable rectangular gradient in the image.

        Based on what you are currently doing, I am not certain on the outcome and would need to see the syntax being used to know what may be happening.

        If using one rectangle works, where two does not and you are sharing a gradient:
        So, is there a problem using gradients with more than one rectangle to fill?
        There may be a problem re-using the same gradient, but again this is just a guess based on what you have provided. You could test this by using a completely separate new gradient for the second rectangle.

        Otherwise if you can provide a sample that draws a single rectangle with the gradient you are using that does not work, I could look further into that as well.

        I look forward to being of further assistance.
        JesseNinjaTrader Customer Service

        Comment


          #5
          I tried eliminating one of the rectangles entirely. Then, I tried using two separate LinearGradientBrush objects, one for each rectangle. The resulting gradients look identical to what I've been seeing: the jaggedness begins to appear when I reduce opacity to 10%. Above that, the gradients appear smooth. Then, however, the problem becomes one of obscuring that which I'm also rendering. See the attached image, which has opacity set to 25%.

          Notice how the opacity decreases from left to right. My guess is that, with TickReplay true (and it needs to be true for this indicator), the gradient gets redrawn on top of itself again and again.

          Is there any way to overcome these obstacles?
          • Perhaps to prevent redrawing existing gradients?
          • Perhaps to force a specific z-order for RenderTarget drawing objects created in the overridden OnRender method?


          Originally posted by NinjaTrader_Jesse View Post
          There may be a problem re-using the same gradient, but again this is just a guess based on what you have provided. You could test this by using a completely separate new gradient for the second rectangle.
          Attached Files

          Comment


            #6
            Hello,

            At this point I would need to see the syntax being used to be able to provide anything further.

            I am not seeing anything apparent with what you are describing, and without testing further I could not really say what may be happening.

            If you could provide a sample that demonstrates drawing a single rectangle along with 1 gradient that shows this would be sufficient. I would not need to see any other logic in the current script so a new sample with only the drawing would be suggested.



            I look forward to being of further assistance.
            JesseNinjaTrader Customer Service

            Comment


              #7
              Originally posted by NinjaTrader_Jesse View Post
              If you could provide a sample that demonstrates drawing a single rectangle along with 1 gradient that shows this would be sufficient. I would not need to see any other logic in the current script so a new sample with only the drawing would be suggested.
              Here you go. It's a clone of your VolumeProfile indicator with gradient highlighting added that demonstrates both the "jagged" and "obscuring" issues.
              Attached Files

              Comment


                #8
                Hello,

                Thank you for supplying the sample, unfortunately I am unable to see the same outcome using this sample in any of the ways I have tested so far.

                I have attached an image of the result I am getting but I am not seeing any distortion of the gradient. I had tried various data series and scales but have not seen the same. The image was from a chart

                Are you only able to see this while utilizing this full indicator or can you also see this if you draw a gradient on a single rectangle and apply opacity? If you have not yet, I would suggest to reduce the code to only creating a single gradient and creating a single rectangle. If it can not be reproduced using a single occurrence, this may have something to do with the logic of the script. Otherwise if you are still able to see this using a single rectangle, I could test that and compare results. This would better tell us where the problem is and why I am unable to see this.

                I look forward to being of further assistance.
                Attached Files
                JesseNinjaTrader Customer Service

                Comment


                  #9
                  I get the same jaggedness with either one or two rectangles. I'm attaching modified code that lets you select the number of rectangles. Within the zip file, I am also including a workspace with two charts as shown in the screenshot.

                  Near as I can tell, this problem surfaces when TickReplay is true, and both OnMarketData and OnRender are overridden. This is why I chose your VolumeProfile indicator, since it appears to the the only built-in that covers all the bases.

                  Originally posted by NinjaTrader_Jesse View Post
                  Are you only able to see this while utilizing this full indicator or can you also see this if you draw a gradient on a single rectangle and apply opacity? If you have not yet, I would suggest to reduce the code to only creating a single gradient and creating a single rectangle. If it can not be reproduced using a single occurrence, this may have something to do with the logic of the script. Otherwise if you are still able to see this using a single rectangle, I could test that and compare results. This would better tell us where the problem is and why I am unable to see this.
                  Attached Files

                  Comment


                    #10
                    Hello,

                    Thank you for providing this sample.

                    While I can not recreate what you are seeing by just running the script, I do actually see the effect while I resize the window and then it is back to normal when i release the mouse. Outside of resizing I do not see the same effect.

                    Based on seeing the effect happening during the resize. I will submit this to development for further review.


                    I look forward to being of further assistance.
                    JesseNinjaTrader Customer Service

                    Comment


                      #11
                      Originally posted by NinjaTrader_Jesse View Post
                      While I can not recreate what you are seeing by just running the script, I do actually see the effect while I resize the window and then it is back to normal when i release the mouse. Outside of resizing I do not see the same effect. Based on seeing the effect happening during the resize. I will submit this to development for further review.
                      That is very strange, you seeing different behavior than I do. Do you think this is a hardware issue? Or a Windows 7 64-bit issue?

                      Comment


                        #12
                        Hello,

                        Honestly I'm not too sure at this point as you said the result is different which is confusing. Because this deals with Rendering, it could be related to hardware /differences in graphics cards/versions of windows etc. Or it could be related to logic used/internal logic. I will need to explore this further to find a more specific cause of the blocky rendering on the gradient.

                        Once I have further details on this, I will post my findings back here.

                        I look forward to being of further assistance.
                        JesseNinjaTrader Customer Service

                        Comment


                          #13
                          Originally posted by NinjaTrader_Jesse View Post
                          Honestly I'm not too sure at this point as you said the result is different which is confusing. Because this deals with Rendering, it could be related to hardware /differences in graphics cards/versions of windows etc. Or it could be related to logic used/internal logic. I will need to explore this further to find a more specific cause of the blocky rendering on the gradient.
                          I had an associate test this on a different and newer machine, and he sees the same gradient segmentation that I do.
                          Attached Files

                          Comment


                            #14
                            Hello,

                            Thank you for the additional details.

                            After looking at the sample further, it seems this is related to the logic being used.

                            I had tried testing using a single rectangle with a gradient first and could not produce the effect.
                            Next I had tried a loop with multiple rectangles being offset and overlapped, I can still not see the effect.
                            Next using the loop and also adjusting the StartPoint and EndPoint locations I am able to see some results or blocky gradient while I resize the window.

                            I will need to continue looking into this to understand what specifically may be happening, but it does seem to be related to drawing multiple gradients over eachother and then adjusting the Start and End points seem to play a role in causing the effect.



                            I look forward to being of further assistance.
                            JesseNinjaTrader Customer Service

                            Comment


                              #15
                              What operating system are you using? Win10? Win7?
                              Originally posted by NinjaTrader_Jesse View Post
                              Next using the loop and also adjusting the StartPoint and EndPoint locations I am able to see some results or blocky gradient while I resize the window.

                              I will need to continue looking into this to understand what specifically may be happening, but it does seem to be related to drawing multiple gradients over each other and then adjusting the Start and End points seem to play a role in causing the effect.

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by RDTrader16, Today, 10:19 PM
                              0 responses
                              5 views
                              0 likes
                              Last Post RDTrader16  
                              Started by gemify, 03-08-2023, 08:02 AM
                              9 responses
                              148 views
                              0 likes
                              Last Post culpepper  
                              Started by elirion, Today, 10:03 PM
                              0 responses
                              2 views
                              0 likes
                              Last Post elirion
                              by elirion
                               
                              Started by RaddiFX, Today, 09:55 PM
                              0 responses
                              10 views
                              0 likes
                              Last Post RaddiFX
                              by RaddiFX
                               
                              Started by Trader146, 03-29-2024, 01:22 PM
                              4 responses
                              27 views
                              0 likes
                              Last Post Trader146  
                              Working...
                              X