x


Road Texture Is Stretching

I'm building a city building game like Sim City or Cities XL. I'm working on creating a tool that will let players build roads. Although, im having an issue when the road stretches to reach the mouse cursor. The texture stretches as well. How can I make the texture tile instead of stretch?

Here is an example of what I have. http://www.youtube.com/watch?v=9_BhisKH0WU

heres an example of what i'd like to acheive http://www.youtube.com/watch?v=qdOHN9bVIz0

more ▼

asked Mar 29 '12 at 05:46 AM

Roger0 gravatar image

Roger0
1 5 5 6

(comments are locked)
10|3000 characters needed characters left

3 answers: sort voted first

The way I am seeing is to play with the UVs in the shader directly. if your texture is good for 4 meters, you can do something like: uv = roadLength / 4 And pass that road length as a shader property.

more ▼

answered Mar 29 '12 at 09:19 PM

daivuk gravatar image

daivuk
85 1 2 3

i've never modified textures before in code. Could you provide an example of how I would do this?

Mar 29 '12 at 10:22 PM Roger0
(comments are locked)
10|3000 characters needed characters left

You'd have to scale the texture coordinates as well.

more ▼

answered Mar 29 '12 at 01:36 PM

Statement gravatar image

Statement ♦♦
20.2k 35 71 176

how would I do that? I dont want to simply make the texture larger, I want to tile it over the road.

Mar 29 '12 at 09:11 PM Roger0
(comments are locked)
10|3000 characters needed characters left

Hey man, I don't know if this is of any use to you (or if you're still interested), but you can achieve a tiling effect like the roads in Cities XL by using an ObjectLinear shader. This basically projects your texture straight down onto your plane, the result of which won't stretch like a standard UV mapped texture, but instead will tile quite nicely. The advantage here is that you don't have to stretch each plane's UVs individually, in fact you don't even need to touch them. here's a shader I made that I'm using in a tile based side scroller I'm working on:

Shader "Custom/ObjectLinear"
{
    Properties
    {
       _MainTex("Texture", 2D) = "" {TexGen ObjectLinear}
    }
    SubShader
    {
       Blend SRCAlpha OneMinusSRCAlpha
       Tags {queue = transparent}
       cull back

       BindChannels
       {
         Bind "vertex", vertex
         Bind "color", color
         Bind "texcoord1", texcoord
       }

       Pass
       {
         SetTexture[_MainTex]
       }
    }
}

Remember, this shader will project down the z-axis, so for it to work on a plane, it has to be facing the z-axis. If you don't, you'll just get a line of pixels stretched across the plane. The standard Unity plane faces the y-axis, so it won't work for that, but you probably won't want to use it anyway since it has a lot of unnecessary geometry. So yeah, just create a plane in 3ds Max or Maya or something and rotate it's pivot so the plane faces the z-axis. Import it into Unity (and check that it's still facing the right direction since I'm pretty sure Maya flips the Z and Y axis'), create a new shader, put that code in I posted and, finally, chuck that shader onto your plane (as a GameObject). If you try stretching it, you'll see that the texture will tile, not stretch. 'Hope this helps.

more ▼

answered Aug 28 '12 at 03:41 AM

brycedaawg gravatar image

brycedaawg
16 1 1 2

thanks for replying, I will try out the script when I can. I have not been working on this particular project for awhile. But I never got a solution to the problem. Thanks again!

Aug 28 '12 at 05:40 AM roger0
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

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

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x3568
x560
x161
x70
x28

asked: Mar 29 '12 at 05:46 AM

Seen: 1158 times

Last Updated: Aug 28 '12 at 05:40 AM