x


Generative seamless textures across multiple planes?

How would you go about generating random textures that can be seamlessly mapped across multiple planes in a grid?

Currently I have a single prefab plane that is instantiated by a for loop to form a grid of identical planes. Certain events cause planes to fade out (thanks to iTween) and then Destroy.

I want the seamless grid to look dirty, without looking repetitive.

I was looking at these questions: http://answers.unity3d.com/questions/135940/how-to-map-texture-across-multiple-objects.html http://answers.unity3d.com/questions/146062/spread-material-over-multiple-objects-or-cubes.html But neither of them suit my purposes.

Any ideas?

more ▼

asked Jul 27 '11 at 02:04 AM

Wesww gravatar image

Wesww
77 8 9 11

Your first link has a good suggestion in one of the answers, you should map the texture based on the object's world position rather than there uvs. Then it should tile more smoothly.

Jul 27 '11 at 02:29 AM Peter G

[edit: moving this to comments]

If you think that would work, I will definitely try to approach it that way. What threw me off is that the user Owen who suggested that method also said "The edges all have bad seems, but there's no way around that."

but now that I am reading it again, perhaps that quote was caused by having to do differently angled walls rather than just one plane. Thanks! I'll get back with how my attempts go.

Jul 27 '11 at 09:37 PM Wesww
(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

So that was great advice, and I've gotten this working really well for my purposes now. I added a couple lines of code to an answer posted by user "Owen Reynolds" on this question so that I could manually tweak the scale of the world-aligned repeating texture from the GUI side.

Here's the full code of the working shader, hope it helps somebody else:

Shader "custom_shaders/Transparent_Diffuse_World_Aligned" {

Properties { _Color ("Main Color", Color) = (1,1,1,1) _MainTex ("Base (RGB) Trans (A)", 2D) = "white" {} _Scale ("Texture Scale Multiplier", Float) = 0.1 }

SubShader { Tags {"Queue"="Transparent-101" "IgnoreProjector"="True" "RenderType"="Transparent"} LOD 200 Cull Off Fog {Mode Off}

CGPROGRAM
#pragma surface surf Lambert alpha

sampler2D _MainTex;
float4 _Color;
float _Scale;

struct Input {
    float2 uv_MainTex; // unused
    float3 worldNormal;
    float3 worldPos;
};

void surf (Input IN, inout SurfaceOutput o) {
  // Guess correct planar map from normal. 0.5 is an arbitrary cutoff
  float2 UV;
  // NOTE: assuming no bottom-facing, otherwise use abs()
  if(IN.worldNormal.y>0.5) UV = IN.worldPos.xz; // top
  else if(abs(IN.worldNormal.x)>0.5) UV = IN.worldPos.yz; // side
  else UV = IN.worldPos.xy; // front

  // 0.1 is an arbitrary x10 texture size scale 
  half4 c = tex2D (_MainTex, UV* _Scale)* _Color;
  o.Albedo = c.rgb;
  o.Alpha = c.a;
}

ENDCG

}

Fallback "Transparent/VertexLit" }

more ▼

answered Aug 03 '11 at 07:21 PM

Wesww gravatar image

Wesww
77 8 9 11

(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:

x2199
x31
x16
x8
x3

asked: Jul 27 '11 at 02:04 AM

Seen: 1062 times

Last Updated: Aug 03 '11 at 07:21 PM