surface.DrawTexturedRect UVs are off?

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

[img_thumb]http://i.imgur.com/s0dz3Xb.jpg[/img_thumb]

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

[img_thumb]http://i.imgur.com/wXTid5P.jpg[/img_thumb]

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

Here’s my test material for reference.
[img_thumb]https://dl.dropboxusercontent.com/u/72472980/test2.png[/img_thumb]

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.

Global.Material

Take a look at the parameters

[editline]30th January 2016[/editline]

https://developer.valvesoftware.com/wiki/Category:List_of_Shader_Parameters 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
[lua]
return CreateMaterial( name, “UnlitGeneric”, {
[ “$nolod” ] = 1,
[ “$ignorez” ] = 1,
[ “$vertexcolor” ] = 1,
[ “$vertexalpha” ] = 1
} )
[/lua]

[editline]30th January 2016[/editline]

$basetexturetransform?

[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.

bump

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.

[img_thumb]http://i.imgur.com/ughvBSY.jpg[/img_thumb]

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


function ENT:Draw()

	self:DrawModel()

	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
	cam.Start3D2D(Pos,ang,0.0604)

		surface.SetDrawColor(255,255,255)
		surface.SetMaterial(Material("shit.png"))
		surface.DrawTexturedRect(100,100,1024,1024)
	cam.End3D2D()

end

Texture:

http://i.imgur.com/s7J3S8i.png[/t]

Result:
[t]http://i.imgur.com/nTXJcvO.jpg

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.

[lua]
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)
tex:Download()

hook.Add(“HUDPaint”,“test”,function()

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

end)
[/lua]

[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.