too many texture interpolators

Hello !

I got this error from a surface shader with a frag program.

This shader have 1 MainTex ( from mesh UV ) and 2 bumps with UV coords generated with _Time in vert prog.

I need to target this shader to PS2.0 boards, in wich i know there are 8 interpolators…
This means that surf shaders use 6 interpolators for doing… NOTHING !
Did UT shaderlab developpers try to reinvent fixed function pipeline ? ROFLMAO ! :smile:

Anyway, all those hidden things ( i just discovered an hidden feature: when you start var with ‘uv_’
and you set it up in VP, for use in surf,it does nothing. If you start it with something else ( eg ‘ab_’ )
it works perfectly ! LOL thanks to dev team, hardcoding crap with common used things ) really
bother the developper. OK, you can do a ‘show_my_mesh_in_a_wonderfull_way’ shader in 2 lines
of code, but if you can’t do anything else, it’s nothin but crap. This is the reason why Pixar invented
shaders, and it’s a shame UT want to kill them…

Well after this small sequence of ‘lemme say what i think’, and as i know UT don’t care about
opinions, can anybody tell me wether or not it’s possible to write a shader having 1 MainTex
and 2 bumps with coordinates generated in FP.
I already did it, but with bumps coords generated in surface. It works for #target 3.0, but for 2.0
it explodes the instruction limit.

Any idea ?

thanks a lot for your answers !

EDIT: when i say:
“This means that surf shaders use 6 interpolators for doing… NOTHING !”, i perfectly know
that the code does things, but, as it’s on purpose hidden undocumented piece of things, i put
myself in the mode ‘i dont care what’s behind’. And this bothers me, as the hidden behind
prevents me for doing what i want to.

So write it yourself without using surface shaders?

I wouldn’t say it’s “doing nothing”. When you write a surface shader, you explicitly want Unity to auto-generate all the lighting shadowing code for you. Passing light vectors, shadowmap UVs and so on does take up interpolators and instructions.

If you don’t want all of the above, then don’t write a surface shader. Surface shader is this “bunch of auto-generated code for lighting shadowing”. If you don’t want that, don’t use it! Your shaders will be smaller and run faster.

Ah ah farfarer !!! 1 point for you !!! :wink:
I really consider this but… To be totally honest it’s not my job, tho there might be no other way.
It’s UT dev team job to provide ppl with tools. In the absolute you’re right, but 40 years ago,
( reals ) computer enginneers invented a thing called compiler. It was a tool allowing programmers
to gain 98% of the time they spent, against a really minimal loss of features ( eg: it became
prohibited to create for example auto-modifying code ( tho in C it’s still possible )). Nowadays,
with all the tech and wisdom of shaderlab developpers, i have no other choice to get back 40 years
ago and do all by myself by hand. This looks like a proof that unity big tech advances are in fact
a big jump in the past.
Ok i’m dumbass saying nothing but lies…
hmm lemme just give an example :wink:
this —>http://forum.unity3d.com/threads/14387-Pro-water-with-3-bump-maps
PS2.0 almost dinausor cards…
3 bumps
legions of textures interpolators
etc…
and this works
surf Shaders brought this to 3 lines of code… It’s really nice ! but i can do much better for the same result. 0 line
of code ! just because it can’t work.
And at last but not least as shaderlab gods ( who say shaders must die… laugh my ass off ! ) think they’re the
only ones in the right way, they don’t consider usefull to document their work and how to still achieve what was
achievable with older tech that is not achievable anymore with new one. A doc about surf shaders few lines
would be worth long pages of doc… instead of this we got only few obfuscated ones and some few useless
examples. Looks really unfair as shaders are the master stone of today’s games.

If anyone have some clue about how to achieve those simple things, please post here :slight_smile:
now i got time to waste because of unity high technology :stuck_out_tongue_winking_eye:

have nice day

@aras:
sry you posted just while i was writing. Yes, that’s the point i came to. Do it myself.
frag and vert are my friends and retrieving all undocumented lighting helpers should
be easy…
thx tho.

The light helpers aren’t undocumented. They’re all in AutoLight.cginc or UnityCG.cginc… most of it’s self-documenting with the naming schemes.

lol farfarer !
self-documenting with the naming schemes. Mostly like an airplane is self-documented thanks to it’s mechanical parts presence ;-D
sounds like a lazy coder answer…

well… anyway, i was going to ask if someone had the might to write a specular frag-vert shader for unity 3.0+ and due to an internet
disconnection, i couldn’t post the question. i then try to do one of my own ( in wich UnityCG.cginc was all but helpfull as it only talks about shadows… )

As community seems pretty jealous on simple code they share, i’m not sure i post it here…

:wink:
ok i do post it, as i believe it’s some kind of unanswered question loads of ppl might ask for.
here’s the piece of code

Shader "try_fp_vp_spec_for_U3" {
    Properties {
        _MainTex ("Base (RGB)", 2D) = "white" {}
		_SpecColor ("Specular Color", Color) = (0.5, 0.5, 0.5, 0)
		_spechardness ("Spec hardness", Range (0.01, 128)) = 0.078125

		_blop ("Spec strength", Range (0.9, 2)) = 0.078125

    }
    SubShader {
        Tags { "RenderType"="Opaque" }
        LOD 200
        
        Pass {
            CGPROGRAM
                #pragma vertex vert
                #pragma fragment frag
                #include "UnityCG.cginc"
            
                struct v2f {
                    float4 pos : SV_POSITION;
                    float2 uv_MainTex : TEXCOORD0;
					float3 lightdir;
					float3 viewdir;
					float3 norm;
                };
            
                float4 _MainTex_ST;
				half4 _SpecColor;
				half _spechardness; 
				half _blop;



				inline half4 SpecularLight( half3 lightDir, half3 viewDir, half3 normal, half4 color, float spec_hardness)
				{
					lightDir = normalize(lightDir);
					viewDir = normalize(viewDir);

					half3 h = normalize( lightDir + viewDir );
					half diffuse = dot( normal, lightDir );
					
					float nh = saturate( dot( h, normal) )*_blop;
					float spec = pow( nh, spec_hardness ) * color.a;
					
					half4 c;
					c.rgb = (color.rgb  * diffuse + _SpecColor.rgb * spec)*2; // smash observer eyes with enhanced luminance
					c.a =  _SpecColor.a * spec;
					return c;
				}


                v2f vert(appdata_full v) 
				{
                    v2f o;
                    o.pos = mul(UNITY_MATRIX_MVP, v.vertex);
                    o.uv_MainTex = TRANSFORM_TEX(v.texcoord, _MainTex);
					
					o.norm = v.normal;
			
					o.lightdir = ObjSpaceLightDir(_WorldSpaceLightPos0); // hopefully _WorldSpaceLightPos0 is not empty crap ! once is not use....
					o.viewdir = ObjSpaceViewDir( v.vertex );
					
                    return o;
                }
            
                sampler2D _MainTex;
            
                float4 frag(v2f IN) : COLOR 
				{
                    half4 Albedo = tex2D (_MainTex, IN.uv_MainTex);
					half4 c = SpecularLight( IN.lightdir, IN.viewdir, IN.norm,Albedo, _spechardness); // no atten for directionnal light. sry for thos who need atten...
                    return c;
                }
            ENDCG
        }
    }
}

i grabbed the spec inline function in old 2.6 unityCG.cginc.

NOTE: this code is from a dumb-ass shader programmer: ME
if you can enhance it ( wich is more than probable ) please share it :wink:

thanks to all and regards !

One more question…

How can i handle ambient light in fragment and vertex programs ?
UNITY_LIGHTMODEL_AMBIENT.xyz builtin variable seems not to match correctly unity generic shaders ambient handling…

please help on this.

thanks

In Unity’s surface shaders, the ambient light contribution works out to be

ambient * albedo * 2

Ok, got it with _PPLAmbient.
Thanks farfarer for your answer about surf shaders, but i don’t use this feature atm :wink:
I’m trying to write a specular vert frag shader from scratch for U3.0+

The deal is to find the good var in *.CGINC among all the unused ones, like those:
float4 unity_LightColor[4];
float4 unity_LightPosition[4];
float4 unity_LightAtten[4];

Finally, _PPLAmbient is nowhere ( rofl ) and undocumented ( except from its name that you can find in some site on the web. didn’t find it on unity’s one tho…) but still used and seems to work properly as an ambient color provider…

Now i’m bugged with _lightcolor0 wich seems to be the directionnal light color during the pass corresponding to it.
At some angle of the camera, this light color drops to 0 and mesh becomes unlit… I think i’m gonna bring my own light color value to the shader as i found nothing among the mess of docs, examples and other discussions…
what you think 'bout it ?

ah here the current spec shader from scratch with PPLAmbient:

Shader "VPFP_specular" {
    Properties {
        _MainTex ("Base (RGB)", 2D) = "white" {}
		_SpecColor ("Specular Color", Color) = (0.5, 0.5, 0.5, 0)
		_Shininess ("Shininess", Range (0.01,1)) = 0.078125

		_Gloss ("Gloss", Float) = 0.078125

    }
    SubShader {
        Tags {"Queue"="Geometry" "RenderType" = "Opaque" 	"IgnoreProjector"="True"}
        LOD 200

        Pass {
            CGPROGRAM

                #pragma vertex vert
                #pragma fragment frag
				#include "UnityCG.cginc"
            
                struct v2f {
                    float4 pos : SV_POSITION;
                    float2 uv_MainTex : TEXCOORD0;
					float3 lightdir;
					float3 viewdir;
					float3 norm;
                };
            
                float4 _MainTex_ST;
				half4 _SpecColor;
				half _Shininess; 
				half _Gloss;
  
				fixed4 _LightColor0; // apparemment ca c'est setté en extérieur par unity. encore un truc claqué en dur

				inline half4 SpecularLight( half3 lightDir, half3 viewDir, half3 normal, half4 color, float spec_shine)
				{
					lightDir = normalize(lightDir);
					viewDir = normalize(viewDir);
					float3 h = normalize( lightDir + viewDir );
					
					
					fixed diffuse = max (0, dot (normal, lightDir));
					
					float nh = max (0, dot (normal, h));
					
					float spec = pow (nh, spec_shine*128.0) * _Gloss;
					
					float3 litecolor = _LightColor0.rgb;
					
					half4 c;
					c.rgb = (_PPLAmbient*color.rgb+color.rgb * litecolor * diffuse + _SpecColor.rgb * litecolor * spec)*2;

					c.a =  _SpecColor.a * spec;
					return c;
				}


                v2f vert(appdata_full v) 
				{
                    v2f o;
                    o.pos = mul(UNITY_MATRIX_MVP, v.vertex);
                    o.uv_MainTex = TRANSFORM_TEX(v.texcoord, _MainTex);
					
					o.norm = v.normal;
			
					o.lightdir = WorldSpaceLightDir(_WorldSpaceLightPos0); // hopefully _WorldSpaceLightPos0 is not empty crap ! once is not use....
					o.viewdir =WorldSpaceViewDir( v.vertex );
					
                    return o;
                }
            
                sampler2D _MainTex;
            
                float4 frag(v2f IN) : COLOR 
				{
                    half4 Albedo = tex2D (_MainTex, IN.uv_MainTex);
					half4 c = SpecularLight( IN.lightdir, IN.viewdir, IN.norm,Albedo, _Shininess); // no atten for directionnal light. sry for thos who need atten...
                    return c;
                }
            ENDCG
        }
    }
}

If you try it and find some crappy behavious please report here :wink:

And thanks to those who could help efficiently. i’m really wasting time on this.

have fun

EDIT:
Ah at last but not least, i found info about how ambient is handled in the online docs here:

Tho it only talks about fixed func shaders, it’s the only place where i found usefull info
( with plusses and multiplies ) about the ambient light:

My point was that Unity’s built in shaders, which you’re trying to match, use something like

fixed3 finalAmbient = UNITY_LIGHTMODEL_AMBIENT.xyz * diffuse.rgb * 2;

Okies farfarer.

Thanks you to confirm this !!!
Do you have a clue about the difference between
UNITY_LIGHTMODEL_AMBIENT
and
_PPLAmbient
?

As an apart thought, i gotta say that it’s really stunning to see all the code you can put in shaders
when you don’t use surface shaders !!!
This is really an unshown unity feature, and it’s too bad. Though surface shaders are nice as it allows
people to easily change small things i’d really like to see a word about ‘old fashion shaders’ just like
i’m doing in the present topic. Docs are really missing this.

farfarer, if you have 5min to waste and try my lil piece of shader, and find some weird thing please can you
post you feedback here ?
Thanks :wink:

have nice day…

EDIT Oh ! and if you have a clue about _LightColor0 please give a post there too :wink:
as i dunno where it comes from and where it goes to. And atm i plan to replace it with
my own lightcolor set from a script ( a crappy and ugly but efficient way to have it working )

_PPLAmbient holds the Per Pixel Light Ambient color to use in your calculation
PPL variables are for the pixel light rendering path and would not exist for vertex lit render paths.

and I wouldn’t call it unknown. its how unity 2 worked all the time cause surface shaders are a new Unity 3 thing to simplify it cause its a little nightmare trying to get shadows, lights, lightmaps etc all going and that fine across all platforms. Its only fun when you dev for 1 platform and can ignore the rest.

Yes i totally agree with your POV dreamora. writing tools for all platforms and all cases and for vertex, forward and deffered is a totally mad challenge, and i gotta admit that for this SL dev team did an impressive good job.
What am angrying about is just the obfuscation of the doc. IMHO unity should enroll writers and produce thousands pages books they should sell about just shaderlabs. I thing this would worth the investment, would lighten the forum from stoopid questions like mine and would allow more people to have a deeper comprehension of shaderlab backgrounds…
But this is not the point.
OK and thanks for the clue about _PPLAmbient. i imagined what you confirm. However, i found nowhere this info.
I only call it unknown, as it’s ( IMHO ) an important element ( ambient light IS important ) whis is found nowhere in docs.
I found it in shaders examples somewhere on the web, without clear explanation, als now here, from your knowledge.
I just hope that this topic will make it more popular 8-D

Now as a last part, i found a solution about the lil mess about _LightColor0 wich is present in cginc but undocumented and set nowhere ( at least not in some accessible code ). Aside i had to guess it was the good usable light color for the current pass ( among all other appearently ( always 0 ) unused light colors like : float4 unity_LightColor[4];float3 unity_LightColor0, unity_LightColor1, unity_LightColor2, unity_LightColor3; ) i also found why it sometimes disappeared ( depending on the drawing order )…
I just had to add a lil tag in the pass:
Tags { “LightMode” = “ForwardBase” }

As i use forward rendering.

So now, it seems i got a simple specular shader for U3.0+ without shadows as am still on indie, that works properly.
Here’s the final piece of code for those who feel it usefull:

Shader "VPFP_specular" {
    Properties {
        _MainTex ("Base (RGB)", 2D) = "white" {}
		_SpecColor ("Specular Color", Color) = (0.5, 0.5, 0.5, 0)
		_Shininess ("Shininess", Range (0.01,1)) = 0.078125

		_Gloss ("Gloss", Float) = 0.078125

    }
    SubShader {
        Tags {"Queue"="Geometry" "RenderType" = "Opaque" 	"IgnoreProjector"="True"}
        LOD 200

        Pass {
		Tags { "LightMode" = "ForwardBase" }
            CGPROGRAM

                #pragma vertex vert
                #pragma fragment frag
				#include "UnityCG.cginc"
				#include "Lighting.cginc" // for having _LightColor0  _SpecColor uniforms
            
                struct v2f {
                    float4 pos : SV_POSITION;
                    float2 uv_MainTex : TEXCOORD0;
					float3 lightdir;
					float3 viewdir;
					float3 norm;
                };
            
                float4 _MainTex_ST;
				half _Shininess; 
				half _Gloss;
  
				inline half4 SpecularLight( half3 lightDir, half3 viewDir, half3 normal, half4 color, float spec_shine)
				{
					lightDir = normalize(lightDir);
					viewDir = normalize(viewDir);
					float3 h = normalize( lightDir + viewDir );
					
					
					fixed diffuse = max (0, dot (normal, lightDir));
					
					float nh = max (0, dot (normal, h));
					
					float spec = pow (nh, spec_shine*128.0) * _Gloss;
					
					float3 litecolor = _LightColor0.rgb; //ca, ca merdouille
					
					half4 c;
					c.rgb = (_PPLAmbient*color.rgb+color.rgb * litecolor * diffuse + _SpecColor.rgb * litecolor * spec)*2;
					c.a =  _SpecColor.a * spec;
					return c;
				}


                v2f vert(appdata_full v) 
				{
                    v2f o;
                    o.pos = mul(UNITY_MATRIX_MVP, v.vertex);
                    o.uv_MainTex = TRANSFORM_TEX(v.texcoord, _MainTex);
					
					o.norm = v.normal;
			
					o.lightdir = ObjSpaceLightDir(_WorldSpaceLightPos0); // hopefully _WorldSpaceLightPos0 is not empty crap ! once is not use....
					o.viewdir = ObjSpaceViewDir( v.vertex );
					
                    return o;
                }
            
                sampler2D _MainTex;
            
                float4 frag(v2f IN) : COLOR 
				{
                    half4 Albedo = tex2D (_MainTex, IN.uv_MainTex);
					half4 c = SpecularLight( IN.lightdir, IN.viewdir, IN.norm,Albedo, _Shininess); // no atten for directionnal light. sry for thos who need atten...
                    return c;
                }
            ENDCG
        }
    }
}

If you try this and have problems please give a post here.

And if you find it usefull, say it too. I’d be curious to see if am the only moron thinking
having this kind of shader is important. I might be totally wrong… :wink:

have fun