surface.DrawTexturedRect UVs are off?

If I do surface.DrawTexturedRect with my test material, I get this.


However, if I draw it with

surface.DrawTexturedRectUV with the UVs as -0.016, -0.016 and 0.016 and 0.016 (for my 1024x1024 texture) the result is this


Is there any way to fix this so that UVs aren’t offsetted?

Here’s my test material for reference.

Wait, aren’t the UVs meant to be between 0 and 1?

So, if you’re doing less than 0, won’t it always be off slightly?

It’s already off, but applying those UVs fixes it. I’m thinking maybe the UVs are offsetted internally in order to keep texture filtering from wrapping the texture around when one side of the texture is transparent and one side is opaque. Maybe I just need to rescale the texture so that there is a 1.6% size empty border.


Take a look at the parameters

[editline]30th January 2016[/editline] if it’s not a png

Yeah it’s not a png. Which shader parameter are you referring me to?

This is my current code
return CreateMaterial( name, “UnlitGeneric”, {
[ “$nolod” ] = 1,
[ “$ignorez” ] = 1,
[ “$vertexcolor” ] = 1,
[ “$vertexalpha” ] = 1
} )

[editline]30th January 2016[/editline]


[editline]30th January 2016[/editline]

I tried, lua_run_cl Material(“my_material”):SetMatrix("$basetexturetransform", Matrix({{0.7,0,0,0},{0,0.7,0,100},{0,0,0.7,0},{0,0,0,1}}))

But nothing happened

[editline]30th January 2016[/editline]

Also tried

lua_run_cl Material(“my_material”):SetString("$basetexturetransform", “center .5 .5 scale 1 1 rotate 0 translate 0 10”)

But also nothing

You have a space in “$basetexturetransform”
Also, try setting it in your CreateMerial call as a string like your second try (“center .5 .5 scale 1 1 rotate 0 translate 0 10”) also try $nocull

And don’t forget to set $basetextrure

(Also, if you’re using a vtf, put the above in your vmt to avoid the need for CreateMaterial)

I think facepunch always puts a space in certain places in a long sentence for some reason, it happened to me before (I think it’s a bug)

EDIT: Even if the sentence doesn’t actually have a space

There’s actually no space, idk why facepunch is doing that. The space doesn’t show when I try to edit it.

“center .5 .5 scale 1.032 1.032 rotate 0 translate 0 0”
Works inside the CreateMaterial function. Seems like a hack rather than a fix though.

I wonder what’s causing that… I’ll download your material and have a look soon.


Pretty sure that’s how it is supposed to look, you just can’t see the difference due to scale. Make the black border a red/lime green border and see the difference.

[editline]1st February 2016[/editline]

Rather not color, since i see 1px lines in your texture, but try this:

  1. completely white texture
  2. your texture

Make it rapidly alter between those two textures, and see the difference.

Solution: Make the lines on your texture thicker.

It’s not the scale causing the lines not to appear since I’m using anisotropic filtering. I can set the scale back to 1:1 and translate the UVs and I’ll be able to see them. The problem is that the lines are outside of the rectangle (due to texture bordering or however surface.drawTexturedRect handles its UVs).

[editline]31st January 2016[/editline]

Here it is with the UVs set to -0.014, -0.014, 1.014, 1.014. You can see the lines moving into the edge of the rectangle.


Here’s a 1024x1024 png drawn with this code:

function ENT:Draw()


	local ang = self:GetAngles()
	ang:RotateAroundAxis( ang:Right(), -90 )
	ang:RotateAroundAxis( ang:Up(), 0 )
	ang:RotateAroundAxis( ang:Forward(), 0 )
	local Pos = self:GetPos() + self:GetRight() * -15.5 + self:GetUp() * 15.5





If you don’t need help, then I will be on my way.

I ran your code and it does work.
Here’s a test that emulates my code.

local png = Material(“test2.png”,“unlitgeneric”)

local m = CreateMaterial( “TestTexture”, “UnlitGeneric”, {
[ “$nolod” ] = 1,
[ “$ignorez” ] = 1,
[ “$vertexcolor” ] = 1,
[ “$vertexalpha” ] = 1,
–[ “$basetexturetransform”] = “center .5 .5 scale 1.032 1.032 rotate 0 translate 0 0”
} )

local tex = png:GetTexture("$basetexture")
m:SetTexture("$basetexture", tex)


local scrw, scrh = ScrW(), ScrH()
surface.DrawTexturedRect(scrw/2-scrh/2, 0, scrh, scrh)


[editline]31st January 2016[/editline]

So something to do with creating the new material and setting the texture is causing this.

CreateMaterial probably isn’t configuring the texture border correctly.

If you are using a .vtf, what harm is there to making a .vmt and shipping it along with it?

The materials are generated dynamically using any in-game texture. I’ll leave the hack in for now, but hopefully it gets fixed. I’ll put it on github so it doesn’t get forgotten.

The correct question is why don’t you use the method I gave you, which works perfectly as you have confirmed?

Because I need unlitgeneric materials that can use any hl2 texture. Those materials don’t exist and must be created using CreateMaterial.