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 /
  • Help Room /
avatar image
0
Question by Eudaimonium · Aug 29, 2017 at 08:14 AM · lightingshaderslightmappingsurface shader

Need help with Lightmapping and Surface shader

== This is a cross-post from Unity3D Reddit as well as official forum - you can answer anywhere==

Hi,

I have been busting my head over this problem for quite some time now, and I'm at my wits end. I have contradicting and incomplete documentation on the matter.

The TL;DR version are these 3 images with respective Imgur comments: http://imgur.com/a/k2W8B

Onwards to the problem: I have some prefabs (trees in this case) in my scene. They are static, and the only directional light in the scene is Baked type. There are no realtime shadow casters. This gives me the following result:

Incorrect Baked Lighting: http://imgur.com/tgWLM9t alt text

As you can see it's all noisy and splotchy all over the place. This is because the quads that make up the canopy are arbitrarily oriented (a.k.a. all over the damn place), and they are shaded according to their angle towards the light.

Bear with me as I attempt to explain what I'm trying to achieve. I have switched my scene from baked, to all-realtime lighting and shadows. This is the same problem as displayed in realtime conditions:

Realtime reproduction of the problem: http://imgur.com/kCbGcqE alt text

Now, using the realtime lighting as example, THIS is what I'm trying to achieve:

Correctly shaded trees: http://imgur.com/5U06kn3 alt text

This fix was very simple, as within my surface shader I needed only add this in my vertex function:

 v.normal = _WorldSpaceLightPos0.xyz;

This simply flips all the normals towards the directional light source. How can I achieve this with Lightmapped lighting? I am aiming for very low hardware requirements of the game and I'd prefer not to use realtime shadow casters if at all possible.

The shader which produces correct Realtime result can be found on this Pastebin link, however it does not work with lightmapping at all as it shows all black surface - apparently, lightmapping and custom Surface shaders do not play well.

The shader which produces incorrect lightmapped and realtime result (first two images) can be found on this Pastebin link - the only difference is the definition of a custom Lighting Model code as so:

Code (CSharp):

       #pragma surface surf LambertZ ... and then:
  
            inline half4 LightingLambertZ(SurfaceOutput s, half3 lightDir, half atten)
            {
                half4 c;
  
                /*  half NdotL = dot(s.Normal, lightDir);
                    c.rgb = s.Albedo * _LightColor0.rgb * (atten * NdotL);*/
  
                    c.rgb = s.Albedo * _LightColor0.rgb * (atten);
                    c.a = s.Alpha;
                    return c;
                    return half4(1,1,1,1);
            }



This bit does change the way the shader interacts with realtime lights, but it has absolutely no effect on lightmapping whatsoever.

Now, if you're reading this far, thank you so much, and to save you time, let me finish off by listing all the things I so far have tried and which did not help me:

  • Making a custom META pass to change the way Lightmapper receives data, via this example code, because this is literally not documented

  • Trying to override any of the provided Lighting methods via documentation which is severly lacking. An example of overriding the actual GI method which is used for lightmapping here, very last example does not appear to actually do anything. The compiler will complain about function definitions, but once compiled it does not do anything - I've tried simply outputting gibberish on color and light channels, or moving vertices to 0,0,0 - it does not make any change between Lightmap bakes whatsoever.

  • Trying to affect Normals in vertex function, surface functions or overriden Lighting methods - they reliably work on realtime lights but there's no change at all in baked lighting - is the fact I'm using "surface shader" approach of any relevance? Should I rework it into standard vertex/fragment shader?

So there we go. Sorry for long post. Any smallest hint of help will be greatly appreciated because, like I said, I'm going crazy over this completely mysterious part of Unity's rendering pipeline.

P.S. I just realised that identical scene and lighting setup is significantly brighter in realtime lighting conditions, than baked lighting. Throw that into the overflowing bucket of sighs.

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

133 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

Related Questions

how to get the camera settings similar to Lara croft GO? 0 Answers

SpriteDiffuse shader has inconsistent interaction with point/spot lights? 1 Answer

Ugly blocky light map. Unity 2019. Tried everything I can think of. 0 Answers

Unity stuck at 11/17 Bake Runtime, Please help! 0 Answers

How to set up reflection probes for big scenes 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