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 MaT227 · Sep 19, 2014 at 06:05 AM · shaderlightingshaderscgsurface shader

Spherical Hamonics - ShadeSH9 and Surface Shader issue

Hey everyone,

After a loooooong time of research I finally decide to explain to you my issue and I hope someone can figure out what's happening.

I am trying to control Spherical Harmonics in my surface shader. This is very easy, you just need to follow the example provided by @Kuba in this thread Amplifying the Light Probes contribution.

But I don't want to use it like this, I can't apply my ShadeSH9 result in the Emission output. I have a lighting function and I want to apply the ShadeSH9 result inside it in my lighting algorithm. It works great BUT when I add a real-time point light I have strange results. I absolutely don't know how does it comes from (look at the gif to see the strange behaviour).

If I add the ShadeSH9 inside Emission and don't use it inside my lighting function like in the example, there is no problem but the visual result is not good.

Why this is happening ? How can I solve it ?

alt text

The scene uses only one point light in forward rendering mode (same issue in deferred) with some objects using probes and others not.

Update 1

If I check the different term of the ShadeSH9 I can see that the glitch is cause by unity_SHAr, unity_SHAg, unity_SHAb, unitySHBr, unitySHBg, unitySHBb.

But why is it failing if I use it inside the Lighting function of the Surface Shader ?! And why this doesn't fail if I apply the result of ShadeSH9 in the Emission output inside the Surface function.

Update 2

Here is the shader provided by @Kuba.

 Shader "Custom/ModifyLightProbes" {
 Properties {
     _Color ("Main Color", Color) = (1,1,1,1)
     _MainTex ("Base (RGB)", 2D) = "white" {}
     _Amount ("SH scale", Float) = 1
 }
 SubShader {
     Tags { "RenderType"="Opaque" }
     LOD 200
  
     CGPROGRAM
     #pragma surface surf MyLambert noambient vertex:vert nolightmap nodirlightmap
     #pragma debug
  
     sampler2D _MainTex;
     fixed4 _Color;
     float _Amount;
  
     struct Input {
         float2 uv_MainTex;
         float3 shLight;
     };
  
     struct CustomLambertOutput {
         half3 Albedo;
         half3 Normal;
         half3 Emission;
         half Specular;
         half Alpha;
     };
  
     half4 LightingMyLambert(CustomLambertOutput o, half3 lightDir, half3 viewDir, half atten) {
         half4 color = half4(0.0, 0.0, 0.0, 0.0);
         return color;
     }
  
     void vert (inout appdata_full v, out Input o) {
         UNITY_INITIALIZE_OUTPUT(Input, o);
         // evaluate SH light
         float3 worldN = mul ((float3x3)_Object2World, SCALED_NORMAL);
         o.shLight = ShadeSH9(float4 (worldN, 1.0));
     }
  
     void surf (Input IN, inout CustomLambertOutput o) {
         half4 c = tex2D (_MainTex, IN.uv_MainTex) * _Color;
         o.Albedo = c.rgb;
         o.Alpha = c.a;
    
         // modify the SH lighting anyway you want,
         // here's just simple scaling
         float3 shLight = _Amount * IN.shLight;
    
         // emission is just added to the final color,
         // so SH light needs to be multiplied by albedo
         o.Emission = shLight;
     }
     ENDCG
 }
 FallBack "Diffuse"
 }

Here is a failing example (Only the different parts)

   half4 LightingMyLambert(CustomLambertOutput o, half3 lightDir, half3 viewDir, half atten) {
      half4 color = half4(0.0, 0.0, 0.0, 0.0);
      color.rgb = o.Albedo;    //////////////////// CHANGE
      return color;
   }
  
   void surf (Input IN, inout CustomLambertOutput o) {
   half4 c = tex2D (_MainTex, IN.uv_MainTex) * _Color;
   o.Albedo = c.rgb;
   o.Alpha = c.a;
  
   // modify the SH lighting anyway you want,
   // here's just simple scaling
   float3 shLight = _Amount * IN.shLight;
  
   // emission is just added to the final color,
   // so SH light needs to be multiplied by albedo
      o.Albedo = shLight;    //////////////////// CHANGE
   }

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

24 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

Related Questions

How to add shadows to surface shader? 1 Answer

_LightMatrix0 and Directional Light 1 Answer

Shadow artifacts on vertex animation shader 1 Answer

Why are Cubemaps and Specular highlights not equally blurry at the same Roughness / Glossyness value with standard pbr shader? 0 Answers

Shader: get nearest point light's color, direction and general custom lighting questions 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