- Home /
using textures larger than 4096x4096 using multi pass shader
I am trying to shade a tiled big texture to a quad. I think I can follow this approach. There is a single pass shader combining four textures in the following post. http://www.41post.com/4416/programming/unity3d-using-textures-larger-than-4096x4096
Since I need more than 16 textures to be tiled I need to make a multipass shader. So I try to convert the above shader. But the doubling of texture coordinates trick that used in the above shader is not getting right for me. Please help me to convert the shader.
Shader "Custom/FourPartTexMultipass" {
Properties {
_MainTex0 ("0th Tex", 2D) = "white" {}
_MainTex1 ("1st Tex", 2D) = "white" {}
_MainTex2 ("2nd Tex", 2D) = "white" {}
_MainTex3 ("3rd Tex", 2D) = "white" {}
}
SubShader {
Tags { "RenderType"="Opaque" }
LOD 200
Pass {
Cull Off
AlphaTest Off
Blend Off
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
sampler2D _MainTex0;
float4 _MainTex0_ST;
struct a2v
{
float4 vertex : POSITION;
float4 texcoord : TEXCOORD0;
};
struct v2f
{
float4 pos : POSITION;
float2 uv : TEXCOORD0;
};
v2f vert (a2v v)
{
v2f o;
o.pos = mul( UNITY_MATRIX_MVP, v.vertex);
o.uv = TRANSFORM_TEX (v.texcoord, _MainTex0);
return o;
}
half4 frag(v2f i) : COLOR
{
half4 c;
float2 duv = i.uv;
if(i.uv.x<=0.5 && i.uv.y>0.5)
{
c = tex2D (_MainTex0, duv);
}
else
{
c = 0;
}
return c;
}
ENDCG
}
Pass {
Cull Off
AlphaTest Off
Blend SrcAlpha OneMinusSrcAlpha
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
sampler2D _MainTex1;
float4 _MainTex1_ST;
struct a2v
{
float4 vertex : POSITION;
float4 texcoord : TEXCOORD0;
};
struct v2f
{
float4 pos : POSITION;
float2 uv : TEXCOORD0;
};
v2f vert (a2v v)
{
v2f o;
o.pos = mul( UNITY_MATRIX_MVP, v.vertex);
o.uv = TRANSFORM_TEX (v.texcoord, _MainTex1);
return o;
}
half4 frag(v2f i) : COLOR
{
half4 c;
float2 duv = i.uv;
if(i.uv.x>0.5 && i.uv.y>0.5)
{
c = tex2D (_MainTex1, duv);
}
else
{
c = 0;
}
return c;
}
ENDCG
}
Pass {
Cull Off
AlphaTest Off
Blend SrcAlpha OneMinusSrcAlpha
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
sampler2D _MainTex2;
float4 _MainTex2_ST;
struct a2v
{
float4 vertex : POSITION;
float4 texcoord : TEXCOORD0;
};
struct v2f
{
float4 pos : POSITION;
float2 uv : TEXCOORD0;
};
v2f vert (a2v v)
{
v2f o;
o.pos = mul( UNITY_MATRIX_MVP, v.vertex);
o.uv = TRANSFORM_TEX (v.texcoord, _MainTex2);
return o;
}
half4 frag(v2f i) : COLOR
{
half4 c;
float2 duv = i.uv;
if(i.uv.x<=0.5 && i.uv.y<0.5)
{
c = tex2D (_MainTex2, duv);
}
else
{
c = 0;
}
return c;
}
ENDCG
}
Pass {
Cull Off
AlphaTest Off
Blend SrcAlpha OneMinusSrcAlpha
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
sampler2D _MainTex3;
float4 _MainTex3_ST;
struct a2v
{
float4 vertex : POSITION;
float4 texcoord : TEXCOORD0;
};
struct v2f
{
float4 pos : POSITION;
float2 uv : TEXCOORD0;
};
v2f vert (a2v v)
{
v2f o;
o.pos = mul( UNITY_MATRIX_MVP, v.vertex);
o.uv = TRANSFORM_TEX (v.texcoord, _MainTex3);
return o;
}
half4 frag(v2f i) : COLOR
{
half4 c;
float2 duv = i.uv;
if(i.uv.x>0.5 && i.uv.y<=0.5)
{
c = tex2D (_MainTex3, duv);
}
else
{
c = 0;
}
return c;
}
ENDCG
}
}
FallBack "Diffuse"
}
hey! I have been searching for such a thing for a long time! did you manage to solve your problem?
Your answer
Follow this Question
Related Questions
Transparency and texture atlases, shader calls affecting performance? 2 Answers
how to solve shader/texture problem: putting white icons on colored planes 1 Answer
Combine Shaders 0 Answers
Why is my UV'd texture displaying wrapped with the wrong scale? 0 Answers
Transparent shader and scrolling 0 Answers