Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.
Sign upBlend modes! #185
Conversation
termhn
added some commits
Oct 6, 2017
This comment has been minimized.
This comment has been minimized.
|
Nice. Is it possible to use this to set blend modes for arbitrary images without custom shaders being involved as well? I vaguely recall doing something for that but don't remember what it looks like. |
This comment has been minimized.
This comment has been minimized.
|
Hmm... you could just switch the blend mode, draw the image, then switch it back to the default blend mode, but I don't think it's possible (at least with this) to have an image have a different blend mode. From what I've gathered from kvark, the blend mode is an immutable piece of the gfx PSO, and so to change blend modes we create multiple PSOs (one for each blend mode) and then have it use the correct one based on the requested blend mode. We could add a piece of state on the ggez I've made the default shader program have PSOs for all of the blend modes, so you can set any blend mode when you have the default shader active. For user shaders, the user has to specify all the blend modes that they want to be able to use with that shader. |
This comment has been minimized.
This comment has been minimized.
|
This is super cool! |
termhn
added some commits
Oct 8, 2017
This comment has been minimized.
This comment has been minimized.
|
Alright, all the TODOs are now implemented (hopefully) and I experimentally added in the ability for you to individually set the blend mode of any Drawable, which will override the general blend mode that is set, based on @icefoxen 's comment. |
This comment has been minimized.
This comment has been minimized.
|
@nlordell Can you test this on your macbook? I hadn't until now and it seems as though something is being messed up with the new high dpi stuff on mine. I probably messed something up when rebasing it and didn't notice until now heh. @icefoxen I think this will be ready to merge once I get the above-mentioned bug fixed |
This comment has been minimized.
This comment has been minimized.
|
This looks generally fantastic! I just need to grok what the Pso structs are doing more fully. |
This comment has been minimized.
This comment has been minimized.
|
Basically, in gfx, because Vulkan and DX are more strict about how blend modes work than GL is, blend modes are a baked in piece of state for a PSO and you can't change it dynamically. After chatting with @kvark on IRC and looking how he does it in three-rs, the best way to change blend modes is to just make multiple PSOs with a blend mode baked in. The This is fine for when you only have one shader program, but since shaders are also baked into a PSO, if you want to have multiple shaders in which each supports all the blend modes, you also have to make a PSO per blend mode per shader. Since creating all the blend mode PSOs for multiple shaders would be a bit ridiculous when you probably aren't going to use all of them, for custom shaders you have to specify when you create the shader a list of BlendModes that you want to be able to use with that shader. If you supply |
This comment has been minimized.
This comment has been minimized.
|
Makes sense. Sounds, as I suspected from the placement and organization of the code, rather similar to the |
This comment has been minimized.
This comment has been minimized.
|
Yes, it's basically a modified |
This comment has been minimized.
This comment has been minimized.
|
Done! Ready to merge if you are I think. |
termhn commentedOct 8, 2017
•
edited
An easy to use API (basically the same as LOVE's) to switch the blend mode of the current shader program. The main limitation is that it requires you to provide a list of blend modes that you want your shader program to support when you create it (or
Noneto apply only the default Alpha blend mode). The default shader program comes with all of them by default. This allows us to do things like this :D (the updated shadows example).TODO:
Still need to figure out how to implement the Lighten and Darken blend modes using gfx's API--for now they're just placeholders. All the rest of the blend modes work, though.Perhaps restructure where a few things live; I'm not sure it makes sense to have thegraphics::set_blend_mode()function insidepixelshader.rs