How to use a texture with particle system to create lightnings effect? - unity3d

I have a lightning texture tga file type :
and i dragged the lightning texture to a new particle system :
two problems :
how to make the 3d start size to be random ?
from youtube tutorial he did something that give him a random settings ine the 3d start size:
but my 3d start size is not random and i'm not sure how to apply the random settings :
the second problem is how to display the lightning in the particle system without the black box square around and to show only the lightning ?

For the first question, I can't say much more than try to play with the parameters in the same section "Shape" where you can change the "randomize" parameters.
For the second question: Do you see that "Alpha Is Transparency" check mark? Yes, that's it. Solves your problem ;)

For the first problem the random on the 3D Start Size.
on the right of it there is a small arrow click on it to expand and then you have some options, select Random Between Two Constants or play with it with the other options. then you can set the X and Y and Z random ranges.
I marked with red circle the arrow to click and expand to get to the options.
The second problem was the box(cube) in black around the lightning.
to remove it just go to the object with the particle system scroll down to the bottom to the shader, expand the shader options and in Rendering Mode change it to Transparent.
I marked with red circle again on the right what you have to change to make it transparent.
and we have nice lightnings and this is the basic i guess but it's working nice.

Related

Unity Line Mesh Inward Shader

I am pretty new to shaders in unity and am stuck on a problem.
I am using ShaderGraph and unity 2021. I understood the ShaderGraph examples from the unity page and "implemented" an OutlineShader thinking I could simply "inverse" the direction (not multiply by some value to get a bigger object then coloring that object and laying the original object ontop). Yet I am nowhere near what I want.
Basically what I am trying to achive is a stepped color gradient to the inside of the object. As an image it should look something like this:
Starting from color0 (green) going inward to color1 (yellow) until i reach the center with colorN (white) and repeat the same for the other side. The shader is then used on a material that is applied to a MeshLineRenderer (LineRendererPro from asset store with minor modifications for custom behavior) which kind of looks like this:
In the end the line should be colored according to the specified colors and the direction the line is going.
Explanation of a simple "Inline" Shader (similar to an outline) would help alot. I think I would be able to adapt that concept and implement multiple colors with (maybe) percentages of width. I don't want to use a fixed image/texture since i want to change the widths and colors.
Any input is welcome and thank you in advance.

Transparent shader allows the objects below to show on top

In my scene, the smileys(Quad with png image) are placed at Y:0 and the dots(Quad with tiling 3X3) are placed at Y: -0.25.
The shader I need to use for the smileys is Transparent-Diffuse as I am using a circle png image.
But the dots I use below are showing up above the smiley. Using any other shader like Diffuse solves the issue but the smiley becomes a square.
Screenshot:
If you need any more clarifications please dont hesitate to ask.
Edit:
I have attached the shader details of both the smiley and the dots from the inspector panel.
link: http://postimg.org/image/cvws1os7d/
Edit 2:
I have found that the issue should be with the MainCamera and especially with distance & "Field Of View".
I need to use "Perspective" as projection type and 140 as Field of View.
If I change the projection type to Orthographic the issue is completely fixed.
The below screenshots show how the distance and Field of View controls the appearance of the dots over the smiley.
Screenshot 1:
Y position: 8.48
Field of View: 30
link: http://postimg.org/image/s31tttrkp/
Screenshot 2:
Y position: 9.7
Field of View: 30
link: http://postimg.org/image/f71sq0y4b/
Screenshot 3:
Y position: 11.41
Field of View: 30
link: http://postimg.org/image/3uk4az3d3/
Screenshot 4:
Y position: 1
Field of View: 140
link: http://postimg.org/image/bul9zwg7z/
Can this be a clue?
Just a couple of info, on how transparency is typically implemented (not only by Unity).
Meanwhile opaque objects can be drawn in any order (even if sorting them in front-to-back order can eventually improve some GPU performances relying on an early z-cull). Which pixels are visible can be deduced using the depth value stored into the z-buffer.
You can't rely on z-buffer for transparency.
For rendering translucent objects a typical approach is to draw them after all opaque objects, and sorting them in back-to-front order (transparent objects more distant from the camera are drawn first).
Now the question is: how do you sort objects? with a perspective camera and meshes of a generic shape, the solution is not obvious.
For quad meshes oriented parallel to a ortographic camera view plane, the z order is implicitly correct (that's why it always works for you).
You can also notice that camera position influences the drawing order, because with perspective camera the order is calculated as distance between object position and camera.
So what can you do with Unity3d, in your specific use case scenario?
A couple of tricks:
Explicitly set the render queue of the material
Explicitly set the render order inside the shader (similar of the above, but equals to every object with the same shader)
Fake the depth using Offset into the shader (not that useful in your case but worth to be known)
hope this helps
EDIT
I didn't know that, the camera transparency sorting mode appears to be customizable. So this is another solution, maybe the best for your case if you want to use a perspective camera.
If you are using Sprite Renderer component to render the images, you have to change the rendering order with Sorting Layer and Order in Layer parameters instead of changing the Y position.
Sorting layers can be added by clicking the "default" and choosing "Add Sorting Layer..". The order of the layers is changed by dragging them into different order. With Order in Layer lower numbers are rendered first. This means that higher numbers will be drawn on top of lower ones.

Unity, GameObject Sprite(2D) how to remove transparent part?

I had join few pieces image to be a Map, and i make it able to click also.
but the problem is the image itself had transparent part, so when i click "Section A", maybe will trigger "Section B". Because "Section B" had transparent part is overlap on the Section A area.
So my question is, is that possible had any properties can adjust like it will auto remove transparent part?
or is must manual to adjust the Collider area? because my images had a lot, if manual adjust one by one, then is really take a lot of time.
And i using Box Collider for additional information.
Option 1. Pick some layered sprites. Access the texture of each sprite and read pixel from it, providing coordinates sophisticatedly extracted from mouse position, sprite position on screen and texture bounds provided by sprite. Supposing that opaque parts of sprites are not intersected, any sprite that have opaque pixel at given coordinates will be the result of picking.
Option 2. Replace box colliders with procedurally generated mesh colliders. The procedure will receive the same texture of sprite as an input and generate outline(s) using, say, marching squares algorithm. To convert outline vertices into mesh the procedure may use any trianulation algorithm that works well with concave polygons.

How to use a different texture on intersecting part of 2 quads

I'm looking for a way to dynamically change a part of a Quad that has a SpriteRenderer attached to it. Let's say I have a red Quad and a blue Quad, and then I drag one onto the other (fast or slow), the intersecting part should be colored using a green sprite. This illustration shows the scenario I'm trying to solve.
Can someone please help me with this?
You have two options:
First, if your mid color will be the correct mixture of other two color, in this case it would be yellow, you can use Mobile Particle/Additive or Mobile Particle/Multiply Shaders.
In a second way, you can write your own shader that takes the intersection area as parameter and paint your textures according to parameters.

How can I segment bones from an x ray image?

I want to remove the skin particles from my X-Ray of hand image. I want bones as white Color and all other areas including the skin area in the x ray as black. I am doing my project in mat lab.
You can use this script for Local Adaptive Thresholding.
Or if you want bones as white color you should use sobel-operator, as in this example.
A simple way,you can just change the value of a pixel, when it is higher than 125 change it to 255,or set 0. the number 125,you can change it,to get a best one.
you can search "binarization" on google to get more information.