Ebiten: shader: Functions to get the texture size

Created on 5 Jul 2020  路  9Comments  路  Source: hajimehoshi/ebiten

Now the destination texture's size is retrieved from viewportSize, and we might rename this for consistency.

CC @kyeett

feature

Most helpful comment

Ebiten's image is a part of an internal texture atlas. In the shader's level, the texture atlases are 'textures'. I'm not confident using 'image' is correct in the shader layer. The notions of 'size' are different anyway.

In that case I would stick with texture.

All 9 comments

This would be useful

The tricky thing is that texture variables are different from regular variables in GLSL. You cannot define or use a local texture variable for example. Then, I'm thinking to define these functions (or global variables)

  • func destinationTextureSize() vec2
  • func source0TextureSize() vec2
  • func source1TextureSize() vec2
  • func source2TextureSize() vec2
  • func source3TextureSize() vec2
    ...

This is how it looks in shadertoy, if you want a reference

uniform vec3 iResolution;
uniform float iTime;
uniform float iTimeDelta;
uniform float iFrame;
uniform float iChannelTime[4];
uniform vec4 iMouse;
uniform vec4 iDate;
uniform float iSampleRate;
uniform vec3 iChannelResolution[4];
uniform samplerXX iChanneli;

Not sure how they map to the ebiten concepts
https://www.shadertoy.com/howto

Now Ebiten stopped to treat textures as a variable in order to avoid confusion.

Instead of texture2D, you have to call texture[N]At like texture0At. This name might be renamed later.

I think I'll add these functions:

  • textureDestinationInternalSize() // a.k.a. viewportSize() now
  • texture0InternalSize()
  • texture1InternalSize()
  • texture2InternalSize()
  • texture3InternalSize()

I adopted Internal because the size indicates the backend size of the images. For example, an image might be a part of a texture atlas. Even though an image is not on a texture atlas, the image might be a part of a bigger image, that size is power of 2.

For 'actual' sizes, users can pass them as uniform variables if necessary. I don't think there are use cases to use them though.

@kyeett @nanoslayer Any thoughts?

I'll omit 'Internal' since 'textures' are already internal things. Also, Destination seems verbose. Then

  • textureDstSize() // a.k.a. viewportSize() now
  • texture0Size()
  • texture1Size()
  • texture2Size()
  • texture3Size()

Maybe texture should be renamed to image? texture is fine, but image is more consistent with the rest of Ebiten. I guess texture is more universal, and makes sense in contexts other than Ebiten.

Maybe texture should be renamed to image?

Good point. Ebiten's image is a part of an internal texture atlas. In the shader's level, the texture atlases are 'textures'. I'm not confident using 'image' is correct in the shader layer. The notions of 'size' are different anyway. Let me think...

Ebiten's image is a part of an internal texture atlas. In the shader's level, the texture atlases are 'textures'. I'm not confident using 'image' is correct in the shader layer. The notions of 'size' are different anyway.

In that case I would stick with texture.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

hajimehoshi picture hajimehoshi  路  6Comments

cretz picture cretz  路  4Comments

joaowiciuk picture joaowiciuk  路  5Comments

hajimehoshi picture hajimehoshi  路  3Comments

hajimehoshi picture hajimehoshi  路  4Comments