- Home /
Vert/Frag, Fixed function, Surface shaders, unitycg.inc etc?
Hi,
I've been working with shaders a while now and am still utterly baffled by some core understanding of what's going on.
My limited understanding (or lack therein) is:
-Fixed function shaders work on pretty much anything, they are usually the fastest.
-vert/frag shaders work on modern machines, and can be faster than the above, but won't work on "dinosaurs" (a unity definition that sometimes seems to span everything over 4 years old or costing less than a grand).
-Surface shaders are prettied up vert/frag shaders with a load of unity specific stuff thrown in to handle lights, bumpmaps etc for you, again forget older/simpler devices.
Excuse my layman's descriptions above, but the terminology I'm finding online is at least half of the problem. Also excuse the fact that it may be utterly wrong, but it is based on months of exploration (unity docs/nvidia/jessys videos/trial and error).
Barr the work of Jessy, which is coherent and useable, Much documentation seems to leap from glaringly obvious "this is a colour" statements and a few unusably simple examples to the wildly obtuse with nothing in between, and unity's shaders have a tendency to rely on libraries that are hard to find and easy to conflict with (I spent a week discovering that I couldn't use the worldNormal variable for triplanar uv testing because it needs to remain untouched for something happening specifically under the hood in unity).
I recently found this, which really confused me:
Properties {
_MainTex ("Base (RGB)", 2D) = "white" {}
}
SubShader {
Tags { "Queue" = "Transparent" "IgnoreProjector"="True" }
Pass {
CGPROGRAM
// Upgrade NOTE: excluded shader from OpenGL ES 2.0 because it does not contain a surface program or both vertex and fragment programs.
#pragma exclude_renderers gles
#pragma vertex vert
#include "UnityCG.cginc"
struct v2f {
float4 pos : POSITION;
float fog : FOGC;
float4 color : COLOR0;
float2 uv : TEXCOORD0;
};
v2f vert (appdata_full v) {
v2f o;
o.pos = mul(UNITY_MATRIX_P, mul(UNITY_MATRIX_MV, float4(0.0, 0.0, 0.0, 1))+ float4(v.vertex.x, v.vertex.y, v.vertex.z, 0.0));
o.fog = o.pos.z;
o.uv.x = v.texcoord.x;
o.uv.y = v.texcoord.y;
o.color = v.color;
return o;
}
ENDCG
ColorMask rgb
Blend SrcAlpha OneMinusSrcAlpha
ZWrite Off Cull Off
AlphaTest Greater 0
SetTexture [_MainTex] { combine texture * primary, texture }
}
}
Fallback Off
}
It's actually not what I need, but I got fairly excited at the ability to access and possibly bypass vertex/normal data, for this problem, and more.
What firstly confuses me here is that it mixes a vert cg-function with a fixed function shader. is there any beneit to this?
Secondly, even disregarding the "UNITY_MATRIX_P"etc stuff this shader needs unitycg.inc. Again, why?
Can shaders be "coded" at all and yet work within older environments?
If so, an example of a fixed function shader (or other kind of shader that's DX7 frendly) with hacked vertex data and no funny includes would be really appreciated.
What variables and edits can be pushed through a fixed function shader, before it becomes unusable on old machines and thus a pointless and academic pursuit?
All I want to do at this point is access a vertex/face normal in a fixed function shader and either ignore it, or force it to a given unchanging value, but generally some good documentation written in plain english would be a godsend If anybody knows of it.
I can achieve quite a lot with surface and fragment shaders now, but my emphasis as a web developer is on speed and compatibility (old pcs, old phones, Integrated graphics cards) so getting maximum leverage out of fixed function shaders is what I think I need.
Any help here greatly appreciated.