Hi there, I don't have a clue about the unity shader language and only need a very simple shader that is basically a combination of the Alpha-Diffuse and Unlit-Alpha shader. I need it to be like the unlit shader but want to control the alpha channel via script to fade it out which works in the standard alpha-diffuse shader but not in the unlit-alpha shader. How do I accomplish this really quick? EDIT: oh, and it needs to run on the iPhone which the two base shaders do
This is not a mindset that is going to work around here. Code (csharp): Shader "Somian/Unlit/Transparent" { Properties { _Color ("Main Color (A=Opacity)", Color) = (1,1,1,1) _MainTex ("Base (A=Opacity)", 2D) = "" } Category { Tags {"Queue"="Transparent" "IgnoreProjector"="True"} ZWrite Off Blend SrcAlpha OneMinusSrcAlpha SubShader {Pass { GLSLPROGRAM varying mediump vec2 uv; #ifdef VERTEX uniform mediump vec4 _MainTex_ST; void main() { gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex; uv = gl_MultiTexCoord0.xy * _MainTex_ST.xy + _MainTex_ST.zw; } #endif #ifdef FRAGMENT uniform lowp sampler2D _MainTex; uniform lowp vec4 _Color; void main() { gl_FragColor = texture2D(_MainTex, uv) * _Color; } #endif ENDGLSL }} SubShader {Pass { SetTexture[_MainTex] {Combine texture * constant ConstantColor[_Color]} }} } }
Thanks a lot! works perfectly. Did't know it was so complicated. I tried to puzzle something together from the source of the two original shaders but with no success since I don't know how it works (yet)^^ and don't have time to grapple with the basic concepts of the shader language Sorry for the "i want it to work and I want it now"^^
is it okay if I use this in my game too please? I would write my own shader, but seeing as yours is right there...
Definitely. Everything I post here is free to be used by all, unless I say otherwise (which I don't recall doing).
Hi, I'd like to know the reason for the second pass in this shader. I've removed it and it seems to work just fine. Thanks
Nevermind, I get it. It's the same thing but in shaderlab language if the GLSL sub shader fails to work on the hardware running the game.
I just compiled it in Unity4 and code didn't break for me... I am using it in a particle effect material that is fed a "star" with transparent bg...I will try to compile on ios and see if the transparency is still retailed
tested in OUYA and works perfect!! thank you Jessy!!! you will be in the credits of our game! (Dragon Maze)
Hi there, one question about this shader...if I want to remove the transparency from it which lines should I modify and how? I know nothing about shaders but I'm using a map plugin that is using this same exact shader to render the map planes and I want to remove the transparency because it lets me see through the map plane and I don't want that. thanks!
I've been using Jessy's shader here for bullets and muzzle flash. However, I seem to get weird layering results. Despite the muzzleflash being positioned above the bullets, some of the bullets show through the muzzleflash gameobject depending on the angle you look at it! It's kind of a weird issue. Anyone know what's causing it?
I found a good free asset here https://www.assetstore.unity3d.com/en/#!/content/18282 After import, choose Unlit/Transparent Color and change the alpha on the main color property.
Hello! Thanks for your shader, It works fine, but I can't animate the opacity. How can I do that? Thanks JC
Hey there! I tested your shader on a quad as a means of rendering clouds. I change the texture offset to match my wind zone main speed multiplied by a reductive speed modifier. When I look straight up at the 3000 x 3000 quad, the shader works perfectly! As soon as I look down the offset stops changing. Also, there are moments when the clouds render strangely. Are these problems caused by the Unity 5 update? Do you know any workarounds for what I'm trying to accomplish?
Same issue here, I have a couple of fading materials which animating alpha doesn't work. Does someone know why this shader's Alpha can't be animated?
Does anyone know why I can't animate the Alpha value in this shader example? Or is this a bug with the animation tools?
Jessy, I am trying to use the shader you posted above, but I keep getting this error message GLSL compilation failed: ERROR: 0:16: 'varying' : syntax error: syntax error Any suggestions, anyone, how I could fix this?
I changed 2 lines and it started working: Code (CSharp): Shader "Somian/Unlit/Transparent" { Properties { _Color ("Main Color (A=Opacity)", Color) = (1,1,1,1) _MainTex ("Base (A=Opacity)", 2D) = "" } Category { Tags {"Queue"="Transparent" "IgnoreProjector"="True"} ZWrite Off Blend SrcAlpha OneMinusSrcAlpha SubShader { Pass { GLSLPROGRAM #ifdef VERTEX varying mediump vec2 uv; uniform mediump vec4 _MainTex_ST; void main() { gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex; uv = gl_MultiTexCoord0.xy * _MainTex_ST.xy + _MainTex_ST.zw; } #endif #ifdef FRAGMENT varying mediump vec2 uv; uniform lowp sampler2D _MainTex; uniform lowp vec4 _Color; void main() { gl_FragColor = texture2D(_MainTex, uv) * _Color; } #endif ENDGLSL } } SubShader {Pass { SetTexture[_MainTex] {Combine texture * constant ConstantColor[_Color]} }} } }
Thanks! It works! Also it may help to drag an all white 128*128 texture as "Base" to the shadered material to make it all white. Because it's multiplying Color with Base by default so if there's no Base it seems to be around 50% transparent at max.
You could also change line 4 to: Code (CSharp): _MainTex ("Base (A=Opacity)", 2D) = "white" {} This will set the texture to a blank white by default if no texture is provided in editor.
Hi, I am trying to make an unlit transparent shader that will enable me to make an object opaque when an object is placed close to the camera. I was thinking if I could write a condition like this to set alpha to 0 if (alpha == 1){ alpha ==0 } I do not know how I can accomplish this. Please does anyone have any suggestions?
Oh my GOD! Tried to figure out forever why this shader (and also the standard diffuse shader set to fade) will be "self-transparent" even if Alpha is 0. Meaning for example, despite the object fading from invisible to full opaqueness, you could still see parts of the model that should be occluded. Like when you look at a tree you could see the hidden branches on the backside. So by noobishly trying out "ZWrite On" on line 9, this problem gets SOLVED! crazy I know. Thanks for the original code in any way!