How can I make part of a mesh transparent? - unity3d

Is it possible to make some % of my mesh transparent?
For example, imagine I have a mesh that is a house. At first the mesh is transparent. As a person clicks on the house, it becomes opaque along the Y-axis so it looks like it's being built up.
Any ideas how to approach this problem?

"a house. At first the mesh is transparent. As a person clicks on the house, it becomes opaque along the Y-axis so it looks like it's being built up"
Literally in answer to your question, in general:
I would approach this by making a shader which was sensitive to the global Y value of the point in question. It would use that value, over time, to decide on alpha at a given point.
alternately
Imagine a second texture of the house, call it GUIDE, which is: imagine a monochrome house: at the ground it is black and it slowly becomes pure white at the tops. Additionally you could color it any way you want, for example, the window frames and quoining could be black and so on. Now, the shader would use the GUIDE texture as a key, to know at what time, that area, should become transparent.
That would actually look quite incredible and offer amazing control. You could fade in different parts in whatever order you wish.
It would be beyond the scope of an answer here to actually engineer this. But I believe the key here is, unfortunately for what you describe that is really all done in the shader, I'd say.
Note that if you just want "a clean hole", look in to approaches using a depth mask shader And indeed https://www.youtube.com/watch?v=s3RKGAj9Uzk
for 2D consider this, http://answers.unity3d.com/questions/449034/see-through-hole-via-shaders-on-a-2d-plane.html
in other cases you may literally want to cut a sharp hole in the mesh which is a "whole" different technology. https://gamedev.stackexchange.com/questions/72978/shader-that-cuts-hole-through-all-geometry
if you want this effect http://answers.unity3d.com/questions/622089/how-can-i-render-a-semi-transparent-texture-with-a.html (see mario image) that's totally different again - it's nothing more than a gray image with a hole!

Related

Unity 2D: How to make tiles merge with equal textured neighbors?

Let me show you what I mean:
Suppose we have a puzzle game with colored square tiles/blocks falling, and they stack like this:
My question is, instead of each tile/block sprite stay visually separated from others, what technique can be used to make each tile aware of their neighbors when they stop falling, and change its sprite (and neighbors) to become visually "glued" with them, like this:
I cant seem to come up with a simple and efficient solution for this, any ideas?
Here are two options that come to mind:
Easier approach - Use a tilemap, each item should have variants for every color and connection in every direction
Harder approach - Build your meshes in realtime and calculate the actual sizes yourself. I think this option could be more robust, but it's much more complex to do (especially if you haven't done something of the sort in the past)

Unity 3D Character Customization

Lets say I create many different 3D objects (Arms, legs, body, head). How would I go about making it so all of them can connect to form a body. And after the body is formed make it so they all animate in the same way. Can anyone help me in the right direction with tutorials or links on these topics?
Here are some good tutorials:
https://www.youtube.com/watch?v=q3oVAXhvQl0
https://www.youtube.com/watch?v=Ch1aJljEYp4
https://medium.com/#larissaredeker/3d-character-customization-fd95a1d57ae
And here a reddit user's answer(Named DankP3):
For body sliders you will probably want to look at blendshapes, this is done in the modelling programme. The more blendshapes you have the more complex it will get. eg. 'normal' 'thin' and 'muscular' bodies at one scale of variation and thicker eye brows at the other.... Of note though, facial morphs don't affect most clothes!
I think one of the most challenging parts will be that using the same animation on a thin character and a muscle bound character will not look good so some significant animation work may be required.
I'd probably apply hairstyle in the same way as clothes (see below), but colour can be manged for hair easily through code, swapping base colours, or textures.
For clothes, you rig to the same skeleton as the character (and you will need the same blendshapes to fit the body or if your body is to change shape). A lot of people put all clothes in the same model and turn them on and off as required (this intuitively seems messy), but looping through the bone array on the meshrenderer is not difficult and contrary to what the other reply says you don't need to match bones by angle and position. if you rig correctly, you can just swap, rather than match, the bones in the clothes mesh renderer for those on the character model when the clothes are put on and you are all done.
Again, all credit goes to DankP3
You can see his answer HERE.

Unity3D: How to make a glowing gradient sphere?

So I need a glowing sphere with a halo of light, which casts light on a near objects. Also, as you see on the image, sphere must have a gradient.
I'm using 2 spheres and point of light at the moment. And I really don't like the results:
There is no gradient at all
I need to use second Point Light to cast light to near objects
So... is there any ideas?
I think you have two needs,
(1) the "actual" light which casts a light on nearby objects.
(So, I mean that is literally a UnityEngine.Light http://docs.unity3d.com/ScriptReference/Light.html )
(2) Separately, you need (basically) a "glowing orb" that looks like the white and yellow thing in your image.
These two things are completely separate.
You should indeed do them separately.
Now regarding "2" how to make a glow, that's called a "bloom". There is a lot to look in to but this will probably do it for you:
http://answers.unity3d.com/questions/914945/what-replaces-the-glow-effect-in-unity-5.html
Note that getting a good glow is not that easy.
Here's a really great asset, that's actually free for goodness sake,
https://www.assetstore.unity3d.com/en/#!/content/28044
you should surely get that to experiment with at first. There are other well-known assets as well, like https://www.assetstore.unity3d.com/en/#!/content/8238
Be sure to google for many QA on the glow topic.

Drawing a 3D arc and helix in SceneKit

A recent question here made me think of SceneKit again, and I remembered a problem I never solved.
My app displays antenna designs using SK. Most antennas use metal rods and mesh reflectors so I used SCNCylinder for the rods, SCNPlane for the reflector and SCNFloor for the ground. The whole thing took a couple of hours, and I'm utterly noob at 3D.
But some antennas use wires bent into arcs or helixes, and I punted here and made crappy segmented objects using several cylinders end-to-end. It looks ass-tastic.
Ideally I would like a single object that renders the arc or helix with a cylindrical cross section. Basically SCNTorus, but with a start and end angle. This post talks about using a UIBezierPath in SK, but it uses extrude to produce a ribbon-like shape. Is there a way to do something similar but with a cylinder cross section (like a partial SCNTorus)?
I know I can make a custom shape by creating the vertexes (and normals and such) but I'm hoping I missed a simpler solution.
An arc you can do with SCNShape. Start with the technique from my other answer to get an extruded, ribbon-like arc. You'll want to make sure that the part where your path traces back on itself is offset by a distance the same as your extrusion depth, so you end up with a shape that's square in cross section.
To make it circular in cross section, use the chamferProfile property — give it a path that's a quarter circle, and set the chamfer radius equal to half the extrusion depth, and the four quarter-circle chamfers will meet, forming a circular cross section.
A helix is another story. SCNShape takes a planar path — one that varies in only two dimensions — and extrudes it to make a three-dimensional solid. A helix is a path that varies in three dimensions to start with. SceneKit doesn't have anything that describes a shape in such terms, so there's no super simple answer here.
The shader modifier solution #HalMueller alludes to is interesting, but problematic. It's simple to use a modifier at the geometry entry point to make a simple bend — say, offset every y coordinate by some amount, even by an amount that's a function of why. But that's a one-dimensional transform, so you can't use it to wrap a wire around on itself. (It also changes the cross section.) And on top of that, shader modifiers happen on the GPU at render time, so their effects are an illusion: the "real" geometry in SceneKit's model is still a cylinder, so features like hit testing apply to that and not to the transformed geometry.
The best solution to making something like a helix is probably custom geometry — generating your own vertex data (SCNGeometrySource). The math for finding the set of points on a helix is pretty simple if you follow that shape's definition. To wrap a cross section around it, follow the Frenet formulas to create a local coordinate frame at each point on the helix. Then make an index buffer (SCNGeometryElement) to stitch all those points into a surface with triangles or tristrips. (Okay, that's a lot of hand-waving around a deep topic, but a full tutorial is too big for an SO answer. This should be enough of a breadcrumb to get started, though...)
Here are some starting points that might help.
One approach would be to use more cylinders and make them shorter. That's the same idea behind the various segmentCount properties on the SCNGeometry primitives. Can we see a screenshot of the current linked cylinders version?
If you increase the heightSegmentCount, you could use the approach outlined here: scenekit, how to bend an object.
I just took a look at SCNShape. I was thinking you could use a shader modifier to warp the extruded shape into a circular cross section. But SCNShape doesn't seem to expose a segment count property, which I think you'd need to create enough extrusion segments for a good look. The chamferRadius and chamferProfile properties look interesting. I wonder if you could use those to create an extrusion that looks good.

Unity - Avoid quad clipping or set rendering order

I am using Unity 5 to develop a game. I'm still learning, so this may be a dumb question. I have read about Depth Buffer and Depth Texture, but I cannot seem to understand if that applies here or not.
My setting is simple: I create a grid using several quads (40x40) which I use to snap buildings. Those buildings also have a base, made with quads. Every time I put one one the map, the Quads overlap and they look like the picture.
As you can see, the red quad is "merging" with the floor (white quads).
How can I make sure Unity renders the red one first, and the white ones are background? Of course, I can change the red quad Y position, but that seems like the wrong way of solving this.
This is a common issue, called Z-Fighting.
Usually you can reduce it by reducing the range of “Clipping Planes” of the camera, but in your case the quads are at the same Y position, so you can’t avoid it without changing the Y position.
I don't know if it is an option for you, but if you use SpriteRenderer (Unity 2D) you don’t have that problem and you can just set “Sorting Layer” or “Order in Layer” if you want modify the rendering order.