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 pnyx · Apr 08, 2015 at 03:05 AM · graphicslightmapcg

How to add a Meta Pass to a custom shader to Emit light using enlighten

Hi, I'm using custom cg shaders in my game and I want one of them to emit light. It should be baked into the lightmap.

A little research showed that this has to be done using a Meta pass, but how exactly that needs to look was nowhere to be found.

In the buildin Shaders zip file I found an example though, but that does not seem to be working.

here is the Meta pass I'm currently using, as found in the buildin_Shaders.zip ("Legacy Shaders/Self-Illumin/VertexLit")

     Pass
     {
     
         Name "META" 
         Tags { "LightMode" = "Meta" }
         Lighting on
         CGPROGRAM
         #pragma vertex vert
         #pragma fragment frag
         #include "UnityCG.cginc"
         #include "UnityMetaPass.cginc"
 
         struct v2f
         {
             float4 pos : SV_POSITION;
             float2 uvMain : TEXCOORD0;
             float2 uvIllum : TEXCOORD1;
         };
 
         float4 _MainTex_ST;
         float4 _Illum_ST;
 
         v2f vert (appdata_full v)
         {
             v2f o;
             o.pos = UnityMetaVertexPosition(v.vertex, v.texcoord1.xy, v.texcoord2.xy, unity_LightmapST, unity_DynamicLightmapST);
             o.uvMain = TRANSFORM_TEX(v.texcoord, _MainTex);
             o.uvIllum = TRANSFORM_TEX(v.texcoord, _Illum);
             return o;
         }
 
         sampler2D _MainTex;
         sampler2D _Illum;
         fixed4 _Color;
 
         half4 frag (v2f i) : SV_Target
         {
             UnityMetaInput metaIN;
             UNITY_INITIALIZE_OUTPUT(UnityMetaInput, metaIN);
 
             fixed4 tex = tex2D(_MainTex, i.uvMain);
             fixed4 c = tex * _Color;
             metaIN.Albedo = c.rgb;
             metaIN.Emission = c.rgb * tex2D(_Illum, i.uvIllum).a;
             return UnityMetaFragment(metaIN);
         }
         ENDCG
     }


The whole thing seems a little wonky anyway, sometime it works with the legacy self illu shader, sometimes it does not, or only after restarting. I don't know enough about how the system works to have an Idea what goes wrong here. does anyone have an idea how to get this working?

cheers Simon

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

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by Jesper Mortensen · Feb 11, 2016 at 07:28 AM

Check here: http://forum.unity3d.com/threads/meta-pass-and-precomputed-realtime-gi-question.346000/

Comment
Add comment · 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
0

Answer by essimoon2 · Sep 26, 2015 at 06:46 AM

Another Simon here with the same question :D Did you find a solution?

Comment
Add comment · Show 1 · 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 pnyx · Sep 26, 2015 at 07:04 AM 0
Share

Sadly no. It was just one material in my case so I worked around it and swap the material at bake time.

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

How can I make my own shader include file (.cginc or .glslinc)? 2 Answers

How to get camera location in object space? 1 Answer

load scene Assetbundle and the lightmap crash 0 Answers

Weird black overlay(look like shadow) in WebGL build 0 Answers

Unity CG Include not at all working 2 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