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
0
Question by Ishkur · Dec 21, 2019 at 06:11 AM · shadershadersshader programming

How to set shader vertex normals to face up

I am having a lot of trouble with this and haven't been able stumble upon the answer. Here's what I've tried:


             void vert (inout appdata_full v, out Input o)
             {
                 #if defined(PIXELSNAP_ON)
                 v.vertex = UnityPixelSnap (v.vertex);
                 #endif
 
                 fixed3 normal = mul(unity_ObjectToWorld, v.normal);
 
                 v.normal += abs(normal - fixed3(0,1,0));
 
                 UNITY_INITIALIZE_OUTPUT(Input, o);
                 o.color = v.color * _Color * _RendererColor;
             }
 
             void vert (inout appdata_full v, out Input o)
             {
                 #if defined(PIXELSNAP_ON)
                 v.vertex = UnityPixelSnap (v.vertex);
                 #endif
 
                 v.normal = fixed3(0,1,0);
 
                 UNITY_INITIALIZE_OUTPUT(Input, o);
                 o.color = v.color * _Color * _RendererColor;
             }


And others.

I'm trying to do this to get my billboarding sprite to be lit from behind. Other questions asked on this topic are unresolved:

https://answers.unity.com/questions/1468837/how-to-light-a-plane-from-behind.html https://forum.unity.com/threads/lighting-sprites-uniformly-from-behind.686731/

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
1
Best Answer

Answer by Namey5 · Dec 30, 2019 at 08:48 AM

Assuming you're using a surface shader, you can just use a custom lighting function that ignores normals altogether and just samples the light's attenuation;

 #pragma surface surf Uniform ...
 
 //Then, later in the shader
 half4 LightingUniform (SurfaceOutput s, half3 lightDir, fixed atten)
 {
     half4 c;
     c.rgb = (s.Albedo * atten) * _LightColor0.rgb;
     c.a = s.Alpha;
     return c;
 }
Comment
Add comment · Show 6 · 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 Ishkur · Dec 31, 2019 at 03:08 AM 0
Share

This is wonderful, thank you, where did you read about this surface function?

avatar image Namey5 Ishkur · Dec 31, 2019 at 03:56 AM 0
Share

The manual has a few pages about custom lighting models in surface shaders. This one is just a simplified Lambert.

https://docs.unity3d.com/$$anonymous$$anual/SL-SurfaceShaderLighting.html

https://docs.unity3d.com/$$anonymous$$anual/SL-SurfaceShaderLightingExamples.html

avatar image Ishkur Namey5 · Dec 31, 2019 at 04:26 AM 0
Share

Yeah, I've read those but there's not anything referenced that follows the lighting model that you used as far as the parameters called or a reference to the Uniform surf directive, which I'm really interested in. Its behavior seems identical to SimpleLambert and I'm also wondering what the difference is between the two. Why are you required (and how did you know) to pass the half3 parameter lightDir?

Show more comments

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

192 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 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

post shader: reconstruct worldspace plane coordinates 1 Answer

Help me understand stencil shader logic 1 Answer

Where do I put this shader code? Getting weird error? 1 Answer

Setting custom camera projection matrix 2 Answers

How to make a "Cuphead" shader effect? 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