Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Tried to modify mobile bumped shader to include an alpha test... and then gibberish happened

Discussion in 'Shaders' started by leftchannel, Sep 17, 2014.

  1. leftchannel

    leftchannel

    Joined:
    Feb 28, 2014
    Posts:
    25
    Basically what the title says. This is the mobile bumped shader from 4.5.4, and I tried to add an alpha cutoff to it. When I tried to build my game to device, I get:
    Shader compiler: internal error compiling shader snippet type=1 platform=9: Error polling external process
    (platform switches back and forth between 5 and 9, and i get about 100 of these errors)
    I should note that, in Editor, the shader works exactly as expected. On device, it's pure black.

    The operative line that was changed was:
    1. #pragma surface surf Lambert alphatest:_Cutoff


    Code (csharp):
    1. // Simplified Bumped shader. Differences from regular Bumped one:
    2. // - no Main Color
    3. // - Normalmap uses Tiling/Offset of the Base texture
    4. // - fully supports only 1 directional light. Other lights can affect it, but it will be per-vertex/SH.
    5.  
    6. Shader "Mobile/Bumped Diffuse Cutoff" {
    7. Properties {
    8. _MainTex ("Base (RGB) Cutoff (A)", 2D) = "white" {}
    9. _BumpMap ("Normalmap", 2D) = "bump" {}
    10. _Cutoff ("Alpha cutoff", Range(0,1)) = 0.5
    11. }
    12.  
    13. SubShader {
    14. Tags { "RenderType"="Opaque" }
    15. LOD 250
    16.  
    17. CGPROGRAM
    18. #pragma surface surf Lambert alphatest:_Cutoff
    19.  
    20. sampler2D _MainTex;
    21. sampler2D _BumpMap;
    22.  
    23. struct Input {
    24. float2 uv_MainTex;
    25. };
    26. void surf (Input IN, inout SurfaceOutput o) {
    27. fixed4 c = tex2D(_MainTex, IN.uv_MainTex);
    28. o.Albedo = c.rgb;
    29. o.Alpha = c.a;
    30. o.Normal = UnpackNormal(tex2D(_BumpMap, IN.uv_MainTex));
    31. }
    32.  
    33. ENDCG
    34. }
    35.  
    36. FallBack "Mobile/Diffuse"
    37. }
    38.  
     
  2. Daniel_Brauer

    Daniel_Brauer

    Unity Technologies

    Joined:
    Aug 11, 2006
    Posts:
    3,355
    You're attempting to use _Cutoff for alpha testing, but you don't have any mention of it in your Cg. Either the surface shader interpreter or the resulting code is likely choking on that.
     
  3. leftchannel

    leftchannel

    Joined:
    Feb 28, 2014
    Posts:
    25
    Is the line on line 10 not sufficient? How do I get that value into the Cg?

    ....alternately, can I just use a constant instead? I don't need that value to be configurable.
     
  4. Daniel_Brauer

    Daniel_Brauer

    Unity Technologies

    Joined:
    Aug 11, 2006
    Posts:
    3,355
    At least declare it in the Cg code, like you would any other exposed property.
     
  5. leftchannel

    leftchannel

    Joined:
    Feb 28, 2014
    Posts:
    25
    I must not have the right syntax on this. I've tried adding "fixed _Cutoff;" next to the two sampler2D declarations, and it gives me this:
    Code (csharp):
    1. Shader error in 'Mobile/Bumped Diffuse Cutoff': declaration of "_Cutoff" conflicts with previous declaration at (22) at line 97
    (I also tried it with 'float', same effect)

    Bear in mind I am not in any way a shader programmer, and anytime I do shader programming it's pretty much always cobbled together from anything I can Google.

    (Sidenote: Error messages like this one, which appears to point me to a line that does not exist, are, in fact, the exact reason I've never been able to learn shader programming despite several attempts.)
     
  6. Daniel_Brauer

    Daniel_Brauer

    Unity Technologies

    Joined:
    Aug 11, 2006
    Posts:
    3,355
    Re-reading your first post, I think I might've sent you down the wrong path: I think your original shader is totally fine. The issue is likely a bug in Unity. Try contacting support.