• 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
1
Question by Garrom · Feb 01, 2018 at 02:14 PM · shadershaderlabshader writingemission

Shader Help : Add emission to my shader.

Hi all. I'm totally newbie to shaders and I need some help. I created shader below(with help of internet) and i need somehow add real time emission based on emission map.I need parts on emission map look bright and illuminate surrounding area. Do someone help me ?

 Shader "Simple Memory Saving Shader"
 {
     Properties
     {
         _Color("Color",COLOR)=(0.5,0.5,0.5,1.0)
         _MainTex ("Base (RGB)", 2D) = "white" {}
     }
  
     SubShader
     {
         Tags { "Queue"="Transparent" "RenderType"="Transparent"}
         LOD 150
         CGPROGRAM
         #pragma surface surf Lambert alpha
  
         sampler2D _MainTex;
         fixed4 _Color;
  
         struct Input
         {
             float2 uv_MainTex;
         };
  
         void surf (Input IN, inout SurfaceOutput o)
         {
             fixed4 c = tex2D(_MainTex, IN.uv_MainTex) * _Color;
             o.Albedo = c.rgb;
             o.Alpha = tex2D (_MainTex, IN.uv_MainTex).a* c.a;
         }
         ENDCG
     }
     Fallback "Diffuse"
 }

-Garrom

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
0

Answer by Pangamini · Feb 01, 2018 at 04:11 PM

Shader itself cannot act as a source of light. The only exception is when you are using some kind of lightmaps (baking), in which case you have to write a standard emissive shader (just write some color to o.Emission in your surf shader)

Comment
Add comment · Show 3 · 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 Garrom · Feb 01, 2018 at 06:19 PM 0
Share

@Panga$$anonymous$$i Alright, now i have

 _Emission$$anonymous$$ap ("Emission $$anonymous$$ap", 2D) = "black" {}
 _EmissionColor ("Emission Color", Color) = (0,0,0)

But i don't know how to pass it to o.Emission. Can you give me line of code please ?I really didn't write any shaders before. I'm now forced to write own shader because my levels are GIANT and standard shader need lot of memory.

avatar image Pangamini · Feb 02, 2018 at 09:21 AM 0
Share

try o.Emission = tex2D(Emission$$anonymous$$ap, IN.uv$$anonymous$$ainTex).rgb * _EmissionColor.rgb;

avatar image Pangamini Pangamini · Feb 02, 2018 at 09:22 AM 0
Share

Also you have to declare your variables in the CG code, not just in properties; note how it's done in your code above struct Input; Just do the same with the emission properties

avatar image
0

Answer by shadowx311 · Sep 17, 2018 at 05:46 PM

I'm trying to add a second emission, but it's not working: https://pastebin.com/dLvDG5tA

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

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

170 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image 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

Custom Shader Giving Unexpected token error for period ' . ' 1 Answer

Additive Blending Shader for Mobile - parse error 1 Answer

Operate the shader, rotate the material 90 degrees 0 Answers

Fog not working in my own Vertext Shader 2 Answers

Is it possible to set the 'ForceNoShadowCasting' SubShader Tag via shader properties or a custom material editor? 1 Answer


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