Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
  • Help Room /
avatar image
0
Question by colinmbo · Oct 24, 2015 at 06:08 PM · shaderlightingshadersshaderlabdiffuse

Half Lambert / Wrap Diffuse Shader

Hello! I am a complete noob when it comes to shaders. The problem is, you NEED to have shaders in order to make your game look good. I did a ton of research about the kind of shaders I would want in my game, and then shader that I think would fit the best for me is a 'wrapped diffuse' or 'half lambert' shader. I wanted to go for the Super Smash Bros 4 look and feel. I can't seem to find very much documentation at all about these shaders, and considering I don't know anything about writing in ShaderLab, this is almost an impossible task for me. I have spent HOURS trying to figure it out, so I thought I would just direct myself to Unity Answers to solve my problem. The trouble I am having is that all the code online has serious problems. Even the Unity documentation about surface shaders includes code for a 'wrap shader', but it's really messed up. The code snippet from that documentation looks really good, but only if you delete the 'Fallback' at the end, as it causes weird pixelation around the line that divides what is dark and what is lit. If I remove the 'fallback' line, it works, but for some reason the shadows from other objects with other shaders can be seen on top of the the object with the wrap shader applied. It's like it's transparent but only to shadows. The other problem is I have no idea how to program shadows into the shader. All I need to do is fix these three problems, and I should have a working shader. Can anyone write me a CORRECT 'wrap diffuse' shader that actually WORKS?? I would GREATLY appreciate it. I know I've written a book, but if anyone has an answer to this problem I wouldn't be able to thank you enough. Thanks. Here is the code I've been using that has these problems:

 Shader "Shader Test" {
     Properties {
         _Color ("Main Color", Color) = (1,1,1,1)
         _MainTex ("Base (RGB)", 2D) = "white" {}
     }
     SubShader {
         Tags { "RenderType"="Opaque" }
         LOD 200
 
         CGPROGRAM
         #pragma surface surf WrapLambert
         
         half4 LightingWrapLambert (SurfaceOutput s, half3 lightDir, half atten) {
             half NdotL = dot (s.Normal, lightDir);
             half diff = NdotL * 0.5 + 0.5;
             half4 c;
             c.rgb = s.Albedo * _LightColor0.rgb * (diff * atten);
             c.a = s.Alpha;
             return c;
         }
 
         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 = c.a;
         }
         ENDCG
     }
     //Fallback "Legacy Shaders/VertexLit"
 }

As you can see on the last line, I had to cancel out the 'Fallback' section as it really messed with the shader.

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

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.

Follow this Question

Answers Answers and Comments

32 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

Related Questions

SpriteDiffuse shader has inconsistent interaction with point/spot lights? 1 Answer

Operate the shader, rotate the material 90 degrees 0 Answers

How to map letters on mesh with shader? 0 Answers

Unity equivalent to glDepthMask or alternative? 0 Answers

Remove circular shadow from object 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