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
0
Question by Suddenly_Bacon · Aug 12, 2014 at 08:40 PM · lightingobjectworld

Need help with lighting objects.

I am currently working on a basic FPS game. The problem is that the left side of the gun while looking at it in first person mode is brighter than the right side of it due to my directional lighting. I know how to use layers and all that to make light only affect certain objects, but I was looking for lighting similar to the environment lighting available in Blender, so that every face on the gun is equally lit. Is there a way to do this in Unity?

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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Vladimir-Shafran · Aug 13, 2014 at 12:24 PM

You can create a special shader for your gun like in Half-Life. This model of lighting is called Half Lambert.

 Shader "Custom/NewShader" {
     Properties {
         _MainTex ("Base (RGB)", 2D) = "white" {}
     }
     SubShader {
         Tags { "RenderType"="Opaque" }
         LOD 200
         
         CGPROGRAM
         #pragma surface surf BasicDiffuse
 
         sampler2D _MainTex;
 
         struct Input {
             float2 uv_MainTex;
         };
         
         inline float4 LightingBasicDiffuse(SurfaceOutput s, fixed3 lightDir, fixed atten)
         {
             float difLight = dot(s.Normal, lightDir);
             float hLambert = difLight * 0.5 + 0.5;
              
             float4 col;
             col.rgb = s.Albedo * _LightColor0.rgb * (hLambert * atten * 2);
             col.a = s.Alpha;
             return col;
         }
 
         void surf (Input IN, inout SurfaceOutput o) {
             half4 c = tex2D (_MainTex, IN.uv_MainTex);
             o.Albedo = c.rgb;
             o.Alpha = c.a;
         }
         
         ENDCG
     } 
     FallBack "Diffuse"
 }
 

When you will change value of hLambert parameter, you will see how lighting will be pass through object. When

 hLambert = 1 

lighting will be identical for both side

Before

alt text

hLambert = 1

alt text


screen shot 2014-08-13 at 3.27.59 pm.png (27.9 kB)
screen shot 2014-08-13 at 3.28.24 pm.png (33.7 kB)
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 Suddenly_Bacon · Aug 13, 2014 at 01:37 PM 0
Share

Thanks for the reply, but I'm not entirely sure how to go about making a shader. Can you explain it or should I just search for tutorials online (I'm O$$anonymous$$ with either)?

avatar image Vladimir-Shafran · Aug 15, 2014 at 12:46 PM 0
Share

As I understood you have problem with lighting 3D weapon. Your weapon contains a material. You can create a new shader which will be similar with $$anonymous$$e. And add this shader to your weapon’s material. Thats all.

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Lighting seams between objects 0 Answers

World object in front of GUI object 3 Answers

1stPersonController bigger than World. HELP PLS :( 3 Answers

Make multiple duplicated consecutive objects look like one 0 Answers

Light falling on whole object, instead in prescribed angle of spot light, how to fix it? 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