1. Hey! Guest! The 35th GMC Jam will take place between November 28th, 12:00 UTC - December 2nd, 12:00 UTC. Why not join in! Click here to find out more!
    Dismiss Notice

Shaders Can I reshape regular shapes?

Discussion in 'Programming' started by Sam04, Jan 9, 2019.

  1. Sam04

    Sam04 Member

    Joined:
    Nov 26, 2018
    Posts:
    28
    Hello everyone. This is more a couple of questions about if something can be done instead of a problem I have.

    First, I know I can draw simple shapes with the regular drawing functions and weird ones with the primitive functions. I have this situation in which I want to draw a rectangle with a dent in it (as exemplified in the first image). One solution is to draw it as a primtive, or to draw it as the sum of various simple shapes (in the second image I exemplify how I would break it down).

    [​IMG] [​IMG]

    So, my questions are:
    1. Can this be done with shaders?
      1. If yes, would it be better to do it with shaders or with the regular drawing functions I proposed?
      2. What about other more advanced gpu functions? (Something like the dynamic rendering masks shown here https://www.yoyogames.com/blog/430/dynamic-rendering-masks)
    2. If the dent was half a circle instead of a triangle shape I would replace the triangles with a bunch of lines. Would the same answers apply to this case?
    3. Can it be done if instead of being a dent (inwards) it would be a bulge (outwards)?
    4. If these things can be done in several ways
      1. Which option is better for the end user performance?
      2. Which one would be easier to code on a fixed, specific scenario? (A scenario where the end picture will always be the same to the point that I might as well use a sprite).
      3. Which one would be easier to code on a dynamic scenario? (A scenario where I can choose and even change mid-game the parameters of the deformation be it size, shape, and/or position)
    If you have an example or a tutorial with the information I require that would be amazing. But really I just want to know if it is possible and if it would be better so I can start learning about it.

    Thank you in advance for your time and your replies.
     
  2. sp202

    sp202 Member

    Joined:
    Sep 26, 2016
    Posts:
    967
    Look into surfaces and blend modes, you can use the subtract blend mode to cut out pieces, so you could draw a square and then draw a triangle with the subtract blend mode to create the dent.
     
  3. Sam04

    Sam04 Member

    Joined:
    Nov 26, 2018
    Posts:
    28
    Great! thanks a lot. I'll check it out.

    But, will it work also if I want to make a bulge? What about if I want to twist a line? Or if, for example, I want to draw the outline of the new figure wouldn't that just make a part of the outline dissapear instead of bending itself to accomodate to the new figure?
     
  4. The Reverend

    The Reverend Member

    Joined:
    Sep 8, 2016
    Posts:
    557
    The surface approach @sp202 mentioned is a rather easy way and depending on what exactly you want to do a good way to do this.

    If you want to use primitives and dynamics using the vertex shader, this video will teach you the basics:


    You'll learn creating primitives and manipulating vertices inside the GPU. but be warned, that get's complicated very quickly and the video is only showing techniques but not a solution to your request.
     
  5. sp202

    sp202 Member

    Joined:
    Sep 26, 2016
    Posts:
    967
    There isn't one method that works for everything, you'll have to use various techniques depending on the effect you want. If you want a bulge, depending on its complexity you could just draw two shapes.
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice