Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by andrew_196 · Sep 06, 2015 at 12:45 PM · c#materialtiling

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.

alt text

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

Thanks

aaa.png (34.4 kB)
Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image andrew_196 · Sep 06, 2015 at 02:49 PM 0
Share

maybe there is a way to have like an "offset" but for each tile?

2 Replies

· Add your reply
  • Sort: 
avatar image
1
Best Answer

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

Comment
Add comment · Show 4 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image andrew_196 · Sep 06, 2015 at 05:01 PM 0
Share

Thanks Will look at this now too.

avatar image andrew_196 · Sep 06, 2015 at 05:16 PM 0
Share

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

avatar image andrew_196 · Sep 06, 2015 at 05:21 PM 0
Share

Okay figured it out but I don't know how to change a material field from c#

Thanks

more specifically the "linelength" and "spacing"

avatar image andrew_196 · Sep 06, 2015 at 06:18 PM 0
Share

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

avatar image
1

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.

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image andrew_196 · Sep 06, 2015 at 04:34 PM 0
Share

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

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

29 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

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


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges