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

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.

Related

Accessing a secondary texture normal map in shader graph?

I'm using Unity 2020.1.3f1's URP, with the new 2D renderer system.
As of right now, I have objects that change between the built in "Sprite-Lit-Default" material, and a material with the custom built pixel outline shader detailed here: https://danielilett.com/2020-04-27-tut5-6-urp-2d-outlines/
This worked well and good, but I recently added lights, and a normal map to my sprites as a secondary texture in the import settings. The default lit texture has no problems displaying the normal map, but when I attempted to modify my shader graph to include the normal map, it doesn't import like the sprite texture does when _MainTex is set as the reference.
I've tried _NormalMap (which is the name of the secondary texture in the importer!) as well as _NormalTex, but it always ends up not importing the normal map. I even attempted changing _MainTex to a Texture2D, but given that kept sparking an error, I didn't think it was the right way to go about it. (This one to be specific.)
Error assigning 2D texture to 2DArray texture property '_MainTex': Dimensions must match
UnityEditor.EditorApplication:Internal_CallUpdateFunctions()
Am I missing something here? All the tutorials I can find online only show people dragging the normal map in through the inspector, but this material is going to be used by many different sprites, so that seems...counterintuitive.
On top of this, the default material/shader has no issues with this, so I feel like I'm either missing something, or I'm going to end up having to code my sprites to change material through code instead of the animator, just for this small, annoying quirk..
Blackboard Properties, and nodes. This just goes into the normals input.
Inspector panel showing the missing normal map slot.
And the Secondary Textures in case I somehow misnamed it, why not?
(EDIT)
So, an update on this, for anyone else who runs into this same issue.
I managed to find a section of the shadergraph documentation that seems to be the only part talking about this:
It is required to name the reference for MainTex as _MainTex to render Sprites. It is also recommended to name the references for Mask as _MaskTex and Normal as _NormalMap to match the Shader inputs used in this package.
So from what I gather from that, _MainTex is the only one that's automatic in ShaderGraph.
After a full day of looking up tutorials, I've noticed that every single one of them simply set the normal map and extra textures as the default textures so they'll show up without being assigned manually.
I think this is possible with hand-written shaders, but I've decided to just go with a simple unlit shadergraph on a hand-drawn sprite outline, displayed on a separate gameobject parented to the main object.
I'm not posting this as an answer in case someone else finds a solution to it in the future, and since this isn't...really a solution in my eyes.
I don't know if you have figured this out yet but I'll try to answer since I had the same problem. Create a new Texture2D node, convert it to a property, and have the reference as _NormalMap, connect that to the sample texture 2D node as normal, and plug that into the sprite lit master. Now go into the sprite editor, assign the normal maps as a secondary texture, and make sure the name is the same as in your shader, _NormalMap (or something else, as long as it's the same). This currently has worked for me, shader graph detects the normal map texture by reference automatically. Attached below are some images to help and the finished result on the character sprite, which uses a custom shader I picked up from a tutorial and added the normal map to.
Shader Graph Sprite EditorSprite Editor 2 Normal Map result

Recommendations for clipping an entire scene in Unity

I'm looking for ways to clip an entire unity scene to a set of 4 planes. This is for an AR game, where I want to be able to zoom into a terrain, yet still have it only take up a given amount of space on a table (i.e: not extend over the edges of the table).
Thus far I've got clipping working as I want for the terrain and a water effect:
The above shows a much larger terrain being clipped to the size of the table. The other scene objects aren't clipped, since they use unmodifed standard shaders.
Here's a pic showing the terrain clipping in the editor.
You can see the clipping planes around the visible part of the terrain, and that other objects (trees etc) are not clipped and appear off the edge of the table.
The way I've done it involves adding parameters to each shader to define the clipping planes. This means customizing every shader I want to clip, which was fine when I was considering just terrain.
While this works, I'm not sure it's a great approach for hundreds of scene objects. I would need to modify whatever shaders I'm using, and then I'd have to be setting additional shader parameters every update for every object.
Not being an expert in Unity, I'm wondering if there are other approaches that are not "per shader" based that I might investigate?
The end goal is to render a scene within the bounds of some plane.
One easy way would be to use Box Colliders as triggers on each side of your plane. You could then turn off Renderers on objects staying in the trigger with OnTriggerEnter/OnTriggerStay and turn them on with OnTriggerExit.
You can also use Bounds.Contains.

Making a custom skybox for Unity

I'm struggling to find any simple/up to date tutorials on how to make my own skybox for Unity. I want the skybox to be cartoony/vector based so preferably I would like to make it in Adobe Illustrator.
How do I do this? Could anyone direct me to any tutorials? Also, are there any programs that allow you to upload an image that generates a skybox for you?
Thanks!
You may create a new "Skybox/6 Sided" material, and asing it instead the default skybox material. It's the same principle, a cube with 6 images that correspond to each side "front, back, up, down, left, right".
You have to generate a cubemap to have a skybox object, young padawan.
From the Unity Manual:
http://docs.unity3d.com/Manual/class-Cubemap.html
A Cubemap is a collection of six square textures that represent the reflections on an environment. The six squares form the faces of an imaginary cube that surrounds an object; each face represents the view along the directions of the world axes (up, down, left, right, forward and back).
Cubemaps are often used to capture reflections or “surroundings” of objects; for example skyboxes and environment reflections often use cubemaps.

Unity3d: Texture viewable from inside object?

I am trying to make a globe around the camera so that everywhere the camera views it is surrounded by the texture placed on the globe.
I have been able to achieve the exact effect i am after by setting the shader of the sphere to Particles/Alpha Blended, and putting the camera inside the sphere. This way I have the camera inside a sphere object and all around it is the texture.
My problem though is this. I want to use a chroma key shader (to remove all occurances of a color) on the globe object. This means the shader is not set to Particles/Alpha Blended. And from inside the object the walls of the sphere are not textured.
Can anyone point me in the right direction to how i could achieve the effect i am after. I have a few ideas, however im not sure how to go about it. Im thinking i could:
1) Edit the chroma key shader to work in the same way as a Particles/Alpha Blended shader would (I have no experience in shader coding, or anything of the sort) 2) Use a hollow sphere, rather than the solid one unity creates (Im not sure where i would get that) 3) Use a different object all together that just renders a texture in a sphere shape, without it being a fully solid object (Im not sure if such a thing exists)
Any help would be greatly appreciated, I have searched the forums and cannot find what i am looking for.

Rotate an object or change the culled face?

In OpenGL which one would result in a better performance. To change the culled face or to rotate my object?
The scenario is the following:
I compute the matrix to feed into my shaders, this will draw texture A in a certain culling position (front). When I see the object from infront i can see it, but from behind i cant, this is my desired behavior. Now i would like to add "something" behind, lets say texture B, so that when the object is seen from behind this other texture will appear in the same position and orientation as was the texture A but now with texture B.
I thought that other than building a cube with 2 sides i could simply "redraw on top" of my previous object. If i were to rotate the object i suppose I can assume that OpenGL will simply not overwrite texture A since it will not pass the face culling test. This require one extra matrix multiplication to mirror mi object on its own axis. However what if i simply change the culling property and try to draw it? Wouldn't it have the same effect of failing the text from infront but passing it from behind?
Which of these 2 options is better?
(PD: I am doing this on the iPhone so every single bit of performance is quite relevant for older devices.)
Thank you.
I'm not sure if I understood you correctly, but it sounds like you are trying to draw a billboard here? In that case, you should disable backface culling altogether and in your fragment shader check gl_FrontFacing. Depending on this, you can flip your texture coordinates and change your texture (just bind both textures and send them to the shader). This way you have only one draw call and don't have to do any strange tricks or change the OpenGL state.