Horizontal gradient over image in Unity? - unity3d

I'm trying to have the sides of an image fade to black, but I can't find a good way to do this manually or in any way other than with a shader graph. I'm looking to apply an effect like this:
to an existing image, but the gradient in the shader graph applies the same color to the whole texture. I'm very new to shaders, so any help would be great. Thanks!

Using Shader Graph you create a gradient example then you add a Texture2D input, use a Texture 2D sampler node and finally combine them with a multiply node.

Related

Rendering one mesh before another in Unity 2018?

I have a bunch of models with inverted normals for outlines. However, I want to render the meshes in front of the outlines so there's no glitchy clipping. Does anyone know of a shader or way to render the meshes in front of the outlines?enter image description here
Changing the render queue for the outline shader should fix your issues.
In the outline shader:
Tags{ "Queue" = "Geometry-1"}
Just make sure the queue number to render the outline is before the other objects. Example of tags location below.

How to resize shader area?

I made 2d outline shader but The outline does not render beyond the boundary of the sprite.
so I need to resize shader area.
Is there a simple way to solve it, other than remaking sprites and changing positions in the vertex shader?
In principle you can only draw within the geometry of your object.
In theory, you could tweak the geometry in the shader to expand the border but I have no idea how to do it reliably.
Almost all of the edge shaders I'm aware of use a full-screen post-processing pass to render outlines

Shader to warp or pinch specific areas of a texture in Unity3d

I've mocked up what I am trying to accomplish in the image below - trying to pinch the pixels in towards the center of an AR marker so when I overlay AR content the AR marker is less noticeable.
I am looking for some examples or tutorials that I can reference to start to learn how to create a shader to distort the texture but I am coming up with nothing.
What's the best way to accomplish this?
This can be achieved using GrabPass.
From the manual:
GrabPass is a special pass type - it grabs the contents of the screen where the object is about to be drawn into a texture. This texture can be used in subsequent passes to do advanced image based effects.
The way distortion effects work is basically that you render the contents of the GrabPass texture on top of your mesh, except with its UVs distorted. A common way of doing this (for effects such as heat distortion or shockwaves) is to render a billboarded plane with a normal map on it, where the normal map controls how much the UVs for the background sample are distorted. This works by transforming the normal from world space to screen space, multiplying it with a strength value, and applying it to the UV. There is a good example of such a shader here. You can also technically use any mesh and use its vertex normal for the displacement in a similar way.
Apart from normal mapped planes, another way of achieving this effect would be to pass in the screen-space position of the tracker into the shader using Shader.SetGlobalVector. Then, inside your shader, you can calculate the vector between your fragment and the object and use that to offset the UV, possibly using some remap function (like squaring the distance). For instance, you can use float2 uv_displace = normalize(delta) * saturate(1 - length(delta)).
If you want to control exactly how and when this effect is applied, make it so that has ZTest and ZWrite set to Off, and then set the render queue to be after the background but before your tracker.
For AR apps, it is likely possible to avoid the preformance overhead from using GrabPass by using the camera background texture instead of a GrabPass texture. You can try looking inside your camera background script to see how it passes over the camera texture to the shader and try to replicate that.
Here are two videos demonstrating how GrabPass works:
https://www.youtube.com/watch?v=OgsdGhY-TWM
https://www.youtube.com/watch?v=aX7wIp-r48c

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.

Shader to bevel the edges of a cube?

This question relates to using shaders (probably in the Unity3D milieu, but Metal or OpenGL is fine), to achieve rounded edges on a mesh-minimal cube.
I wish to use only 12-triangle minimalist mesh cubes,
and then via the shader,
Achieve the edges (/corners) of each block being slightly bevelled.
In fact, can this be done with a shader?
I recently finished creating such shader. The only way it can work is by providing 4 normal vectors instead of one for each vertex (smooth, sharp and one for each edge of the triangle for the given vertex). You will also need one float3 to detect edges.
To add such data in a mesh I made a custom mesh editor, comes with Playtime Painter Asset from Unity Asset Store. Will post the shader with the next update. Also will post to public GitHub.
You can see some dark lines, it's because it starts to interpolate to a normal vector which facing away from light source, but since there are no additional triangles, the result is visible on a triangle which is facing the camera.
Update (2/12/2018)
Realised that by clipping pixels that end up having a normal facing away from the camera, it is possible to smooth the outline shape. It wasn't tested for all possible scenarios but works great for simple shapes:
As per request added a comparison cube:
Currently, Playtime Painter has a simplified version of that shader, which interpolates between 2 normal vectors and gives ok results on some edges.
Wrote an article.
In general the Relief Mapping is able to modify the object silhouette like on this picture. You'd need to prepare a heightmap that lowers at the borders and that's it. However I think that using such shader might be an overkill for such a simple effect so maybe it's better to just make it in your geometry.