Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Doesn't work on mobile? #1

Open
FVSHaLuan opened this issue Aug 14, 2020 · 5 comments
Open

Doesn't work on mobile? #1

FVSHaLuan opened this issue Aug 14, 2020 · 5 comments

Comments

@FVSHaLuan
Copy link

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

@Nrjwolf
Copy link
Owner

Nrjwolf commented Aug 18, 2020

Have you got some screenshot?

@FVSHaLuan
Copy link
Author

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
Copy link

hanthuyen8 commented Mar 3, 2021

@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
Copy link
Author

FVSHaLuan commented Mar 3, 2021 via email

@Theo-Eclipse
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants