Hello,
I wish to do Vertex painting using 8 textures for my Single mesh/material environment.
I have made a very big Strumpy Shader Graph for this and it works perfectly on desktop… but wont let me :
1: Have any more than 8 textures (it starts throwing a UV error beyond that)
2: Wont let me lerp more than twice (Else the shader goes all Black when applied!)
I am at a loss here… help?
Additional Info…
BTW, I am setting the textures using a condition where :
if R = 0-0.5 then render Texture1
if R = 0.5-1 then render Texture2
if G = 0-0.5 then render Texture3
if G = 0.5-1 then render Texture4
if B = 0-0.5 then render Texture5
if B = 0.5-1 then render Texture6
if A = 0-0.5 then render Texture7
if A = 0.5-1 then render Texture8
Here is my Strumpy Shader Graph
https://www.dropbox.com/s/vejgqbz2cn0wng9/GodShader.sgraph
Here is the Unity Package containing The Shader and the Materials with some dummy textures.
https://www.dropbox.com/s/h69mbyc7xe7ls86/GodShaderV3.unitypackage
Works fine on PC, goes all black on iOS.
And This is the syntax to the compiled shader.
Shader "GodShaderV3"
{
Properties
{
_Red("_Red", 2D) = "black" {}
_Red_R("_Red_R", 2D) = "black" {}
_Blue("_Blue", 2D) = "black" {}
_Blue_R("_Blue_R", 2D) = "black" {}
_Green("_Green", 2D) = "black" {}
_Green_R("_Green_R", 2D) = "black" {}
_Alpha("_Alpha", 2D) = "black" {}
_Alpha_R("_Alpha_R", 2D) = "black" {}
}
SubShader
{
Tags
{
"Queue"="Geometry"
"IgnoreProjector"="False"
"RenderType"="Opaque"
}
Cull Back
ZWrite On
ZTest LEqual
ColorMask RGBA
Fog{
}
CGPROGRAM
#pragma surface surf BlinnPhongEditor vertex:vert
#pragma target 3.0
sampler2D _Red;
sampler2D _Red_R;
sampler2D _Blue;
sampler2D _Blue_R;
sampler2D _Green;
sampler2D _Green_R;
sampler2D _Alpha;
sampler2D _Alpha_R;
struct EditorSurfaceOutput {
half3 Albedo;
half3 Normal;
half3 Emission;
half3 Gloss;
half Specular;
half Alpha;
half4 Custom;
};
inline half4 LightingBlinnPhongEditor_PrePass (EditorSurfaceOutput s, half4 light)
{
half3 spec = light.a * s.Gloss;
half4 c;
c.rgb = (s.Albedo * light.rgb + light.rgb * spec);
c.a = s.Alpha;
return c;
}
inline half4 LightingBlinnPhongEditor (EditorSurfaceOutput s, half3 lightDir, half3 viewDir, half atten)
{
half3 h = normalize (lightDir + viewDir);
half diff = max (0, dot ( lightDir, s.Normal ));
float nh = max (0, dot (s.Normal, h));
float spec = pow (nh, s.Specular*128.0);
half4 res;
res.rgb = _LightColor0.rgb * diff;
res.w = spec * Luminance (_LightColor0.rgb);
res *= atten * 2.0;
return LightingBlinnPhongEditor_PrePass( s, res );
}
inline half4 LightingBlinnPhongEditor_DirLightmap (EditorSurfaceOutput s, fixed4 color, fixed4 scale, half3 viewDir, bool surfFuncWritesNormal, out half3 specColor)
{
UNITY_DIRBASIS
half3 scalePerBasisVector;
half3 lm = DirLightmapDiffuse (unity_DirBasis, color, scale, s.Normal, surfFuncWritesNormal, scalePerBasisVector);
half3 lightDir = normalize (scalePerBasisVector.x * unity_DirBasis[0] + scalePerBasisVector.y * unity_DirBasis[1] + scalePerBasisVector.z * unity_DirBasis[2]);
half3 h = normalize (lightDir + viewDir);
float nh = max (0, dot (s.Normal, h));
float spec = pow (nh, s.Specular * 128.0);
// specColor used outside in the forward path, compiled out in prepass
specColor = lm * _SpecColor.rgb * s.Gloss * spec;
// spec from the alpha component is used to calculate specular
// in the Lighting*_Prepass function, it's not used in forward
return half4(lm, spec);
}
struct Input {
float4 color : COLOR;
float2 uv_Red;
float2 uv_Red_R;
float2 uv_Green;
float2 uv_Green_R;
float2 uv_Blue;
float2 uv_Blue_R;
float2 uv_Alpha;
float2 uv_Alpha_R;
};
void vert (inout appdata_full v, out Input o) {
float4 VertexOutputMaster0_0_NoInput = float4(0,0,0,0);
float4 VertexOutputMaster0_1_NoInput = float4(0,0,0,0);
float4 VertexOutputMaster0_2_NoInput = float4(0,0,0,0);
float4 VertexOutputMaster0_3_NoInput = float4(0,0,0,0);
}
void surf (Input IN, inout EditorSurfaceOutput o) {
o.Normal = float3(0.0,0.0,1.0);
o.Alpha = 1.0;
o.Albedo = 0.0;
o.Emission = 0.0;
o.Gloss = 0.0;
o.Specular = 0.0;
o.Custom = 0.0;
float4 Split0=IN.color;
float4 Step0=step(float4( Split0.x, Split0.x, Split0.x, Split0.x),float4( 0.5,0.5,0.5,0.5 ));
float4 Subtract0=float4( 1.0, 1.0, 1.0, 1.0 ) - Step0;
float4 Abs0=abs(Subtract0);
float4 Sampled2D1=tex2D(_Red,IN.uv_Red.xy);
float4 Multiply0=Abs0 * Sampled2D1;
float4 Subtract1=float4( 0.0, 0.0, 0.0, 0.0 ) - Step0;
float4 Abs1=abs(Subtract1);
float4 Sampled2D0=tex2D(_Red_R,IN.uv_Red_R.xy);
float4 Multiply1=Abs1 * Sampled2D0;
float4 Add0=Multiply0 + Multiply1;
float4 Lerp0=lerp(float4( 0,0,0,0),Add0,float4( Split0.x, Split0.x, Split0.x, Split0.x));
float4 Split1=IN.color;
float4 Step2=step(float4( Split1.y, Split1.y, Split1.y, Split1.y),float4( 0.5,0.5,0.5,0.5 ));
float4 Subtract4=float4( 1.0, 1.0, 1.0, 1.0 ) - Step2;
float4 Abs4=abs(Subtract4);
float4 Sampled2D5=tex2D(_Green,IN.uv_Green.xy);
float4 Multiply4=Abs4 * Sampled2D5;
float4 Subtract5=float4( 0.0, 0.0, 0.0, 0.0 ) - Step2;
float4 Abs5=abs(Subtract5);
float4 Sampled2D4=tex2D(_Green_R,IN.uv_Green_R.xy);
float4 Multiply5=Abs5 * Sampled2D4;
float4 Add2=Multiply4 + Multiply5;
float4 Lerp2=lerp(Lerp0,Add2,float4( Split1.y, Split1.y, Split1.y, Split1.y));
float4 Split2=IN.color;
float4 Step3=step(float4( Split2.z, Split2.z, Split2.z, Split2.z),float4( 0.5,0.5,0.5,0.5 ));
float4 Subtract6=float4( 1.0, 1.0, 1.0, 1.0 ) - Step3;
float4 Abs6=abs(Subtract6);
float4 Sampled2D7=tex2D(_Blue,IN.uv_Blue.xy);
float4 Multiply6=Abs6 * Sampled2D7;
float4 Subtract7=float4( 0.0, 0.0, 0.0, 0.0 ) - Step3;
float4 Abs7=abs(Subtract7);
float4 Sampled2D6=tex2D(_Blue_R,IN.uv_Blue_R.xy);
float4 Multiply7=Abs7 * Sampled2D6;
float4 Add3=Multiply6 + Multiply7;
float4 Lerp1=lerp(Lerp2,Add3,float4( Split2.z, Split2.z, Split2.z, Split2.z));
float4 Split3=IN.color;
float4 Step1=step(float4( Split3.w, Split3.w, Split3.w, Split3.w),float4( 0.5,0.5,0.5,0.5 ));
float4 Subtract2=float4( 1.0, 1.0, 1.0, 1.0 ) - Step1;
float4 Abs2=abs(Subtract2);
float4 Sampled2D8=tex2D(_Alpha,IN.uv_Alpha.xy);
float4 Multiply2=Abs2 * Sampled2D8;
float4 Subtract3=float4( 0.0, 0.0, 0.0, 0.0 ) - Step1;
float4 Abs3=abs(Subtract3);
float4 Sampled2D3=tex2D(_Alpha_R,IN.uv_Alpha_R.xy);
float4 Multiply3=Abs3 * Sampled2D3;
float4 Add1=Multiply2 + Multiply3;
float4 Lerp3=lerp(Lerp1,Add1,float4( Split3.w, Split3.w, Split3.w, Split3.w));
float4 Master0_1_NoInput = float4(0,0,1,1);
float4 Master0_2_NoInput = float4(0,0,0,0);
float4 Master0_3_NoInput = float4(0,0,0,0);
float4 Master0_4_NoInput = float4(0,0,0,0);
float4 Master0_5_NoInput = float4(1,1,1,1);
float4 Master0_7_NoInput = float4(0,0,0,0);
float4 Master0_6_NoInput = float4(1,1,1,1);
o.Albedo = Lerp3;
o.Normal = normalize(o.Normal);
}
ENDCG
}
Fallback "Diffuse"
}