Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
1
Question by antiNT · Oct 26, 2017 at 08:20 PM · shader2d gamefree

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
Comment
Add comment · Show 3
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Hellium · Oct 26, 2017 at 08:45 PM 0
Share

Have you tried what I suggested here?

avatar image antiNT Hellium · Oct 26, 2017 at 08:51 PM 0
Share

Yes but it didn't work.

avatar image antiNT Hellium · Oct 26, 2017 at 08:52 PM 0
Share

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"
 
 }

2 Replies

· Add your reply
  • Sort: 
avatar image
7
Best Answer

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
Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by furroy · Mar 28, 2018 at 12:08 AM

@antiNT thank you so much for posting this fix!!!

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

121 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

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


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges