- Home /
shader MainTex.width ?
hi...
I'm trying to make a Shader ....
all that I need , to split the Main texture to two parts( as mask )
example : sampler2D MainTex;
sampler2D FirstHalf; sampler2D SecondHalf;
MainTex contain the main texture
FirstHalf = from 0 to MainTex.width/2
SecondHalf = from MainTex.width/2 to end of the texture ( 1 )
how can I do that ??
thank you
that's what I want to do
the shader i use has two textures, one for the normal image and other for the alpha image , i need to put them at the same image
Answer by Jessespike · Jun 16, 2015 at 08:25 PM
Calculate the UV.
float4 FirstHalf = tex2D(_MainTex, i.uv.xy * float2(0.5, 1) );
thank you so much , but how can I get the second half ?
it's hard to write a shader , specially there's no autocomplete :(
second half is the same thing, but has an offset.
float2 uv1 = i.uv.xy * (_$$anonymous$$ainTex_ST.xy * float2(0.5, 1)) + _$$anonymous$$ainTex_ST.zw;
float2 uv2 = i.uv.xy * (_$$anonymous$$ainTex_ST.xy * float2(0.5, 1)) + _$$anonymous$$ainTex_ST.zw + float2(0.5, 0);
On a separate note, if I were writing this shader, I would keep the two textures separate and they would both use the same UV coords. I presume the idea of the combined texture was to optimize for performance, but I don't think there is any benefit. There are still two texture samplers being called, only difference now is the combined texture stores half the data that a separate texture can. Which might cause artifacts and reduced visual quality, depending how it's being used.