Passing Arbitrary INT data in a texture
Asked Answered
C

7

0

I'm trying to pass arbitrary int data to the shader by treating each of RGBA as an 8-bit int. I'm using these values as lookups into another texture. The results I've gotten so far give incorrect results, however, often performing lookups into an adjacent lookup instead.

I read that TexelFetch doesn't give correct results, here: https://github.com/godotengine/godot/issues/31732 So, I'm using the following workaround:

vec4 Get_Texel( sampler2D image, ivec2 position, int level_of_detail ) {
	vec2 texel = 1.0 / vec2(textureSize(image, 0));
	vec2 final_position = (vec2(position) * texel) + (texel * 0.5);
	return texture(image, final_position, float(level_of_detail));
}

Are there any existing solutions for seemlessly working with int arrays in shaders?

Concertante answered 23/12, 2021 at 1:7 Comment(0)
V
0

You have to make sure filtering is disabled, I think you do that by setting flags to 0.

Valentinevalentino answered 23/12, 2021 at 5:55 Comment(0)
M
0

Hasn't texelFetch's linear vs srgb problem been resolved?

Machinegun answered 23/12, 2021 at 15:39 Comment(0)
V
0

You can force sRGB by using hint_albedo:

uniform sampler2D lut : hint_albedo;

Without that I believe it should be linear.

Valentinevalentino answered 23/12, 2021 at 17:0 Comment(0)
C
0

@xyz said: Hasn't texelFetch's linear vs srgb problem been resolved?

The issue's still open on Github, and I'm still having problems getting my texture to display with the same value.

@cybereality said: You have to make sure filtering is disabled, I think you do that by setting flags to 0.

I've turned off filtering, but I was still having issues.

@cybereality said: You can force sRGB by using hint_albedo:

uniform sampler2D lut : hint_albedo;

Without that I believe it should be linear.

I've never seen the lut keyword before. I couldn't find it in the documentation: https://docs.godotengine.org/en/stable/tutorials/shading/shading_reference/shading_language.html What exactly does it do?

I'll be honest, I'm an artist, and not much up on the difference between sRGB and linear. I'm most familiar with Photoshop and hexcodes. Which do want if I want to be able to deal with color as if it were a hexcode?

The workaround I'm trying right now is to use the RGBAF format and place a number between 0.0-256.0 into it that the shader converts back into an int, which seems to work at the expense of bloating my texture 4 times over, but which I should have enough room for...

Concertante answered 24/12, 2021 at 17:38 Comment(0)
M
0

If you want to use texture pixels as data then texelFetch() from a linear texture is your best bet. sRGB applies gama transformation to the data, while texture() could have potential problems targeting exact pixels (due uv precision and filtering). I don't see any benefits in using float texture format over byte format.

'lut' was just an example uniform name.

Machinegun answered 24/12, 2021 at 18:28 Comment(0)
R
0

@Lake said: I've never seen the lut keyword before.

LUT or a LookUp Table. A fairly common term when it comes to computer graphics and color management, but not limited to only those.

Rimple answered 24/12, 2021 at 20:20 Comment(0)
V
0

Yeah, LUT is a look up table. But that is just a uniform variable, not a keyword. It can be anything you want.

Honestly, you should be able to get accurate enough results using texture. I've had no problems.

vec4 your_pixel = textureLod(your_sampler, your_uv, 0.0);
Valentinevalentino answered 24/12, 2021 at 22:40 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.