Is it possible to access the dimensions of a texture in a shader?

I’m trying to make a screen space shader that renders a texture which keeps always its natural size, regardless of the screen resolution or aspect ratio. That would mean the bigger the resolution the more times the texture would repeat. I would also like it to work for whatever texture, maybe even one provided by the user, so hard coding the actual picture dimensions wouldn’t work, although that’s what I’m doing right now.

Is there any way to access them? The code so far is like this:

float2 screenUV = IN.screenPos.xy / IN.screenPos.w;
screenUV *= float2(_ScreenParams.x/[[Texture.Width]],_ScreenParams.y/[[Texture.Height]]);


look at Special Texture properties:

Texture size

{TextureName}_TexelSize - a float4 property contains texture size information:

x contains 1.0/width
y contains 1.0/height
z contains width
w contains height


For example, if a shader contains texture named _MainTex, the size information will be in a _MainTex_TexelSize vector.

_MainTex_TexelSize.z //contains width
_MainTex_TexelSize.w //contains height