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 Rombo · Nov 03, 2010 at 02:34 PM · shadersurface

How can I use more than 3 texture channels in a Surface Shader?

I'm writing a surface shader that have a base texture, a reflection cube map, a Normal map and a Light map. When I use all four maps inside surface function, I get the error:

Shader error in 'Reflective/Diffuseprb': Too many texture interpolators would be used for ForwardBase pass at line 21

Here is the code:

Shader "Reflective/Diffuseprb" {

Properties { _Color ("Main Color", Color) = (1, 1, 1, 1) _ReflectColor ("Reflection Color", Color) = (1, 1, 1, 1) _MainTex ("Base (RGB) RefStrength (A)", 2D) = "white" {} _Cube ("Reflection Cubemap", Cube) = "_Skybox" { TexGen CubeReflect } _BumpMap ("Normalmap", 2D) = "bump" {} _LightMap ("Lightmap (RGB)", 2D) = "black" {} }

SubShader { Tags { "Queue"="Transparent" "RenderType"="Transparent"} LOD 300

 Cull Off
 Lighting On
 AlphaTest Greater 0.5


 CGPROGRAM

// #pragma surface surf Lambert alpha // #pragma vertex vert_img #pragma surface surf Lambert alpha #pragma debug

 sampler2D _MainTex;
 samplerCUBE _Cube;
 sampler2D _BumpMap;
 sampler2D _LightMap;

 float4 _Color;
 float4 _ReflectColor;

 struct Input {
     float2 uv_MainTex;
     float3 worldRefl;
     float2 uv_BumpMap;
     float2 uv_LightMap;
     INTERNAL_DATA
 };

 void surf (Input IN, inout SurfaceOutput o) {
     half4 tex = tex2D(_MainTex, IN.uv_MainTex);
     half4 c = tex * _Color;
     o.Albedo = c.rgb;

     half4 reflcol = texCUBE (_Cube, IN.worldRefl) * _ReflectColor;
     c = tex2D(_LightMap, IN.uv_LightMap);
     o.Emission = (reflcol.rgb * _ReflectColor.a) + c.rgb;
     o.Alpha = _Color.a + reflcol.a * _ReflectColor.a;
     o.Normal = UnpackNormal(tex2D(_BumpMap, IN.uv_BumpMap)) * 2.0;
 }


 ENDCG

}

 Fallback "Transparent/VertexLit"

}

Please, help me

Thanks

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

3 Replies

· Add your reply
  • Sort: 
avatar image
2
Best Answer

Answer by skovacs1 · Nov 03, 2010 at 05:20 PM

The UVs on your Input are the UV coordinates for each vertex stored with the mesh and Unity only takes in 2 sets of them so you can have at most two of them. See the docs on CG program inputs.

Because of this, you will have to share, but if the mapping coordinates are the same then it won't matter and you could even use the same coords for all three textures (in which case you might consider just baking some of the textures together like your lightmap for this example). You might want to consider actually using the second UV channel for your second UV if you actually intend to use both UVs (specified with uv2).

Shader "Reflective/Diffuseprb" { Properties { _Color ("Main Color", Color) = (1, 1, 1, 1) _ReflectColor ("Reflection Color", Color) = (1, 1, 1, 1) _MainTex ("Base (RGB) RefStrength (A)", 2D) = "white" {} _BumpMap ("Normalmap", 2D) = "bump" {} _LightMap ("Lightmap (RGB)", 2D) = "black" {} _Cube ("Reflection Cubemap", Cube) = "_Skybox" { TexGen CubeReflect } }

 SubShader {
     Tags { "Queue"="Transparent" "RenderType"="Transparent"}
     LOD 300
     Cull Off
     Lighting On
     AlphaTest Greater 0.5

     CGPROGRAM
     //#pragma surface surf Lambert alpha
     //#pragma vertex vert_img
     #pragma surface surf Lambert alpha
     #pragma debug

     sampler2D _MainTex;
     sampler2D _BumpMap;
     sampler2D _LightMap;
     samplerCUBE _Cube;
     float4 _Color;
     float4 _ReflectColor;

     struct Input {
         float2 uv_MainTex;
         float2 uv_LightMap;
         float3 worldRefl;
         INTERNAL_DATA
     };

     void surf (Input IN, inout SurfaceOutput o) {
         half4 tex = tex2D(_MainTex, IN.uv_MainTex);
         half4 c = tex * _Color;
         o.Albedo = c.rgb;

         half4 reflcol = texCUBE (_Cube, IN.worldRefl) * _ReflectColor;
         c = tex2D(_LightMap, IN.uv_LightMap);
         o.Alpha = _Color.a + reflcol.a * _ReflectColor.a;
         o.Normal = UnpackNormal(tex2D(_BumpMap, IN.uv_MainTex)) * 2.0;
         o.Emission = (reflcol.rgb * _ReflectColor.a) + c.rgb;
     }
     ENDCG

 }
 Fallback "Transparent/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 Rombo · Nov 04, 2010 at 04:36 AM 0
Share

Thank you very much! You have solved my problem :)

avatar image
0

Answer by jpcorp · Feb 01, 2011 at 04:58 AM

remove cubemap calaulation.

Comment
Add comment · 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
0

Answer by petersvp · Jun 16, 2015 at 09:51 PM

Your Input structure consumes too much interpolators. Assign semantics to members. Like TEXCOORD, COLOR, etx.

Comment
Add comment · 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

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

1 Person is following this question.

avatar image

Related Questions

A node in a childnode? 1 Answer

Hard surface shader tutorial? 0 Answers

How can I get GLSL shaders to work in Unity? 0 Answers

Coloured specularity mapping? 1 Answer

Using TEXCOORD1 in surface shader 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