• 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
Question by sydan · Jul 13, 2012 at 08:40 PM · shadertransparent

A shader with transparent lit area

Hi there, I found this shader on the forums, it works well, but I need one that does the inverse: The 'non-lit' areas need to be opaque and the lit areas completely transparent. I'm really struggling with shaders. Could someone help me understand how to adapt it?

 Shader "Lighting Only" 
     {
         Properties 
      {
             _Color ("Main Color", Color) = (1,1,1,1)
             _MainTex ("Base (RGB)", 2D) = "white" {}
         }
         SubShader 
      {
             Blend SrcAlpha One
             ZWrite Off
             Tags {Queue = Transparent}
             ColorMask RGB
             // Vertex lights
             Pass 
      { 
                 Tags {"LightMode" = "Vertex"}
                 Lighting On
                 Material 
      {
                     Diffuse [_Color]
                 }
                 SetTexture [_MainTex] 
      {
                     constantColor [_Color]
                     Combine texture * primary DOUBLE, texture * constant
                 }
             }
         }
         Fallback "VertexLit", 2
     }

Edit

Image for ScroodgeM:

alt text

Hey, this is what I get :/ Light is from left to right. There's another sphere inside, you can see it with the gizmo's on... but it doesn't appear visible through the outer sphere. I'm not sure why this is...

atmosphereproblem.png (27.2 kB)
Comment
catcall
encryptX3

People who like this

2 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 encryptX3 · Feb 12, 2017 at 08:06 PM 0
Share

I was actually needing this "Lighting Only" shader, couldn't find it anywhere since i wasn't sure what to search for, thanks!

1 Reply

  • Sort: 
avatar image
Best Answer

Answer by ScroodgeM · Jul 14, 2012 at 09:16 AM

 Shader "Lighting Only"
 {
     Properties 
     {
         _Color ("Main Color", Color) = (1,1,1,1)
         _MainTex ("Base (RGB)", 2D) = "white" {}
     }
     SubShader 
     {
         Blend SrcAlpha One
         ZWrite Off
         Tags
         {
             Queue = Transparent
         }
         ColorMask RGB
 
         CGPROGRAM
 
         #pragma surface surf MyLight alpha finalcolor:mycolor
 
         sampler2D _MainTex;
         fixed4 _Color;
 
         struct Input
         {
             float2 uv_MainTex;
         };
 
         void surf(Input IN, inout SurfaceOutput o)
         {
             fixed4 tex = tex2D(_MainTex, IN.uv_MainTex) * _Color;
             o.Albedo = tex.rgb;
             o.Alpha = tex.a;
         }
 
         float lightPower;
         fixed4 LightingMyLight(SurfaceOutput s, half3 lightDir, fixed atten)
         {
             lightPower = 1 - saturate(dot(normalize(s.Normal), lightDir));
             return fixed4((s.Albedo * _LightColor0.rgb) * (lightPower * atten * 2), 1);
         }
  
         void mycolor(Input IN, SurfaceOutput o, inout fixed4 color)
         {
             color.a = o.Alpha * lightPower;
         }
 
         ENDCG
     }
     Fallback "VertexLit", 2
 }



edit 15.07.2012

on this screen two spheres. one inside other. small sphere have white opaque material (diffuse) and the second have this shader colored to red. light direction is right-to-left on screen. lighted surface is transparent on red sphere because lighted and we can see second one.

alt text


1.jpg (5.4 kB)
Comment
catcall

People who like this

1 Show 16 · 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 sydan · Jul 15, 2012 at 02:27 PM 0
Share

Hi ScroodgeM! Thanks for the edit, but it doesn't seem to produce the correct result. The object is lit in reverse which is what I wanted... but the unlit sections need to be transparent, which is my main problem at the moment. Do you know how I could edit what you've given me to produce that effect? Cheers!

avatar image ScroodgeM · Jul 15, 2012 at 02:35 PM 0
Share

in my example lighted surface is 100% transparent, not lighted is opaque (0%), that is reverse of your first example - there's lighted surface is 100% opaque and unlighted is 100% transparent

how can i reverse your first example (where unlit surface is transparent) and at the same time leave unlit sections in transparent as you said in last comment? 8)

avatar image sydan · Jul 15, 2012 at 03:17 PM 0
Share

I fear I am confusing myself... I think I wrote my last comment wrong so I'm going to write it all out and see if I can work out what I need. My first shader had:

  • Opaque and coloured lit areas

  • Transparent and black unlit areas

The shader you adapted for me has:

  • Opaque and black lit areas

  • Opaque and coloured unlit areas

The shader is only half there, the coloured 'highlight' is in the right place (on the unlit side) but the lit side remains opaque and cannot be seen through. Sorry if I'm making this really complicated. Do you know if I can places where I can learn how to do this myself?

avatar image ScroodgeM · Jul 15, 2012 at 03:50 PM 0
Share

look edit in answer (comment doesn't allow pictures)

what platform do you use?

avatar image sydan · Jul 15, 2012 at 06:06 PM 0
Share

Hi, I responded to your image by editing my original post... our images aren't the same though. :( Erm, I'm using Windows XP.

Show more comments

Unity Answers is in Read-Only mode

Unity Answers content will be migrated to a new Community platform and we are aiming to launch a public beta by June 9. Please note, Unity Answers is now in read-only so we can prepare for the final data migration.

For more information and updates, please read our full announcement thread in the Unity Forum.

Follow this Question

Answers Answers and Comments

7 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

2sided Shader - Strumpy Shader Editor 1 Answer

Shadows with Transparent Standard Shader? 2 Answers

Transparent objects and shadow 0 Answers

How to force transparent shader for smooth lod transition to receive shadows? 0 Answers

Opaque to Transparent animation effect on a textured object (Lerpz)? 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