Opened 10 years ago

Closed 8 years ago

Last modified 8 years ago

#2421 closed enhancement (fixed)

[PATCH] Add alternative mode to add_color effect which only applies to non-transparent pixels

Reported by: Michael Owned by: Michael
Priority: Nice to Have Milestone: Alpha 20
Component: Core engine Keywords: effect shader
Cc: wraitii Patch:

Description

Currently the add_color effect is applied on the complete image. This is convenient when it's used on images without transparency but might not be intended for partly transparent images.

It would be good, if there would be a second mode in which the effect is not applied on transparent pixels.

Attachments (6)

colorAdd_TextureMaskMode_v1.patch (6.4 KB ) - added by Michael 10 years ago.
testGfx.zip (2.8 KB ) - added by Michael 10 years ago.
Images to test. Put in "binaries\data\mods\public\art\textures\ui\test"
test_textureMask_v1.patch (1.4 KB ) - added by Michael 10 years ago.
Patch to see what the real patch does.
colorAdd_TextureMaskMode_v2.patch (6.5 KB ) - added by Michael 10 years ago.
Replaced seperator, changed shader (use texture only as mask in maskMode)
colorAdd_TextureMaskMode_v3.patch (7.4 KB ) - added by Michael 10 years ago.
suggestions made by wraitii
2421.1.patch (7.4 KB ) - added by Stan 9 years ago.
Hopefully Fix what wraitii wanted so it can be commited. Can someone review this ?

Download all attachments as: .zip

Change History (20)

comment:1 by Michael, 10 years ago

The patch adds two attributes which can be used in XML files:

  • textureMaskMode="true|false" which can be used as optinal parameter with add_color="r g b o" in the effect tag
    <effect add_color="175 60 255 255" textureMaskMode="true"/>
    
  • alternative syntax to "colour" of sprite: "colour: r g b o|filenameMask.ext" in an sprite attribute
    <object name="x" type="image" size="0 0 250 250" sprite="colour: 175 60 255 150|path/to/mask.png"/>
    
  • special case: addColorMask="filenameMask.ext" can be used in objects of type "image" to automatically add this mask to a colorFade
    <object name="x" type="image" size="0 0 250 250" addColorMask="session/overlay.png" />
    

by Michael, 10 years ago

by Michael, 10 years ago

Attachment: testGfx.zip added

Images to test. Put in "binaries\data\mods\public\art\textures\ui\test"

by Michael, 10 years ago

Attachment: test_textureMask_v1.patch added

Patch to see what the real patch does.

comment:2 by Michael, 10 years ago

To test the patch, add the two images in testGfx.zip to "binaries\data\mods\public\art\textures\ui\test" and apply also test_textureMask_v1.patch​.

What does the test patch:

  • creates an (very nice and obvious ;)) color gradient in all buttons
  • starts two simple color fades when a game is started

comment:3 by Michael, 10 years ago

Keywords: patch review added
Summary: Add alternative mode to add_color effect which only applies to non-transparent pixels[PATCH] Add alternative mode to add_color effect which only applies to non-transparent pixels

by Michael, 10 years ago

Replaced seperator, changed shader (use texture only as mask in maskMode)

comment:4 by wraitii, 10 years ago

Some comments: line 144 of CGUIRenderer.h should be a size_t, not an int.

I don't think you need the texture mask mode if you replace the shader with "gl_FragColor = t + color * min(t.a,color.a);" and use a proper color. So I would remove that.

I also don't really like the "addColourMask" element since it only seems useful for the ticking functions, so I'd rather add this as a parameter of the ticking functions.

However I like the add of a mask to the "colour:" effect.

in reply to:  4 comment:5 by Michael, 10 years ago

Replying to wraitii:

Some comments: line 144 of CGUIRenderer.h should be a size_t, not an int.

I changed that.

I don't think you need the texture mask mode if you replace the shader with "gl_FragColor = t + color * min(t.a,color.a);" and use a proper color. So I would remove that.

What do you mean with "use a proper color"? If I change the shader like you suggested its function is broken (test with #2357).

I also don't really like the "addColourMask" element since it only seems useful for the ticking functions, so I'd rather add this as a parameter of the ticking functions.

I agree that it's a bit dirty because its only working for the color fades. Because of that I removed it.

However I like the add of a mask to the "colour:" effect.

:)

by Michael, 10 years ago

suggestions made by wraitii

comment:6 by wraitii, 10 years ago

My bad, that line should read " gl_FragColor = color*min(t.a,1.0);". If you just put that, according to my tests, it works nicely, and you don't need this fancy mode.

comment:7 by historic_bruno, 10 years ago

Milestone: BacklogAlpha 17

comment:8 by Itms, 10 years ago

Milestone: Alpha 17Alpha 18

comment:9 by leper, 9 years ago

Did you get around to updating this with wraitii's suggestion?

by Stan, 9 years ago

Attachment: 2421.1.patch added

Hopefully Fix what wraitii wanted so it can be commited. Can someone review this ?

comment:10 by Itms, 9 years ago

Milestone: Alpha 18Alpha 19

comment:11 by wraitii, 9 years ago

I don't think this removes the "textureMaskMode" which I still think is useless.

comment:12 by elexis, 9 years ago

Keywords: add_color transparent removed
Milestone: Alpha 19Alpha 20

comment:13 by wraitii, 8 years ago

Resolution: fixed
Status: newclosed

In 17456:

Allow multiple special sprites, to facilitate cases where we want to add an overlay to a sprite.

"color" can make use of the sprite's alpha texture, and the "add_color" effect will now take the original image's alpha into account.
Remove the no longer needed "unaffordableMask" images on a variety of panels.

Somewhat based on a patch by BoeseRaupe. Fixes #2421 and #3688.

comment:14 by wraitii, 8 years ago

Keywords: patch review removed
Note: See TracTickets for help on using tickets.