Hi guys
I've searched the forums in and out, but can't seem to find any way of masking images in gideros.
The answers I've found seem to be workarounds, but I'm not sure whether that info is still relevant, or whether masks are now possible.
Thank you heaps for your help!
Comments
There is a few ways to achieve masking in OpenGL:
- Using stencil buffer to impress a mask picture and then render others shapes only in places where stencil was marked. This is the technique used by Path2D. It allows precise masking at the expense of a double rendering pass. This is not (yet) exposed to lua by Gideros
- Using alpha blending composition: you can multiply a mask bitmap with a regular Sprite. This is already available in Gideros and is most of the time faster than the first technique.
- Using shader (like in the vignette exemple I sent you): probably the fastest way.
Thank you for the answers, I will have a look at the vignette example as soon as I can get the sharers working
I've had a look at your example, but to be honest I have no idea what any of the values mean, lol. I think I would need to go through some sort of manual, in order to understand how to make shaders.
If anyone would be able to show me a small example how to do this using blending modes, I would be eternally grateful
Thanks you very much for all your help - you guys rock!
Sorry for pop up again,
I have an image png and I want to make 6 part (2*3) from this image by using mask images (They are not square nor rectangle but like the jigsaw puzzle). How can I do this in Gideros, at this time (I see many new apis added so I hope it will be easy now)
(Example mask shape and game that I want to make: https://play.google.com/store/apps/details?id=com.kristanix.android.jigsawpuzzleepic)
Thank so much!
A recent feature is that you can now select a region of the bitmap using render target.
I did a similar thing in Grammar Smash English for the smashing effect.
In my game, the mask is defined and are fixed images (As I attach bellow). So basically, I think it can not create by vector shape using path2D?
The first way is using rendertargets and alpha blending: create a render target, draw your image on it, then draw the mask right above using multiply blending mode, so that white pixels in the mask will leave underlying color untouched and black pixels will turn them to black. Better: if the mask 'black' color could be actually transparent, then your rendertarget cutted part shall become transparent too.
The second way would be to use a shader with double texture input (image and mask): the shader would then automatically eliminate masked pixels, but shaders are still not completely portable, meaning that you need to write a GLSL one (for open gl based platforms) and an HLSL one (for windows RT/UWP).
Likes: vitalitymobile
Yes, thank so much I follow the first way and have resulted as expected.
The remain jobs are change black to transparent and check for touch area of pieces (Do not allow user to hold transparent area to move the piece )
In theory, the second method would be great if we can write both GLSL and HLSL and put it into Gideros API as simple setMask Method
(From Mask Requirement session here https://docs.coronalabs.com/guide/media/imageMask/index.html
I guess they use your the second way in above comment
)
Thank so much!
Likes: antix
Likes: simwhi, vitalitymobile
https://github.com/gideros/gideros
https://www.youtube.com/c/JohnBlackburn1975
Could you please show me "shader program" to using this file bellow as the mask and then apply into an image?
(I just playing with http://giderosmobile.com/forum/discussion/6816/how-to-create-a-circle-transition-with-transparency#Item_2
But can not procedure the result
)
Thank!
Likes: keszegh, vitalitymobile, antix, SinisterSoft
Likes: pie, vitalitymobile, simwhi, totebo
Fragmenter - animated loop machine and IKONOMIKON - the memory game
How can I modify relate x,y position of the mask in the image (I mean reposition mask in the image so that we have difference parts)?
So assuming you want to map ix,iy,iw,ih source rect of your image to your jigsaw piece, x,y,w,h could be computed like this:
Likes: SinisterSoft
It works! You are the Master of math and the King of shader. Two achievements!
Likes: hgy29, SinisterSoft, totebo, muro
Likes: vitalitymobile, pie
piece:setTexture(jigsaw,1)
Can I make 16 TextureRegion from main texture (jigsaw) and then set TextureRegion to piece instead of the main texture?
piece:setTexture(one_jigsaw_texture_region,1)
(I try it but it does not work maybe because of class TextureRegion is not the child of class TextureBase)
Thanks!
Now I am implementing drag piece, how can I get alpha or something similar to avoid user drag when clicking on the transparent area (black area of mask image)?
(Like this idea: http://giderosmobile.com/forum/discussion/6561/bitmapx-bitmap-class-with-pixel-perfect-hit-detection/p1)
( piece is Pixel class: local piece=Pixel.new(Texture.new(mask_path,true),544,544))
Likes: vitalitymobile