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 tcz8 · Feb 10, 2017 at 07:39 PM · shaderlightingshaderslightformula

What kind of values come out of _WorldSpaceLightPos0?

Hi,

I am writting a shader were I need to format the X rotation value of my directional light (_WorldSpaceLightPos0.x) in a certain way.

The table bellow shows how I need the value to behave at certain points (ie.: above 90degree i need negative value until 180 degree):

Input X Rotation   Required float value
0 degrees         1
45 degrees       0.2929
90 degrees       0
135 degrees       -0.2929
180 degrees       -1

Here is my current code:

 float3 lightDirection = normalize(_WorldSpaceLightPos0.xyz);
 float LightDirAdjust = 1;
 float v; // the float value I need
 
 if (_WorldSpaceLightPos0.x > 90 && _WorldSpaceLightPos0.x < 180)
     LightDirAdjust = -1;
 
 v = ((lightDirection.y * -1) + 1) * LightDirAdjust;

In the last line I multiply by -1 to reverse the value then add 1 so when X Rotation=0 my float = 1. It also works fine for X45 = float 0.2929 and X90=float 0.

Whe I go above 90 degrees for some reason the values stays positive, I tried a lot of things to make the value work as I expect and i just cant get it.

I think I am lost somewere in bettwen quaternions, euler angles and simply not understanding what comes out of _WorldSpaceLightPos0.xyz in relation to the actual rotation values in the inspecter. I also smell a potential issue with worldspace vs localspace values... im a bit lost.

Would someone please turn on a search light for me?

Thank you!

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

Answer by tcz8 · Feb 13, 2017 at 04:18 AM

Here is my own answer:

Since _WorldSpaceLightPos0 is a value being fed by Unity to the shader, you can inspect it's values by using the frame debugger.

Here is how:

  1. Go to Window > Frame Debugger

  2. Click ENABLE on the top left

  3. Expand the Camera.Render all the way down to the "Draw Dynamic" entries

  4. Select them one by one until you identify (by looking at the game view) the draw pass were you are using _WorldSpaceLightPos0

  5. Once you found the right entry, click on "shader properties" in the right pane

That's it, _WorldSpaceLightPos0 and its values will be listed right there under "Vectors". You can dynamicly move and rotate your directional light and see the X,Y,Z values change in realtime.

In my case I realized I was using X where I should have been using the Z value... With that figured out, it was easy to fix my code. Damn you worldspace!

Please note that on a few occations, the values being shown in the frame debugger either stopped refreshing or showed values that stopped making sense. Closing and reopening (also maybe disabling/re enabling) the debugger fixes the problem.

Good luck and thanks for stopping by!

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 AlexWei · Jan 09, 2019 at 03:06 AM 0
Share

Thanks a lot for pointing out using frame debugger.

avatar image MJonee · Jan 02, 2020 at 12:33 PM 0
Share

Thank you!

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

107 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

Related Questions

How to illuminate sprite's back and front face but display result of lighting only on the front face? 0 Answers

a 'bar' or neon like light. 3 Answers

Help with Shader that blends between two textures based on light 0 Answers

How do I keep an object lit when a light moves past it? 0 Answers

How to send an array of positions to a 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