# Divided Huge Texture Shader

**URL:** https://discussions.unity.com/t/divided-huge-texture-shader/48029
**Category:** Questions & Answers
**Created:** [July 31, 2012, 2:02pm UTC](https://discussions.unity.com/t/divided-huge-texture-shader/48029 "2012-07-31T14:02:40Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![SuperProgrammer](https://avatars.discourse-cdn.com/v4/letter/s/f14d63/32.png) [@SuperProgrammer](https://discussions.unity.com/u/SuperProgrammer)
#### Post date: [July 31, 2012, 2:02pm UTC](https://discussions.unity.com/t/divided-huge-texture-shader/48029/1 "2012-07-31T14:02:40Z")

</div>

I have a huge sphere (you can think a planet) and 21600x10800 texture for it. (That size req because there is a zoom option) Sure i will divide that texture. But how to use? I need a shader for it.

That scene havent much object but i dont want waste performance too.  
I need a basic diffuse with a little self lightning. I mean if there is no light, it req visible a little instead of black. with light it will be more lighter. (No lightning texture only not black without light)

How to write that shader?

---

<div class="post-metadata">

### Author: ![ScroodgeM](https://avatars.discourse-cdn.com/v4/letter/s/85f322/32.png) [@ScroodgeM](https://discussions.unity.com/u/ScroodgeM)
#### Post date: [July 31, 2012, 9:25pm UTC](https://discussions.unity.com/t/divided-huge-texture-shader/48029/2 "2012-07-31T21:25:26Z")

</div>

unity supports maximum of 4096x4096 textures, so you should split it to 18 textures.

and the best way even in performance reason is to make a 3d model of sphere mapped to 18 different materials. then use just a regular shader.

P.S. “No lightning texture only not black without light” is also known as Ambient Light

P.P.S. i could help you to write a shader with 18 textures, but i’m not sure this will be better then 18 materials with simple shaders…

---

<div class="post-metadata">

### Author: ![SuperProgrammer](https://avatars.discourse-cdn.com/v4/letter/s/f14d63/32.png) [@SuperProgrammer](https://discussions.unity.com/u/SuperProgrammer)
#### Post date: [August 1, 2012, 11:42am UTC](https://discussions.unity.com/t/divided-huge-texture-shader/48029/3 "2012-08-01T11:42:51Z")

</div>

If i change it to clamp, only 1 texture normal others getting one color. So i cant choose clamp i think it req divide sphere to objects. Currently one object and 18 material. If i divide it to 18 sphere part. It will get smoothing problem.

Shader:

```auto
Shader "Custom/Planet" {
	Properties {
		_MainTex11 ("Texture 1 1", 2D) = "white" {}
		_MainTex12 ("Texture 1 2", 2D) = "white" {}
		_MainTex13 ("Texture 1 3", 2D) = "white" {}
		_MainTex21 ("Texture 2 1", 2D) = "white" {}
		_MainTex22 ("Texture 2 2", 2D) = "white" {}
		_MainTex23 ("Texture 2 3", 2D) = "white" {}
		_MainTex31 ("Texture 3 1", 2D) = "white" {}
		_MainTex32 ("Texture 3 2", 2D) = "white" {}
		_MainTex33 ("Texture 3 3", 2D) = "white" {}
		_MainTex41 ("Texture 4 1", 2D) = "white" {}
		_MainTex42 ("Texture 4 2", 2D) = "white" {}
		_MainTex43 ("Texture 4 3", 2D) = "white" {}
		_MainTex51 ("Texture 5 1", 2D) = "white" {}
		_MainTex52 ("Texture 5 2", 2D) = "white" {}
		_MainTex53 ("Texture 5 3", 2D) = "white" {}
		_MainTex61 ("Texture 6 1", 2D) = "white" {}
		_MainTex62 ("Texture 6 2", 2D) = "white" {}
		_MainTex63 ("Texture 6 3", 2D) = "white" {}
	}
	SubShader {
		Tags { "RenderType"="Opaque" }
		LOD 200
		
		CGPROGRAM
		#pragma surface surf Lambert

		sampler2D _MainTex11;
		sampler2D _MainTex12;
		sampler2D _MainTex13;
		sampler2D _MainTex21;
		sampler2D _MainTex22;
		sampler2D _MainTex23;
		sampler2D _MainTex31;
		sampler2D _MainTex32;
		sampler2D _MainTex33;
		sampler2D _MainTex41;
		sampler2D _MainTex42;
		sampler2D _MainTex43;
		sampler2D _MainTex51;
		sampler2D _MainTex52;
		sampler2D _MainTex53;
		sampler2D _MainTex61;
		sampler2D _MainTex62;
		sampler2D _MainTex63;

		struct Input {
			float2 uv_MainTex11;
		};

		void surf (Input IN, inout SurfaceOutput o) {
			if (IN.uv_MainTex11.x >= 5.0/6.0) {
				if (IN.uv_MainTex11.y >= 2.0/3.0) {
					o.Albedo = tex2D (_MainTex61, IN.uv_MainTex11 * float2(6.0, 3.0)).rgb;
				}
				else if (IN.uv_MainTex11.y >= 1.0/3.0) {
					o.Albedo = tex2D (_MainTex62, IN.uv_MainTex11 * float2(6.0, 3.0)).rgb;
				}
				else {
					o.Albedo = tex2D (_MainTex63, IN.uv_MainTex11 * float2(6.0, 3.0)).rgb;
				}
			}
			else if (IN.uv_MainTex11.x >= 4.0/6.0) {
				if (IN.uv_MainTex11.y >= 2.0/3.0) {
					o.Albedo = tex2D (_MainTex51, IN.uv_MainTex11 * float2(6.0, 3.0)).rgb;
				}
				else if (IN.uv_MainTex11.y >= 1.0/3.0) {
					o.Albedo = tex2D (_MainTex52, IN.uv_MainTex11 * float2(6.0, 3.0)).rgb;
				}
				else {
					o.Albedo = tex2D (_MainTex53, IN.uv_MainTex11 * float2(6.0, 3.0)).rgb;
				}
			}
			else if (IN.uv_MainTex11.x >= 3.0/6.0) {
				if (IN.uv_MainTex11.y >= 2.0/3.0) {
					o.Albedo = tex2D (_MainTex41, IN.uv_MainTex11 * float2(6.0, 3.0)).rgb;
				}
				else if (IN.uv_MainTex11.y >= 1.0/3.0) {
					o.Albedo = tex2D (_MainTex42, IN.uv_MainTex11 * float2(6.0, 3.0)).rgb;
				}
				else {
					o.Albedo = tex2D (_MainTex43, IN.uv_MainTex11 * float2(6.0, 3.0)).rgb;
				}
			}
			else if (IN.uv_MainTex11.x >= 2.0/6.0) {
				if (IN.uv_MainTex11.y >= 2.0/3.0) {
					o.Albedo = tex2D (_MainTex31, IN.uv_MainTex11 * float2(6.0, 3.0)).rgb;
				}
				else if (IN.uv_MainTex11.y >= 1.0/3.0) {
					o.Albedo = tex2D (_MainTex32, IN.uv_MainTex11 * float2(6.0, 3.0)).rgb;
				}
				else {
					o.Albedo = tex2D (_MainTex33, IN.uv_MainTex11 * float2(6.0, 3.0)).rgb;
				}
			}
			else if (IN.uv_MainTex11.x >= 1.0/6.0) {
				if (IN.uv_MainTex11.y >= 2.0/3.0) {
					o.Albedo = tex2D (_MainTex21, IN.uv_MainTex11 * float2(6.0, 3.0)).rgb;
				}
				else if (IN.uv_MainTex11.y >= 1.0/3.0) {
					o.Albedo = tex2D (_MainTex22, IN.uv_MainTex11 * float2(6.0, 3.0)).rgb;
				}
				else {
					o.Albedo = tex2D (_MainTex23, IN.uv_MainTex11 * float2(6.0, 3.0)).rgb;
				}
			}
			else {
				if (IN.uv_MainTex11.y >= 2.0/3.0) {
					o.Albedo = tex2D (_MainTex11, IN.uv_MainTex11 * float2(6.0, 3.0)).rgb;
				}
				else if (IN.uv_MainTex11.y >= 1.0/3.0) {
					o.Albedo = tex2D (_MainTex12, IN.uv_MainTex11 * float2(6.0, 3.0)).rgb;
				}
				else {
					o.Albedo = tex2D (_MainTex13, IN.uv_MainTex11 * float2(6.0, 3.0)).rgb;
				}
			}
		}
		ENDCG
	}
	FallBack "Diffuse"
}

```

---

<div class="post-metadata">

### Author: ![SuperProgrammer](https://avatars.discourse-cdn.com/v4/letter/s/f14d63/32.png) [@SuperProgrammer](https://discussions.unity.com/u/SuperProgrammer)
#### Post date: [August 2, 2012, 3:25pm UTC](https://discussions.unity.com/t/divided-huge-texture-shader/48029/4 "2012-08-02T15:25:53Z")

</div>

Final Answer:  
Using multi-sub material better then shader.  
Always use power of 2 sized textures for less size. (Bigger size for less size 😉

As i found “Do not download big images dynamically” because no runtime compression.  
Sure there is a function “Texture2D.Compress” but not enough.

I will load DDS file instead of jpg (DXT1 compressed texture). I will take care of its size with some other methods.

Btw again ScroodgeM thanks for help.
