Team Spartan Cookies & Milk Forums
  • Issue Tracker
  • Donations
  • Search
  • Member List
  • Help

Register

Team Spartan Cookies & Milk Forums Garry's Mod Starfall v
« Previous 1 2 3 4 5 6 … 18 Next »
UV issue in drawTexturedRect
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Linear Mode
UV issue in drawTexturedRect
11-07-2020, 11:03 PM, (This post was last modified: 12-07-2020, 05:55 AM by Tomeno. Edited 2 times in total.)
#1
Tomeno Offline
TSCM Member
***
Posts: 10
Threads: 3
Joined: Jul 2020
UV issue in drawTexturedRect
There's some sort of an issue with DrawTexturedRect and co. where UV coordinated of 0,0 aren't the same as 1,1 and so on on looping materials. Some sort of a transform seems to be applied, and 1 in UV coordinates doesn't actually correspond to 1 width/height of the texture. Based on some pixel counting and testing on a reliable 512x512 texture, the actually used starting UV seems to be shifted by 8 pixels down and right with the end UV being shifted up and left by 8 pixels.

UV position test case:

local last = nil
local function UVIssueShowcase(x,y,w,h)
local offset = math.floor(time.curTime()) % 3
if offset ~= last then last = offset print(offset) end
render.drawTexturedRectUV(x, y, w, h, offset, offset, 1 + offset, 1 + offset)
end

local texture = render.getTextureID("spacebuild/hazard2")
hook( "render", "render", function()
render.clear()
render.setTexture(texture)
render.setColor(255, 255, 255, 255)
UVIssueShowcase(0,0,512,512)
end)

It seems that StarfallEx has some code to deal with this bug.
https://github.com/thegrb93/StarfallEx/b....lua#L1094

Applying this "UVHack" to the test case seems to work, except that starting UVs are clamped to 0, so the starting position ends up being zoomed in.

local function UVHack(x,y,w,h,startU,startV,endU,endV)
startU = ( startU * 32 - 0.5 ) / 31
startV = ( startV * 32 - 0.5 ) / 31
endU = ( endU * 32 - 0.5 ) / 31
endV = ( endV * 32 - 0.5 ) / 31
render.drawTexturedRectUV(x,y,w,h,startU,startV,endU,endV)
end

local last = nil
local function UVIssueShowcase(x,y,w,h)
local offset = math.floor(time.curTime()) % 3
if offset ~= last then last = offset print(offset) end
--render.drawTexturedRectUV(x, y, w, h, offset, offset, 1 + offset, 1 + offset)
UVHack(x, y, w, h, offset, offset, 1 + offset, 1 + offset)
end

local texture = render.getTextureID("spacebuild/hazard2")
hook( "render", "render", function()
render.clear()
render.setTexture(texture)
render.setColor(255, 255, 255, 255)
UVIssueShowcase(0,0,512,512)
end)
Find
Reply
« Next Oldest | Next Newest »


Messages In This Thread
UV issue in drawTexturedRect - by Tomeno - 11-07-2020, 11:03 PM
RE: UV issue in drawTexturedRect - by Person8880 - 12-07-2020, 09:53 AM
RE: UV issue in drawTexturedRect - by Tomeno - 12-07-2020, 10:13 AM
RE: UV issue in drawTexturedRect - by Person8880 - 12-07-2020, 10:39 AM
RE: UV issue in drawTexturedRect - by Tomeno - 12-07-2020, 10:43 AM
RE: UV issue in drawTexturedRect - by Person8880 - 12-07-2020, 10:48 AM
RE: UV issue in drawTexturedRect - by Tomeno - 12-07-2020, 10:53 AM
RE: UV issue in drawTexturedRect - by Person8880 - 12-07-2020, 11:08 AM
RE: UV issue in drawTexturedRect - by Tomeno - 12-07-2020, 01:22 PM
RE: UV issue in drawTexturedRect - by Person8880 - 12-07-2020, 01:35 PM
RE: UV issue in drawTexturedRect - by Tomeno - 12-07-2020, 02:04 PM
RE: UV issue in drawTexturedRect - by Person8880 - 12-07-2020, 02:19 PM
RE: UV issue in drawTexturedRect - by Tomeno - 12-07-2020, 02:48 PM
RE: UV issue in drawTexturedRect - by Person8880 - 12-07-2020, 02:51 PM

  • View a Printable Version
Forum Jump:


Users browsing this thread: 1 Guest(s)
Contact UsTeam Spartan Cookies & MilkReturn to TopLite (Archive) ModeMark all forums readRSS Syndication

Powered By MyBB, © 2002-2026 MyBB Group.