Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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
5
Question by jeffpk · Jun 23, 2012 at 12:05 AM · lightingshadersnormalssurface shader

How to write unlit surface shader?

Ive written a clipping unlit surface shader for something Im working on. It works great except that I get that annoying "shader wants normals" error. I don't use the normals. How can I tell shaderlab that they aren't necessary for this shader?

Code is below for reference

 Shader "Custom/ClippingUnlitTransparent" {
     Properties {
         _MainTex ("Base (RGB)", 2D) = "white" {}
         _cliprect ("Clip Rectangle", Vector) = (-1,-1,-1,-1) 
         
     }
     SubShader {
         Lighting Off
         AlphaTest Greater 0.5
         Tags { "RenderType"="Opaque" }
         LOD 200
         
         CGPROGRAM
         #pragma surface surf Unlit 
         #include "UnityCG.cginc" 
         
         half4 LightingUnlit (SurfaceOutput s, half3 lightDir, half atten) {
           half4 c;
           c.rgb = s.Albedo;
           c.a = s.Alpha;
           return c;
         }
 
         sampler2D _MainTex;
         float4 _cliprect;
         
 
         struct Input {
           float2 uv_MainTex;
           float4 screenPos;
         };
 
         void surf (Input IN, inout SurfaceOutput o) {
             float2 screenPosition = IN.screenPos.xy / IN.screenPos.w;
             screenPosition.y = 1.0 - screenPosition.y;
             screenPosition.xy = screenPosition.xy * _ScreenParams.xy;
             
             if ((screenPosition.x>=_cliprect[0])&&
                 (screenPosition.x<=_cliprect[2])&&
                 (screenPosition.y>=_cliprect[1])&&
                 (screenPosition.y<=_cliprect[3]))
             {
                 half4 c = tex2D (_MainTex, IN.uv_MainTex);
                 o.Albedo = c.rgb;
                 o.Alpha = c.a;
             }  else{
                 o.Albedo = float3(0,0,0);
                 o.Alpha = 0;
             }
             
         }
         ENDCG
     } 
     FallBack "Diffuse"
 }
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

6 Replies

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

Answer by mtalbott · Jun 18, 2014 at 03:03 PM

just FYI, I found that the s.Albedo value in the lighting shader function was at double the correct intensity. i.e. //c.rgb = s.Albedo; //should be: c.rgb = s.Albedo*0.5f;

Comment
Add comment · Show 3 · 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 mtalbott · Jun 18, 2014 at 09:48 PM 2
Share

Actually, disregard the previous comment. Even s.Albedo*0.5f returned an over cooked color. $$anonymous$$y solution is to store the unlit color in the Emission slot (o.Emission = c.rgb) in the Surface function and in the LightingNoLighting Function just return a blank color (fixed4(0,0,0,0)).

avatar image ifurkend mtalbott · Feb 25, 2018 at 07:25 AM 0
Share

You're right. I think you should update your answer to reflect it.

avatar image tuanpham · Mar 29, 2018 at 11:13 AM 0
Share
 Yeah! It should like this
 
 void surf (Input IN, inout SurfaceOutput o) {
         //o.Albedo = _Color.rgb * _Color.a;
         o.Emission = _Color.rgb;
           o.Alpha = _Color.a;
     }
 fixed4 LightingNoLighting(SurfaceOutput s, fixed3 lightDir, fixed atten) {
         return fixed4(0,0,0,0);//half4(s.Albedo, s.Alpha);
     }

avatar image
15

Answer by FlyingOstriche · Jan 12, 2013 at 09:04 PM

You can also create a no lighting shader function.

 #pragma surface surf NoLighting

...

 fixed4 LightingNoLighting(SurfaceOutput s, fixed3 lightDir, fixed atten)
     {
         fixed4 c;
         c.rgb = s.Albedo; 
         c.a = s.Alpha;
         return c;
     }
Comment
Add comment · Show 5 · 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 PatHightree · Oct 19, 2014 at 05:00 PM 0
Share

This last comment needs to be upvoted SO much! Totally fixed my not-unlit-shader :D

Thanks mtalbott

avatar image SoylentGraham · Jan 23, 2015 at 12:43 PM 0
Share

upvote that comment! fixed4 LightingNoLighting(SurfaceOutput s, fixed3 lightDir, fixed atten) { return fixed4(0,0,0,0); }

avatar image sgoodrow · May 01, 2015 at 02:12 AM 1
Share

Ins$$anonymous$$d of setting the Emission and letting the forward add passes crunch over a 0'd albedo, just use the "noforwardadd" command, like so:

pragma surface surf NoLighting noforwardadd

avatar image jitwtttl · Jul 09, 2015 at 06:15 AM 0
Share

noforwardadd doesn't work. @mtalbott's comment works well.

avatar image ABerlemont · Jul 17, 2015 at 01:49 PM 0
Share

Is LightingNoLighting called AFTER the surface function ? $$anonymous$$y object stays black no matter what I'm doing with the SurfaceOutput in the surface function :/

avatar image
3

Answer by MyPad3DAssets · May 24, 2018 at 11:26 PM

For anyone else that comes across this problem and is trying to make this work, the best solution that I found was to add a "noambient" pragma to @FlyingOstriche's solution. This makes it so that the lighting function uses just the base colors as intended

 #pragma surface surf NoLighting noambient

and

 fixed4 LightingNoLighting(SurfaceOutput s, fixed3 lightDir, fixed atten) {
             return fixed4(s.Albedo, s.Alpha);
         }

This should provide a good look for an unlit material. The reason that the colors were blown out in earlier solutions was because the ambient light was being added to the final output after the lighting function. "noforwardadd" could also be used, though I doubt its very necessary.

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 ScroodgeM · Jul 14, 2012 at 01:45 PM

http://docs.unity3d.com/Documentation/Components/SL-SurfaceShaders.html

try to disable all lighting method listed there.

also, best way to write shader that doesn't interact with lighting is to make a vertex/fragment shader, not surface.

also, in your shader you really interact with lighting - try to light your model by more than 1 light source and you'll show over-lighting effect. so you can just ignore light function (return;) and write color to emission in frag method or use amient color instead.

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 Ukitakemalcom · Nov 07, 2016 at 07:30 PM 0
Share

In my case, I put the tag "novertexlights" and it worked.

avatar image
2

Answer by sgoodrow · May 01, 2015 at 04:06 AM

In addition to use a NoLighting shader function, you might also like to add noforwardadd, so that point lights do not affect the albedo. The Emission control ignores forward add passes, so that is a workaround that accomplishes the same thing, except the additional pass still takes place with 0s in the Albedo, resulting in 0 in the additive output.

Better to just skip it entirely!

Comment
Add comment · Show 2 · 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 tomekkie2 · May 28, 2017 at 01:54 PM 0
Share

Doesn't work in Unity 5.6. The Unity 5.6.1 message says: Surface lighting model 'NoLighting' not found. Available models: BlinnPhong, Lambert

avatar image killer_mech tomekkie2 · Sep 30, 2017 at 10:23 AM 1
Share

*Bump.... same issue here with me. I was trying learning shaders and came across this 'No Lighting' Problem. $$anonymous$$y holographic shader seems to be working fine but i dont want lights to be affecting it. But sadly that directive seems to be not working for me. Has anybody have suggestions? Iam tried it on unity 5.6.0 and 2017.1. I have read some answers with people using it on 5.6.3. Iam posting this as another question though for now. $$anonymous$$aybe iam missing something.

  • 1
  • 2
  • ›

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

15 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

Related Questions

How to edit the new particle surface shader? / Make it so particles receive light from all angles 0 Answers

I'm computing my surface normals in the fragment program - so why does Unity still require per-vertex normals/tangents? 1 Answer

Lighting support in Unlit shader 0 Answers

How to fix this point light bug in surface shader? 1 Answer

Problem with Normal Maps 1 Answer


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