-
Notifications
You must be signed in to change notification settings - Fork 58
Description
Details
IMAGE_FORMAT_RGBA16161616F doesn't return the values you would expect from render.ReadPixel.
In my specific case, I am trying to generate a displacement map from an image. (There isn't a way to bind a vertex texture to a shader, so I am forced to return data to the CPU to generate a mesh. rubatplsfix)
The values returned are integers ranging from 0-255, but it would be nice for the more precise formats to return a float, or at the very least the full information of that specific pixel. (For parity, you can still return the 0-255 range, but allow decimal values. So a return could look like 50.25 100.5 150.75)
Steps to reproduce
local rt = GetRenderTargetEx("test_rt", 3, 3, 0, 2, 1, 0, IMAGE_FORMAT_RGBA16161616F)
local clear_mat = CreateMaterial("clear_mat", "UnlitGeneric", {
["$basetexture"] = "lights/white",
["$color2"] = "[0.12345 3.1415 2.7182]",
["$ignorez"] = 1,
["$linearwrite"] = 1
}) -- cant use render.Clear
render.PushRenderTarget(rt)
cam.Start2D()
-- clear to our precise color
render.SetMaterial(clear_mat)
render.DrawBox(Vector(), Angle(), Vector(0, 0, 1), Vector(3, 3, 1))
render.CapturePixels()
cam.End2D()
render.PopRenderTarget()
print(render.ReadPixel(1, 1)) -- sample in centerYou can check the rendertarget with mat_texture_list 1. It should be a very vibrant cyan blue
Ideally, this would print something consistent. You would expect this to return 31 255 255 or 0.12345 3.1415 2.7182 but for me it returns 111 110 116 (omitting alpha channel)
IMAGE_FORMAT_RGBA16161616 does appear to be pretty consistent, although the data is heavily truncated.
(65536 possible color values -> 256 possible color values). Fixing this would be nice too
Version of the game
Protocol version 24
Network version 2025.03.26 (garrysmod)
Exe build: 15:00:14 Dec 3 2025 (9888) (4000)
GMod version 2025.12.03, branch: x86-64, multicore: 1
Windows 64bit
Beta
x86-64 beta