Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by primat · Jun 11, 2013 at 02:13 PM · shadertexturesurface shader

Too many texture interpolators would be used... Why?

Hey everybody,

I tried everything but there is still the message: Too many texture interpolators would be used for ForwardBase pass at line 16. The input and outputs structs are already tweaked. I don't understand what's wrong. Has anybody an idea?

     Shader "Reflection/SpecularNormal"
     {
     
         Properties
         {
             _MainTexture("Diffuse Map", 2D) = "white"{}
             _NormalMap("Normal Map", 2D) = "bump"{}
             _ReflectionMap("Reflection Map", 2D) = "white"{}
             _Cube ("Reflection Cubemap", Cube) = "_Skybox" { TexGen CubeReflect }
         }
         
         SubShader 
         {
             Tags { "RenderType" = "Opaque" }
             
             CGPROGRAM
             #pragma surface surf ColoredSpecular
             
     
             struct MySurfaceOutput 
             {
                 fixed3 Albedo;
                 fixed3 Normal;
                 fixed3 Emission;
                 fixed Alpha;
             };
             
             inline half4 LightingColoredSpecular (MySurfaceOutput s, half3 lightDirection, half3 viewDirection, half attenuation)
             {
                 half3 halfVector = normalize (lightDirection + viewDirection);
                 half diffuseLight = max (0, dot (s.Normal, lightDirection));
                 float specularBase = max (0, dot (s.Normal, halfVector));
                 float specularLight = pow (specularBase, 128.0 * 0.55f); //Magic numbers because the struct must be small
                 half3 specColor = 0.15f * specularLight * s.Albedo;
                 half4 c;
                 c.rgb = (s.Albedo * _LightColor0.rgb * diffuseLight + _LightColor0.rgb * specColor) * (attenuation * 2);
                 c.a = s.Alpha;
                 return c;
             }
     
             struct Input 
             {
                 float2 uv_MainTexture;
                 float3 worldRefl;
             };
             
             sampler2D _MainTexture;
             sampler2D _NormalMap;
             sampler2D _ReflectionMap;
             samplerCUBE _Cube;
             fixed4 _ReflectColor;
             
             void surf (Input IN, inout MySurfaceOutput o)
             {
                 fixed4 tex = tex2D(_MainTexture, IN.uv_MainTexture);
                 o.Albedo = tex.rgb;
                 o.Normal = UnpackNormal(tex2D(_NormalMap, IN.uv_MainTexture));
                 
                 fixed4 reflectionColor = tex2D(_ReflectionMap, IN.uv_MainTexture);
                 fixed4 reflcol = texCUBE (_Cube, IN.worldRefl);
                 reflcol *= tex.a;
                 o.Emission = reflcol.rgb * reflectionColor.rgb;
                 o.Alpha = reflcol.a * reflectionColor.a;
             }
             
             ENDCG
         }
         
     
         Fallback "Reflective/VertexLit"
     }
     
 
Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
7

Answer by keeperkai2 · Jun 26, 2013 at 04:20 PM

by adding:

#pragma target 3.0

#pragma debug

under the surface function declaration(#pragma surface surf ColoredSpecular) and removing your "MySurfaceOutput" struct declaration and replacing MySurfaceOutput with the unity built-in struct SurfaceOutput. The shader will work. So let's take a look at the compiled cg code:

 struct v2f_surf {
   float4 pos : SV_POSITION;
   float2 pack0 : TEXCOORD0;
   fixed4 TtoW0 : TEXCOORD1;
   fixed4 TtoW1 : TEXCOORD2;
   fixed4 TtoW2 : TEXCOORD3;
   fixed3 lightDir : TEXCOORD4;
   fixed3 vlight : TEXCOORD5;
   float3 viewDir : TEXCOORD6;
   LIGHTING_COORDS(7,8)
 };

this is the vertex output of the vertex shader, as you can see, the struct v2f contains 0-8, 9 in total interpolated values, the default shader model for unity is shader model 2.0, which only supports 8, so by declaring #pragma target 3.0, we will get 2 more interpolaters for us to use( if your graphics cards supports shader model 3.0). here is the code that works:

 Shader "Reflection/SpecularNormal"
 {
  
 Properties
 {
 _MainTexture("Diffuse Map", 2D) = "white"{}
 _NormalMap("Normal Map", 2D) = "bump"{}
 _ReflectionMap("Reflection Map", 2D) = "white"{}
 _Cube ("Reflection Cubemap", Cube) = "_Skybox" { TexGen CubeReflect }
 }
  
 SubShader
 {
 Tags { "RenderType" = "Opaque" }
  
 CGPROGRAM
 #pragma surface surf ColoredSpecular
 #pragma target 3.0
 #pragma debug
 inline half4 LightingColoredSpecular (SurfaceOutput s, half3 lightDirection, half3 viewDirection, half attenuation)
 {
 half3 halfVector = normalize (lightDirection + viewDirection);
 half diffuseLight = max (0, dot (s.Normal, lightDirection));
 float specularBase = max (0, dot (s.Normal, halfVector));
 float specularLight = pow (specularBase, 128.0 * 0.55f); //Magic numbers because the struct must be small
 half3 specColor = 0.15f * specularLight * s.Albedo;
 half4 c;
 c.rgb = (s.Albedo * _LightColor0.rgb * diffuseLight + _LightColor0.rgb * specColor) * (attenuation * 2);
 c.a = s.Alpha;
 return c;
 }
  
 struct Input
 {
 float2 uv_MainTexture;
 float3 worldRefl;
 INTERNAL_DATA
 };
  
 sampler2D _MainTexture;
 sampler2D _NormalMap;
 sampler2D _ReflectionMap;
 samplerCUBE _Cube;
 fixed4 _ReflectColor;
  
 void surf (Input IN, inout SurfaceOutput o)
 {
 fixed4 tex = tex2D(_MainTexture, IN.uv_MainTexture);
 o.Albedo = tex.rgb;
 o.Normal = UnpackNormal(tex2D(_NormalMap, IN.uv_MainTexture));
  
 fixed4 reflectionColor = tex2D(_ReflectionMap, IN.uv_MainTexture);
 fixed4 reflcol = texCUBE (_Cube, IN.worldRefl);
 reflcol *= tex.a;
 o.Emission = reflcol.rgb * reflectionColor.rgb;
 o.Alpha = reflcol.a * reflectionColor.a;
 }
  
 ENDCG
 }
  
  
 Fallback "Reflective/VertexLit"
 }
Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Benproductions1 · Jun 29, 2013 at 04:19 AM 0
Share

Very good answer, would be better if the code was indented properly

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

17 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Is using texture offset with displacement shader possible? 0 Answers

apply a map to a surface shader using its original size and tiling 0 Answers

Can you get texture scale/offset in a surface shader? 0 Answers

Textures missing after extended gameplay on Playstation game,Missing Textures after extended play on Playstation 4 game 1 Answer

how to import a mixed texture from blender 2 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges