Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct here to familiarize yourself with the rules and how to post constructively.

  2. Unity 2022.1 is now available as the latest Tech release.
    Dismiss Notice
  3. Improve your project's performance with our new guide on profiling in Unity.
    Dismiss Notice

Why this shader is expensive?

Discussion in 'Shaders' started by hvilela, Jul 8, 2013.

  1. hvilela

    hvilela

    Joined:
    Dec 6, 2010
    Posts:
    24
    I have this simple shader, why would Unity tell me that it's "expensive on this platform"?
    Does it looks expensive somehow?

    Code (csharp):
    1. Shader "Test" {
    2.     Properties {
    3.         _MainTex ("Diffuse Texture, gloss(A)", 2D) = "white" {}
    4.     }
    5.  
    6.     SubShader {
    7.         Tags { "Queue"="Geometry" "RenderType"="Opaque"}
    8.  
    9.         LOD 400
    10.         Pass {
    11.             Name "FORWARD"
    12.             Tags { "LightMode" = "ForwardBase" }
    13.             Program "vp" {
    14. // Vertex combos: 8
    15. //   opengl - ALU: 6 to 21
    16. SubProgram "opengl " {
    17. Keywords { "DIRECTIONAL" "LIGHTMAP_OFF" "DIRLIGHTMAP_OFF" "SHADOWS_OFF" }
    18. Bind "vertex" Vertex
    19. Bind "tangent" ATTR14
    20. Bind "normal" Normal
    21. Bind "texcoord" TexCoord0
    22. Vector 10 [_WorldSpaceLightPos0]
    23. Matrix 5 [_World2Object]
    24. Vector 11 [_MainTex_ST]
    25. "3.0-!!ARBvp1.0
    26. # 16 ALU
    27. PARAM c[12] = { program.local[0],
    28.         state.matrix.mvp,
    29.         program.local[5..11] };
    30. TEMP R0;
    31. TEMP R1;
    32. TEMP R2;
    33. MOV R0.xyz, vertex.attrib[14];
    34. MUL R1.xyz, vertex.normal.zxyw, R0.yzxw;
    35. MAD R0.xyz, vertex.normal.yzxw, R0.zxyw, -R1;
    36. MOV R1, c[10];
    37. DP4 R2.z, R1, c[7];
    38. DP4 R2.y, R1, c[6];
    39. DP4 R2.x, R1, c[5];
    40. MUL R0.xyz, R0, vertex.attrib[14].w;
    41. DP3 result.texcoord[4].y, R2, R0;
    42. DP3 result.texcoord[4].z, vertex.normal, R2;
    43. DP3 result.texcoord[4].x, R2, vertex.attrib[14];
    44. MAD result.texcoord[0].xy, vertex.texcoord[0], c[11], c[11].zwzw;
    45. DP4 result.position.w, vertex.position, c[4];
    46. DP4 result.position.z, vertex.position, c[3];
    47. DP4 result.position.y, vertex.position, c[2];
    48. DP4 result.position.x, vertex.position, c[1];
    49. END
    50. # 16 instructions, 3 R-regs
    51. "
    52. }
    53. }
     
    Last edited: Jul 8, 2013
  2. Daniel_Brauer

    Daniel_Brauer

    Unity Technologies

    Joined:
    Aug 11, 2006
    Posts:
    3,356
    Can you provide the original shader code? That's just the first part of the compiled shader.
     
  3. hvilela

    hvilela

    Joined:
    Dec 6, 2010
    Posts:
    24
    Here it goes:

    Code (csharp):
    1. Shader "Teste" {
    2.     Properties {
    3.         _MainTex ("Diffuse Texture, gloss(A)", 2D) = "white" {}
    4.     }
    5.  
    6.     SubShader {
    7.         Tags { "Queue"="Geometry" "RenderType"="Opaque"}
    8.  
    9.         Pass {
    10.             Tags { "LightMode" = "ForwardBase" }
    11.  
    12.             CGPROGRAM
    13.  
    14.             #pragma vertex vert_surf
    15.             #pragma fragment frag_surf
    16.             #pragma fragmentoption ARB_precision_hint_fastest
    17.             #pragma multi_compile_fwdbase
    18.             #pragma only_renderers opengl
    19.  
    20.             #include "HLSLSupport.cginc"
    21.             #include "UnityCG.cginc"
    22.             #include "Lighting.cginc"
    23.             #include "AutoLight.cginc"
    24.  
    25.             sampler2D _MainTex;
    26.  
    27.             struct Input {
    28.                 float2 uv_MainTex;
    29.             };
    30.  
    31.             void surf (Input IN, inout SurfaceOutput o) {
    32.                 o.Albedo = tex2D(_MainTex, IN.uv_MainTex).rgb;
    33.                 o.Normal = fixed3(0.0, 0.0, 1.0);
    34.             }
    35.  
    36.             struct v2f_surf {
    37.                 float4 pos : SV_POSITION;
    38.                 float4 pack0 : TEXCOORD0;
    39.                 fixed3 lightDir : TEXCOORD1;
    40.                 LIGHTING_COORDS(2, 3)
    41.             };
    42.    
    43.             float4 _MainTex_ST;
    44.            
    45.             v2f_surf vert_surf (appdata_full v) {
    46.                 v2f_surf o;
    47.                 o.pos = mul (UNITY_MATRIX_MVP, v.vertex);
    48.                 o.pack0.xy = TRANSFORM_TEX(v.texcoord, _MainTex);
    49.  
    50.                 TANGENT_SPACE_ROTATION;
    51.    
    52.                 o.lightDir = mul (rotation, ObjSpaceLightDir(v.vertex));
    53.    
    54.                 TRANSFER_VERTEX_TO_FRAGMENT(o);
    55.    
    56.                 return o;
    57.             }
    58.    
    59.             fixed4 frag_surf (v2f_surf IN) : COLOR {
    60.                 Input surfIN;
    61.                 surfIN.uv_MainTex = IN.pack0.xy;
    62.  
    63.                 SurfaceOutput o;
    64.                 surf (surfIN, o);
    65.                
    66.                 return LightingLambert (o, IN.lightDir, LIGHT_ATTENUATION(IN));
    67.             }
    68.  
    69.             ENDCG
    70.         }
    71.     }
    72. }
     
unityunity