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 Hamesh81 · Jan 02, 2014 at 05:08 AM · shadershadershighlight

How can I make rim lighting appear in front of everything?

I'm experimenting with rim lighting using a shader from the Unity Surface Shader Examples page. I would like to be able to have the rim light appear in front of all other objects so that it works as a highlighting system like in the pic below:

alt text

I would like to add a separate pass to the below shader where I only want to have the rim lighting. This way I can turn the ZWrite "On" and the ZTest to "Always" only for the rim lighting, and have it in front of everything but not the entire character. To ensure I don't increase the drawcalls with the extra pass I'm going to have 2 versions of the shader; one with the extra rim lighting pass and one without, and switch between the two as necessary via script. I've looked at the Outline shader on the Unity Wiki but it's process is a little too performance heavy so I'm trying to simplify things via rim lighting and avoid the complex calculations used in that one. Here is the shader code I'm using:

 Shader "Example/Rim" {
     Properties {
       _MainTex ("Texture", 2D) = "white" {}
       _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 {
       Tags { "RenderType" = "Opaque" }
       CGPROGRAM
       #pragma surface surf Lambert
       struct Input {
           float2 uv_MainTex;
           float2 uv_BumpMap;
           float3 viewDir;
       };
       sampler2D _MainTex;
       sampler2D _BumpMap;
       float4 _RimColor;
       float _RimPower;
       void surf (Input IN, inout SurfaceOutput o) {
           o.Albedo = tex2D (_MainTex, IN.uv_MainTex).rgb;
           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 "Diffuse"
   }

How can I add an extra pass for the rim lighting?

rimoutline.jpg (138.8 kB)
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 Hamesh81 · Jan 03, 2014 at 05:28 AM 0
Share

I ended up actually finding a way to do this. I used a second mesh parented to my character and that way I could focus on only the rim light part of the shader. I also added transparency controlled by the rim light intensity so anything without rim light on it is transparent, a very nice effect. To get the shader to appear "in front of everything" I simply added a pass with ZWrite "On" and the ZTest set to "Always". Also if you only want the shader to appear when its behind something use ZTest Greater ins$$anonymous$$d.

1 Reply

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

Answer by tanoshimi · Jan 02, 2014 at 09:15 AM

You can't separate the logic of surface shaders into separate passes; you can think of surface shaders as a bit like shader "wizards" - they provide a template and simplify the coding required to create many common shader effects, but at the expense of fine control over how the resulting code is structured.

If you want to create multiple pass shaders you'll have to learn vertex/fragment coding: http://docs.unity3d.com/Documentation/Components/SL-ShaderPrograms.html

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 Hamesh81 · Jan 02, 2014 at 11:16 AM 0
Share

Ah ok, well that's a bummer. Looks like I'm going to have to do things a different way then.

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

20 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

Related Questions

How can I have the camera forward in a vertex shader? 0 Answers

create a texture with shader code? ( without using a texture ) 1 Answer

vertex displacement shader and ssao 0 Answers

Depth mask with alpha / adding alpha to frag grabpass shader 0 Answers

How to make a 2d shader with edge waves 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