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 Damocles · Nov 16, 2012 at 09:32 AM · shaderblendunlit

Problem with unlit additive shader

I'm having a real headache trying to get a shader to adopt no lighting and additive blending. This is what I have after hours of trial and error:

 Shader "Animated/Trans Unlit" {
     Properties {
         _MainTex ("Base (RGB)", 2D) = "black" {}
         _XMul ("UV.x mul", Float) = 0.25
         _YMul ("UV.y mul", Float) = 0.25
         _Offsets ("_Offsets from script", Vector) = (0,0,0.25,0.25)
         _Blend ("blend factor between frames", Range(0,1)) = 0
     }
 
     SubShader
     {
         Tags
         {
             "RenderType"="Transparent"
             "Queue"="Transparent-1"
         }
         
         ZWrite Off
         Cull Off    
         Lighting Off
         Blend One One
         
         CGPROGRAM
         #pragma surface surf Lambert alpha
 
         sampler2D _MainTex;
         float4 _Offsets;
         float _XMul;
         float _YMul;
         float _Blend;
 
         struct Input {
             float2 uv_MainTex;
         };
 
         void surf (Input IN, inout SurfaceOutput o)
         {
             float2 uv = IN.uv_MainTex * float2(_XMul, _YMul);
             uv += float2(_Offsets.x, _Offsets.y);
             half4 c1 = tex2D (_MainTex, uv);
             
             uv = IN.uv_MainTex * float2(_XMul, _YMul);
             uv += float2(_Offsets.z, _Offsets.w);
             half4 c2 = tex2D (_MainTex, uv);
             
             o.Albedo = lerp(c1.rgb, c2.rgb, _Blend);
             o.Alpha = lerp(c1.a, c2.a, _Blend);
         }
         ENDCG
     } 
     FallBack "Particles/Additive"
 }


I've tried moving the Lighting and Blend settings into different Pass blocks and Category blocks, and outside of pass blocks. I've tried several variations and mixtures of different locations for these settings, and they all come up the same. They all look like this:

alt text

As you can see, the ZWriting and Culling are turned off, and there is some kind of blending, but it's not Additive. It's also not unlit.

I can turn ZWriting and Culling on or off successfully, but Lighting seems to stay on no matter what, and Blending is acting plain weird. The results are exactly the same in-game.

Anyone have any idea what's causing this strange behaviour?

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
0

Answer by Paulius-Liekis · Nov 16, 2012 at 10:41 AM

If you want no lighting then it's better to write smimple programmable shader then work with suface shaders.

I think your problem in this case is that you're specifying Lambert lighting model for this surface shader. See how to repalce lighting model by your own and I think you'll solve this problem.

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 Damocles · Nov 16, 2012 at 12:42 PM 0
Share

The problem there is I would also like to create a lit version of the same shader. Writing a pure fragment shader would indeed work fine for this shader, but I could really do with a way of making this work with surface shaders. It also doesn't solve the problem of the blending mode being a bit...weird.

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

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

How To Replicate the Untitled Goose Game Art Style? 0 Answers

alpha adjustable additive blender 1 Answer

Shader: Normal Angle 1 Answer

Shader Darkening the UI sprite behind it! 1 Answer

Can't find unlit shader in material shader selection!, 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