Page MenuHome

Cycles - Image Alpha Association
ClosedPublic

Authored by Carlo Andreacchio (candreacchio) on Apr 27 2014, 3:17 PM.

Details

Summary

This patch allows the artist to control whether the image should be premultiplied or not, when loading into memory... This would allow the artist to load up bump maps / specular maps / dirt maps into the alpha channel instead of transparency, allowing a saving with memory usage.

I could not figure out how to edit the OIIO flags within OSL when it loads up the image, so i have removed that code... Right now OSL does not respect the switch. Do you have any insight in to how to enable this?

I have added this drop down menu for both the image texture and the environment texture.

If there are any changes / modifications to the code just let me know!

Carlo

Diff Detail

Event Timeline

Brecht Van Lommel (brecht) requested changes to this revision.Apr 27 2014, 3:34 PM

I don't think it should be implemented this way, we should rather follow the same design as used for the rest of Blender:
http://wiki.blender.org/index.php/Dev:Ref/Release_Notes/2.66/Image_Transparency

That means you can disable "Use Alpha" if you don't want to use the alpha channel, and I'm fine with support for that option in Cycles. Blender also has an option to indicate of the file is stored with premultiplied or straight alpha in case it cannot be automatically detected, however Blender will automatically pick the appropriate target alpha type depending on the use case. For rendering that's premultiplied alpha to get correct texture filtering.

For OSL, the only way to support control over this kind of thing is to implement it in OpenImageIO. If you don't want to do that, the code somehow needs to disable this option in the UI if OSL is used.

Carlo Andreacchio (candreacchio) updated this revision to Unknown Object (????).Apr 28 2014, 2:45 PM

So I have updated the diff, to better respect the current UI of the compositor. It is picking up whether or not the use alpha is enabled or not... is this all that is needed? or do we need to reference the drop down aswell.

Ran into a few problems (that I am unsure as to how to fix)....

  • The environment node has never had this drop down menu... the cycles code is there to pick it up, just unsure as to give it the sidebar UI
  • Hiding of the dropdown if OSL is enabled

Are there any example patches / documentation that you know of that could help? I believe the code for the UI switching the dropdown on / off lies under editors/space_image/image_buttons.c but not 100% sure that this is the case.

Carlo

Brecht Van Lommel (brecht) requested changes to this revision.Apr 29 2014, 1:33 PM

Ok, the way I think this should work is that it just use the "use_alpha" property of the image, without any UI changes. It does not need to be added to the node and no OSL specific checks are needed, since this is already an image property that Blender uses regardless if Cycles supports it.

The way you implemented this doesn't follow the way Blender does it though, see inline comments.

intern/cycles/blender/blender_mesh.cpp
225

This should use "false" instead of "0", same in other places, for booleans "true" and "false" should be used instead of "1" and "0".

intern/cycles/render/image.cpp
313–315

This isn't quite correct. The way it should work is.

  • If use_alpha == false, then oiio:UnassociatedAlpha should be enabled
  • If use_alpha == false, later on in this function the alpha channel for all pixels should be set to 255 or 1.0f.
intern/cycles/render/nodes.cpp
172–180

No need to have an enum for a boolean on/off.

Carlo Andreacchio (candreacchio) updated this revision to Unknown Object (????).Apr 29 2014, 3:03 PM

Hi again,

I have updated the code based off Brechts notes... One thing I did not implement was :

  • If use_alpha == false, later on in this function the alpha channel for all pixels should be set to 255 or 1.0f.

This would make the patch redundant for the purposes I was hoping for... allowing the 'alpha channel' to be used for something other then 'transparency'... Loading up another black/white image, such as a bump or specular map or dirt map. Maybe changing of the UI is needed to allow for this functionality?

One other note, is that the environment texture does not have this switch in the UI currently. no way of enabling / disabling the alpha channel. Should we remove the code from the environment texture entirely?

Carlo

Carlo Andreacchio (candreacchio) updated this revision to Unknown Object (????).Apr 30 2014, 12:10 AM

Hi Again,

Only thing that has changed in this patch is the overriding of the alpha channel.

If there are any more modifications / changes to the code just let me know!

Carlo

Looks good to me, besides minor style issue with ){ vs. ) {, but I can fix that when I commit this.

Carlo Andreacchio (candreacchio) updated this revision to Unknown Object (????).May 3 2014, 7:51 AM

Coding Style Changes, changed "){" to ") {"
Nothing else has changed.