Hi,I'm trying to translate one of my shaders from HLSL to Cg,but it seems that I'm not able to use more than 8 textures in a single pass? In HLSL I used a total of 16,so the number of texture units on my card must be sufficient for more... Here's the shader code,when adding additional textures,i get some vague error.Try uncommenting one of the lines in frag portion to see what i mean. Am I missing something? Code (csharp): Shader "Terrain/ThreeLayer Bumped" { Properties { _Color ("Main Color", Color) = (1,1,1,1) _Shadow ("AO shadow", Color) = (1,1,1,1) _Roughness ("Roughness", Range (0.0, 1.0)) = 0.0 // _Burn ("Lightmap multiplier", Range (0.0, 2.0)) = 1.3 _SpecColor ("Specular Color", Color) = (0.5, 0.5, 0.5, 1) _Shininess ("Shininess", Range (0.01, 1)) = 0.078125 _Parallax ("Height", Range (0.005, 0.08)) = 0.02 _MainTex ("Base (RGBA)", 2D) = "white" {} _MainTex_b ("Bumpmap (RGBA)", 2D) = "bump" {} _MainTex2 ("Base 2 (RGBA)", 2D) = "white" {} _MainTex2_b ("Bumpmap 2 (RGBA)", 2D) = "bump" {} _MainTex3 ("Base 3 (RGBA)", 2D) = "white" {} _MainTex3_b ("Bumpmap 3 (RGBA)", 2D) = "bump" {} _MainTex4 ("Base 4 (RGBA)", 2D) = "white" {} _MainTex4_b ("Bumpmap 4 (RGBA)", 2D) = "bump" {} _lightmap ("Lightmap", 2D) = "white" {} _Mask ("Mix Mask (RGBA)", 2D) = "gray" {} } Category { Tags{ "RenderType"="Opaque"} Blend AppSrcAdd AppDstAdd // Cull Back SubShader { UsePass "Diffuse/BASE" Pass { Name "Blend_Layers" Tags { "LightMode" = "Pixel"} Color [_PPLAmbient] Material { Diffuse [_Color] } CGPROGRAM #pragma target 3.0 #pragma vertex vert #pragma fragment frag #pragma fragmentoption ARB_fog_exp2 #pragma fragmentoption ARB_precision_hint_fastest #pragma multi_compile_builtin #include "UnityCG.cginc" #include "AutoLight.cginc" struct v2f { V2F_POS_FOG; LIGHTING_COORDS half3 uv; half2 uv2 ; half3 viewDirT; half3 lightDirT; }; half4 _MainTex_ST,_Mask_ST; uniform half _Shininess; v2f vert (appdata_tan v) { v2f o; PositionFog( v.vertex, o.pos, o.fog ); o.uv.xy = TRANSFORM_TEX(v.texcoord, _MainTex); o.uv.z = _Shininess * 128; o.uv2 = TRANSFORM_TEX(v.texcoord, _Mask); TANGENT_SPACE_ROTATION; o.viewDirT = mul( rotation, ObjSpaceViewDir( v.vertex ) ); o.lightDirT = mul( rotation, ObjSpaceLightDir( v.vertex ) ); TRANSFER_VERTEX_TO_FRAGMENT(o); return o; } uniform sampler2D _MainTex; uniform sampler2D _MainTex2; uniform sampler2D _MainTex3; uniform sampler2D _MainTex4; uniform sampler2D _MainTex_b; uniform sampler2D _MainTex2_b; uniform sampler2D _MainTex3_b; uniform sampler2D _MainTex4_b; uniform sampler2D _lightmap; uniform sampler2D _Mask; uniform half _Parallax; uniform half _Roughness; uniform half3 _Shadow; //uniform half _Burn; float4 frag (v2f i) : COLOR { half2 uv=1-(i.uv.xy); half4 mix = tex2D(_Mask,i.uv2); half n1 = tex2D(_MainTex_b, uv).a ; half n2 = tex2D(_MainTex2_b, uv).a ; half n3 = tex2D(_MainTex3_b, uv).a ; half n4 = tex2D(_MainTex4_b, uv).a ; half result=n1; result=((result*(1-mix.r)) + n4*(mix.r)); result=((result*(1-mix.g)) + n2*(mix.g)); result=((result*(1-mix.b))+n3*(mix.b)); half2 offset1 = ParallaxOffset( result, -_Parallax, i.viewDirT )+uv; half2 offset2 = ParallaxOffset( result, -_Parallax, i.viewDirT )+uv; half2 offset3 = ParallaxOffset( result, -_Parallax, i.viewDirT )+uv; half2 offset4 = ParallaxOffset( result, -_Parallax, i.viewDirT )+uv; half3 normal1 = tex2D(_MainTex_b, (offset1)).rgb * 2 -1; half3 normal2 = tex2D(_MainTex2_b, (offset2)).rgb * 2 -1; half3 normal3 = tex2D(_MainTex3_b, (offset3)).rgb * 2 -1; half3 normal4 = tex2D(_MainTex4_b, (offset4)).rgb * 2 -1; half3 resultn=normal1; //resultn= ((resultn*(1-mix.r))+normal4*(mix.r)); resultn= ((resultn*(1-mix.g)) + normal2*(mix.g)); resultn= ((resultn*(1-mix.b))+normal3*(mix.b)); half4 col1 = tex2D(_MainTex,offset1); half4 col2 = tex2D(_MainTex2,offset2); half4 col3 = tex2D(_MainTex3,offset3); //half4 col4 = tex2D(_MainTex4,offset4); half3 lightmap = tex2D(_lightmap,(i.uv2)).rgb; half4 result1=col1; //result1= ((result1*(1-mix.r)) + col4*(mix.r)); result1= ((result1*(1-mix.g)) + col2*(mix.g)); result1= ((result1*(1-mix.b))+col3*(mix.b)); result1.rgb *=1.2*lightmap; result1.rgb=lerp(result1.rgb,result1.rgb*_Shadow,((1-result)+resultn.r+resultn.g)*_Roughness); return SpecularLight( i.lightDirT, i.viewDirT,resultn, result1,i.uv.z-(result1.rgb*_Shadow), LIGHT_ATTENUATION(i) ); } ENDCG } } } Fallback "Diffuse", 1 }
apple_motion definitely made a shader that uses nine textures. That said, there are definitely some unanswered questions about Unity's texture limits, or how it interacts with different cards.
What's the error you are getting exactly. I'm running into a texture indirection limit error which is specific to ATI cards. I'm not sure that's the same error that you're seeing though. You should probably look into fixing the texture indirection problem even if it's not an error you're seeing though. (Do a search for Texture Indirection here for an explanation: http://oss.sgi.com/projects/ogl-sample/registry/ARB/fragment_program.txt) ATI cards have a limit of 4.
I did run into texture indirection error,but from what i've read on the forum,its an OpenGL problem. So i added some code to compile only to D3D9: Code (csharp): #pragma profileoption MaxTexIndirections=16 #pragma only_renderers d3d9 #pragma exclude_renderers opengl Now i do get 10 textures on the object,but also get a constant bad texcoord index error.Plus,when shadows are enabled,my object turns black and i get a hall-of-mirrors effect when zoomed close to it.