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 /
avatar image
4
Question by x4000 · May 26, 2011 at 09:18 PM · shadershadersblendingadditivesurfaceshader

How to set up additive blending on a surface shader?

So, in a normal shader I have the line:

 Blend SrcAlpha One

And that gives me additive blending of the sort I want. It works with transparency, and so on. However, when I use a surface shader this line does literally nothing. I take it that the CGPROGRAM section overrides the blend specifications and such above it. How do I do the equivalent thing in my surface shader?

I did try decal:add on the #pragma surface line, and that was additive blending in some respects, but it also destroyed the alpha blending so that's definitely not what I want.

Comment
Add comment · Show 2
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 The_Beast · Oct 17, 2012 at 06:36 PM 0
Share

I'd like to know how you would do this as well.

avatar image deram_scholzara · Jul 09, 2013 at 11:44 PM 0
Share

I'm looking for an answer to this as well.

The "alpha" and "decal:add" tags override each other based on which comes last. "decal:add" does exactly the kind of additive color blending we're looking for (SrcAlpha One), but it doesn't care about alpha blending at all.

Why is there not a tag along the lines of "alpha:add"?

2 Replies

· Add your reply
  • Sort: 
avatar image
2

Answer by deram_scholzara · Jul 10, 2013 at 01:00 AM

Ah-ha! I figured it out...

So apparently when you do not use the "alpha", "decal:add", or "decal:blend" tags, the blending mode is defined by the old-style Blend settings.

So in short, don't use those tags, and, in your case, use "Blend SrcAlpha One" instead.

Comment
Add comment · Show 4 · 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 PokeJoe · Jan 09, 2014 at 08:55 AM 0
Share

But this doesn't answer the question. This would require NOT using a surface shader, unless I misunderstand something?

avatar image deram_scholzara · Jan 09, 2014 at 05:35 PM 0
Share

Actually, it exactly answers the question. x4000 wanted to know how to set up a surface shader to use additive blending, and the way to do it is to use the "Blend SrcAlpha One" tag as with a non-CGPROGRA$$anonymous$$ shader, and leave out the "alpha", "decal:add", and "decal:blend" tags from the CGPROGRA$$anonymous$$. In the post, x4000 mentions that the "Blend" tag does nothing when writing a surface shader, and my explanation makes it do something - thereby allowing x4000 to do exactly what they want.

Are you wondering about something else that my answer doesn't fix?

avatar image PokeJoe · Jan 10, 2014 at 07:26 AM 0
Share

Hm. I'm new to this, sorry. $$anonymous$$y understanding is this (and correct me where I'm wrong): if you're using a surface shader, then you don't include a Pass { } block. But if you want to use the old-style Blend settings you have to put them in a Pass.

To test, I have this shader that works already - it's an emissive shader that uses both texture alpha and alpha based on normal falloff.

 Shader "Falloff/GhostFlat" {
     Properties {
         _Color ("$$anonymous$$ain Color", Color) = (1,1,1,1)
         _$$anonymous$$ainTex ("Base (RGB) Trans (A)", 2D) = "white" {}
         _RimPower ("Rim Exponent", Range(0.5,25.0)) = 3.0
         _BaseAlpha ("Base Alpha", Range(0.0,1.0)) = 1.0
     }
 
 
 
     SubShader {
         Tags {"Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent"}
 
         CGPROGRA$$anonymous$$
         #pragma surface surf Lambert alpha
         
 
         sampler2D _$$anonymous$$ainTex;
         fixed4 _Color;
         float _RimPower;
         float _BaseAlpha;
 
         struct Input {
             float2 uv_$$anonymous$$ainTex;
             float3 viewDir;
         };
 
         void surf (Input IN, inout SurfaceOutput o) {
             fixed4 c = tex2D(_$$anonymous$$ainTex, IN.uv_$$anonymous$$ainTex) * _Color;
             half rim = saturate(dot (normalize(IN.viewDir), o.Normal));
             //o.Albedo = c.rgb;        //No albedo, only emission
             o.Emission = c.rgb;
             o.Alpha =  pow (rim, _RimPower) * _BaseAlpha * c.a;
         }
         ENDCG
     }
     FallBack "Self-Illu$$anonymous$$/Diffuse"
 }


But if I wanted to make it additive as well, how would I do that? I tried taking the "alpha" out of the #pragma line, and adding this under the Tags {} block: Pass { Blend One One } but that caused a bunch of errors. So how can you combine these?

avatar image deram_scholzara · Jan 10, 2014 at 08:27 PM 0
Share

To the best of my knowledge, there is no such thing as "additive as well". There is only additive or not.

The Blend mode does not need to be in a Pass of its own, you can just put it under the SubShader block.

A surface shader basically creates its own Pass block, so when you put the Blend mode in a Pass block, it's a completely separate pass from the CGPROGRA$$anonymous$$ section, and therefore does not affect it. When you do not specify a blend pragma (using the alpha or decal options), it would appear that the shader defaults to whatever was specified in the subshader. As I understand it, this is how it works with fixed function Pass blocks as well - they default to the SubShader Blend mode, which is opaque (Zero One, I believe) when unspecified.

avatar image
0

Answer by JBC · Jun 08, 2011 at 05:52 AM

Did you try adding "alpha" or "alphatest:_Cutoff" in the pragma line? Curious if that would help.

Comment
Add comment · 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

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Multiply Shader with Alpha 0 Answers

Particle effects against light backgrounds 2 Answers

Iphone - Blend two textures + Additive blending 3 Answers

Simple texture blender shader not working properly 0 Answers

Additive Surface Shader in Unity 5 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