Sorry to necrobump, but this is the only option I got for what I’m doing…
I’ve tried Werewraith’s shader (Unity 3.2 here), but I get a compiler error saying it would need too many texture interpolators…
If I replace the vert function by the local one, I get a number of different errors, but I assume those are caught before the one above…
Can anyone confirm that this shader works? I don’t have shaderfusion here, but I assume it isn’t necessary… right?
As always, thanks in advance!
Cheers
EDIT:
I managed to fix the errors by commenting out the bumpmap… right now I just want this thing to work…
So, it worked, kind of… It displays very well, but it seems to be in global space, even after changing the vert function to the one below…
Here’s the code now:
// this code was wrong. check below for improved version (same code, only it works now)
I also added a new texture for the side projections, since I want this as a terrain shader…
It worked, but it’s still in world space…
Any thoughts?
Cheers again!
EDIT 2::
I got it to work on local space now!! turns out you HAVE to write to the output normal… I had commented it out because of the bump map issues…
Now I’m faced with a new problem… what to write on this normal?
I tried just writing the localaNormal vector onto it, and while it does work, it’s not fully aligned with the light’s position… meaning the light seems to shine from the sides, while it’s actually straight above the mesh…
I’ll keep trying… in the meantime, if anyone comes up with anything… please… let me know!
Cheers
EDIT 3::
Third time’s the charm as it seems ;D
I think I got it!! just giving a float3(0,0,1) to the normal output produced the expected result!!
It’s working in localspace now! no bumpmap as of yet, but working!!
Here is code:
Shader "Terrain/TexProjWorld" {
Properties {
_Color ("Diffuse Color", Color) = (1.0, 1.0, 1.0, 1.0)
_SpecColor ("Specular Color", Color) = (1.0, 1.0, 1.0, 1.0)
_Cutoff ("Alpha cutoff", Range(0,1)) = 0.5
_Tiling ("Tiling", Float) = 1
_MainTex ("MainTex", 2D) = "white" {}
_SideTex ("SideTex", 2D) = "white" {}
_BumpMap ("NormalMap", 2D) = "white" {}
}
Category {
SubShader {
//#Blend
ZWrite On
//#CatTags
Tags { "RenderType"="Opaque" }
//Tags { "RenderType"="Opaque" }
//#LOD
LOD 400
//#GrabPass
CGPROGRAM
//#LightingModelTag
#pragma surface surf ShaderFusion vertex:vert alphatest:_Cutoff
//use custom lighting functions
//custom surface output structure
struct SurfaceShaderFusion {
half3 Albedo;
half3 Normal;
half3 Emission;
half Specular;
half3 GlossColor; //Gloss is now three-channel
half Alpha;
};
//forward lighting function
inline half4 LightingShaderFusion (SurfaceShaderFusion s, half3 lightDir, half3 viewDir, half atten) {
#ifndef USING_DIRECTIONAL_LIGHT
lightDir = normalize(lightDir);
#endif
viewDir = normalize(viewDir);
half3 h = normalize (lightDir + viewDir);
half diff = max (0, dot (s.Normal, lightDir));
float nh = max (0, dot (s.Normal, h));
float spec = pow (nh, s.Specular*128.0);
half4 c;
//Use gloss colour instead of gloss
c.rgb = (s.Albedo * _LightColor0.rgb * diff + _LightColor0.rgb * s.GlossColor * spec) * (atten * 2);
//We use gloss luminance to determine its overbright contribution
c.a = s.Alpha + _LightColor0.a * Luminance(s.GlossColor) * spec * atten;
return c;
}
//deferred lighting function
inline half4 LightingShaderFusion_PrePass (SurfaceShaderFusion s, half4 light) {
//Use gloss colour instead of gloss
half3 spec = light.a * s.GlossColor;
half4 c;
c.rgb = (s.Albedo * light.rgb + light.rgb * spec.rgb);
//We use gloss luminance to determine its overbright contribution
c.a = s.Alpha + Luminance(spec);
return c;
}
//#TargetSM
#pragma target 3.0
#pragma multi_compile_builtin
//#UnlitCGDefs
float _Tiling;
sampler2D _MainTex;
sampler2D _SideTex;
sampler2D _BumpMap;
float4 _Color;
struct Input {
float4 vertex;
//#UVDefs
float3 normal;
float3 localPos;
float2 uvCoords;
float3 localNormal;
INTERNAL_DATA
};
//void vert (inout appdata_full v, out Input o) {
// o.localNormal = mul(_Object2World, float4(v.normal, 0.0f)).xyz;
// o.localPos = mul(_Object2World, v.vertex);
//}
void vert (inout appdata_full v, out Input o) {
o.localNormal = v.normal;
o.localPos = v.vertex;
}
void surf (Input IN, inout SurfaceShaderFusion o) {
//float4 bump = float4(1.0, 1.0, 1.0, 1.0);
float3 emissive = 0.0;
float3 specular = 1.0;
float gloss = 1.0;
float3 diffuse = 1.0;
float alpha = 1.0;
//#PreFragBody
float2 s = float2(_Tiling/10, _Tiling/10);
float2 tex0 = s * IN.localPos.xy;
float2 tex1 = s * IN.localPos.zx;
float2 tex2 = s * IN.localPos.zy;
float4 color0_ = tex2D(_SideTex, tex0);
float4 color1_ = tex2D(_MainTex, tex1);
float4 color2_ = tex2D(_SideTex, tex2);
//float4 ncolor0_ = tex2D(_BumpMap, tex0);
//float4 ncolor1_ = tex2D(_BumpMap, tex1);
//float4 ncolor2_ = tex2D(_BumpMap, tex2);
float3 projnormal = saturate(pow(normalize(IN.localNormal)*1.5, 5));
diffuse = lerp(lerp(color1_, color0_, projnormal.z), color2_, projnormal.x);
//bump = lerp(lerp(ncolor1_, ncolor0_, projnormal.z), ncolor2_, projnormal.x);
o.Albedo = diffuse.rgb * _Color;
o.Emission = emissive * _Color;
//o.GlossColor = specular * _SpecColor;//They are inverted O_o?
o.Alpha = alpha;
//o.Specular = gloss;
o.Normal = float3(0, 0, 1);
}
ENDCG
}
}
FallBack "Diffuse"
}
Now, onwards onto giving it a heap of textures to interpolate depending on terrain height 
Cheers