• 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 joeybubble1 · Nov 28, 2012 at 08:25 PM · shaderdiffuse

Shader help?

Hey everyone, my name is Tz and I have no knowledge on how to code shaders, I have a shader that I downloaded but I want to make it "Self Illuminated" but I don't know how.

Here is the shader.

  Shader "Dif_Nor_Spec"
     {
         Properties 
         {
     _Diff_Color("_Diff_Color", Color) = (0.4701493,0.4385721,0.4385721,1)
     _Gloss("_Gloss", Range(0,1) ) = 0
     _Dif("_Dif", 2D) = "gray" {}
     _Nor("_Nor", 2D) = "bump" {}
     _Spec("_Spec", 2D) = "black" {}
     
         }
         
         SubShader 
         {
             Tags
             {
     "Queue"="Geometry"
     "IgnoreProjector"="False"
     "RenderType"="Opaque"
     
             }
     
             
     Cull Back
     ZWrite On
     ZTest LEqual
     ColorMask RGBA
     Fog{
     }
     
     
             CGPROGRAM
     #pragma surface surf BlinnPhongEditor  vertex:vert
     #pragma target 2.0
     
     
     float4 _Diff_Color;
     float _Gloss;
     sampler2D _Dif;
     sampler2D _Nor;
     sampler2D _Spec;
     
                 struct EditorSurfaceOutput {
                     half3 Albedo;
                     half3 Normal;
                     half3 Emission;
                     half3 Gloss;
                     half Specular;
                     half Alpha;
                     half4 Custom;
                 };
                 
                 inline half4 LightingBlinnPhongEditor_PrePass (EditorSurfaceOutput s, half4 light)
                 {
     half3 spec = light.a * s.Gloss;
     half4 c;
     c.rgb = (s.Albedo * light.rgb + light.rgb * spec);
     c.a = s.Alpha;
     return c;
     
                 }
     
                 inline half4 LightingBlinnPhongEditor (EditorSurfaceOutput s, half3 lightDir, half3 viewDir, half atten)
                 {
                     half3 h = normalize (lightDir + viewDir);
                     
                     half diff = max (0, dot ( lightDir, s.Normal ));
                     
                     float nh = max (0, dot (s.Normal, h));
                     float spec = pow (nh, s.Specular*128.0);
                     
                     half4 res;
                     res.rgb = _LightColor0.rgb * diff;
                     res.w = spec * Luminance (_LightColor0.rgb);
                     res *= atten * 2.0;
     
                     return LightingBlinnPhongEditor_PrePass( s, res );
                 }
                 
                 struct Input {
                     float2 uv_Dif;
     float2 uv_Nor;
     float2 uv_Spec;
     
                 };
     
                 void vert (inout appdata_full v, out Input o) {
     float4 VertexOutputMaster0_0_NoInput = float4(0,0,0,0);
     float4 VertexOutputMaster0_1_NoInput = float4(0,0,0,0);
     float4 VertexOutputMaster0_2_NoInput = float4(0,0,0,0);
     float4 VertexOutputMaster0_3_NoInput = float4(0,0,0,0);
     
     
                 }
                 
     
                 void surf (Input IN, inout EditorSurfaceOutput o) {
                     o.Normal = float3(0.0,0.0,1.0);
                     o.Alpha = 1.0;
                     o.Albedo = 0.0;
                     o.Emission = 0.0;
                     o.Gloss = 0.0;
                     o.Specular = 0.0;
                     o.Custom = 0.0;
                     
     float4 Tex2D1=tex2D(_Dif,(IN.uv_Dif.xyxy).xy);
     float4 Multiply0=Tex2D1 * _Diff_Color;
     float4 Tex2D0=tex2D(_Nor,(IN.uv_Nor.xyxy).xy);
     float4 UnpackNormal0=float4(UnpackNormal(Tex2D0).xyz, 1.0);
     float4 Tex2D2=tex2D(_Spec,(IN.uv_Spec.xyxy).xy);
     float4 Master0_2_NoInput = float4(0,0,0,0);
     float4 Master0_5_NoInput = float4(1,1,1,1);
     float4 Master0_7_NoInput = float4(0,0,0,0);
     float4 Master0_6_NoInput = float4(1,1,1,1);
     o.Albedo = Multiply0;
     o.Normal = UnpackNormal0;
     o.Specular = _Gloss.xxxx;
     o.Gloss = Tex2D2;
     
                     o.Normal = normalize(o.Normal);
                 }
             ENDCG
         }
         Fallback "Diffuse"
     }

So if anybody knows how to add "Self Illumination" to it, please say. Thanks Tz

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

1 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by Tim-Michels · Nov 29, 2012 at 09:25 AM

Well to make your object "Self Illuminating", you need to set the emission of your surface shader. Right now you're setting the emission to 0.0 (o.Emission = 0.0;)

Either you want a seperate color for your emission, or you use a property you allready use. The only thing you should change in your shader is change the line

o.Emission = 0.0;

to

o.Emission = _Diff_Color;

That is when you want to use your diffuse color for your emission. If you want to have seperate control over your emission, you should add a color value.

This should cover your question, please mark as answered, and if you're having trouble adding a seperate color let me know, I'll help you further if necessary.

Cheers ;)

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 joeybubble1 · Nov 29, 2012 at 03:47 PM 0
Share

Thanks so much ;)

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

11 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

Related Questions

Silhouette Toon Shader 0 Answers

How to make a Diffuse Bump Blending 1 Answer

What's the difference in z sorting transparent vs diffuse 0 Answers

Batching draw calls changes shadows? 0 Answers

How to make sprite to react to light? 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