Welcome,
Guest
. Please
login
or
register
.
March 09, 2026, 01:09:37 AM
Home
Help
Search
Login
Register
Tasharen Entertainment Forum
»
Support
»
NGUI 3 Support
»
Alternative to Solidify (Premultiply Alpha)
« previous
next »
Print
Pages: [
1
]
Author
Topic: Alternative to Solidify (Premultiply Alpha) (Read 7906 times)
FizzPow
Jr. Member
Thank You
-Given: 0
-Receive: 0
Posts: 83
Alternative to Solidify (Premultiply Alpha)
«
on:
December 27, 2012, 03:50:30 PM »
So I was not happy with the 'Solidify' photoshop filter approach to cleaning up interior sprite edges and found another solution for anyone interested. This involves using Texture Packer to create your textures with "Premultiply Alpha" checked and then using this shader:
// unlit, vertex colour, premultiplied alpha blend
Shader
"PremulVertexColor"
{
Properties
{
_MainTex
(
"Base (RGB) Trans (A)"
, 2D
)
=
"white"
{
}
}
SubShader
{
Tags
{
"Queue"
=
"Transparent"
"IgnoreProjector"
=
"True"
"RenderType"
=
"Transparent"
}
ZWrite Off Lighting Off Cull Off Fog
{
Mode Off
}
Blend One OneMinusSrcAlpha
LOD
110
Pass
{
CGPROGRAM
#pragma vertex vert_vct
#pragma fragment frag_mult
#pragma fragmentoption ARB_precision_hint_fastest
#include "UnityCG.cginc"
sampler2D _MainTex
;
float4 _MainTex_ST
;
struct
vin_vct
{
float4 vertex
:
POSITION
;
float4 color
:
COLOR
;
float2 texcoord
:
TEXCOORD0
;
}
;
struct
v2f_vct
{
float4 vertex
:
POSITION
;
fixed4 color
:
COLOR
;
half2 texcoord
:
TEXCOORD0
;
}
;
v2f_vct vert_vct
(
vin_vct v
)
{
v2f_vct o
;
o
.
vertex
=
mul
(
UNITY_MATRIX_MVP, v
.
vertex
)
;
o
.
color
=
v
.
color
;
o
.
texcoord
=
v
.
texcoord
;
return
o
;
}
fixed4 frag_mult
(
v2f_vct i
)
:
COLOR
{
fixed4 col
=
tex2D
(
_MainTex, i
.
texcoord
)
*
i
.
color
;
return
col
;
}
ENDCG
}
}
SubShader
{
Tags
{
"Queue"
=
"Transparent"
"IgnoreProjector"
=
"True"
"RenderType"
=
"Transparent"
}
ZWrite Off Blend One OneMinusSrcAlpha Cull Off Fog
{
Mode Off
}
LOD
100
BindChannels
{
Bind
"Vertex"
, vertex
Bind
"TexCoord"
, texcoord
Bind
"Color"
, color
}
Pass
{
Lighting Off
SetTexture
[
_MainTex
]
{
combine texture
*
primary
}
}
}
}
This works fantastic, but I would love to see this functionality native to NGUI at some point.
Logged
FizzPow
Jr. Member
Thank You
-Given: 0
-Receive: 0
Posts: 83
Re: Alternative to Solidify (Premultiply Alpha)
«
Reply #1 on:
December 27, 2012, 05:04:18 PM »
Interesting aside using this process, to adjust alpha on a sprite, you have to adjust all 4 RGBA to match what you want alpha to be. So instead of just Alpha to 100, have to set RGB to 100 as well, or it looks quite wrong =)
Logged
jeldrez
Sr. Member
Thank You
-Given: 8
-Receive: 4
Posts: 352
Re: Alternative to Solidify (Premultiply Alpha)
«
Reply #2 on:
June 11, 2013, 09:03:33 AM »
Sorry for the bump, but somebody test this script? it could be more useful than applying Solidify A to all the assets.
Logged
FizzPow
Jr. Member
Thank You
-Given: 0
-Receive: 0
Posts: 83
Re: Alternative to Solidify (Premultiply Alpha)
«
Reply #3 on:
June 11, 2013, 12:12:13 PM »
I can only tell you it works great for us. I have two apps live in store using this approach (See JamTok Spanish and Japanese). My understanding is the latest versions of NGUI natively support a pre-multiply alpha option now in atlas creation, but I prefer the workflow of using Texture Packer right now, and how I can set it to auto-create for all 3 resolutions.
Logged
ArenMook
Administrator
Hero Member
Thank You
-Given: 337
-Receive: 1171
Posts: 22,128
Toronto, Canada
Re: Alternative to Solidify (Premultiply Alpha)
«
Reply #4 on:
June 11, 2013, 01:15:22 PM »
Pre-multiplied alpha approach doesn't exhibit the same issues as alpha-based, and is supposedly also faster on some mobile devices. I used it in Starlink just to be safe, which is why I added the option to the atlas maker.
To use the pre multiplied alpha, simply select the "Unlit/Premultiplied Colored" shader instead of "Unlit/Transparent Colored".
Logged
jeldrez
Sr. Member
Thank You
-Given: 8
-Receive: 4
Posts: 352
Re: Alternative to Solidify (Premultiply Alpha)
«
Reply #5 on:
June 11, 2013, 03:58:05 PM »
Thanks Aren!
Logged
YourUncleBob
Newbie
Thank You
-Given: 0
-Receive: 0
Posts: 4
Re: Alternative to Solidify (Premultiply Alpha)
«
Reply #6 on:
July 08, 2013, 07:01:34 PM »
>>
>> which is why I added the option to the atlas maker.
>>
Does the atlas maker have any sort of premultiply support? All the widgets support adjusting their colors to correctly work with a premultiplied shader, but as far as I can see the atlas maker doesn't do anything different when a premultiply shader is used.
We added support for this to our local copy of NGUI and I think it would be worth adding as an option to the real version. We changed the atlas maker and texture packer to perform a premultiply on textures when adding them to the atlas. To better support this we also export the atlas as a TGA file rather than a PNG (I've seen different PNG readers/writers do weird things to the foreground color of pixels with 0 alpha, where everything seems to leave TGA files alone). We also fudge in something so that any texture with _Add in its name will be treated as additive (all its alphas will be 0).
It's an easy addition and saves artists from having to figure out how to create premultiplied art.
Logged
ArenMook
Administrator
Hero Member
Thank You
-Given: 337
-Receive: 1171
Posts: 22,128
Toronto, Canada
Re: Alternative to Solidify (Premultiply Alpha)
«
Reply #7 on:
July 08, 2013, 11:22:56 PM »
"Use PMA shader" is an option in atlas maker. It automatically multiplies RGB by alpha when adding sprites. If you don't see it, then your NGUI is out of date.
Logged
Print
Pages: [
1
]
« previous
next »
Tasharen Entertainment Forum
»
Support
»
NGUI 3 Support
»
Alternative to Solidify (Premultiply Alpha)