Hi,
In the material inspector for each texture it shows XY tiling and XY offset fields.
-
To set that tiling field of a texture in code, is this the same as Material.SetTextureScale? If not, what/how does this work in a shader? Or is it only an editor preview setting?
-
How can I access the tiling property in a Shaderlab shader?
-
If tiling isn’t available at all, is the best way to set it as a property in the shader?
Thanks,
Brett
Check the UnityCG.cginc include file, there is a function there like follows:
TRANSFORM_TEX(tex,name) (tex.xy * name##_ST.xy + name##_ST.zw)
and that is how you use the tiling and offset properties.
Note that if you want to use that, you have to define your samplers like follows
_MainTex
_MainTex_ST
@Aubergine, thanks for your note.
Can I use UnityCG.cginc in Shaderlab fixed function shaders? I need to target PowerVR MBX fixed function and I thought pure Shaderlab was my only choice and that CG doesn’t work at all for this?
Thanks!
MBX devices only support fixed function shaders, so no Cg or GLSL. What are you trying to accomplish? Perhaps there is another way.
@Daniel, Thanks for your post.
Yeah, so I’m trying to figure out what could be done using the fixed function shaders with regards to texture coordinate manipulation. I was under the assumption that fixed function shaders require fixed UV coords in uv and uv2 and they can’t be manipulated at all in a fixed function shader, is that correct?
And I was also wondering if the scaling value of the material translates to the tiling values? And if so, how does this effect the texture coords sent to the shader?
Cheers
In fixed function shaders, the transformation of UV coordinates by texture tiling and offset values happens automatically. All you have to do is specify which UV set is used for each texture stage with BindChannels. Without BindChannels, all texture stages will use the first UV set.
ST stands for Scale and Translate. Scaling and tiling are arithmetic synonyms. Translation, offset and bias are arithmetic synonyms.