Nrjwolf / unity-shader-sprite-radial-fill

Radial fill mask for sprite
179 stars 29 forks source link

Doesn't work on mobile? #1

Open FVSHaLuan opened 4 years ago

FVSHaLuan commented 4 years ago

I'm using Unity 2019.4.5f1, built for Android 10, it just rendered the full sprite

Nrjwolf commented 4 years ago

Have you got some screenshot?

FVSHaLuan commented 4 years ago

I moved on from the project so too lazy to take a screenshot now. But you can easily imagine when on my Android device, it was just like default sprite shader. Did some research, some guy said Android doesn't recognize the discard operator in the shader. I did change discard to something like c = (0,0,0,0), and once again it worked on PC but not on mobile. That was what I experienced, don't have much knowledge about graphics though.

hanthuyen8 commented 3 years ago

@FVSHaLuan Hi, try fix the frag() function to this one. I tested in android 6.0.

fixed4 frag(v2f IN) : SV_Target
{
fixed4 c = SampleSpriteTexture (IN.texcoord) * IN.color;
c.rgb *= c.a;

//-------- Creating arc --------//
// sector start/end angles
float startAngle = _Angle - _Arc1;
float endAngle = _Angle + _Arc2;

// check offsets
float offset0 = clamp(0, 360, startAngle + 360);
float offset360 = clamp(0, 360, endAngle - 360);

// convert uv to atan coordinates
float2 atan2Coord = float2(lerp(-1, 1, IN.texcoord.x), lerp(-1, 1, IN.texcoord.y));
float atanAngle = atan2(atan2Coord.y, atan2Coord.x) * 57.3; // angle in degrees

// convert angle to 360 system

//if(atanAngle < 0) atanAngle = 360 + atanAngle;
float f = step(atanAngle, 0);
atanAngle = ((360 + atanAngle) * f) + ((1 - f) * atanAngle);

//if(atanAngle >= startAngle && atanAngle <= endAngle) discard;
c.a *= step(1, step(atanAngle, startAngle) + step(endAngle, atanAngle));

//if(atanAngle <= offset360) discard;
c.a *= step(offset360, atanAngle);

//if(atanAngle >= offset0) discard;
c.a *= step(atanAngle, offset0);

return c;
}
FVSHaLuan commented 3 years ago

Don't even know what I needed this for, but thanks 😁


FVS


From: Nguyễn Hy Nhân notifications@github.com Sent: Wednesday, March 3, 2021 11:51 PM To: Nrjwolf/unity-shader-sprite-radial-fill unity-shader-sprite-radial-fill@noreply.github.com Cc: FVS Hà Luận fvs922@gmail.com; Mention mention@noreply.github.com Subject: Re: [Nrjwolf/unity-shader-sprite-radial-fill] Doesn't work on mobile? (#1)

@FVSHaLuanhttps://apac01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2FFVSHaLuan&data=04%7C01%7C%7C56406546829f477e6edd08d8de649607%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C637503870892546377%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&sdata=n61VHMVo6%2F79Ze7%2BCwHwNfJdotRw8chOHZSY6SpngfY%3D&reserved=0 Hi, try fix the frag() function to this one. I tested in android 6.0.

`fixed4 frag(v2f IN) : SV_Target { fixed4 c = SampleSpriteTexture (IN.texcoord) IN.color; c.rgb = c.a;

                    //-------- Creating arc --------//
                    // sector start/end angles
                    float startAngle = _Angle - _Arc1;
                    float endAngle = _Angle + _Arc2;

                    // check offsets
                    float offset0 = clamp(0, 360, startAngle + 360);
                    float offset360 = clamp(0, 360, endAngle - 360);

                    // convert uv to atan coordinates
                    float2 atan2Coord = float2(lerp(-1, 1, IN.texcoord.x), lerp(-1, 1, IN.texcoord.y));
                    float atanAngle = atan2(atan2Coord.y, atan2Coord.x) * 57.3; // angle in degrees

                    // convert angle to 360 system

                    //if(atanAngle < 0) atanAngle = 360 + atanAngle;
                    float f = step(atanAngle, 0);
                    atanAngle = ((360 + atanAngle) * f) + ((1 - f) * atanAngle);

                    //if(atanAngle >= startAngle && atanAngle <= endAngle) discard;
                    c.a *= step(1, step(atanAngle, startAngle) + step(endAngle, atanAngle));

                    //if(atanAngle <= offset360) discard;
                    c.a *= step(offset360, atanAngle);

                    //if(atanAngle >= offset0) discard;
                    c.a *= step(atanAngle, offset0);

                    return c;
            }`

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHubhttps://apac01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2FNrjwolf%2Funity-shader-sprite-radial-fill%2Fissues%2F1%23issuecomment-789872116&data=04%7C01%7C%7C56406546829f477e6edd08d8de649607%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C637503870892551357%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&sdata=FWwzVmwwtcszc8OW0N99P1oRkog9Bnky1UQ9rTn42i4%3D&reserved=0, or unsubscribehttps://apac01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fnotifications%2Funsubscribe-auth%2FACZUUMNN3SQRDSUVYPDFJH3TBZSIZANCNFSM4P7CAP3Q&data=04%7C01%7C%7C56406546829f477e6edd08d8de649607%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C637503870892556340%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&sdata=YTo%2BeaEIqAm21%2B5nGLznD5v7%2FcMRZ097vfVqJo%2B70SY%3D&reserved=0.

Theo-Eclipse commented 3 years ago

discard

Didn't worked for me on android 10. I've simply used clip instead of discard, which is not recommended by unity because Clip has higher performance cost, but i haven't found any other solution for android.

// convert angle to 360 system
if(atanAngle < 0) atanAngle = 360 + atanAngle;

if(atanAngle >= startAngle && atanAngle <= endAngle) clip(c.a - 1.0);
if(atanAngle <= offset360) clip(c.a - 1.0);
if(atanAngle >= offset0) clip(c.a - 1.0);

return c;

And it works both on android and PC. have not tested it on iOS, but i think it should be fine there too.