It looks like you're new here. If you want to get involved, click one of these buttons!
local topTex = Texture.new("top.png",true) local btmTex = Texture.new("btm.png",true) lh @ 10 -- label height local w = (application:getDeviceWidth() - lh) / 11 local h = (application:getDeviceHeight() - lh) / 11 local s = math.min(w, h) for x = 1, 11 do for y = 1, 11 do local top = Pixel.new(topTex, s, s) local btm = Pixel.new(btmTex, s, s) stage:addChild(btm) btm:addChild(top) btm:setBlendMode(x, y) btm:setPosition(lh + s * (x-1), lh + s * (y-1)) end end local t = {} for k,v in pairs(Sprite) do if tonumber(v) == v then t[v] = k end end for n = 1, 11 do local label = TextField.new(nil, t[n], "|") label:setX(lh + (n-1) * s + 2) label:setY(1) label:setClip(0, 0, s - 2, lh) stage:addChild(label) local line = Pixel.new(0x666666, 1, 1, lh + 11*s) line:setX(lh + n * s) stage:addChild(line) end for n = 1, 11 do local label = TextField.new(nil, t[n], "|") label:setY(lh + (n-0) * s - 2) label:setX(1) label:setRotation(-90) label:setClip(0, 0, s - 2, lh) stage:addChild(label) local line = Pixel.new(0x666666, 1, lh + 11*s, 1) line:setY(lh + n * s) stage:addChild(line) end |
Likes: totebo, pie, SinisterSoft, Apollo14
Comments
I can grasp the @ macro, Pixel and setBlendMode. What I don't get is the little bit in the middle.
for k,v in pairs(Sprite) do
if tonumber(v) == v then t[v] = k end
end
I don't think I've ever seen someone iterate over Sprite before. What exactly are you doing (besides generating the 11-item table)? Can you iterate over other classes/objects? Why does it show the BlendModes when you do this?
Thanks in advance.
John
Since I know Sprite contains numeric constants (1 to 11) only for blend functions I can iterate over Sprite class and when value is a number I am adding it to reverse table: that number becomes a key and that Sprite key becomes a value. In the end I have following table:
t = {
[1] = "ZERO",
[2] = "ONE",
[3] = "SRC_COLOR"
.....
}
And I use that strings as labels on the top and on the left side of the example app.
In Gideros each Sprite class and subclass is represented as a Lua table. Try to iterate over some class with `for k,v in pairs(some_class) do print(k,v) end` and you will see it's methods, constants, etc. That's why we can easily create new subclasses: we are using usual Lua tables and we can store anything we want in them.
I just wasn't sure why the Sprite class returns the blend constants, but once you know, it's definitely an elegant way to display everything.
Great example and thanks for the explanation.
At the beginning, only setBlendFunc is available, setBlendMode is just a simplified function for setBlendFunc most use case.
If we need more blend modes, it's better to just make the setBlendFunc available for advanced users, and keep the setBlendMode simple .
atilim discussed the idea here
http://giderosmobile.com/forum/discussion/406/setblendfunc-help-/p1
Do you mean it's better to create`setBlendFunc` method for this and avoid overloading?
setBlendFunc was set to nil after setBlendMode is created.
It can be made available easily.
https://github.com/gideros/gideros/commit/0bfc155d7f1cb30598f4c9c4a7c6e71bf9bc2c33
As you can see I have refactored Gideros blending source to make it much more clean and simple, without the need of extra utils like `bin2c` and lua-files. Also in this particular case overloading makes sense because setBlendMode(src, dst) still means you set blend mode, only composed from 2 blend functions. Compare it for example with overloaded `Sprite:setScale` where you can use both simplified 1-arg and more complex 2-arg versions.
The creator of the engine atilim won't do such a lot of work to just add a setBlendMode function instead of make the binder code complicated like this.
I think @atilim won't make this modification according to the this thread:
http://giderosmobile.com/forum/discussion/406/setblendfunc-help-/p1
setBlendMode accept two parameters for blendfunc really NOT make sense.
I think you can make the setBlendFunc be available in any way as you like, but just leave anything else as it was.
Dislikes: PaulH
Likes: MoKaLux
I'm trying to understand Blend Modes.
How to choose blendmode{5,8}? (I've marked it on attached picture)
I've tried
Btw, I've iterated through Sprite class, like in @n1cke 's first post:
Did these values break blendmode order of numbers?
"What one programmer can do in one month, two programmers can do in two months." - Fred Brooks
“The more you do coding stuff, the better you get at it.” - Aristotle (322 BC)
see the attached image what happens now, the middle of the curve is 100% opacity and it is fading out gradually towards its ends. i hope you understand the effect i want to achieve instead of how it looks now.
you can also notice that there is a boundary of the curve which tries to emulate anti-alias and that's also darker than both the curve's red color and the background's blue color, which is not the desired outcome.
EDIT: i've checked and e.g. in Krita if i paint with this red on this blue then it also gives dark blue boundary instead of proper anti-aliasing, strange. yet i hope there is some combination of blend modes that gives what i'd like to achieve.
Fragmenter - animated loop machine and IKONOMIKON - the memory game
Fragmenter - animated loop machine and IKONOMIKON - the memory game
i use meshes though, so there may be a difference with a very low chance. i will try to make an example with both pixels and meshes.
the issue is that i don't really know which would be the 'right' color halfway, but in any case something that does not give an antialias outline which feels darker, whatever this implies.
Fragmenter - animated loop machine and IKONOMIKON - the memory game
i think the issue is that while this gradient is 'correct', it has darker colors in the middle than in the two endpoints. i've found some texts that seem to be somewhat related to this (perceived) brightness issue:
https://medium.com/the-mvp/finally-a-definitive-way-to-make-gradients-beautiful-6b27af88f5f
https://graphicdesign.stackexchange.com/questions/6246/if-these-colors-all-have-the-same-lightness-then-why-does-my-brain-tell-me-some
but i did not find any solution to the issue using blend modes. neither do i know which would be a 'visually right' 'middle' color.
Likes: MoKaLux
Fragmenter - animated loop machine and IKONOMIKON - the memory game
https://blog.johnnovak.net/2016/09/21/what-every-coder-should-know-about-gamma/#gradients
Fragmenter - animated loop machine and IKONOMIKON - the memory game
Made an example: https://github.com/MultiPain/Gideros_examples/tree/master/FXAA_shader
Likes: antix
another issue with the shader solution is that in my initial image you can see that strokes can fade out towards their end in my animation app, here also the non-correct gamma issue is apparent, and that won't be solved by an aa shader.
it would be nice to be able to set what color mixing scheme (what is gamma) is used by the app, but i don't know if opengl can do something like this.
ps: i am happy to be on this forum, lot's of knowledge here.
Likes: MoKaLux
Fragmenter - animated loop machine and IKONOMIKON - the memory game
https://github.com/MultiPain/Gideros_examples/tree/master/GammaCorrection
Its super simple
Hm, the problem is that you cant apply shader to a Mesh :P
Fragmenter - animated loop machine and IKONOMIKON - the memory game
so wouldn't this little change help?:
glEnable(GL_FRAMEBUFFER_SRGB);
can you test it somehow, @hgy29 ?
thanks guys
Fragmenter - animated loop machine and IKONOMIKON - the memory game
for reference i attach a gradient between the two above colors which i think is the 'correct' one.
Fragmenter - animated loop machine and IKONOMIKON - the memory game
Fragmenter - animated loop machine and IKONOMIKON - the memory game
For the Sprite's default shader: there is not one default shader but severals, nine I think. Gideros selects the appropriate shader depending n the sprite type and settings, but you can override the shader to use with a custom one on a sprite by sprite basis.
Likes: MoKaLux