- Home /
Shader Transperency issue
Hi all,
I have a model of human leg and I want to create an opacity factor for muscles and bones, by playing with their's alpha channel. And currently I am using Transparent/VertexLit with Z shader.......
The problem occours when I try to fade off muscle(which is kept in front of bones), it then create this issue, and as per my thinking it is the shader issue.
I've tried these shaders from the forums also, but no luck till now :
http://forum.unity3d.com/threads/102785-Z-Sorting-Alpha-shader
http://forum.unity3d.com/threads/93189-Two-sided-cutout-shader-for-U3-wanted
Please help me from this issue, I'm just kinda stuck here
Thanks in advance....
EDIT : uploaded a new file for more clarification
Also image desc : 1. when there is nothing applied(normal models, one above another), 2&3 when alpha channel is reduced(along with rotation).
I can't see your picture for some reason - can you try again?
Do your muscle/bone etc models have separate meshes/renderers?
Hi, sorry for very late response, but I was preparing the rest of my build.... I've uploaded the png file again.
As you can see above, the problem here is generated from shader only. Here my muscle's opacity is reduced but it affects the bone also, I can't see my bone clearly.
And yes, my muscle/bones have seperate mesh renderers.
well i know the opacity of a shader can make the entire model go see-through (even the parts where the alpha is completely white)
if you have 1 shader on them both try making 1 shader for the bone with no opacity, and putting a completely different shader on the muscles and changing the opacity of that shader
Hi Tim,
Actually I want something like two bars, one which controls the opacity of muscles and another of bones. And if muscles opacity would be 50% , i should see the bones clearly(and vise versa)
So for achieving this, I've to add an opacity shader to bones also. Correct me if i m wrong here...? Also if there is another better way of doing this, please explain that too.......
Also I've uploaded a new png for my problem.
Answer by mrmadprofessor · Apr 08, 2013 at 08:53 AM
This is always the issue with alpha blend sorting between objects. The issue is that you have bones in the middle and muscles around and therefor Unity doesn't know what is supposed to be in front. It can't sort in the bones inside the muscles.
A way you could do this is if you only faded one of them down at a time. So if you fade down the muscles the bones is set to a opaque shader and if you fade the bones the muscles is set to a opaque shader. This way you can only fade down one at a time but it will solve the problem.
Hi @mrmadprofessor, could you just tell me which opaque shader are you talking about here. I mean which shader should I choose to replace?
Also I don't think this will work for me. As this would be an iOS app, so two button events(both the slider bars) could takes place together.
I would create two materials per object, one diffuse and one transparent. If the object isn't faded it would be set to the diffuse material and when the user starts fading it the material would be set to the transparent one.
Note that only one object can use their transparent material at the same time or you will end up with strange sorting. So if object1 is faded you would have to lock object2´s fading slider.
ok..noted!!, but if I reduces the opacity of bones first, let's say at 30%, and then when I come back to the muscle slider, the bones shader then turn to diffuse?(as per your statement), and this in turn , (Correct me if I am wrong) will cause bone as normal mesh(without any fade out effect) at that time?
And also the diffuse shader cannot be used for making an object transparent, if we wanted this to store the previous bone mesh shader values to itself(Correct me here too cuz I don't know anything about shader :( )
Yes in this case the bones would pop to non-transparent as soon as the muscle slider is changed. Correct, the diffuse shader can't be faded since it doesn´t use alpha/transparency.
The issue you are struggling with is that unity renders two objects and one of them is wrapped around the other one so unity can't sort them the way you want. One object will always be in front or behind the other.
One way you could do this (i think) is if both the bones and muscles use the same material (and texture of course) and were asigned a vertex color shader. Then you could modify the mesh.color (vertex color) for each mesh. Then Unity would render both objects at the same time and be able to sort them together back to front.
Here is someones question about just that, be sure to use a vertex color shader if you try this since the standard transparent shader doesn't take vertex color into account:
http://answers.unity3d.com/questions/13709/changing-the-alpha-of-specific-vertexes.html
Your answer
Follow this Question
Related Questions
Getting transparency issue on android build 1 Answer
How would I add transparency to an outline shader? 2 Answers
Prefab's High poly mesh VS lower poly transparency cutout 2 Answers
Shader Constants - Lighting Params require Queue=Geometry? 1 Answer
How to properly set alpha transparency in PSD's to work with Unity 1 Answer