- Home /
Is there an any way to use batching with UV tiling?
Hey. I will have a lot of object (1000+) in the scene with the same material but different tiling values. I have created a shader for it in the shader graph and assign a script with MaterialPropertyBlock to change tiling. Everything is working fine except the batching. Is there an any way to have 1 batch for 1000 objects with the same material but different tiling values? Thanks!
UPDATE: I have found this https://docs.unity3d.com/Manual/GPUInstancing.html? but have no idea how to right this type of shader with texture and tiling instead of color
Answer by ArtemAppside · Jan 11, 2021 at 10:56 AM
Guy with nickname fiveampsoftware shared with me this shader
Shader "Test/TestShader"
{
Properties
{
_MainTex ("MainTexture", 2D) = "white" {}
_MainScaleOffset ("Main Scale (XY) Offset (ZW)", Vector) = (1,1,0,0)
}
SubShader
{
Tags
{
"RenderType"="Opaque"
}
LOD 200
CGPROGRAM
#pragma surface surf Lambert
sampler2D _MainTex;
UNITY_INSTANCING_BUFFER_START(Props)
UNITY_DEFINE_INSTANCED_PROP(float4, _MainScaleOffset)
UNITY_INSTANCING_BUFFER_END(Props)
struct Input
{
float2 uv_MainTex;
};
void surf(Input IN, inout SurfaceOutput o)
{
float4 scaleOffset = UNITY_ACCESS_INSTANCED_PROP(Props, _MainScaleOffset);
float2 uv = IN.uv_MainTex * scaleOffset.xy + scaleOffset.zw;
o.Albedo = tex2D(_MainTex, uv).rgb;
}
ENDCG
}
FallBack "Mobile/Diffuse"
}
I have used GPU Instancing and this code
[SerializeField]
private Vector4 _size;
private MaterialPropertyBlock _myMatBlock;
void Start()
{
_myMatBlock = new MaterialPropertyBlock();
_myMatBlock.SetVector("_MainScaleOffset", new Vector4(_size.x,_size.y , _size.z, _size.w));
GetComponent<MeshRenderer>().SetPropertyBlock(_myMatBlock);
}
Your answer
![](https://koobas.hobune.stream/wayback/20220613022124im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Custom Shader with Canvas Renderer limit draw calls. 0 Answers
Polybrush Shaders 0 Answers
Manually z-sorting opaque geometry 1 Answer
Multiple Shaders vs. Single Texture - Please help me overthink this. 2 Answers
Shader: get back scene pixel color? 1 Answer