-
-
Notifications
You must be signed in to change notification settings - Fork 21.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Shader isampler2D
and usampler2D
incorrect encoding
#69880
Comments
What are you doing to create the texture? Samplers tell the shader how to read data, they don't tell the engine how the data is stored, you do that when you create the image. |
I do this, as in the reproduction project: func _ready():
var texture_data = PackedByteArray()
texture_data.resize(1024 * 600)
texture_data.fill(127)
var test_image = Image.create_from_data(1024, 600, false, Image.FORMAT_R8, texture_data)
var test_texture = ImageTexture.create_from_image(test_image)
material.set_shader_parameter("tex", test_texture) This means I am filling the image with the integer value
Sorry, I don't find a way to express it better in English, but this is what the shader should do (one possibility):
The value should stay |
Duplicate of #57841 ? |
Godot version
3.5 stable, 4.0 beta8
System information
Linux Vulkan, GLES3
Issue description
Similar to this issue: https://stackoverflow.com/questions/67479596/cant-read-a-format-r8-uniform-sampler2d-texture-correctly-from-within-a-shader
isampler2D
andusampler2D
is supposed to bind uniforms in integer format, but the actual format is float.Expected behavior:
If an input image has format
RGB8
, expect shader using uniformusampler2D
to read each channel with range0-255
integers.Actual behavior:
Value read is encoded as normalized 32-bit float with range
0.0-1.0
but read as integers, producing nonsense values. This behavior is identical tosampler2D
(with the unnecessary normalization and encoding), and incorrect decoding.Hack to work around:
Use
uintBitsToFloat
then multiply by 255. This does not guarantee precision.Steps to reproduce
Check the reproduction project, written for Godot 4.0 beta 8. Similar things happen to Godot 3.5 or possibly earlier.
Test.tscn
Test.gd
initializes texture toR8
format, filled127
Test.gdshader
readsisampler2D
0.5
Minimal reproduction project
sampler_bug.zip
The text was updated successfully, but these errors were encountered: