- Home /
Transparency render issue
I understand that this has been asked before but I've done almost everything to get it to work. This might be beyond the scope of my expertise because I barely messed with shaders which I'm saving for last in regards to learning Unity.
Here's the problem as I'm sure you've seen before:
So there are a lot of solutions out there but none that I understand.
I tried the custom shader solution but I have a feeling that I'm adding the shader code incorrectly. I create a new shader, open the compiled shader, and replace the existing code with the solution code, correct? Or is there somewhere I place the code within the shader code that Unity provides in the shader?
I also tried the 'creating the face at a distance from the main object as part of the object to force render priority' trick but that didn't work.
Then there's renderQueue. I really have no idea how to use that or if it solves this problem.
If any one of these answers is the correct solution, can you say step by step how to fix this seemingly minor problem rather than responding with vague external resources or solutions?
I know that sounds rude but I see this problem as kind of an annoying obstacle that's taking time away from what I should be doing. Sorry, I have really bad OCD and I'd rather not get into writing my own shaders just yet. :)
EDIT: They key is not rendering correctly which is spinning and some of the faces of the key are showing instead of the closer faces. I will need to fade this key out so that's why I'm using the transparent/specular shader. Here are some images...Unity's kind of being a pain right now so I'll need a minute.
Edit:
I did find something on this thread concerning Zwrite because the guy has the same problem but Zwrite doesn't seem to be in the shader.
http://forum.unity3d.com/threads/41007-Transparent-Diffusr-shader-problem-Done
Commented out Zwrite in the transparent/diffuse shader. Didn't work.
Then I tried this shader:
Shader "Transparent/VertexLit with Z" {
Properties {
_Color ("Main Color", Color) = (1,1,1,1)
_SpecColor ("Spec Color", Color) = (1,1,1,0)
_Emission ("Emissive Color", Color) = (0,0,0,0)
_Shininess ("Shininess", Range (0.1, 1)) = 0.7
_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]
Shininess [_Shininess]
Specular [_SpecColor]
Emission [_Emission]
}
Lighting On
SetTexture [_MainTex] {
Combine texture * primary DOUBLE, texture * primary
}
}
}
}
This strangely made the object disappear altogether. Sigh.
Can you be more specific with what you want to achieve? Not knowing what you're shooting for makes it hard to see the problem.
I'm guessing from the title you want an object to be transparent but it's not working correctly? In the image you've provided, which object?
Have you tried making a new material (Right click in project view, Create/$$anonymous$$aterial ) and then assigning it the Transparent/Diffuse shader?
The key is rendering incorrectly. Sorry, I read what I wrote and afterward realized I left out a few things. Yeah, that key is showing 'holes' in the mesh as it rotates. I'll update with another image. One sec.
Answer by zafadadynamic · Oct 24, 2013 at 07:48 PM
Here's the shader that worked to my surprise because I tried this yesterday and there was no change:
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
}
}
}
}
And probably all I had to do was add Zwrite Off instead of just commenting it out in the transparent/diffuse shader.
Anyway, it's not polite for me to accept my own answer like last time so I'll pick someone. Here's what the final product should look like:
It's amazing how different the result is. I was going to use @Griffo 's method yesterday but I'm just way too stubborn for compromises, lol.
You can accept your own answer. The whole point is for other people with the same Q to see it later.
I think the problem was you were seeing the bright back-face of the key (hard to tell w/o being able to move it around.) Seems like backface-culling would also have solved it. Or just not having it lit from behind.
If you think it'd clarify the answer for people more, I can take a video, reprodeuce the problem, and see if backface cull would repair it too. That's just CULL OFF in the shader, right?
First result in "unity shader cull" says/shows how to use it. also has the shader you're using.
I'm wondering if you don't have extra, doubled faces. That's the only reason their robot looks odd.
Answer by Owen-Reynolds · Oct 24, 2013 at 06:22 PM
Those missing faces in the key probably means it was modelled with some flipped normals. In other words, the key is the problem, not your part.
You could turn off backface culling in the shader, but better to fix the key (lots of places here about flipped normals, missing faces ... , but might be better to look at a site for the program you made the key with.) If someone else made it, the mere words "some flipped normals" are all you have to tell them.
Also, you didn't write you did this, but in the Material for the key, switch to the new shader (whatever name you put in the very top of the new shader code, that should appear in the shader dropdown) (but if you fix the key, you won't need a new shader.)
Ya know, I was wondering if it was a flipped normal problem so I'll flip them in $$anonymous$$ax to see what happens. This problem only exists with the transparent shader.
I'll also make sure I did what you said about the material.
Okay, that was a no-go. The faces are all unified and facing the correct direction. Even went through the normals individually. I have the shader labeled 'test shader' which is selected. I may have even used the wrong code. I'll keep looking around and update the problem.
Answer by jonnyhopper · Oct 24, 2013 at 06:35 PM
If it's not flipped normals then it might be a sort order problem - bet it goes away if you turn it back to a non-transparent shader?
That is correct. I need the transparent shader so I can gradually fade out the alpha channel.
I use a normal shader then just before I fade out the game object I swap the shade to transparent in run time and fade it out, and it's not noticeable ..
Your answer
![](https://koobas.hobune.stream/wayback/20220613120552im_/https://answers.unity.com/themes/thub/images/avi.jpg)