- Home /
How to render certain colors of GameObject as transparent?
I have a 3D mesh in .fbx format that I've already pre-segmented into 3 colors. For example, the parts of the mesh are already colored (using vertex RGB colors) as red, blue, or green. I'd like the user to be able to 'turn off' the rendering of the blue parts of the GameObject once they're done interacting with it, but still be able to see the red and green parts.
How can I accomplish this?,I have an imported 3D mesh in .fbx format. In this mesh, I've already pre-segmented it into 3 different colors (vertex RGB). Certain parts are highlighted in red, green, or blue. I'd like to be able to see all of the colors until the user is done interacting with the mesh. Once they're done, they should be able to turn off the blue part of the mesh.
How can I accomplish this?
Checkout the post below for creating custom shaders where one colour is transparent:
https://answers.unity.com/questions/1041383/set-one-color-transparent-in-texture-shader.html
It might be simpler to break it into a submesh for each color. Or else create 7 textures, with each combination of active colors (which also enables you to draw a nice "this part is finished" image for each). You could even modify the texture in code: newTexture=removeColorFrom(oldTexture, color).
Unless this is a project to learn shader-writing.
Answer by Pangamini · Jun 12, 2019 at 01:17 PM
Write a shader that reads the vertex colors and clip pixels that match your filtering condition (eg. clip(IN.color.r - 0.5)
will discard any pixel whose interpolated vertex color is less than 0.5) You could even have those pixels fade out, but that'd mean you have to render your object as trasnaprent, which has other disadvantages
Thanks for your response, I appreciate it.
I've already written a shader that reads the vertex colors. You can see it here.
https://gist.github.com/$$anonymous$$ichaelZhou/c3056f5efed0129171fc4e84770062e7
Could you help me by elaborating more on how to code the filtering condition? For example, if I have an .fbx file with RGB vertex colors, how do I deter$$anonymous$$e the individual interpolated vertex colors?
Thanks again
This is your fragment
void surf(Input IN, inout SurfaceOutput o) {
o.Albedo = IN.vertColor.rgb;
}
fragment input is already the interpolated data from verts. So just do what i wrote above clip(IN.vertColor.r - 0.5)
The part that I'm having trouble understanding is what having an interpolated vertex color less than 0.5 actually means. For example, what colors would have an interpolated vertex color less than 0.5? Is there a way to deter$$anonymous$$e a color's interpolated vertex color?
What if had a partially uncolored .fbx mesh and wanted to discard only the uncolored portions?
Cheers
Your answer
Follow this Question
Related Questions
Help understanding transparency in Deferred Rendering? 0 Answers
Transparency Sort Axis on Y with Pivot instead of Center of object? 1 Answer
Fading in/out SVGs without showing the half-transparent SVG-layers 1 Answer
DrawProcedural() in OnPostRender() drawing over transparent objects 1 Answer
Standard shader's Fade rendering mode won't allow full opacity with a textured material 0 Answers