#Tracer Effect

1 messages · Page 1 of 1 (latest)

main yacht
#

Hi

#

These are some tracers
I want to replicate this effect with a shader (I can't use gameobjects)
How do I go about it?

#

Specifically, I need help with the shader itself

#

I am currently rendering using Graphics.DrawMesh

royal vigil
#

Ok, based on this info alone, it doesn't change my reply, if you have a trace mesh already(for example, if you generate it at runtime), you just need to apply a shader to it. Any kind of shader would work really, but you probably want an unlit shader, so that the trace is not affected by lighting. I'd try the unity unlit one for starters, as I suggested.

main yacht
#

@royal vigil
Trail renderers are no good, the variable length depending on the speed is a bad thing
A small mesh with bloom is problematic because eventually there won't even be one pixel to display for post processing

royal vigil
# main yacht <@209684227720085505> Trail renderers are no good, the variable length dependin...

Do you understand how shaders work? Vertex shader runs for each vertex of a mesh, transforms the vertices position to clip space + some other transformation and passes them on. The GPU fills the screen space triangles with pixels and calls a pixel shader for each screen pixel in the visible triangle. That's super simplified, but the point is, you need something for the vertex shader to work with. It can't make things out of thin air. That's why you need a mesh of the trace. That or it has to be a full screen shader, a post processing effect basically.

royal vigil
main yacht
#

Current look

#

The problem

royal vigil
#

Well, how you rendering it? It's weird that a long shape mesh would render as a point like that. Unless it's rotated orthogonally to the camera.

sly rock
#

For that exact problem I used a shader that extrudes the mesh (adds the normals to vertex positions) over distance to camera

old bone
#

What stops you from using Particle System? Every game source and engine I had a chance to touch used Particle System implementation, this is like battle proven solution. It does many things out of the box.
Since you are restricted to Graphics.DrawMesh, I would look into possibility to limit minimum size of the object either though mesh or shader itself, I would dig into particle system code and see how its done in Render tab.
I have not done this that way, sorry to be useless.
But.
With Particle System you can build physical bullets, or ray cast based. You can have a bullet mesh, or/with traces that keeps its minimal size on distance, as alternative you might have different particle blending half way through to display far tracer as more visible/simplified one. With visibility over distance you might replace it with simple glare texture.

hexed orbit
#

I suggested particles or VFX Graph specifically for this purpose in the other thread that we already had

#

Particle System and VFX Graph particles already let you define min/max screen size, and then you'd just fade the color or alpha when it get far away

main yacht
#

I'm demonstrating that the effect is much worse when you are facing towards the bullet

#

I don't want to use a particle system, it would be annoying to write the code for setting the positions and direction for every particle in the system, that is what I did the first time around

#

This is a thread about creating a shader for a small mesh to keep it visible as it gets further away

sly rock
# main yacht This is what I'm looking for

You use shader graph?
Add the vertex normals to the vertex position in the shader. This makes the mesh extrude outwards along its normals.
Get the distance to the camera and use that as a multiplier for the extrusion.

main yacht
#

Which one?

sly rock
#

I dont use URP but probably URP > Unlit Shader Graph

main yacht
#

Unlit?

sly rock
#

Since it will just emit light it doesnt need to be lit

main yacht
#

Right

sly rock
#

Lit = receive lighting, shadows and such

main yacht
#

@sly rock Well that's not right...

sly rock
#

Is the position input World space or Object space?

#

If you unplug it you will see

sly rock
#

Good

main yacht
#

@sly rock ???

#

It's not even visible in the scene

sly rock
#

You missed the 'very small multiplier' part

#

Also your muliply should be before the addition, not after

#

You only need to multiply the normal with distance * some small number

#

Then add it to the position

main yacht
brittle forum
#

If you push out the normals you need to have a continuous mesh. No split edges. All shared vertex indices.

#

Otherwise u get that effect

#

Another thing to consider that I tend to forget how to do (but remember to do) is you need to account for the fov of the camera for scaling problems like this. When multiplying by the projection matrix iirc the value you need for accounting for it is often stored in the w of a transformed xyz(w).

main yacht
#

@brittle forum @sly rock This kind of works

#

But the object likes to disappear before it's fully off screen and the scaling is really weird

brittle forum
#

You'll need to update the bounds of the object to reflect the increased scale.

#

It's getting culled

main yacht
#

uhuh

brittle forum
#

Pretty sure.

main yacht
#

how

brittle forum
#

This is a tricky one. The way you have it written it could almost be a c# script.

#

But the bounds are a cpu side thing

#

So you can't get them in a shader

#

It's J a problem with making things larger than they really are in shader

hexed orbit
#

A solved problem with particles

brittle forum
#

You can still use meshes with particles too.

main yacht
hexed orbit
#

I recommend VFX Graph, not the PS

main yacht
#

What is the VFX graph?

hexed orbit
#

GPU particle simulation

main yacht
hexed orbit
#

So fading particle color over distance can be done within it without shaders
Screen space scaling is an included operation

main yacht
#

I'll look into it

#

Hell, I might be better off with a 2D texture rather than a mesh. I mean, look at this

hexed orbit
#

It's not quite possible to tell which one that is

brittle forum
#

U still have the problem you're describing where it's not visible from the front

hexed orbit
#

A 2D Texture will have to be made into a mesh to be rendered

brittle forum
#

That's tru too

main yacht
#

Rather than my 4

#

We'll see

hexed orbit
#

Billboarding a stretched quad towards camera is tough to do manually, and tougher if it also needs to retain solid appearance frontally as hol mentions
Luckily VFX Graph has all kinds of billboarding options for quad particles

sly rock
sly rock
royal vigil
#

I wonder if frustum/distance culling is playing a part in what they describe as the "object disappearing"..?🤔

royal vigil
royal vigil
#

That is if they were visible in real life.

main yacht
main yacht
royal vigil
# main yacht What?

You'd be surprised, but normal bullets don't produce shiny traces as they fly through the air.

#

In real life*

royal vigil
#

I feel like it's less "aliasing" and more has to do with the shape of your mesh.

#

Is it just 1 long triangle?

main yacht
royal vigil
#

Hmm.. Okay. So can you record a video of what it looks like?

main yacht
#

I dunno what you're looking for, small object get so small that it become < 1 pixel big

royal vigil
#

Yes, I just wanted to confirm I understand the issue correctly.

main yacht
#

The fact that post processing is... post processing doesn't help the issue at all, so it's either blooming really bright or completely invisible

royal vigil
#

Well, what Osmal was suggesting should work. Although, I'd think what Spazi was suggesting is a more correct approach and provides more room for customization.

main yacht
#

I will look into converting over to a VFX graph, good excuse to learn it anyway

sly rock
#

If that doesnt work out, try the extrusion approach, you were very close to having it working. The mesh just needs to have a couple more vertices and no hard edges

#

Funny to hear the approach called incorrect when it solved this exact issue for me

#

Ofc the downside is having a few more vertices compared to a quad, but it probably wont make a difference

#

I dont remember running into any culling issues 🤔

hexed orbit
sly rock
#

Yeah it makes sense, I need to check again if its an issue

main yacht
#

I can just... scale it outwards. Like from the cone's tip.