- Home /
Autoscale Shader with multiple random texture selection.
Hello everyone i have this problem i have this shader in CG which i use to autofit and rescale my textures to fit my surface which i create with multiple meshes Shader "Texturing" { Properties { _Texture("Texture", 2D) = "white" {} _TextureScale("Texture Scale", Float) = 1 }
SubShader {
Tags {
"Queue"="Geometry"
"IgnoreProjector"="False"
"RenderType"="Opaque"
}
Cull Back
ZWrite On
CGPROGRAM
#pragma surface surf Lambert
#pragma exclude_renderers flash
sampler2D _Texture;
float _TextureScale;
struct Input {
float3 worldPos;
float3 worldNormal;
};
void surf (Input IN, inout SurfaceOutput o) {
float3 projNormal = saturate(pow(IN.worldNormal * 1.6, 6));
//Scaling
float3 x = tex2D(_Texture, frac(IN.worldPos.zy * _TextureScale)) * abs(IN.worldNormal.x);
float3 y = tex2D(_Texture, frac(IN.worldPos.zx * _TextureScale)) * abs(IN.worldNormal.y);
float3 z = tex2D(_Texture, frac(IN.worldPos.xy * _TextureScale)) * abs(IN.worldNormal.z);
o.Albedo = z;
o.Albedo = lerp(o.Albedo, x, projNormal.x);
o.Albedo = lerp(o.Albedo, y, projNormal.y);
}
ENDCG
}
Fallback "Diffuse"
}
my problem is that this works perfect if you use the same texture to fill all meshes. When i try to use multiple (similar) textures in random i have fitting problems as you see in the screenshots.. all the textures are created in 512 X 512 and they have the endings the same so to fit between them.
I need the autoscale shader because i have some random meshes which i create with code and i use them to create the whole map (different triangles and dimensions) so i was wondering if there is any way to improve the shader and fits different variations of the texture without the above problem.. this is an example of how i create my map
as you see if i use one texture it works perfect..
Hope i described it well.. my english are not very good and i apologize for this... thank you in advance!
Your answer
![](https://koobas.hobune.stream/wayback/20220613162921im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
A node in a childnode? 1 Answer
Change Pivot Point- Maya 3 Answers
Importing Mesh from Maya into Unity Issues 0 Answers
Imported Maya File mesh missing after Git sync 1 Answer
Coin shine 1 Answer