Problem with Vertex Normal and INTERNAL_DATA
Posted: Tue Jul 31, 2018 5:07 pm
Hello, I was trying to create a shader with custom light and a kind of effect of overlap for the objects, I made both parts separately, and then when I was trying to mix them it fails, the first thing I tried was modify the code and delete de ";" from "INTERNAL_DATA", but then it send this error:
"unrecognized identifier 'INTERNAL_DATA' "
I try to find what was wrong, and I didn't find anything, the only thing I discover was when the Overlap part was connected to Local Vertex Offset, and at the same time some node of "Vertex Normal" was connected to Custom Light, and I didn't mean literaly connected, if there is any vertex normal in the function and then is connected to Custom Light it fails.
This is the self-generated code
"unrecognized identifier 'INTERNAL_DATA' "
I try to find what was wrong, and I didn't find anything, the only thing I discover was when the Overlap part was connected to Local Vertex Offset, and at the same time some node of "Vertex Normal" was connected to Custom Light, and I didn't mean literaly connected, if there is any vertex normal in the function and then is connected to Custom Light it fails.
This is the self-generated code
- Code: Select all
// Made with Amplify Shader Editor
// Available at the Unity Asset Store - http://u3d.as/y3X
Shader "TestShader"
{
Properties
{
_ASEOutlineWidth( "Outline Width", Float ) = 0
_OverlapColor("OverlapColor", Color) = (1,0,0,1)
[HideInInspector] __dirty( "", Int ) = 1
}
SubShader
{
Pass
{
ColorMask 0
ZWrite On
}
Tags{ "RenderType" = "Transparent" "Queue" = "Transparent+0"}
ZWrite Off
ZTest Always
Cull Back
CGPROGRAM
#pragma target 3.0
#pragma surface outlineSurf Outline nofog alpha:fade keepalpha noshadow noambient novertexlights nolightmap nodynlightmap nodirlightmap nometa noforwardadd vertex:outlineVertexDataFunc
uniform half _ASEOutlineWidth;
void outlineVertexDataFunc( inout appdata_full v, out Input o )
{
UNITY_INITIALIZE_OUTPUT( Input, o );
v.vertex.xyz += ( v.normal * _ASEOutlineWidth );
}
inline half4 LightingOutline( SurfaceOutput s, half3 lightDir, half atten ) { return half4 ( 0,0,0, s.Alpha); }
void outlineSurf( Input i, inout SurfaceOutput o )
{
float3 ase_worldPos = i.worldPos;
float3 ase_worldViewDir = normalize( UnityWorldSpaceViewDir( ase_worldPos ) );
float3 ase_worldNormal = WorldNormalVector( i, float3( 0, 0, 1 ) );
float fresnelNdotV4 = dot( ase_worldNormal, ase_worldViewDir );
float fresnelNode4 = ( 0.0 + 1.0 * pow( 1.0 - fresnelNdotV4, 0.0 ) );
o.Emission = ( fresnelNode4 * _OverlapColor ).rgb;
o.Alpha = ( fresnelNode4 * (_OverlapColor).a );
o.Normal = float3(0,0,-1);
}
ENDCG
Tags{ "RenderType" = "Opaque" "Queue" = "Geometry+0" }
Cull Back
ZWrite On
ZTest LEqual
CGINCLUDE
#include "UnityPBSLighting.cginc"
#include "Lighting.cginc"
#pragma target 5.0
struct Input
{
float3 worldNormal;
float3 worldPos;
INTERNAL_DATA;
};
struct SurfaceOutputCustomLightingCustom
{
half3 Albedo;
half3 Normal;
half3 Emission;
half Metallic;
half Smoothness;
half Occlusion;
half Alpha;
Input SurfInput;
UnityGIInput GIData;
};
uniform float4 _OverlapColor;
void vertexDataFunc( inout appdata_full v, out Input o )
{
UNITY_INITIALIZE_OUTPUT( Input, o );
v.vertex.xyz += 0;
}
inline half4 LightingStandardCustomLighting( inout SurfaceOutputCustomLightingCustom s, half3 viewDir, UnityGI gi )
{
UnityGIInput data = s.GIData;
Input i = s.SurfInput;
half4 c = 0;
float3 ase_worldNormal = i.worldNormal;
float3 ase_vertexNormal = mul( unity_WorldToObject, float4( ase_worldNormal, 0 ) );
c.rgb = ase_vertexNormal;
c.a = 1;
return c;
}
inline void LightingStandardCustomLighting_GI( inout SurfaceOutputCustomLightingCustom s, UnityGIInput data, inout UnityGI gi )
{
s.GIData = data;
}
void surf( Input i , inout SurfaceOutputCustomLightingCustom o )
{
o.SurfInput = i;
}
ENDCG
CGPROGRAM
#pragma surface surf StandardCustomLighting keepalpha fullforwardshadows vertex:vertexDataFunc
ENDCG
Pass
{
Name "ShadowCaster"
Tags{ "LightMode" = "ShadowCaster" }
ZWrite On
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#pragma target 5.0
#pragma multi_compile_shadowcaster
#pragma multi_compile UNITY_PASS_SHADOWCASTER
#pragma skip_variants FOG_LINEAR FOG_EXP FOG_EXP2
#include "HLSLSupport.cginc"
#if ( SHADER_API_D3D11 || SHADER_API_GLCORE || SHADER_API_GLES3 || SHADER_API_METAL || SHADER_API_VULKAN )
#define CAN_SKIP_VPOS
#endif
#include "UnityCG.cginc"
#include "Lighting.cginc"
#include "UnityPBSLighting.cginc"
struct v2f
{
V2F_SHADOW_CASTER;
float3 worldPos : TEXCOORD1;
float3 worldNormal : TEXCOORD2;
UNITY_VERTEX_INPUT_INSTANCE_ID
};
v2f vert( appdata_full v )
{
v2f o;
UNITY_SETUP_INSTANCE_ID( v );
UNITY_INITIALIZE_OUTPUT( v2f, o );
UNITY_TRANSFER_INSTANCE_ID( v, o );
Input customInputData;
vertexDataFunc( v, customInputData );
float3 worldPos = mul( unity_ObjectToWorld, v.vertex ).xyz;
half3 worldNormal = UnityObjectToWorldNormal( v.normal );
o.worldNormal = worldNormal;
o.worldPos = worldPos;
TRANSFER_SHADOW_CASTER_NORMALOFFSET( o )
return o;
}
half4 frag( v2f IN
#if !defined( CAN_SKIP_VPOS )
, UNITY_VPOS_TYPE vpos : VPOS
#endif
) : SV_Target
{
UNITY_SETUP_INSTANCE_ID( IN );
Input surfIN;
UNITY_INITIALIZE_OUTPUT( Input, surfIN );
float3 worldPos = IN.worldPos;
half3 worldViewDir = normalize( UnityWorldSpaceViewDir( worldPos ) );
surfIN.worldNormal = IN.worldNormal;
SurfaceOutputCustomLightingCustom o;
UNITY_INITIALIZE_OUTPUT( SurfaceOutputCustomLightingCustom, o )
surf( surfIN, o );
#if defined( CAN_SKIP_VPOS )
float2 vpos = IN.pos;
#endif
SHADOW_CASTER_FRAGMENT( IN )
}
ENDCG
}
}
Fallback "Diffuse"
CustomEditor "ASEMaterialInspector"
}
/*ASEBEGIN
Version=15401
2;203;1906;1036;1297;117;1;True;False
Node;AmplifyShaderEditor.CommentaryNode;1;-469.6656,417.4896;Float;False;872.4865;481.3362;;6;7;6;5;4;3;2;Overlap;1,1,1,1;0;0
Node;AmplifyShaderEditor.ColorNode;2;-364.1548,691.8254;Float;False;Property;_OverlapColor;OverlapColor;0;0;Create;True;0;0;False;0;1,0,0,1;0.2663759,0.5766683,0.7735849,1;0;5;COLOR;0;FLOAT;1;FLOAT;2;FLOAT;3;FLOAT;4
Node;AmplifyShaderEditor.SwizzleNode;3;-147.4368,792.1509;Float;False;FLOAT;3;1;2;3;1;0;COLOR;0,0,0,0;False;1;FLOAT;0
Node;AmplifyShaderEditor.FresnelNode;4;-395.3851,464.2521;Float;True;Standard;TangentNormal;ViewDir;False;5;0;FLOAT3;0,0,1;False;4;FLOAT3;0,0,0;False;1;FLOAT;0;False;2;FLOAT;1;False;3;FLOAT;0;False;1;FLOAT;0
Node;AmplifyShaderEditor.SimpleMultiplyOpNode;6;28.98923,584.6754;Float;False;2;2;0;FLOAT;0;False;1;FLOAT;0;False;1;FLOAT;0
Node;AmplifyShaderEditor.SimpleMultiplyOpNode;5;-11.56796,484.5822;Float;False;2;2;0;FLOAT;0;False;1;COLOR;0,0,0,0;False;1;COLOR;0
Node;AmplifyShaderEditor.NormalVertexDataNode;10;-768,240;Float;False;0;5;FLOAT3;0;FLOAT;1;FLOAT;2;FLOAT;3;FLOAT;4
Node;AmplifyShaderEditor.OutlineNode;7;176.2209,492.0242;Float;False;0;True;Transparent;2;7;Back;3;0;FLOAT3;0,0,0;False;2;FLOAT;0;False;1;FLOAT;0;False;1;FLOAT3;0
Node;AmplifyShaderEditor.StandardSurfaceOutputNode;0;0,0;Float;False;True;7;Float;ASEMaterialInspector;0;0;CustomLighting;TestShader;False;False;False;False;False;False;False;False;False;False;False;False;False;False;False;False;False;False;False;False;Back;1;False;-1;3;False;-1;False;0;False;-1;0;False;-1;True;0;Opaque;0.5;True;True;0;False;Opaque;;Geometry;All;True;True;True;True;True;True;True;True;True;True;True;True;True;True;True;True;True;0;False;-1;False;0;False;-1;255;False;-1;255;False;-1;0;False;-1;0;False;-1;0;False;-1;0;False;-1;0;False;-1;0;False;-1;0;False;-1;0;False;-1;False;2;15;10;25;False;0.5;True;0;0;False;-1;0;False;-1;0;0;False;-1;0;False;-1;-1;False;-1;-1;False;-1;0;False;0;0,0,0,0;VertexOffset;True;False;Cylindrical;False;Relative;0;;-1;-1;-1;-1;0;False;0;0;False;-1;-1;0;False;-1;0;0;15;0;FLOAT3;0,0,0;False;1;FLOAT3;0,0,0;False;2;FLOAT3;0,0,0;False;3;FLOAT3;0,0,0;False;4;FLOAT;0;False;6;FLOAT3;0,0,0;False;7;FLOAT3;0,0,0;False;8;FLOAT;0;False;9;FLOAT;0;False;10;FLOAT;0;False;13;FLOAT3;0,0,0;False;11;FLOAT3;0,0,0;False;12;FLOAT3;0,0,0;False;14;FLOAT4;0,0,0,0;False;15;FLOAT3;0,0,0;False;0
WireConnection;3;0;2;0
WireConnection;6;0;4;0
WireConnection;6;1;3;0
WireConnection;5;0;4;0
WireConnection;5;1;2;0
WireConnection;7;0;5;0
WireConnection;7;2;6;0
WireConnection;0;13;10;0
WireConnection;0;11;7;0
ASEEND*/
//CHKSM=D08D58288D182DA421C70E15212672767D3129C1