How to set direction of arrows in shadergraph - unity3d

I'm pretty new to shader graph and shaders in general. I'm working on a 2D project and I'm trying to make a shader that rotates an arrow to make a flow-like material and use it on a sprite shape.
Basically what I want to do is make a proper version of this:
What I'm currently doing is multiplying the Y position of the position node by an exposed vector 1 and using it in Rotate node (which I know is pretty hacky and won't work if the shape is not an arc.)

Aligning UV with arbitrary mesh seems bit hard. Why not bend pre-made mesh instead? Graph below bends vertex positions around axis Z at given point and strength (0 makes mesh invisible tho), but, you can easily replace that Position node with UV and plug results into Sample Texture 2D. I just guess bending a mesh will give you better/easier results.
Create a subdivided and well UV-mapped rectangle plane
Bend that plane with a vertex shader (attached graph bends around Z axis)
graph is based on code from Blender source

Related

Is it possible to pass a custom position to calculate lighting in unity surface shaders?

I want to create a shader that uses different coordinates for light calculations than for what's being displayed. This probably sounds strange, but I would like to do this for lighting a top-down 2D game.
I want to write a vertex shader that offsets the Z coordinate by the value of the Y coordinate for display, but uses unmodified coordinates for lighting calculation.
Is this possible to do, and if so, where would I start?
So far I have a surface shader that offsets the Z coordinate by the value of the Y coordinate, but unity is using the modified coordinates to calculate lighting, I would like unity to use the unmodified coordinates for light calculations.

Unity mirroring a mesh but the colors are facing down

I am trying to mirror a mesh to another mesh by using procedural mesh generation as seen below. The original mesh is at the positive z axis while the mirrored is at the negative z axis.
The vertices are all mirrored as I wanted but the color is facing down instead of up.
I tried to change the mesh uvs and normals but both did no affect on the mirrored mesh. I heard the triangles have to be reversed in their array or something that I do not understand. How do I make the mirrored mesh color face up?
The black plane is supposed to be half transparent blue water plane but it is not part of my question so I guess do not mind it.
Not 100% sure but I suspect it is the triangles as you say.
You would probably simply need to invert the triangles => simply invert the array e.g. using Array.Reverse like e.g.
var triangles = mirroredMesh.triangles;
Array.Reverse(triangles);
mirroredMesh.triangles = triangles;

Rotate vertices selected using weight map on UVs in Unity3D's Shader Graph around pivot point

TLDR: Can't figure out the correct Shader Graph setup for using UV and vertex displacement to cheaply animate a (unrigged) mesh.
I am trying to rotate a part of the mesh based on the UV coordinates, e.g: fromX 0 toX 0.4, fromY 0 toY 0.6. The mesh is created uv-mapped with this in mind.
I have no problem getting the affected vertices in this area. Problem is that I want to rotate these verts for customizable axis e.g. axis(X:1, Y:0, Z:1) using a weight so that the rotation takes place around a pivoted point. I want the bottom selection to stay connected to the rest of the mesh while the other affected vertices neatly rotate around this point.
The weight can be painted by using split UV channels as seen in the picture:
I multiply the weighted area with a rotation node to rotate it.
And I add that to the negative multiplied position (the rest of the verts, excluding the rotated area) to get the final output displacement.
But the rotated mesh is bent. I need it to be stiff as in the whole part rotated with weight=1 except for the very pivoting vertex.
I can get it as described using a weight=1 based rotation, but the pivot point becomes the center of the mesh, not the desired point.
How can I do this correctly?
Been at it for days, please help :')
I started using Unity about a month ago, and this is one of the first issues I faced.
The node you are using will always transform the vertices around the origin.
I think you have two options available:
Translate the vertices by the offset of where you want to rotate the wings. This would require storing the pivot point of the wings in the mesh somehow - This could done by utilizing a spare UV channel, or by using the vertex color channel.
Use bones and paint the weights in your chosen 3D package. This way, you can record the animation, and use Unity's skinned mesh shader to render it.
Hope that helps.
Try this:
I've used the UV ranges from your example applied to a sphere of unit size. The spheres original pivot is in the centre, and its adjusted pivot is shifted 0.5 on the Y axis.
The only variable the shader doesn't know, is the adjusted pivot position; so I pass this through the material.
I've not implemented your weight in the graph, as I just wanted to show you the process. You can easily plug that in.
The color output is just being used for debug purposes.
The first image is with the default object pivot.
The second image is with the adjusted pivot.
The final image is the graph. (Note the logic group is driving the vertex rotation based on the UV mask).

Shader is not working properly in my 2d game

I was looking for doing a sprite wave like water on a lake/ocean, i found a tutorial on internet, but it was for a 3d game, i applied the tutorial but the shader is moving the sprite in the Z axis, so the wave effect is not notizable from 2d view, but in 3d view it looks fine, it's a 2d game so i need it to move in the correct direcction, this is my first shader so i don't understand it so much.
Use a x=0, y=1, z=0 vector instead of the Normal Vector node.
That will make the wave motion go in the "upward" direction on the object instead of the "outward" direction.

reduce vertices and triangles for plane made with unity

I am creating a plane using unity. The thing is that this plane has 200 triangles and 100+ vertices. Because my plane is not altered( i only set a texture on it), i think that the plane should have 2 triangles and 4 vertices. Can this be done?
UPDATE:
i think i need to change the mesh filter for my plane. I've created one with only 4 vertices in blender, but after i delete the original plane mesh in unity and place the new 4-vertices mesh, i only get a color that can be found on my texture, but not the texture itself. Can i place a texture on a 4 vertices mesh? if so, what am i doing wrong?
Using a 4 vertices/2 triangles planes should work, and is also a good idea :-)
It's probably only showing part of the texture because it has some wrong UV coordinates.
Try using this plane:
https://dl.dropbox.com/u/4375689/Permanent/Plane.3DS
I'm not sure if the size is correct, but it should have the correct UV coordinates.
That is right, the default Unity plane has more than 2 tris and 4 vertices. To have such a mesh you need to either import it or create it in code.
I've built this script called ProceduralPlane that allows you to set the number of segments in the editor: https://github.com/doukasd/Unity-Components/tree/master/UnityPackages