How do I scale a texture applied to an object (such as tiling command), keeping the original proportions? Tiling command adapt texture to the object face.
I have little texture (256x256) must I tile many time on various object, manteining proportion.
If you need to scale the texture image data itself, and need the image data, you can use my Texture Scaler script. Helical version process the data on the CPU, while my script scales the texture on the GPU. But my requires Unity 5. Here is the code: Unity3d Texture Image Scaler - Pastebin.com
I implemented a ScaleTexture function today
Its not the most accurate scaler. but it works well enough for my purpose. Also note that for a 800x640 picture which is 500k pixels it takes a second or two to do this.
private Texture2D ScaleTexture(Texture2D source,int targetWidth,int targetHeight) {
Texture2D result=new Texture2D(targetWidth,targetHeight,source.format,false);
float incX=(1.0f / (float)targetWidth);
float incY=(1.0f / (float)targetHeight);
for (int i = 0; i < result.height; ++i) {
for (int j = 0; j < result.width; ++j) {
Color newColor = source.GetPixelBilinear((float)j / (float)result.width, (float)i / (float)result.height);
result.SetPixel(j, i, newColor);
}
}
result.Apply();
return result;
}
you can use something like this:
Texture myTexture = Resources.Load("some_texture") as Texture;
transform.gameObject.renderer.material.mainTexture = myTexture;
renderer.material.mainTextureScale = new Vector2(transform.lossyScale.x*0.5f,transform.lossyScale.x*0.5f);
This will repeat the texture on your object.