Hi I have this game which tiles a material across a line renderer, shown in the image below. But I couldn’t find this anywhere.

But I wanted to increase the spacing between material tiling. Maybe this could be done with a new shader with an extra field.

Thanks

What are the dynamics?
Is that line a trace of the moving circle or is some sort of “aiming” system?

In the first case, you should have the ball generate particles in world space instead of using a line renderer

In the second case you should enlarge the texture by adding empty spaces on the sides.

I had a play with writing a shader that plonks extra space at the end of the ‘x’. I couldn’t get surface shaders to work properly with the line renderer, so this is a plain old vertex/pixel one with no lighting, but it might give you a good place to start - plus your game doesn’t look like its very ‘lit’ :slight_smile:

Shader "Custom/linerender" {
    Properties
    {
        _MainTex ("Sprite Texture", 2D) = "white" {}
        _Color ("Tint", Color) = (1,1,1,1)
        _LineLength ("Line Length", Float) = 1
        _Spacing ("Spacing", Float) = 0.25
    }

	CGINCLUDE
    #include "UnityCG.cginc"
	struct appdata_t
    {
        float4 vertex   : POSITION;
        float4 color    : COLOR;
        float2 texcoord : TEXCOORD0;
    };
 
    struct v2f
    {
        float4 vertex   : SV_POSITION;
        fixed4 color    : COLOR;
        half2 texcoord  : TEXCOORD0;
    };
           
    fixed4 _Color;
    half _LineLength;
    half _Spacing;
 
    v2f vert(appdata_t IN)
    {
        v2f OUT;
        OUT.vertex = mul(UNITY_MATRIX_MVP, IN.vertex);
        OUT.texcoord = half2(IN.texcoord.x*_LineLength,IN.texcoord.y);
        OUT.color = IN.color * _Color; 
        return OUT;
    }
 
    sampler2D _MainTex;

    fixed4 frag(v2f IN) : COLOR
    {
    	half2 uv = frac(IN.texcoord);
    	uv.x = saturate(uv.x * (1+_Spacing));
        half4 tex_col = tex2D (_MainTex, uv);   
        return tex_col * IN.color;
    }
	ENDCG
 
    SubShader
    {
        Tags
        {
            "Queue"="Transparent"
            "IgnoreProjector"="True"
            "RenderType"="Transparent"
            "PreviewType"="Plane"
            "CanUseSpriteAtlas"="True"
        }
 
        Cull Off
        Lighting Off
        ZWrite Off
        Fog { Mode Off }
        Blend SrcAlpha OneMinusSrcAlpha
 
        Pass
        {
        CGPROGRAM
            #pragma vertex vert
            #pragma fragment frag
        ENDCG
        }
    }
    Fallback "Diffuse"
}

The key bits are:

  • In the vertex shader, I multiply the texture coordinate by line length to account for how far down the line we are
  • In the fragment shader I first ‘frac’ the uv to get only the fractional part of the uv
  • Then I plonk in some extra space into the ‘x’ of the uv, and saturate it so a chunk of the texture sampling is all at x=1

Of course, you could just make your texture bigger, but I was intrigued :slight_smile:

Hope that helps

-Chris