Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Windows 10 Universal - Build and run straight in phone? (and performance & profiler issues)

Discussion in 'Windows' started by pontori, Jan 25, 2016.

  1. pontori

    pontori

    Joined:
    Jun 10, 2013
    Posts:
    15
    Hey! I'm wondering if it's possible to build and run straight to my windows phone. Currently it builds and runs the desktop version and i have to open the VS project to run it on my phone, and this greatly slows down the workflow.

    There's also problems with the game's performance on Windows Phone, on my Lumia 920 the performance is weak (20-30 FPS), compared to to my Android device (Sony Xperia m4 Aqua). Actually the performance is almost in par with the Samsung Galaxy S 1, which is a really old phone. When i try to use the profiler/debug on the Windows Phone build, the game crashes most of the time when it tries to launch. Only once i got in the game with profiler on and the performance was even worse, maybe 2-5 FPS. I looked at the profiler and physics calculations were using most of the power. Sadly i didn't take a screenshot. After this one time i haven't been able to use the profiler.

    One more issue, the ColorCorrectionCurves-image effect doesn't seem to work at all on my Lumia 920. I use it for a partial grayscale effect. Is there a way i can make it work, or is there some other way to accomplish partial grayscale? (not completely black&white, just less saturation)

    I'm trying to port my game for Windows 10 Universal-platform, for the ongoing contest, but without profiler i can not fix the performance so that it's playable.
     
  2. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,507
    Regarding the profiler: make sure you deploy the game in "Release" configuration (rather than debug) and that you have "InternetClientServer" capability enabled in your manifest (otherwise phone OS blocks network connections, including the profiler).
     
  3. pontori

    pontori

    Joined:
    Jun 10, 2013
    Posts:
    15
    Thanks, the profiler is working now.

    I'd like to know, do the image effects work for you guys on Windows 10 phones? I've tried the grayscale, color correction curves, several black&white shaders found on the internet. Same thing with every one of them - gray/bluish gray screen, with UI still showing on top. I just can't figure it out, there must be some way to achieve a working grayscale effect!

    Edit: I've updated Unity to 5.3.1p4, didn't fix it
     
    Last edited: Jan 26, 2016
  4. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,507
    Could you show those shaders you found?
     
  5. pontori

    pontori

    Joined:
    Jun 10, 2013
    Posts:
    15
    Here's one: http://www.alanzucconi.com/2015/07/08/screen-shaders-and-postprocessing-effects-in-unity3d/
    With this one, the game crashed whenever i tried to launch it on Windows Phone. I figured it was probably because of the C# script, so i turned it to be more similar to the scripts that the standard image effects use:

    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. [ExecuteInEditMode]
    5. public class BWEffect : UnityStandardAssets.ImageEffects.ImageEffectBase
    6. {
    7.     public float intensity;
    8.  
    9.     // Postprocess the image
    10.     void OnRenderImage(RenderTexture source, RenderTexture destination)
    11.     {
    12.         if (intensity == 0)
    13.         {
    14.             Graphics.Blit(source, destination);
    15.             return;
    16.         }
    17.         material.SetFloat("_bwBlend", intensity);
    18.         Graphics.Blit(source, destination, material);
    19.     }
    20. }
    After this change, the game doesn't crash but only produces a black screen. I added ZTest Always to the shader:

    Code (CSharp):
    1. Shader "Hidden/BWDiffuse" {
    2.     Properties{
    3.         _MainTex("Base (RGB)", 2D) = "white" {}
    4.     _bwBlend("Black & White blend", Range(0, 1)) = 0
    5.     }
    6.         SubShader{
    7.         Pass{
    8.         ZTest Always
    9.         CGPROGRAM
    10. #pragma vertex vert_img
    11. #pragma fragment frag
    12.  
    13. #include "UnityCG.cginc"
    14.  
    15.         uniform sampler2D _MainTex;
    16.     uniform float _bwBlend;
    17.  
    18.     float4 frag(v2f_img i) : COLOR{
    19.         float4 c = tex2D(_MainTex, i.uv);
    20.  
    21.         float lum = c.r*.3 + c.g*.59 + c.b*.11;
    22.         float3 bw = float3(lum, lum, lum);
    23.  
    24.         float4 result = c;
    25.         result.rgb = lerp(c.rgb, bw, _bwBlend);
    26.         return result;
    27.     }
    28.         ENDCG
    29.     }
    30.     }
    31. }
    After that, i got the gray screen, just like the standard image effects produce.

    Next one:

    Code (CSharp):
    1. Shader "Custom/Image Effects" {
    2.     Properties
    3.     {
    4.         _MainTex("Base (RGB)", 2D) = "white" {}
    5.     _SaturationAmount("Saturation Amount", Range(0.0, 1.0)) = 1.0
    6.         _BrightnessAmount("Brightness Amount", Range(0.0, 1.0)) = 1.0
    7.         _ContrastAmount("Contrast Amount", Range(0.0,1.0)) = 1.0
    8.     }
    9.         SubShader
    10.     {
    11.         Pass
    12.     {
    13.         ZTest Always
    14.         CGPROGRAM
    15. #pragma vertex vert_img
    16. #pragma fragment frag
    17. #pragma fragmentoption ARB_precision_hint_fastest
    18. #include "UnityCG.cginc"
    19.  
    20.         uniform sampler2D _MainTex;
    21.     uniform float _SaturationAmount;
    22.     uniform float _BrightnessAmount;
    23.     uniform float _ContrastAmount;
    24.  
    25.     float3 ContrastSaturationBrightness(float3 color, float brt, float sat, float con)
    26.     {
    27.         //RGB Color Channels
    28.         float AvgLumR = 0.5;
    29.         float AvgLumG = 0.5;
    30.         float AvgLumB = 0.5;
    31.  
    32.         //Luminace Coefficients for brightness of image
    33.         float3 LuminaceCoeff = float3(0.2125,0.7154,0.0721);
    34.  
    35.         //Brigntess calculations
    36.         float3 AvgLumin = float3(AvgLumR,AvgLumG,AvgLumB);
    37.         float3 brtColor = color * brt;
    38.         float intensityf = dot(brtColor, LuminaceCoeff);
    39.         float3 intensity = float3(intensityf, intensityf, intensityf);
    40.  
    41.         //Saturation calculation
    42.         float3 satColor = lerp(intensity, brtColor, sat);
    43.  
    44.         //Contrast calculations
    45.         float3 conColor = lerp(AvgLumin, satColor, con);
    46.  
    47.         return conColor;
    48.     }
    49.  
    50.  
    51.     float4 frag(v2f_img i) : COLOR
    52.     {
    53.         float4 renderTex = tex2D(_MainTex, i.uv);
    54.  
    55.         renderTex.rgb = ContrastSaturationBrightness(renderTex.rgb, _BrightnessAmount, _SaturationAmount, _ContrastAmount);
    56.  
    57.         return renderTex;
    58.     }
    59.  
    60.         ENDCG
    61.     }
    62.  
    63.     }
    64. }
    Code (csharp):
    1.  
    2. using UnityEngine;
    3. using System.Collections;
    4.  
    5.  
    6. [ExecuteInEditMode]
    7. public class RenderImage : MonoBehaviour
    8. {
    9.     #region Variables
    10.     public Shader curShader;
    11.     public float brightnessAmount = 1.0f;
    12.     public float saturationAmount = 1.0f;
    13.     public float contrastAmount = 1.0f;
    14.     private Material curMaterial;
    15.     #endregion
    16.  
    17.     #region Properties
    18.     Material material
    19.     {
    20.         get
    21.         {
    22.             if (curMaterial == null)
    23.             {
    24.                 curMaterial = new Material(curShader);
    25.                 curMaterial.hideFlags = HideFlags.HideAndDontSave;
    26.             }
    27.             return curMaterial;
    28.         }
    29.     }
    30.     #endregion
    31.     // Use this for initialization
    32.     void Start()
    33.     {
    34.         if (!SystemInfo.supportsImageEffects)
    35.         {
    36.             enabled = false;
    37.             return;
    38.         }
    39.     }
    40.  
    41.     void OnRenderImage(RenderTexture sourceTexture, RenderTexture destTexture)
    42.     {
    43.         if (curShader != null)
    44.         {
    45.             material.SetFloat("_BrightnessAmount", brightnessAmount);
    46.             material.SetFloat("_SaturationAmount", saturationAmount);
    47.             material.SetFloat("_ContrastAmount", contrastAmount);
    48.             Graphics.Blit(sourceTexture, destTexture, material);
    49.         }
    50.         else
    51.         {
    52.             Graphics.Blit(sourceTexture, destTexture);
    53.         }
    54.  
    55.  
    56.     }
    57.  
    58.     // Update is called once per frame
    59.     void Update()
    60.     {
    61.         brightnessAmount = Mathf.Clamp(brightnessAmount, 0.0f, 1.5f);
    62.         saturationAmount = Mathf.Clamp(saturationAmount, 0.0f, 2.0f);
    63.         contrastAmount = Mathf.Clamp(contrastAmount, 0.0f, 3.0f);
    64.     }
    65.  
    66.     void OnDisable()
    67.     {
    68.         if (curMaterial)
    69.         {
    70.             DestroyImmediate(curMaterial);
    71.         }
    72.  
    73.     }
    74. }
    75.  
    Here too i had to add ZTest Always to get rid of black screen, only to get the gray screen.
     
  6. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,507
    Can you show a screenshot of what you're getting in terms of video output on a phone?
     
  7. pontori

    pontori

    Joined:
    Jun 10, 2013
    Posts:
    15

    With ZTest Always


    And without
     
  8. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,507
    Which Unity version is this? I cannot reproduce it on 5.3 (I just made a new project, added a cube, added your image effects and they seem to work just fine, either with or without ZTest).
     
  9. pontori

    pontori

    Joined:
    Jun 10, 2013
    Posts:
    15
    Tried 5.3.1p4 and 5.3.1p3 for the WP builds. Version 3.1 didn't work for us at all, there was some bug that caused very low performance even on PC. I just noticed that 5.3.2 is out, gonna try that next.

    Just to clarify: the image effects work great on PC & Android. Just not on Windows Phone 10.
     
  10. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,507
    Yup I tried it on a phone too. Does the project have any other image effects? We'd love to get a repro project and a bug report for these issues if you can still reproduce it.
     
  11. pontori

    pontori

    Joined:
    Jun 10, 2013
    Posts:
    15
    No other image effects. I tried with another effect, the noise and scratches standard image effect. It gave me this:
    The same blue background with noise added on top. So far none of the standard image effects haven't worked.
    This is with 5.3.2, so no luck with it either.
     
  12. pontori

    pontori

    Joined:
    Jun 10, 2013
    Posts:
    15
    Alright - now i took the time to create a new empty project with just an camera, a cube and a directional light. Color correction curves seems to work. I'll try to find out what's different in my game project settings..
     
  13. pontori

    pontori

    Joined:
    Jun 10, 2013
    Posts:
    15
    I think i found it. In the test project, i disabled antialiasing and the image effects stopped working. In my game i set antialiasing to 2x multi sampling and the effects do work now. The thing is, its too big of a performance hit to use antialiasing. :(
     
  14. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,507
    I just tried disabling anti aliasing on my tiny project and I could still not reproduce it. Are you sure it's disabling antialiasing that causes the issue?
     
  15. pontori

    pontori

    Joined:
    Jun 10, 2013
    Posts:
    15
  16. pontori

    pontori

    Joined:
    Jun 10, 2013
    Posts:
    15
    Any solution to the image effect problem?

    Also, yet another problem: Screen.SetResolution doesn't work. As currently, i'm forced to use antialiasing, i need to lower the resolution to achieve a playable FPS. But Screen.SetResolution does nothing, i've tried with fullscreen true and false, and different resolutions. Tried in Start() and in Awake(). It does nothing. Is there a trick that i'm missing? Works on Android.
     
  17. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,507
    The fix for Screen.resolution is coming in this weeks patch release (5.3.2p2).

    We're still trying to reproduce this issue internally. Our QA tried it on 4 phones so far, and last time I checked they were updated a 920 to Windows 10, as it wasn't reproducible on Windows 8.1.
     
  18. pontori

    pontori

    Joined:
    Jun 10, 2013
    Posts:
    15
    Thats odd.. I even updated my phone through Windows Insider, still no luck.
     
  19. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,507
    Hi,

    our QA managed to reproduce the issue only after updating Lumia 920 to Windows 10. We couldn't reproduce it on any other phone so far. Stay tuned, we'll be investigating it.
     
  20. Namal

    Namal

    Joined:
    Jul 6, 2012
    Posts:
    15
    Hi guys
    We have the same performances issues with Universal 10 builds on Lumia 950 (and 550 of course ^^).
    On "old" iOS/Android devices like iPhone 5 (2012), Nexus 7 (2013), Galaxy Note 2 (2012) have 50+ FPS, but it's impossible to reach more than 30 on Lumia 950 :eek: in release mode (and 15 fps on 550)...
    We are trying to lower the resolution (but it's seems there are some problems yet) and we tried to drastically drop the Quality settings but it's not a big win (very low improvement for a crappy quality...)
    Do you guys found some tricks to increase FPS for Universal 10 ARM build on Win 10 Phones ?
    Thanks