Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
This post has been wikified, any user with enough reputation can edit it.
avatar image
0
Question by mmj · May 31, 2013 at 04:50 PM · shadertexturetexture-atlas

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"
 }
Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image fanchois · Oct 27, 2014 at 09:05 AM 0
Share

hey! I have been searching for such a thing for a long time! did you manage to solve your problem?

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

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

Answers Answers and Comments

15 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

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


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges