- Home /
How to get correct UV's for second texture in a sprite shader
I made a modified version of the default sprite shader. I added another texture input and I'm blending them together using various parameters. The blending works fine but the UV's of the second sprite do not. They are both in the same sprite atlas.. however only the default sprite comes in with correct UV's. The extra texture has UV's that are somewhere else...
the main sprite gets UV's from here... OUT.texcoord = IN.texcoord; Where do I get UV's for the second texture from please? using the same UV's does not work.
Isn't there a way to read texcoord based on which sampler or texture you are using ?
tried doing this... found from super old 2009 post... OUT.texcoord = TRANSFORM_TEX(IN.texcoord, _MainTex); but that results in shader compiler error.... (in unity 5.6) " undeclared identifier '_MainTex_ST' "
any help appreciated, thanks.
Answer by JonPQ · Dec 05, 2017 at 05:17 PM
Found some info that might help others with similar issues.... this gets me part way there..... In your shader, you can define this variables... and info will magically appear...
//tiling info For example, if a shader contains texture named _MainTex,
//...the tiling information will be in a _MainTex_ST vector.
//x contains X tiling value
//y contains Y tiling value
//z contains X offset value
//w contains Y offset value
//texture size info... {TextureName}_TexelSize - a float4 property contains texture size information:
// xxxxx_TexelSize where xxxx if the texture input
//x contains 1.0 / width
//y contains 1.0 / height
//z contains width
//w contains height
Your answer
Follow this Question
Related Questions
Basic surface shader question ... 0 Answers
Using stencil buffer as form of zwrite? 0 Answers
Custom Shader makes sprite darker (unintended side effect) 1 Answer
CustomRenderTexture ignores "ComputeScreenPos" 1 Answer
Allow 2D sprite to receive light from any direction and show on both sides 0 Answers