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 Bas-Smit · Nov 21, 2014 at 12:17 PM · specularlightprobes

Extract dominant light direction from lightprobes?

Im trying to find a way to do specular highlights using lightprobes. This article describes a way to extract the dominant light direction using this equation:

alt text

I am struggling a bit to implement it using the variables exposed by Unity:

 // SH lighting environment
 float4 unity_SHAr;
 float4 unity_SHAg;
 float4 unity_SHAb;
 float4 unity_SHBr;
 float4 unity_SHBg;
 float4 unity_SHBb;
 float4 unity_SHC;

I am not entirely sure how for instance Le3r corresponds to the variables above. Am I correct to assume part of the third band is packed in the w values of bands one and two?

To complicate things further, I have been looking at the example code provided in the article linked above, but the implementation there does not seem to correspond to the equation from the same article:

 vec3 lightDirR = normalize(vec3(-sh1_r.x, -sh0_r.y, sh0_r.z));
 vec3 lightDirG = normalize(vec3(-sh1_g.x, -sh0_g.y, sh0_g.z));
 vec3 lightDirB = normalize(vec3(-sh1_b.x, -sh0_b.y, sh0_b.z));
 vec3 lightDir  = normalize( 0.3*lightDirR + 0.59*lightDirG + 0.11*lightDirB );

It seems that the third band is not used at all, and naively translating this code to CG using the variables exposed by Unity does not yield correct results:

 float3 lightDirR = normalize(float3(-unity_SHBr.x, -unity_SHAr.y, unity_SHAr.z));
 float3 lightDirG = normalize(float3(-unity_SHBg.x, -unity_SHAg.y, unity_SHAg.z));
 float3 lightDirB = normalize(float3(-unity_SHBb.x, -unity_SHAb.y, unity_SHAb.z));
 float3 lightDir  = normalize(0.3*lightDirR + 0.59*lightDirG + 0.11*lightDirB);

I have been seeing good results with the following, but my understanding of sh is not deep enough to be confident this is a robust approach:

 normalize((0.3*unity_SHAr + 0.59*unity_SHAg + 0.11*unity_SHAb).rgb)

Any insights would be appreciated.

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

0 Replies

· Add your reply
  • Sort: 

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

27 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

Related Questions

Specular highlights with lightprobes 0 Answers

Lightmap with bump/specular problem Unity 3 Pro 2 Answers

use Alpha channel for specular mapping 5 Answers

Is this spec method any faster than using pow()? 1 Answer

Without normal map material 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