• 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 PJisAnarchist · Nov 24, 2012 at 12:37 AM · androidshadermobilelight

How to add rim light for mobile in my shader?

Hello community!

I found so many answers here... I finished a game out of it. Now I'm trying stuff to prepare the next game, and I'm facing a wall made of shader-coding-lack-of-knowledge...

I made a shader from unity's doc code sample, and it's fine, except it lacks Rim Lighting. The thing is it works in editor with:

 void surf (Input IN, inout SurfaceOutput o) {
 //Shading stuff
    half rim = 1.0 - saturate(dot (normalize(IN.viewDir), o.Normal));
    o.Emission = _RimColor.rgb * pow (rim, _RimPower);
 //...

But it displays black when I run it on Android. Here is my full shader:

 Shader "Mobile/Diffuse Detail" {
     Properties {
         _MainTex ("Base (RGB)", 2D) = "white" {}
         _Detail ("Detail (RGB)", 2D) = "gray" {}
         _Lightmap ("LightMap (RGB)", 2D) = "gray" {}
         _BumpMap ("Bumpmap", 2D) = "bump" {}
         _RimColor ("Rim Color", Color) = (0.26,0.19,0.16,0.0)
           _RimPower ("Rim Power", Range(0.5,8.0)) = 3.0
         
         
     }
     SubShader {
         
         Pass{
                         
             Lighting On
             Fog { Mode Off }
             SetTexture [_MainTex] { combine texture * primary Double, texture * primary}
             //SetTexture [_Detail] { combine previous * texture Double, previous}
             
         }
         Tags { "RenderType" = "Opaque" }
       CGPROGRAM
       #pragma surface surf WrapLambert
       
       half4 LightingWrapLambert (SurfaceOutput s, half3 lightDir, half atten) {
           half NdotL = dot (s.Normal, lightDir);
           half diff = NdotL * 0.2 + 0.8;
           half4 c;
           c.rgb = s.Albedo * _LightColor0.rgb * (diff * atten * 2);
           c.a = s.Alpha;
           return c;
       }
 
       struct Input {
           float2 uv_MainTex;
           float2 uv_Detail;
           float2 uv_BumpMap;
           float2 uv_Lightmap;
           float3 viewDir;
       };
       sampler2D _MainTex;
       sampler2D _Detail;
       sampler2D _BumpMap;
       sampler2D _LightMap;
       float4 _RimColor;
       float _RimPower;
       
       sampler2D _Lightmap;
       void surf (Input IN, inout SurfaceOutput o) {
           o.Albedo = tex2D (_MainTex, IN.uv_MainTex).rgb;
           o.Albedo *= tex2D (_Detail, IN.uv_Detail).rgb * 1;
           o.Albedo = ((o.Albedo) + (tex2D (_MainTex, IN.uv_MainTex).rgb))/2;
           o.Albedo *= tex2D (_Lightmap, IN.uv_Lightmap).rgb * 2;
           o.Normal = UnpackNormal (tex2D (_BumpMap, IN.uv_BumpMap));
           half rim = 1.0 - saturate(dot (normalize(IN.viewDir), o.Normal));
           o.Emission = _RimColor.rgb * pow (rim, _RimPower);
           
       }
       ENDCG
     } 
     FallBack "VertexLit", 2
 }

So, could someone please tell me how to make this RimLighting work on Android? It really enhances my visuals by giving more volume to the normal mapping. I did research yet, and found this: http://forum.unity3d.com/threads/45264-Rim-Light-Shader-Question-First-Unity-Shader!?p=287554&viewfull=1#post287554 It does work very well on Android, but I really don't know enough about shader coding to understand it and merge it with my shader. Help? Please...

Julien

Comment
Add comment · Show 1
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 PJisAnarchist · Nov 26, 2012 at 03:09 PM 0
Share

Really? No one? It really changes a lot the look of my environment, it would be wonderful if someone could help...

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.

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

Mobile Bumped Specular: Point Lights Only 0 Answers

Weird streak effect, particle sprites, Android but not all devices 1 Answer

RWTexture2D in Compute Shader on Android? 2 Answers

Custom Shader not working on Android Device 0 Answers

Foliage shader makes objects invisible on Android Build 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