- Home /
Increase spacing between material tiling
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
maybe there is a way to have like an "offset" but for each tile?
Answer by wibble82 · Sep 06, 2015 at 04:55 PM
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' :)
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 :)
Hope that helps
-Chris
Hi @wibble82 it seems that it no longer tiles I believe because this is more like a sprite when before I was using a "Unlit/Transparent" does that sound like that would cause the issue.
Thanks Andrew
Okay figured it out but I don't know how to change a material field from c#
Thanks
more specifically the "linelength" and "spacing"
Hi again @wibble82 figured that out too. But I was wondering what I would have to do to put the space before each of the dots.
thanks and sorry for all of the comments
Answer by Cryptomane · Sep 06, 2015 at 04:09 PM
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.
Yes it is an ai$$anonymous$$g system. A particle system would actually be quite a good I edea.
Will try it out otherwise the second thanks.
Your answer
![](https://koobas.hobune.stream/wayback/20220612011850im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Distribute terrain in zones 3 Answers
Multiple Cars not working 1 Answer
Can I change a material name using AssetPostprocessor.OnPreprocessModel 1 Answer
Repeat texture common question 2 Answers
Material Switching Upon Instantiation. over my head 0 Answers