Shaders Can I reshape regular shapes?

Sam04

Member
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).



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.
 

sp202

Member
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.
 

Sam04

Member
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.
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?
 
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.
 

sp202

Member
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?
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.
 
Top