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
0
Question by shionyr · Aug 02, 2011 at 07:06 PM · shadergraphicsshaderlab

Multiply Mode uses strange Alpha

(Link to code: http://pastebin.com/P1WxYquh)

Hey Everyone -

I'm writing my own multi-pass shader for handling several effects at once. This is for a sprite-based game.

This shader has three textures: one for the base colors, one for highlights (using additive mode), and one for interior shadows (using multiply mode). It also has four other settings: an overall opacity (slider), main Tint color, highlight color, and shadow color (all RGBA). These colors have an alpha value to give direct control over the intensity of the highlights and shadows.

Here's how it appears in Unity's GUI: http://grab.by/aEGc

Everything works great, except for the multiply mode when I use "Blend Zero SrcColor."

Here's an image showing the results with various settings (yes, that's Saki from Arcana Heart, which I'm only using for test purposes): http://imm.io/7Mmh

1 - Opacity set to 0, Tint Highlight and Shadow set to Alpha 0.

2 - Same as #1, Opacity set to 1.0

3 - Same as #1, Highlight set to Alpha 1.0 (you can see the alpha in the actual texture map coming through)

4 - Same as #1, Shadow set to Alpha 1.0, using standard blending ("Blend SrcAlpha OneMinusSrcAlpha")

5 - Same as #1, Shadow set to Alpha 1.0, using multiply blending ("Blend Zero SrcColor")

As you can see, the alpha on the multiply texture becomes fragmented when I use Blend Zero SrcColor, oddly enough. Any ideas on how I can handle this issue?

Thanks for your time and insight!

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 shionyr · Aug 04, 2011 at 07:59 PM

Did it!

     // Based on Particles/VertexLit Blended
     Shader "Custom/VertexLit Blended w Add and Mult" {
     Properties {
         // _EmisColor ("Emissive Color", Color) = (.2,.2,.2,0)
         _Opacity ("Object Opacity", Range(0.0, 1.0) ) = 1.0
         
         _MainTex ("Main Diffuse", 2D) = "white" {}        
         _AddTex ("Hilight Texture", 2D) = "white" {}
         _MultTex ("Shadow Texture", 2D) = "white" {}
         
         _TintColor ( "Main Tint Color", Color) = (.5, .5, .5, 0)
         _AddColor ( "Hilight Tint Color", Color) = (0,0,0,0)
         _MultColor ( "Shadow Color", Color) = (1, 1, 1, 0.0)
         
     }
 
     SubShader {
         // Preps and Setup
         Tags { "Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent" }
         Tags { "LightMode" = "Vertex" }
         Cull Off
         Lighting On
         Material { } //Emission [_EmisColor] }
         ColorMaterial AmbientAndDiffuse
         ZWrite Off
         ColorMask RGB
         AlphaTest Greater .001
         Blend SrcAlpha OneMinusSrcAlpha
         
         Pass {
             // Set Tint Color and apply main texture's alpha to it.
             SetTexture [_MainTex]{
                 constantColor [_TintColor]
                 combine constant lerp (constant) texture
             }
             // Apply main texture with the Opacity setting included
             SetTexture [_MainTex]{
                 constantColor(0,0,0,[_Opacity])
                 combine previous, texture * constant
             }
             // Apply lighting
             SetTexture [_MainTex]{
                 combine primary * previous
             }
         }
         
         Blend SrcAlpha One
         Pass {
             // Apply the Highlights, using the opacity in AddTex.
             SetTexture [_AddTex]{
                 ConstantColor [_AddColor]
                 combine constant, texture * constant
             }
             SetTexture [_AddTex] {
                 ConstantColor(0,0,0,[_Opacity])
                 combine previous, previous * constant
             }
         }
         
         Blend DstColor Zero
         Pass {
             SetTexture[_MainTex] {
                 ConstantColor(1,1,1,[_Opacity])
                 combine texture, constant
             }
             SetTexture[_MultTex] {
                 combine previous, previous * texture
             }
             SetTexture[_MultTex] {
                 ConstantColor[_MultColor]
                 combine one-previous alpha + constant
             }
         }
     }
 }
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

2 People are following this question.

avatar image avatar image

Related Questions

Would learning some GLSL help with Unity Shading? 1 Answer

How to smoothen/sharpen edges while using alphatest 0 Answers

Implementing Custom Vertex Lighting Shader 1 Answer

Is there any way to set Shaderlab Pass Tags based on material properties? 1 Answer

How to achive the same look? Which shaders to use? 2 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