Sprite shadow in 3D world - unity3d

I am trying to project shadows from sprites on 3D objects, i followed some tips here and there but i still have issues.
I created a material that use Legacy Shaders/Transparent/Cutout/Diffuse and add it to my sprite, i also enable ShadowCastingMode and receiveShadows on the SpriteRenderer.
The result is that my sprite actually cast a shadow now, but the sprite itself is also shadowed, which is not the result i am looking for.
Without the shader:
With the shader:
I know absolutely nothing about materials and shader so this is me just walking in the dark.
Also this is a brand new project and i am using the template 3D with extra if it makes any difference.

Related

Why SpotLight passes through 3D sprite using this shader?

I'm using Unity2021.3, and this is a URP project.
There is a 3D sprite in the scene that receives and casts shadow, the material for its spriteRender uses a shader that is a simple modification of Unity URP Simple Lit, and there is a spotLight in front of the 3D sprite with shadow enabled, and there is also a directional light in the scene. The 3D sprite casts shadow on the ground due to the directional light and the spotLight, everything is correct.
But if I switch to a new shader, it seems the SpotLight passes through the 3D sprite, rendering the shadow incorrectly, if I move the SpotLight to make it far away from the 3D sprite, then it seems the shadow is correct.
Please see the attached screenshot, the top three screens are custom shader, below two are the URP Simple Lit variant.
I'm wondering what the problem is with the new shader?
Thank you so much.

Unity 2D URP Light: How do I prevent that an object is affected by self shadow of another object

I'm trying to recreate my old 2D top down game (developed with Monogame) in Unity.
For lighting, there is now a usable 2D light (URP) that casts shadows based on the light source in relation to a polygon (same as I used in my old engine).
They even have the "self shadow" feature, as an object that is illuminated (in 2D) from above will naturally appear darker than if it is illuminated from below (front).
But exactly with this function, I have a problem in Unity. An NPC which overlaps with an object with "self shadow" is also darkened.
You can see the shadow shadow from the pillar on the head.
I had exactly the same problem in my old engine. I solved it by excluding the NPCs from the shadow cast and taking the shadow value of one pixel between the feet as the basis for the brightness of the entire NPC. I found an old picture of this problem:
On the left, the problem I have in Unity. On the right is the desired result.
So my question is:
How do I prevent that an object is affected by self shadow of another object in Unity (2D Light).

Unity 3D - Render hole in place of object B, which is placed onto object A

I have a primary object which I'd like to make a hole of any shape in, depending on the overlaying gameobject's shape. I thought this could be done with stencil buffer tricks(https://docs.unity3d.com/Manual/SL-Stencil.html), but as my project is for the HDRP, it doesn't seem to work.
Gameobject A has a shader and material set, so I don't want to change its shader as it's inherited.
Gameobject B, which is the overlaid shape, is free for any approach.
I would be happy if anyone knew what I should be reading up on in order to do this for the HD render pipeline (which makes certain shader code invalid).
Written shader, or made with the shader graph, any is fine.
I believe this shader i used to create a "hole" in the water for a boat. Might be what you seek.
unity3d trouble with ship floating on water
You could then use the intermediary object, as a zone for when the player (or anything else) should be able to drop through the area.

Custom skybox shader for tiled skybox

I am new to writing shaders. I want to use a texture for 6-sided skybox in unity and I want that texture to be repeated several times also called tiling.
But the default 6-sided skybox shader in unity doesn't have tiling option. Can anyone write a custom shader for 6-sided skybox in unity which has option to tile textures? I also want an option to apply a color tint on the texture if possible. Thanks in advance.
Tiling can be achieved by multiplying texcoord by the number of tiles you want. Or in Surface shader it's uv_YourTex (likely MainTex) instead of texcoord. Writing from a phone so can't post an example, but it's really just one multiplication.
I don't know your specific scenario, but I needed to get more detailed sky with not very detailed texture and instead of UV I used view direction to sample a texture. It made it look like clouds in the distance are further away + clouds can move as you move . It's in this asset.
View direction sampling will not help if you are trying to make space though, which seams to be the case.
Also IMHO tiling on the skybox might be too visible.

How to write a custom shader in Unity 3D that lights up a specific pixel or group of pixel?

I'm making a FPS game in Unity, and I want the environment to light up as the player is shooting on his environment.
So say I have a tree. First it would be entirely black or greyish, but if I shoot somewhere, I would see some green.
To accomplish this feature, I'm using a raycast to have the impact point and so I can access any renderer of the point that the player is shooting on.
I guess the next step would be to write a custom shader to light the exact pixel that is shot.
Do you have any idea how I could write this shader or another way of doing this effect?
Regards
If you are using deferred rendering: Deferred decals.
If you are using forward rendering: Projectors.
If you need some more advanced "paint-like" functionality, use render textures coupled with RaycastHit.textureCoord to get the exact UV coordinate at your ray intersection point. You can draw stuff to render textures using Graphics.Blit. Check out this github project for some inspiration on how to do this.