I am writing a shader and as it gets rather long intend to begin splitting it up in pieces.
When I put the code in a separate file an use
CGINCLUDE
#include “main.cginc”
ENDCG
where this one line simply replaces all code I just had in there
I get a syntax error. When I then open the cginc file and add a blank line
at the top of the file the error changes into the following:
Program ‘frag’, syntax error unexpected $undefined at token “” at line 0
Program ‘frag’, type name expected at token “” at line 0
Program ‘vert’, illegal character in shader file (compiling for d3d11) at line 0
Program ‘vert’, syntax error unexpected $undefined at token “” at line 0
Program 'verttype name expected at token “” at line 0
GLSL translate vertex: Failed to find entry function: ‘vert’ at line 20
GLSL vertex shader: 50: ERROR: ‘<’: syntax error parse error at line 20
Shader program had errors at line 21
Cg code
Shader “Custom/CgIncText”
{
Properties
{
_BumpMap(“Bump map”, 2D) = “bump” {}
}
CGINCLUDE
#include "main.cginc"
ENDCG
SubShader
{
Tags { "RenderType"="Opaque" }
Pass
{
CGPROGRAM
#pragma target 3.0
#pragma vertex vert
#pragma fragment frag
#pragma exclude_renderers noprepass
#pragma glsl_no_auto_normalization
ENDCG
}
}
FallBack "Diffuse"
}
Cginc code:
#define NORMAL_MAP
//#define OBJECT_SPACE_NORMALS
//TODO: DERIVATIVE_NORMALS
uniform sampler2D _BumpMap;
struct a2pb
{
fixed4 vertex : POSITION;
fixed3 normal : NORMAL;
#if !defined (OBJECT_SPACE_NORMALS)
fixed3 tangent : TANGENT;
#endif
fixed2 uv : TEXCOORD0;
};
struct pb2pf
{
fixed4 vertex : SV_POSITION;
fixed3 normal : TEXCOORD1;
#if !defined (OBJECT_SPACE_NORMALS)
fixed3 tangent : TEXCOORD2;
#endif
fixed2 uv : TEXCOORD0;
};
pb2pf vert(a2pb v)
{
pb2pf o;
o.vertex = mul(UNITY_MATRIX_MVP, v.vertex);
#if defined(NORMAL_MAP)
#if !defined (OBJECT_SPACE_NORMALS)
o.normal = mul(v.normal, (fixed3x3)_World2Object);
o.tangent = mul((fixed3x3)_Object2World, v.tangent);
#endif
#else
o.normal = mul(v.normal, (fixed3x3)_World2Object);
o.normal = o.normal * 0.5 + 0.5;
#endif
o.uv = v.uv;
return o;
}
fixed4 frag(pb2pf i) : COLOR
{
#if defined(NORMAL_MAP)
#if defined (OBJECT_SPACE_NORMALS)
fixed3 n = tex2D(_OSBumpMap, i.uv).xyz;
n = mul(n * 2 - 1, _World2Object);
#else
fixed3 n;
n.xy = tex2D(_BumpMap, i.uv).ar * 2 - 1;
n.z = sqrt(1-dot(n.xy, n.xy));
fixed3 bitangent = cross(i.normal, i.tangent);
n = mul(n, fixed3x3(i.tangent, bitangent, i.normal));
#endif
return fixed4(n, 1);
#else
i.normal = normalize(i.normal);
return fixed4(i.normal, 1);
#endif
}