Parts of mesh become invisible at certian angles Unity3D - unity3d

I am importing an fbx model but parts of it are invisible in the scene And game at certain angles.
Attached image SS-1 = the full model - You can see that some parts of the mesh are invisible Attached image SS-2 = closeup of an invisible mesh selected
Attached image SS-3 = Main Camera Settings
Attached image SS-4 = Model import settings
Any ideas what's going on?

The normals of your mesh are not set properly, so the culling algorithm treats it as a back-face that should not be rendered.
If you can edit the model so that you can inverse the normals that would work. Most modeling tools have convenient tools or direct routines for "flipping normals". However, if that is not possible, a trick is to change the culling settings from your material: When the culling mode is set to Cull Back (which is the default setting), the polygons that are not facing the camera are not rendered. Then, for the mesh that is not visible, you can change the culling property from Cull Back to Cull Front. This way it will be visible.
The caveat is that most of the time material properties might be overlooked as Cull Front and No Cull settings are not as common as Cull Back. Also, performance-wise, you will have a different shader running because of that mesh.

Try two-sided shader, as suggested here

The easiest solution I found for this problem is:
1.Select the object that's going invisible on certain angles.
2.Navigate to Mesh Renderer > Render Face > Both
The problem should be solved now
My Unity version is 2019.3

Related

Custom 2D Lighting System in Unity

Ok so I've been trying to make a custom 2D lighting system in Unity, and I'm at that annoying stage where I know what I want to do but I'm not sure how to do it.
Here's the plan:
There will be dedicated light objects with their own meshes. These meshes determine the shape of the light.
Before the camera renders the whole scene, it does an extra render of just the light meshes with a black background to create a lightmap.
Then the camera renders the scene as normal (does NOT render the light meshes this time). Every object has a shader that will access the lightmap and shade itself appropriately depending on the color of the lightmap at that point.
That's the idea anyway. I sorta threw together a botched form of this. I used a separate camera to render the lightmap into a render texture with a culling mask so that it only rendered the light meshes, which are on their own layer. I then manually passed that texture to the shaders which use their screen uvs to sample from it.
This works sorta ok, but the scene view is completely messed up since it tries to light things as if you were looking at it from the perspective of the lighting camera. I feel like this would make the system hard to use, so I want to try to make some that feels a bit more cohesive.
Here's some screenshots to explain:
The tan-ish box is my "light," which gets rendered to the light cam, visible in scene. This next shot is what renders to the lightmap:
The black background is not from the big black box, the clear flag is just set to Black.
Now according to this lightmap, the middle of the screen should be lit up. and that's exactly what happens:
Notice that in the game view, since the light camera is set up with the same position/rotation/perspective settings as the game camera, it looks fine:
The main problem is figuring out that extra render. Is there anyway to create an extra pass for the main camera before the scene render that only renders the light meshes? I could probably figure out the rest from there. It would also be nice if I could make the lightmap a global shader variable, that way I don't have to pass it to each individual material, but one thing at a time, right?
Thanks so much to anyone who can shed some light on this subject. I'm still pretty new to shaders and rendering, so any help is much appreciated.
If I understand correctly, your problem is the appearance of your lights in Scene View, right ?
For that, you can create a custom Gizmos for them and hide the original objects. There's a tutorial:
https://learn.unity.com/tutorial/creating-custom-gizmos-for-development-2019-2#5fa30655edbc2a002192105c

Unlit shader issue with fog in Unity's Univeral Render Pipeline

Edit
I figured out a tempoary fix for my initial question "how to disable this weird fog": Disable the fog in the lighting pannel (genius, right ?)
However, since I might need fog later, and it does not behave as I would expect, I still need to fix this issue.
Note: This only happens with exponential fog modes, not with linear.
I'm having issues with unity's universal render pipeline: A light grey fog, whose strength depends on the camera heading (see video)
(see how the plane geometry affects the fog)
The steps to reproduce are very simple (or just download the project here):
Create a universal render pipeline project
Delete the "example assets" from the scene
Create a floor with a quad (create quad, rotate, scale)
Create a new material
Shader: URP / unlit
Base map: black
That's it.
Rotate around, see how the "unlit" plane is actually affected by a fog whose strength depends on the heading of the camera
Rotating the quad has the same effect as rotating the camera.
Rotating the directionnal light has no effect (except on the skybox)
Removing the Directionnal light has no effect (except on the skybox)
Removing the Post processing volume makes the "fog" stronger in all directions so the camera heading effect is less noticeable but still there
This happens in game mode as well as in the editor
Getting close to the ground makes the fog lighter
the camera position has an impact as well (this is more visible when testing with a plane rather than a quad)
system info:
tested on unity versions: 2019.4.18f1, 2019.4.20f1 (LTS), 2020.2.1f1
Windows 10 Home 19042.804
Is it possible this is a bug in the URP/unlit shader ?
Thanks for any help!

Why seen cross-sections of objects?

Why seen cross-sections of objects? I have different meshes on objects with materials (with Standard Shader rendering mode = opaque)
http://prntscr.com/9vt7no
http://prntscr.com/9vt7px
It might be that the backface culling is set wrong (for your meshes). If it is culling front facing triangles while showing the backfacing ones, the effect would be about what you have shown on the pictures.
Either flip the cull mode of your shader, or flip the triangles in your mesh.
For a quick test your can just disable backface culling. If it looks right then, you know that your issue is about the culling.

created a model in blender, imported into Unity and not affected by light

I created a hand model in blender, imported it into my scene in Unity and it does not get affected by my lights.
I created some seam lines and unwrapped the thing. I have other elements that I created in a similar way and the only difference I can appreciate here is that this one is not a mesh renderer, it is a skinned mesh renderer, because it has bones inside.
This is how it looks like, you can see the "torch light" focusing to it, making a round of light, and the hand is getting weird lights, like only the reflected light from below or something.
Those are the settings of the mesh
Looks like the normals are wrong. You can try to invert normals in blender or change the import settings (in Unity) of your hand mesh to calculate normals instead of using the normals in the blend file (See normals & tangents section here).
It is definitely an issue with normals. Something wrong is going on during exporting probably.
Try Calculate option under Normals in Importer settings
Hope that helps.

Lighting effect

The following screenshot is taken from a road that consists of several equal parts:
They all belong to a Blender model and have Shading set to Flat.
The scene has just one directional light and the parts of the road are used to bake a light map.
Material is set to use Mobile / Vertex Lit (Only Directional Lights) shader but I tested other shaders like Mobile / Unlit as well.
I don't get this effect when I take a model consisting of 8 road parts using a repeating texture - at least not in the middle. So it's not related to broken tileability of the texture. But it is visible then at the end as well
The texture import settings are:
Question: Is this the regular behaviour of the standard shaders? Can't believe it, but If so how to omit this when writing my own shader?
I would appreciate if someone could shed some light on this ;-)
It's a problem with normals. Easy fix is to make Unity recalculate all the normals (In model import settings switch Normals -> Import to Normals -> Calculate).
hard to know without seeing more context, but if the objects are lightmapped, make sure to check that they are not reusing the same lightmap texture. #jaceck's suggestion about normals is a good one too.
I do not know if it is this you want, but there is also a component called Line Render that draws a line.