# Render 3D trail effect?

Anyone how to render 3D trail effect?

Whatâ€™s the chance.
There is code at the bottom

woo, cool. is the flag animation using the same technique?

no not at all, the flag vertices are constant in place (relative to the moving geometry). They have spring physics for the segments and some form of sin wave to approximate how cloth moves in wind. Interestingly this problem (cloth moving in wind) is not fully understood/explored yet if you google for scientific papers.

i had try to implement the approach in ur article, there is some function missing

NormalizeLocal()
Saturate()

which do not come with monogame framework, can you provide the function? and what is the â€śvisibilityâ€ť input value for update?

NormalizeLocal is the same as Normalize(), except one can use the Vector right away.

``````public static Vector3 NormalizeLocal(this Vector3 vec3)
{
if (vec3 == Vector3.Zero) return vec3;
vec3.Normalize();
return vec3;
}
``````

Saturate is clamp between 0 and 1

``````    public static float Saturate(this float input)
{
if (input < 0) return 0;
if (input > 1) return 1;
return input;
}
``````

Visibility is the alpha value the trail has at the start. So usually 1.

1 Like

thank you broâ€¦

sry to is disturb u again, i got this error in ur shader.

i got it. just commend output position

sry to is disturb again, i got uv problem, which only render red color part in texture.

Try this

VertexShaderTexturedOutput VertexShaderTrailFunction(float4 Position : SV_POSITION, float2 TexCoord : TEXCOORD0, float Visibility : TExCOORD1)
{

float4 worldPosition = mul(Position, WorldViewProjection);

float vis = saturate(Visibility * 3 â€“ 1);
output.Color = GlobalColor * vis * float4(0.65f,0.65f,0.65f,0.5f);
output.TexCoord = float2(vis, TexCoord.y);
return output;
}

Otherwise you just have to change the texCoord.y of the vertices depending on distance from teh beginning, you have to do that in c# code.

1 Like

itâ€™s work Thanksâ€¦