• 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
0
Question by SaxonHammer · May 13, 2014 at 08:45 PM · shader

Problem with _LightColor0 in unity 4.3.4

I have been learnng about unity shaders but have not got very far as I keep encountering a undefined variable "_LightColor0" at line 30

To my understanding the Tags {"LightMode" = "ForwardBase"} should provide the _LightColor0 variable.

I am using Unity 4.3.4

 Shader "Custom/Test" 
 {
     SubShader
     {
         Tags {"LightMode" = "ForwardBase"} 
         Pass
         {
             CGPROGRAM
             
             #pragma vertex vert
             #pragma fragment frag
             
             //base input structs
             struct vertexI
             {
                 float4 vertex : POSITION;
                 float3 normal : NORMAL;
             };
             struct vertexO
             {
                 float4 pos : SV_POSITION;
                 float4 col : COLOR;
             };
             
             //vertex function
             vertexO vert(vertexI v)
             {
                 vertexO o;
                 o.pos = v.vertex;
                 o.col = _LightColor0;
                 return o;
             }
     
             //fragment function
             float4 frag(vertexO i) : COLOR
             {
                 return i.col;
             }
             
             ENDCG
         }
     } 
     //Commeted out during development
     //FallBack "Diffuse"
 }
 

But this code throws the undefined error please help I have been trying to solve this for nearly a week :(

Comment
Add comment
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

3 Replies

· Add your reply
  • Sort: 
avatar image
-3

Answer by xortrox · May 13, 2014 at 08:50 PM

_LightColor0 is not declared (defined) anywhere

put this before your SubShader and see if that fixes anything

 Properties
 {
 
  _LightColor0 ("Light Color 0", Color)  = (1.0, 1.0, 1.0, 1.0)
 
 }
Comment
Add comment · Show 1 · 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 SaxonHammer · May 14, 2014 at 12:26 PM 0
Share

Thanks for the response......

This works to solve the undifined variable HOWEVER it is not how things are supposed to work within shaders the _LightColor0 variable should be the color of the first (primary) light and be provided by the Tags {"Light$$anonymous$$ode" = "ForwardBase"}

So this does NOT solve the problem

avatar image
0

Answer by jitwtttl · Nov 14, 2014 at 10:08 AM

Although _LightColor0 comes from pipeline input, you have to declare _LightColor0 as uniform variable.

 uniform float4 _LightColor0;


And you have to mux modelview and projection matrix to vertex.

 o.pos = mux(UNITY_MATRIX_MVP, v.vertex);
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
2

Answer by aeroson · May 06, 2018 at 12:11 PM

_LightColor0 comes from Lighting.cging, add this to your shader:

 #include "Lighting.cginc"
Comment
Add comment · Show 1 · 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 Bovine · Feb 19 at 02:51 PM 0
Share

Yep, thanks for this. Also as OP said, requires the lighting tag:

Tags {"LightMode" = "ForwardBase"}

Or it is thoroughly undefined.

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

23 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

Related Questions

How to force the compilation of a shader in Unity? 5 Answers

Trying to write a simple mixing 2 textures shader with alpha support on the 2d texture 1 Answer

Single tone shadows in forward rendering 0 Answers

Implement texture masking into simple existing shader 1 Answer

Adding a clip() to the default shader? 0 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