Err okay my bad, I didn't really read the first post fully (or just read it incorrectly)
With the mesh, I suppose you could create the shape, assign the texture to the mesh, copy that to a RenderTarget, and then use that as a texture for your bitmap.
You could also use a shape but they are a bit munty because they don't get filtering.
@totebo, here's what I have in mind: 1) Build a square mesh to display your bitmap 2) apply the bitmap to it with Mesh:setTexture() 3) attach your pattern as a second texture with Mesh:setTextureSlot(1,) 4) attach a shader to the mesh for combining texture 0 (bitmap) and texture 1 (pattern) while rendering. The shader fragment would do something like multiplying both textures contents. I'll try to come with a practical implementation later.
Sure, I didn't want to pre process your images, but this can be changed in the shader easily. In the fragment shader, I current check if red channel>0.9 as a threshold for masked/unmasked parts. If you ensure alpha=0 for masked parts and alpha=1 for visible ones, then the shader code is even simpler: replace the whole if/else block by frag.rgba=frag.aaaa and you're done.
That is AWESOME. It supports semi-transparency, which means smooth edges. This should be simplified and highlighted as a major feature of Gideros I reckon.
@hgy29 my plan is to apply textures to many bitmaps. With the current implementation it seems I can only apply it to one bitmap, and when I try to apply it to the second bitmap nothing happens. Is this how the shader works?
Found the issue: I created a new shader each time I attempted to apply it. Then only the first shader worked, and subsequent (identical) shaders had no effect.
I solved it by creating a global shader that all objects use.
All works now, amazing. One niggle I have is with the anti-aliasing. Please see below for with and without texture applied. @hgy29, is there anything I can do to make it smoother?
Would it be possible to mask the bitmap with the texture bitmap (see first message), rather than masking a repeated texture?
I think this would actually work better for me, because I then get more control over width and height of the pattern. It would also allow me to use a spritesheet, rather than a png in the library.
Comments
Dislikes: rodri
How would the Mesh method work practically?
With the mesh, I suppose you could create the shape, assign the texture to the mesh, copy that to a RenderTarget, and then use that as a texture for your bitmap.
You could also use a shape but they are a bit munty because they don't get filtering.
Maybe I need to trace the Bitmap (a tool for tracing bitmaps was posted the other day) and use that as a Shape with a Texture?
@hgy29, how would your mesh method work?
Likes: antix
1) Build a square mesh to display your bitmap
2) apply the bitmap to it with Mesh:setTexture()
3) attach your pattern as a second texture with Mesh:setTextureSlot(1,)
4) attach a shader to the mesh for combining texture 0 (bitmap) and texture 1 (pattern) while rendering.
The shader fragment would do something like multiplying both textures contents.
I'll try to come with a practical implementation later.
Likes: antix
Likes: antix, totebo
It looks like you're "popping" the white colour in bitmap.png. I suppose this is done by the shader. Would it be possible to instead use transparency?
Likes: keszegh, hgy29
I solved it by creating a global shader that all objects use.
Likes: hgy29, antix
Likes: n1cke
Likes: antix, n1cke
Without texture:
With texture:
fShader.hlsl:
fShader.glsl:
I think this would actually work better for me, because I then get more control over width and height of the pattern. It would also allow me to use a spritesheet, rather than a png in the library.