Skip to content
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

[linux + vulkan] using textureSize will create empty shader files #101

Closed
sh-dave opened this issue Apr 17, 2023 · 7 comments
Closed

[linux + vulkan] using textureSize will create empty shader files #101

sh-dave opened this issue Apr 17, 2023 · 7 comments

Comments

@sh-dave
Copy link

sh-dave commented Apr 17, 2023

When i use https://registry.khronos.org/OpenGL-Refpages/gl4/html/textureSize.xhtml in a shader, krafix writes a 0 bytes file but it shows no error.

#version 450

in vec2 f_uv;

uniform sampler2D u_msdf;
uniform vec4 u_background_color;
uniform vec4 u_foreground_color;
uniform float u_px_range;

out vec4 FragColor;

float median( float r, float g, float b ) {
	return max(min(r, g), min(max(r, g), b));
}

float screen_px_range() {
	// vec2 unit_range = vec2(u_px_range) / vec2(textureSize(u_msdf, 0));
        vec2 unit_range = vec2(1.0, 1.0);
	vec2 screen_tex_size = vec2(1.0) / fwidth(f_uv);
	return max(0.5 * dot(unit_range, screen_tex_size), 1.0);
}

void main() {
	vec3 msd = texture(u_msdf, f_uv).rgb;
	float sd = median(msd.r, msd.g, msd.b);
	float screen_px_distance = screen_px_range() * (sd - 0.5);
	float opacity = clamp(screen_px_distance + 0.5, 0.0, 1.0);
	FragColor = mix(u_background_color, u_foreground_color, opacity);
}
@RobDangerous
Copy link
Member

I can't reproduce that.

@RobDangerous
Copy link
Member

Oooh, it's commented out in your shader, sneaky.

@RobDangerous
Copy link
Member

Now I can reproduce it. But I can't reproduce it with


in vec2 texcoord;

out vec4 FragColor;

uniform sampler2D texsampler;

void main() {
	vec4 color = texture(texsampler, texcoord);
	FragColor = vec4(color.r, color.g, color.b * textureSize(texsampler, 0).x, 1.0);
}

So it might not actually be about textureSize.

@sh-dave
Copy link
Author

sh-dave commented Apr 17, 2023

Indeed, found an easier way. This will fail, but works when you change a to a vec2.

#version 450

in vec2 texcoord;

out vec4 FragColor;

uniform sampler2D texsampler;
uniform vec2 a; // works when this is vec2
uniform float b;

void main() {
	float foo = b;
	vec4 color = texture(texsampler, texcoord);
	FragColor = vec4(color.r, color.g, color.b * textureSize(texsampler, 0).x, 1.0);
}

@RobDangerous
Copy link
Member

But but but a is already a vec2.

@sh-dave
Copy link
Author

sh-dave commented Apr 17, 2023

Sorry, copied the wrong shader, make it a vec3 and it fails.

@RobDangerous
Copy link
Member

It was indeed completely unrelated to textureSize. Even unrelated to textures overall. It was about uniform alignment and by removing that one line you allowed the compiler to remove a uniform and thereby the problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants