I have a particle effect that renders a bunch of billboard particles over the surface of a sphere mesh. The particles and the sphere have the same color and the same material.
It's everything ok, except for the fact that when my realtime light changes its direction, the sphere changes the color accordingly, but the particles don't. They change their colors, since the particles and the sphere use the same material, but the particle normals point to somewhere else, so they don't react to the light the same way the sphere does.
Is there a way I can set the normals for my particles correctly? That means: when instancing particles in some vertex of the surface of a mesh, how can I pass the normal of that vertex to the material of the particle (so that both the particle and the mesh vertex react to the light equally)?
Related
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.
I want the sphere 2 to be hollow inside, so that the sphere 1 can proceed physics inside.
But I don't know which collider to use.
you could create a Sphere in a 3D modelling software and invert the normals so that they face inside the sphere. in unity place the sphere with the inverted normals as a child to your hollow sphere. this will represent now the inner side of your hollow sphere. remove the meshrenderer and add a meshcollider to the sphere with the inverted normals. now you can place any object with a rigidbody component attached to it inside and it will collide with the inner side of your sphere.
sphere with innerside to collide with
Just reverse Normals and use MeshCollider to fix problem.
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;
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
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.