i’m fading an object out using material color alpha but it doesn’t quite look right.
I just want the current object view to fade to invisible and not to become glass during the transition. i.e. for it’s rear geometry to remain hidden. Doesn’t seem to be anything under the renderer class itself.
There is no renderer related thing involved in that, you would have to write a shader that prevents geometry to be renderered accordingly or alternative modify the geometry data itself to only contain the visible parts
That’s a very hard problem to solve in general case.
I think mostly three approaches are used:
-
render object into a render texture; then display a quad with that render texture, and fade it out. This way the object will fade out “as a whole”, instead of “becoming more transparent”. This will lose correct intersections of the object with other geometry though.
-
do not fade out, but use “dissolve” instead. Use a shader that projects a noise-like texture onto the object, and discard more and more pixels as object needs to fade out. Whether this will look acceptably depends on a lot of things
-
use a shader that first renders object as invisible, but fills the depth buffer. In a later pass, draw the semitransparent object itself. This way depth buffer will be filled with closest surfaces of the object, hence further surfaces will not be displayed.
thanks aras
but that’s disappointing news because it’s not a cosmetic issue. i’m dealing with a “guide shell” into to which other objects are placed. I’m pulsing the alpha of the shell and it works well for simple shapes but can be VERY confusing for more complex forms. Did i mention it’s iPhone too, i posted the thread here because i thought it was more a general issue. Option 3 option sounds most promising but also the most daunting for someone new to unity.
For the iPhone, none of the options will work, you don’t have shaders on the iphone, you only have combiners.
Also the solution is pretty much simpler:
Ensure that your geometry is correct, simply meaning that the face normals of those things you don’t want to see look into the opposite direction which causes them to not be rendered at all. That should normally be the case
This isn’t really the case… he wants to fade out an object without getting the “x-ray inside out” look that is common with semi-transparency and can happen with all sort of shapes regardless of whether or not all the normals are facing the “right” direction.
I think Aras’ #3 would be possible on iPhone… haven’t tried though.
Wrong iPhone does not have vertex/pixel shaders, but it does not mean you can’t use custom shaders that setup depth buffer, combiners and “other stuff”.
I think it should be possible there. I just added a shader that does this to the wiki: http://www.unifycommunity.com/wiki/index.php?title=AlphaVertexLitZ
Don’t have an iPhone to test, but I don’t see why it would not work there.
If the iphone lets you mess with the depth buffer with opaque, then yes.
The main reason I thought it was not is the special behavior on the iphone when it comes to early drop alpha.
EDIT: Tested and works, at least with the color based alpha. Can’t say if it works for the texture end as well
been away from my computer
can’t wait to try the shader
what’s the compile error with the Wiki code? i’m sure it’s just a curly bracket thing but i’ve never seen a shader before so i’m not sure what’s what.
i’ve compared with other examples and it looks right but just won’t compile.
I’ve not had any problems using it.
Copy on the wiki, inserting in a new shader created within unity iphone and selected as shader on a model I had that used the diffuse one before.
it compiled that time
I did the same as you but curiously it doesn’t seem to work for me. zero alpha just goes to black. puzzling. Couldn’t be anything to do with the graphics card on my MBP i suppose. I haven’t tried it on the actual phone. you?
only on the phone but I did not go to 0 alpha, as that wouldn’t make sense. if I don’t want it to be present, I disable the renderer instead
let me rephrase that.
there is NO transparency (like with transparent/diffuse)
opacity just fades the RGB to zero (i.e. black)
Aras missed a single step that I caught (I’'ll never get to say that ever again!).
Try this shader instead:
Shader "Transparent/VertexLit with Z" {
Properties {
_Color ("Main Color", Color) = (1,1,1,1)
_MainTex ("Base (RGB) Trans (A)", 2D) = "white" {}
}
SubShader {
Tags {"RenderType"="Transparent" "Queue"="Transparent"}
// Render into depth buffer only
Pass {
ColorMask 0
}
// Render normally
Pass {
ZWrite Off
Blend SrcAlpha OneMinusSrcAlpha
ColorMask RGB
Material {
Diffuse [_Color]
Ambient [_Color]
}
Lighting On
SetTexture [_MainTex] {
Combine texture * primary DOUBLE, texture * primary
}
}
}
}
way to go aNTeNNa trEE!!! (&thanks aras) it works perfectly.
subShader Tags eh? i must learn more about this stuff (when i’ve learnt all the other stuff of course) but how did how dreamora got the other version to work? Are there other ways of using shaders in the material panel that would have worked OK? it’s not an area of Unity i understand much yet. This is a cool forum. Thanks you guys
-rod
Aras and dreamora got it to “work” because they didn’t test it with other objects in the background… so they saw it render properly against a solid color or Skybox. The Transparent Queue makes sure that in this case the depth buffer is written into after all Opaque geometry has been rendered. Glad it works for your needs now.
I actually tested it against a static mesh that makes the terrain in my scenario and didn’t have problems.
The terrain thought has no alpha or alike.
I am able to add in Light Map, but I couldn’t figure out how to add in Normal Map based on this shader.
I have looked into Unity ShaderLab. It seems like Normal Map is not too easy to add in since it may need Vertex and fragment programs as well. So,just wandering anyone here can help out? Thanks.