0
\$\begingroup\$

I'm trying to use passes from a given built-in shader in Unity. The docs say that the syntax is UsePass "Name". The problem is that built-in shaders don't have names on their passes. How could I do that in this case?

To be more specific, at the moment I need to use the Skybox shader passes. Here is one of the Subshaders in the internal Skybox.shader file:

SubShader {
Tags { "Queue"="Background" "RenderType"="Background" }
Cull Off ZWrite Off Fog { Mode Off }
Color [_Tint]
Pass {
    SetTexture [_FrontTex] { combine texture +- primary, texture * primary }
}
Pass {
    SetTexture [_BackTex]  { combine texture +- primary, texture * primary }
}
Pass {
    SetTexture [_LeftTex]  { combine texture +- primary, texture * primary }
}
Pass {
    SetTexture [_RightTex] { combine texture +- primary, texture * primary }
}
Pass {
    SetTexture [_UpTex]    { combine texture +- primary, texture * primary }
}
Pass {
    SetTexture [_DownTex]  { combine texture +- primary, texture * primary }
}
}

As can be seen there's no name in the passes. My shader is the following:

Shader "Custom/Outline" {
Properties {
_Color ("Main Color", Color) = (.5,.5,.5,1)
    _OutlineColor ("Outline Color", Color) = (1,0,0,1)
    _Outline ("Outline width", Range (0.0, 0.1)) = .05
_SpecColor ("Specular Color", Color) = (0.5, 0.5, 0.5, 1)
_Shininess ("Shininess", Range (0.03, 1)) = 0.078125
_MainTex ("Base (RGB) Gloss (A)", 2D) = "white" {}
}

SubShader {
//Tags { "RenderType"="Opaque" }
Tags { "RenderType"="Background" }
Pass {
    Name "OUTLINE"
    Tags { "LightMode" = "Always" }

    // Outline pass logic (not important for the problem)...
}
UsePass "RenderFX/Skybox/..." // WHAT SHOULD I DO HERE?
//UsePass "Bumped Specular/FORWARD"
}

The problematic line is at the end, as can be seen. The shader works for the Opaque case, using the "Bumped Specular/FORWARD" pass (see the commented lines). The built-in Bumped Specular shader is the following:

Shader "Bumped Specular" {
Properties {
_Color ("Main Color", Color) = (1,1,1,1)
_SpecColor ("Specular Color", Color) = (0.5, 0.5, 0.5, 1)
_Shininess ("Shininess", Range (0.03, 1)) = 0.078125
_MainTex ("Base (RGB) Gloss (A)", 2D) = "white" {}
_BumpMap ("Normalmap", 2D) = "bump" {}
}
SubShader { 
Tags { "RenderType"="Opaque" }
LOD 400

CGPROGRAM
#pragma surface surf BlinnPhong


sampler2D _MainTex;
sampler2D _BumpMap;
fixed4 _Color;
half _Shininess;

struct Input {
float2 uv_MainTex;
float2 uv_BumpMap;
};

void surf (Input IN, inout SurfaceOutput o) {
fixed4 tex = tex2D(_MainTex, IN.uv_MainTex);
o.Albedo = tex.rgb * _Color.rgb;
o.Gloss = tex.a;
o.Alpha = tex.a * _Color.a;
o.Specular = _Shininess;
o.Normal = UnpackNormal(tex2D(_BumpMap, IN.uv_BumpMap));
}
ENDCG
}

FallBack "Specular"
}

Even when using the Bumped Specular I had to find the pass name by trial and error, seeing code snippets from older versions, etc. That's why I like to have code for everything... I could just read the code of the shader management system and figure it out. Anyway... any ideas?

\$\endgroup\$
3
  • \$\begingroup\$ Not quite the answer you're looking for, but you can get the source for the built-in shaders, name the passes, and override the built-in shaders. \$\endgroup\$ – David Cummins Nov 13 '13 at 23:07
  • \$\begingroup\$ How do I override the built-in shaders? \$\endgroup\$ – dsilva.vinicius Nov 13 '13 at 23:30
  • \$\begingroup\$ I can check when I'm at home, as I've done it for the terrain shader, but I think it's just based on the shader name, and you may need to put it in the Standard Assets folder. \$\endgroup\$ – David Cummins Nov 14 '13 at 21:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.