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 Bitcoon · Apr 05, 2014 at 10:50 AM · shadertransparencyalphavertex-lit

Add vertex transparency to shader

I still have a lot to learn when it comes to shaders, but I just added something to my menus which allows me to create a simple rectangle mesh during runtime and assign color values to its vertices to make a gradient. I don't need any sort of lighting or effects, I just need to be able to have an alpha gradient from one side to the other. Ideally this should just be as basic as possible to run nice and fast for mobile processors.

Here's the code that I picked up to make the shader currently in use:

 Material mat = new Material("Shader \"Vertex Color Only\"{Subshader{BindChannels{Bind \"vertex\", vertex Bind \"color\", color}Pass{}}}");

I was pretty surprised that it's really that simple to make a vertex-only shader. But this one doesn't support alpha on the vertex colors. Is there any way to do that? It doesn't seem like any of the default shaders support vertex alpha either.

Edit: I did manage to find a shader that works for my needs... but it only does something on PC. When I use Android it suddenly fails on me. The shader just doesn't render at all.

Here's the shader I'm using now:

 Shader "Custom/VertexAdd"
 {
     Subshader
     {
         Tags { "RenderType" = "Transparent" "Queue" = "Transparent" }
         Blend one one
         BindChannels
         {
             Bind "vertex", vertex
             Bind "color", color
         }
         Pass
         {
             
         }
     }
 }

Trying to dig into the log files from DDMS and I unearthed this:

04-13 01:33:53.841: I/Unity(16620): NullReferenceException 04-13 01:33:53.841: I/Unity(16620): at UnityEngine.Material..ctor (UnityEngine.Shader shader) [0x00000] in :0 04-13 01:33:53.841: I/Unity(16620): at MenuSelection.CreateGradient () [0x001f8] in C:\Users\Max\Documents\PuzzleByte\Assets\Custom Assets\Scripts\Menus\MenuSelection.cs:63

So the shader is coughing up errors. In fact, while that scene is open it's just pouring that error out repeatedly. I tried assigning default materials to see if it was a code error rather than a shader one, but they showed up in Android just as one would expect.

Here's the kicker, though... all this afternoon I've been replacing that with a billion different shaders, trying to get that effect to work. I FINALLY had some success with an extremely similar shader. You may know it as "mobile/particles/additive". And I'm FUMING right now, that it was so simple.

But here's the thing: if I cut out the texture part, the shader continues to work just fine in the editor but it stops showing up on Android. It's literally the one magical ingredient that I needed, and I don't even put a texture in there. And even worse, the surfaces I'm putting it on have no UVs because they're being generated in runtime, and I haven't the faintest clue how to generate UVs for them. (nor do I have any need to do so) And now the editor is the one suffering, because it's throwing out a constant stream of messages about texture coordinates.

So I guess you could say my problem is "solved" now because I have something working, but I REALLY want to know why the solution was so simple and totally unrelated...

Comment
Add comment · Show 4
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 Gruffy · Apr 05, 2014 at 12:14 PM 1
Share

Hello bud, With respect to mobile platforms, it is probably best to use an additive shader for alpha transparency as alpha-blended shaders can be fairly hefty etc. Have you looked at the Unity in-built mobile shader set. Thses may save you alot of work your self, or you could adapt them an alpha based one to use half values to plug in to the lighting model(obviously withthe result of a reduction in lighting quality/accuracy n all that). Hop ethat helps some and here is a link to the Unity Shader Docs online, a really helpful resource at all times for any shader adventures, not to mention here too, which is the Unify Community Shaders Page, well worth a good look and test of. Take care bud Gruffy

avatar image Bitcoon · Apr 06, 2014 at 02:34 AM 2
Share

I ended up adapting the existing shader into a more legible format with its own file so I could actually work with it a bit. But additive blending seems to be good enough for this project. I can just blend the desired color with some amount of black to get that gradient effect I was looking for.

I've had several misadventures with trying to learn shaders, but never really had much stick with me. I can read them and understand generally what's going on but a lot of it still tends to go over my head. I pick up just a bit more every time.

avatar image Gruffy · Apr 06, 2014 at 02:05 PM 0
Share

Such is the plight of Shader learning for some reason, a bit like a rite of passage, they seem to elude your until one day this moment of clarity hits you and you realise, though platform dependent admittedly(D3D, OGL etc) that they all have a very small set of keywords and with a list by your desk of those and some general knowledge based on general program$$anonymous$$g theory (dare I say including maths, though I dunno because in fairness I`m a S#!tty at math overall)....

But ultimately, through other shaders, like on the Unify community wiki etc, I noticed(as is often the case with code generally) that many of the same functions and calls were found with respect to lighting calculations made inside any methods. Suddenly, they started to seem not so bad after all. Like everything codey for me, if I use it, I get used to it, if I leave it for a while, often I find myself returning with a small cloud of forgetfulness for some of the simplest of stuff. A few hours later i`m motoring again, but holding all these different API`s in ya head can make for a messy scenario brain-wise.... SO....

I use things like these to help me refresh during use, I dont know if it`d help you too, but you never know (particularly, like I said, with Shaders these lil things proved invaluable) Not to mention this link too, though you prob already foudn this on your way...ShaderlabReference Take care bud and happy shading/coding Gruffy

avatar image Bitcoon · Apr 13, 2014 at 09:29 AM 0
Share

Okay, so the shader worked in the editor, but totally didn't do anything on Android. After wasting my whole day on this ridiculous problem, the solution was even more ridiculous: add in a texture for no reason and it just works. Which really throws a wrench into my procedurally generated rectangles because it means I need to figure out how to give them UVs just to keep Unity from slowing down the editor with warning messages about the textures I don't need.

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

22 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

Related Questions

Render transparent material without double occlusion 2 Answers

Cant get Alpha Channel to Work with Custom Shader 1 Answer

Add transparency to this shader? 0 Answers

Sorting issues within single transparent mesh 1 Answer

What does the "alpha is transparency" setting actually do? 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