Search Unity

Simple Vertex Lit Shader appearing black

Discussion in 'Flash' started by bigpants, Dec 23, 2012.

  1. bigpants

    bigpants

    Joined:
    Dec 9, 2009
    Posts:
    49
    (using Unity 3.5.5f3)
    This fixed function shader (I wrote it) works fine on PC / MAC / iPad 1,
    but comes out BLACK in Flash:

    Code (csharp):
    1.  
    2. SubShader
    3. {
    4.     Pass
    5.     {
    6.         Lighting On
    7.         ColorMaterial AmbientAndDiffuse
    8.     }
    9. }
    10.  
    Other Details
    1. I have 2 lights - a directional light and a point light.
    2. With "Lighting Off" the above shader works FINE in Flash.
    3. Flash Export targets player 11.2
    4. Tested using Mac OS X v10.8.2 - Safari 6.0.1 - Flash player 11.5.502

    From what I've read, Unity Flash export used to have a problem with vertex lit shaders, but the updated "what is supported" page indicates vertex lit + directional and point lights is fine. http://docs.unity3d.com/Documentation/Manual/flash-whatssupported.html

    Thoughts?
     
  2. mtoivo

    mtoivo

    Joined:
    Jul 30, 2012
    Posts:
    274
    Upgrade to at least to the latest 3.5.x version. But even then, the flash export has not been updated in that branch for a while now (like, several months), don't expect it to be nearly perfect. 4.0 is where the development is taking place. I can give it a go with 4.0 if you like, just post a simple test-project somewhere where it should be working
     
  3. bigpants

    bigpants

    Joined:
    Dec 9, 2009
    Posts:
    49
    I just tested using the free Unity 4.0 trial 4.0.0f7 Flash export and got the same problem.
    I switched all the materials to use diffuse (default) and while that fixed the black issue,
    I noticed some puzzling geometry problems.
    Some procedurally generated cubes had HUGE scaled Z (looks like infinitely big), but only SOME of them.
    Very odd considering they're all generated by the same code.
    So there's more going wrong than I thought :(
    I'm going to build some test apps to narrow down the problem.

    - - -
    Any insight into the original shader issue is still much appreciated.
    My guess is Unity has not tested converting such outdated, simple shader code.
    It's worth noting I'm using my shader to get maximum iPhone/iPad performance.
    According to my tests, the Unity provided mobile shaders were slower on iPad,
    presumably because they do more than mine (Shininess, SpecColor, Emission).
    Maybe that was a wrong conclusion?
     
  4. mtoivo

    mtoivo

    Joined:
    Jul 30, 2012
    Posts:
    274
    Based on what I've read by now, you should totally submit few bug reports. Maybe one with the shader problem and another one about the Z-scale issue. On my experience, bugs get squashed quite fast after submitting reports, and the ones you've come by don't sound that big issues (I might be wrong, of course). The Flash export is not perfect, you might have to compromise on some things for now, but by submitting the bug reports it gets better.

    More than these Unity issues, I've had my dose of headache with just Flash in general. All the versions of player, browsers and computers out there really makes it pretty impossible to create a "cross platform experience" anymore. And now that Google is messing things with their own Flash player, it doesn't make it any easier. I like the idea of being able to push Unity-content to web via Flash, but to be honest, I don't consider that platform so seriously anymore. It works, if you're able to strip down some features, and all due to limitations of "Flash-ecosystem" you have to deal with. And even then when you get something working, you never know what's going to happen after next browser / flash player upgrade (case in point: suddenly fps drops below 1 on Chrome).

    I don't mean to sound discouraging, I will probably publish to Flash from Unity in the future, too, but you just have to know what you're facing there and accept it.
     
  5. bigpants

    bigpants

    Joined:
    Dec 9, 2009
    Posts:
    49
    Update

    The "HUGE scaled Z" issue was definitely a Unity bug.
    However, it had nothing to do with geometry (that was just a side effect).

    Unity 4.0.0f7 Flash export was incrementing the value of a variable in a static class because I defined it like this:
    "public static Vector3 cubeInsideScale = Vector3.one * 0.95f;"
    (cubeInsideScale.z would keep counting up and up and up, which led to my "HUGE scaled Z" geometry)
    switching to this solved the problem:
    "public static Vector3 cubeInsideScale = new Vector3(0.95f, 0.95f, 0.95f);"


    Notes
    • My other static variables worked great.
    • ANY static variable initiated with Vector3.one would be updated constantly by Unity in WEIRD ways.Did not appear to be a problem for local variables or variables that were members of a regular class (have not thoroughly tested)
    • This happened testing the .swf on multiple machines and multiple browsers, all with Flash player 11.5+

    I've submitted 2 bug reports to Unity: 1 for the shader and 1 for the static variable.

    - - -
    @mtoivo
    I'm an expert HTML developer so I know all about "cross platform" problems... Flash has nothing on HTML :)
    The fact Unity exports to Flash whatsoever is a huge technical achievement.
    I'm totally expect to compromise to be part of the Flash-ecosystem - just need to know where.
    More info on Google Chrome's "own" Flash player would be appreciated.
    From my tests on Mac and PC (NOT mobile), Adobe updates Google Chrome's flash player just like Firefox and IE.
    On my test machines, all of the browsers had an up-to-date Adobe Flash player.
    Is there something special about Google Chrome Flash I'm missing?
     
    Last edited: Dec 27, 2012
  6. mtoivo

    mtoivo

    Joined:
    Jul 30, 2012
    Posts:
    274
    The "Chrome-issue" is due to Chrome using it's own version of flash player, not the one that Adobe directly provides. Chrome uses a PPAPI-implemented version of Flash player, which is in theory a better way to run plugins. Only thing is, that they've not managed to get it 100% compatible. They've had some time-drifting issues, but differences in Stage3D-implementation should worry us Unity-developers more. Here's a thread I started about the issue few weeks ago: Unity 3.5 Flash export Google Chrome (Mac)

    Nice thing with tracking the problem about the Verctor3.one issue. Haven't bumped into that one myself yet. By snooping around with the generated AS3-version of the class one might find out why this is happening, but now that it's reported I guess we get fixed version soon.