- Home /
Undeclared identifier free 2D shader on the asset store.
I use the free 2D GPU lightning system from the asset store : https://www.assetstore.unity3d.com/en/#!/content/30953
It works fine in the editor but when I try to compile and build the game, the following errors appear in the console and the build fail instantly : Shader error in 'Light2D/Light Auto Points': undeclared identifier 'PATH_TRACKING_SAMPLES' at Assets/Light2D/Resources/Shaders/LightBase.cginc(93) (on d3d9)
Shader error in 'Light2D/Light Auto Points': undeclared identifier 'PATH_TRACKING_SAMPLES' at Assets/Light2D/Resources/Shaders/LightBase.cginc(93) (on d3d11)
Here's the script:
// Upgrade NOTE: replaced '_Object2World' with 'unity_ObjectToWorld'
// Upgrade NOTE: replaced 'mul(UNITY_MATRIX_MVP,*)' with 'UnityObjectToClipPos(*)'
/*
Base code for standard light shaders.
Light is computed by path tracking with fixed number of steps (PATH_TRACKING_SAMPLES).
*/
#ifndef LIGHT_BASE_INCLUDED
#define LIGHT_BASE_INCLUDED
#pragma glsl_no_auto_normalization
struct light2d_fixed_data_t {
float4 vertex : POSITION;
float2 texcoord : TEXCOORD0;
float4 color : COLOR0;
float2 texcoord1 : TEXCOORD1;
};
struct light2d_fixed_v2f {
float4 vertex : SV_POSITION;
half2 texcoord : TEXCOORD0;
half4 color : COLOR0;
#ifdef PERSPECTIVE_CAMERA
half2 texcoord1 : TEXCOORD1;
float4 projVertex : COLOR1;
float zDistance : TEXCOORD2;
#else
half2 thisPos : TEXCOORD2;
half2 centerPos : TEXCOORD1;
#endif
half2 aspect : TEXCOORD3;
};
uniform sampler2D _ObstacleTex;
uniform sampler2D _MainTex;
uniform half _ObstacleMul;
uniform half _EmissionColorMul;
uniform float2 _ExtendedToSmallTextureScale;
#ifdef UNITY_HALF_TEXEL_OFFSET
uniform half2 _PosOffset;
#endif
light2d_fixed_v2f light2d_fixed_vert (light2d_fixed_data_t v)
{
light2d_fixed_v2f o;
o.vertex = UnityObjectToClipPos(v.vertex);
o.texcoord = v.texcoord;
#ifdef PERSPECTIVE_CAMERA
o.texcoord1 = v.texcoord1;
o.projVertex = o.vertex;
o.zDistance = mul(unity_ObjectToWorld, v.vertex).z;
#else
float4 vPos = ComputeScreenPos(o.vertex);
o.thisPos = (vPos.xy/vPos.w - 0.5)*_ExtendedToSmallTextureScale + 0.5;
float4 cPos = ComputeScreenPos(mul(UNITY_MATRIX_VP, float4(v.texcoord1, 0, 1)));
o.centerPos = (cPos.xy/cPos.w - 0.5)*_ExtendedToSmallTextureScale + 0.5;
#ifdef UNITY_HALF_TEXEL_OFFSET
o.thisPos += _PosOffset;
o.centerPos += _PosOffset;
#endif
#endif
o.color = v.color;
o.aspect = half2(_ScreenParams.x/_ScreenParams.y, 1);
return o;
}
half4 light2_fixed_frag (light2d_fixed_v2f i) : COLOR
{
half4 tex = tex2D(_MainTex, i.texcoord);
#ifdef PERSPECTIVE_CAMERA
half4 vPos = ComputeScreenPos(i.projVertex);
half2 thisPos = (vPos.xy/vPos.w - 0.5)*_ExtendedToSmallTextureScale + 0.5;
half4 cPos = ComputeScreenPos(mul(UNITY_MATRIX_VP, float4(i.texcoord1, i.zDistance, 1)));
half2 centerPos = (cPos.xy/cPos.w - 0.5)*_ExtendedToSmallTextureScale + 0.5;
#ifdef UNITY_HALF_TEXEL_OFFSET
thisPos += _PosOffset;
centerPos += _PosOffset;
#endif
#else
half2 thisPos = i.thisPos;
half2 centerPos = i.centerPos;
#endif
half sub = 1.0/PATH_TRACKING_SAMPLES;
half len = length((thisPos - centerPos)*i.aspect);
half m = _ObstacleMul*sub*len;
half4 col = i.color*tex*tex.a*i.color.a;
half pos = 0;
for(int i = 0; i < PATH_TRACKING_SAMPLES; i++)
{
pos += sub;
half4 obstacle = tex2D(_ObstacleTex, lerp(centerPos, thisPos, pos));
col *= saturate(1 - (1 - obstacle)*obstacle.a*m);
}
col.rgb *= _EmissionColorMul;
return col;//half4(half3((thisPos - centerPos).x*20), 1);//tex2D(_ObstacleTex, thisPos);
}
#endif
There are other scripts who looks like this: /*
Light shader with 90 path tracking steps.
Code contained in LightBase.cginc, only path tracking samples count is defined here.
*/
Shader "Light2D/Light 90 Points" {
Properties {
_$$anonymous$$ainTex ("Light texture", 2D) = "white" {}
_Obstacle$$anonymous$$ul ("Obstacle $$anonymous$$ul", Float) = 500
_EmissionColor$$anonymous$$ul ("Emission color mul", Float) = 1
}
SubShader {
Tags {"Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent"}
LOD 100
Blend One$$anonymous$$inusDstColor One
Cull Off
ZWrite Off
Lighting Off
Pass {
CGPROGRA$$anonymous$$
#define PATH_TRAC$$anonymous$$ING_SA$$anonymous$$PLES 90 // count of path tracking steps
#pragma target 3.0
#pragma multi_compile ORTHOGRAPHIC_CA$$anonymous$$ERA PERSPECTIVE_CA$$anonymous$$ERA
#include "UnityCG.cginc"
#include "Assets/Light2D/Resources/Shaders/LightBase.cginc" // all code is here
#pragma vertex light2d_fixed_vert
#pragma fragment light2_fixed_frag
ENDCG
}
}
Fallback "Light2D/Light 40 Points"
}
Answer by antiNT · Oct 27, 2017 at 09:23 AM
Ok so here's how I managed to fix it, replace the script by this one:
/*
Base code for standard light shaders.
Light is computed by path tracking with fixed number of steps (PATH_TRACKING_SAMPLES).
*/
#ifndef LIGHT_BASE_INCLUDED
#define LIGHT_BASE_INCLUDED
#pragma glsl_no_auto_normalization
struct light2d_fixed_data_t {
float4 vertex : POSITION;
float2 texcoord : TEXCOORD0;
float4 color : COLOR0;
float2 texcoord1 : TEXCOORD1;
};
struct light2d_fixed_v2f {
float4 vertex : SV_POSITION;
half2 texcoord : TEXCOORD0;
half4 color : COLOR0;
#ifdef PERSPECTIVE_CAMERA
half2 texcoord1 : TEXCOORD1;
float4 projVertex : COLOR1;
float zDistance : TEXCOORD2;
#else
half2 thisPos : TEXCOORD2;
half2 centerPos : TEXCOORD1;
#endif
half2 aspect : TEXCOORD3;
};
uniform sampler2D _ObstacleTex;
uniform sampler2D _MainTex;
uniform half _ObstacleMul;
uniform half _EmissionColorMul;
uniform float2 _ExtendedToSmallTextureScale;
#ifdef UNITY_HALF_TEXEL_OFFSET
uniform half2 _PosOffset;
#endif
light2d_fixed_v2f light2d_fixed_vert (light2d_fixed_data_t v)
{
light2d_fixed_v2f o;
o.vertex = UnityObjectToClipPos(v.vertex);
o.texcoord = v.texcoord;
#ifdef PERSPECTIVE_CAMERA
o.texcoord1 = v.texcoord1;
o.projVertex = o.vertex;
o.zDistance = mul(unity_ObjectToWorld, v.vertex).z;
#else
float4 vPos = ComputeScreenPos(o.vertex);
o.thisPos = (vPos.xy/vPos.w - 0.5)*_ExtendedToSmallTextureScale + 0.5;
float4 cPos = ComputeScreenPos(mul(UNITY_MATRIX_VP, float4(v.texcoord1, 0, 1)));
o.centerPos = (cPos.xy/cPos.w - 0.5)*_ExtendedToSmallTextureScale + 0.5;
#ifdef UNITY_HALF_TEXEL_OFFSET
o.thisPos += _PosOffset;
o.centerPos += _PosOffset;
#endif
#endif
o.color = v.color;
o.aspect = half2(_ScreenParams.x/_ScreenParams.y, 1);
return o;
}
half4 light2_fixed_frag (light2d_fixed_v2f i) : COLOR
{
#define PATH_TRACKING_WORKAROUND 90
half4 tex = tex2D(_MainTex, i.texcoord);
#ifdef PERSPECTIVE_CAMERA
half4 vPos = ComputeScreenPos(i.projVertex);
half2 thisPos = (vPos.xy/vPos.w - 0.5)*_ExtendedToSmallTextureScale + 0.5;
half4 cPos = ComputeScreenPos(mul(UNITY_MATRIX_VP, float4(i.texcoord1, i.zDistance, 1)));
half2 centerPos = (cPos.xy/cPos.w - 0.5)*_ExtendedToSmallTextureScale + 0.5;
#ifdef UNITY_HALF_TEXEL_OFFSET
thisPos += _PosOffset;
centerPos += _PosOffset;
#endif
#else
half2 thisPos = i.thisPos;
half2 centerPos = i.centerPos;
#endif
half sub = 1.0/PATH_TRACKING_WORKAROUND;
half len = length((thisPos - centerPos)*i.aspect);
half m = _ObstacleMul*sub*len;
half4 col = i.color*tex*tex.a*i.color.a;
half pos = 0;
for(int i = 0; i < PATH_TRACKING_WORKAROUND; i++)
{
pos += sub;
half4 obstacle = tex2D(_ObstacleTex, lerp(centerPos, thisPos, pos));
col *= saturate(1 - (1 - obstacle)*obstacle.a*m);
}
col.rgb *= _EmissionColorMul;
return col;//half4(half3((thisPos - centerPos).x*20), 1);//tex2D(_ObstacleTex, thisPos);
}
#endif
Your answer
Follow this Question
Related Questions
2D | Material Shader - How to adjust value of material by slider? 2 Answers
Depth of Field with Shader Replacement? 1 Answer
Free Ocean Shaders 2 Answers
2D Game Quality issue on iPhone 0 Answers
Sprite Renderer Boundaries 2 Answers