Is there a way to get textureSize?

Return to “ZGameEditor Visualizer Script Reference”

[You can only see part of this thread as you are not logged in to the forums]
revisualizer
Thu Jun 06, 2024 2:36 am

x

Is there a way to get textureSize?

Is there a way to get the texture size from within shader code?

Using textureSize() calls in shader code in ZGE results in blank textures. It seems it's just not implemented. Same with iChannelResolution[], which is understandable given it's assuming an array of textures. But textureSize() seems feasible if it could be implemented or is implemented somehow.

EDIT: A bit of background. I'm working on a dither effect implemented as a shader. It can use ZGE's Img Src texture as a dither pattern but I need to get the texture's size, otherwise the user would need to specify a size, which is inconvenient since the user won't easily know the size or be able to set it appropriately.

In case it helps, the working shader is unlisted on shadertoy:
https://www.shadertoy.com/view/43VGR1

Kjell
Mon Oct 21, 2024 5:42 pm

x

Re: Is there a way to get textureSize?

revisualizer wrote:Using textureSize() calls in shader code in ZGE results in blank textures. It seems it's just not implemented.
The textureSize() function is part of the GLSL specification, so it should be available as long as your GPU supports it.

+ Just gave it a quick try for posterity:

Image

revisualizer
Tue Oct 22, 2024 10:57 pm

x

Re: Is there a way to get textureSize?

Thanks for looking into this Kjell.

I'm actually trying to use Image Src so the user can utilize any pattern they want for the dither effect. Does ZGE support getting textureSize from an Image Src bitmap?

To clarify, the Image Src parameter:
textureSize.png
And the code where it's failing:
textureSize-iChannel1.png
The textures are defined like so:

Code: Select all

<Textures>
    <MaterialTexture Name="FeedbackMaterialTexture" TexCoords="1"/>
    <MaterialTexture Name="Source1" Texture="Bitmap1"/>
</Textures>
And iChannel0 and iChannel1 are defined in the shader like so:

Code: Select all

uniform sampler2D tex1;
uniform sampler2D tex2;
#define iChannel0 tex1
#define iChannel1 tex2
The code fails at the textureSize() call:

Code: Select all

if (ZGEimgSrc > 0.0) {
    ivec2 ts = textureSize(tex1, 0);
    s = float(ts.x);
}
So maybe it's not possible to call textureSize() for Image Src?
You do not have the required permissions to view the files attached to this post.

Kjell
Wed Oct 23, 2024 8:22 am

x

Re: Is there a way to get textureSize?

revisualizer wrote:
Tue Oct 22, 2024 10:57 pm
Does ZGE support getting textureSize from an Image Src bitmap?
Yup, that's supported. Just to make sure i gave it a try in ZGameEditor Visualizer .. works fine on my end:

Image

revisualizer
Sat Nov 02, 2024 5:11 pm

x

Re: Is there a way to get textureSize?

Thanks so much for your help Kjell, once again.

I was so confused, I asked Claude.ai about it after providing the shader code and Claude mentioned it likely has to do with the glsl version. I changed it from #version 120 to #version 130 and it worked!

Thanks again for your help! Back to trying to get this batch of shaders released.

Kjell
Sat Nov 02, 2024 8:20 pm

x

Re: Is there a way to get textureSize?

revisualizer wrote:
Sat Nov 02, 2024 5:11 pm
I changed it from #version 120 to #version 130 and it worked!
Good to hear :) As listed near the bottom of the GLSL specification page, textureSize() is supported from GLSL version 1.30 onwards.

Image


Return to “ZGameEditor Visualizer Script Reference”