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 sSuite · Dec 04, 2018 at 04:58 AM · lightingshaderslightmapping

In a shader designed for Forward rendering, unity_Lightmap seems to be correct in the base pass and incorrect in the add pass. Am I doing something wrong or is this a bug?

Hey folks! I'm running into a strange problem. Basically, when I try to access the baked lightmap from the Forward Base pass of my shader, it seems fine, but when I do exactly the same thing from the Add pass, there are some errors.


Here's the minimal possible version of the shader that exhibits the problem. Basically all I'm doing here is returning the lightmap in each pass -- no attenuation or realtime shadows or anything else.

 Shader "Lightmap Issue Demo"
 {
     Properties {}
     SubShader
     {
         
         Pass {
             Tags { "RenderType"="Opaque" "LightMode"="ForwardBase" }
             LOD 100
 
 
             CGPROGRAM
             #pragma vertex vert
             #pragma fragment frag
             #pragma multi_compile_fwdbase
             
             #include "UnityCG.cginc"
             #include "AutoLight.cginc"
 
 
             struct appdata {
                 fixed4 pos : POSITION;
                 fixed2 texcoord1 : TEXCOORD1;
             };
 
             struct v2f {
                 fixed4 pos : SV_POSITION;
                 fixed2 light_uv : TEXCOORD0;
                 LIGHTING_COORDS(1,2)
             };
 
 
             
             v2f vert (appdata v) {
                 v2f o;
                 o.pos = UnityObjectToClipPos(v.pos);
                 o.light_uv = v.texcoord1.xy * unity_LightmapST.xy + unity_LightmapST.zw;
                 TRANSFER_VERTEX_TO_FRAGMENT(o);
                 return o;
             }
             
             fixed4 frag (v2f i) : SV_Target {
 
                 return 0;
 
                 fixed4 baked_light = saturate(fixed4(DecodeLightmap(UNITY_SAMPLE_TEX2D(unity_Lightmap, i.light_uv)),1));
                 return baked_light;
             }
             ENDCG
         }
 
 
 
         Pass {    
             Tags { "LightMode" = "ForwardAdd" }
             LOD 100
             Blend One One
  
             CGPROGRAM
             #pragma vertex vert  
             #pragma fragment frag
             #pragma multi_compile_fwdadd_fullshadows
 
             #include "UnityCG.cginc"
             #include "AutoLight.cginc"
 
 
             struct appdata {
                 fixed4 vertex : POSITION;
                 fixed2 texcoord1 : TEXCOORD1;
             };
 
             struct v2f {
                 fixed4 vertex : SV_POSITION;
                 fixed2 light_uv : TEXCOORD0;
                 LIGHTING_COORDS(1,2)
             };
  
             v2f vert(appdata v)  {
                 v2f o;
                 o.vertex = UnityObjectToClipPos(v.vertex);
                 o.light_uv = v.texcoord1.xy * unity_LightmapST.xy + unity_LightmapST.zw;
                 TRANSFER_VERTEX_TO_FRAGMENT(o);
                 return o;
             }
  
             float4 frag(v2f i) : COLOR {
 
                 //return 0;
 
                 fixed4 baked_light = saturate(fixed4(DecodeLightmap(UNITY_SAMPLE_TEX2D(unity_Lightmap, i.light_uv)),1));
                 return baked_light;
             }
  
             ENDCG
         }
     }
 
     Fallback "VertexLit"
 }

This is what it looks like when I disable the add pass and view only the forward pass (I know this lightmap looks a little sloppy but it's correct):

alt text

And with only the add pass (and one nearby point light):

alt text

Interestingly, it's only wrong for specific submeshes of specific objects. This seems to be completely random. There doesn't seem to be anything in common between the submeshes that don't work.

Any ideas? Is it just not possible to reliably access the lightmap from an add pass? I know this is an unusual thing to do but it's necessary for the effect I'm trying to achieve.

Thanks a bunch!

forward-pass.png (168.4 kB)
add-pass.png (155.8 kB)
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

134 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

Related Questions

Make game start looking nice 1 Answer

How to export baked lightmap for use with Unlit Texture? 0 Answers

Lightmap Artifacting After Entering Play Mode 0 Answers

Generate Lighting when loading the game 0 Answers

Can you get how much light is on the surface in 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