Texture offset via property block (Resolved)

Hi guys, How do you set the texture offset via property block on URP. I do below on standard and it works but not on URP Lit. I am thinking the ID is wrong but can’t seem to find the correct one. Any ideas?

            private int mainTex = Shader.PropertyToID("_MainTex_ST");
            private MaterialPropertyBlock materialPropertyBlock;
            private Vector4 mainTexVector = new Vector4(1, 1, 0, 0);

        
            private void Animate()
            {
                targetRend.GetPropertyBlock(materialPropertyBlock);
             
                mainTexVector.w += Time.deltaTime * speed * animationSpeedScale;
                mainTexVector.w %= 1;
                materialPropertyBlock.SetVector(mainTex, mainTexVector);
                targetRend.SetPropertyBlock(materialPropertyBlock);
            }

The SRP batcher does not support MaterialPropertyBlock. I wonder if it will be supported in the future.
For now, you might want to try setting the property directly to the material.

Oh, I forgot. “_MainTex” is also not the main texture property for the main texture for URP Lit.

It should be “_BaseMap_ST” instead of “_MainTex_ST” for all URP shaders

1 Like

MaterialPropertyBlock definitely DOES works in URP. It was the key that was wrong and “_BaseMap_ST” works wonderfully. Thank you very much for the help!!

Do you know where this information is located? I could not find it, although it is possible I was looking at the wrong place. Thanks again.

Unfortunately, URP still suffers from lack of documentation. In order to get the property names that are being used, you need to dig into the shader code itself.

It does work in URP but material blocks are not supported by SRP Batcher.

What does this mean? Does it mean it still does it without using blocks, as in no performance benefit to doing it this way? Sorry, I am pretty new to shaders.

This is SRP Batcher.

What is useful about the SRP Batcher is that you can maintain draw call batching among different materials if the same shader (state) is being used.
Traditional Unity draw call batching requires you to maintain the renderers utilize the same material.
When you use material property blocks, batching is broken even under the traditional batching unless instancing is being used.

Because of how the internals of the SRP Batcher works, it conflicts with the instancing mechanism for batching material property blocks. So under URP when property blocks are used, batching is broken.

2 Likes