How to get the dimensions of an Image passed to a shader?

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
User avatar
Sir_Silver
Party member
Posts: 286
Joined: Mon Aug 22, 2016 2:25 pm
Contact:

How to get the dimensions of an Image passed to a shader?

Post by Sir_Silver »

Code: Select all

vec4 effect(vec4 color, Image texture, vec2 texture_coords, vec2 screen_coords)
{
    vec4 texturecolor = Texel(texture, texture_coords);
    return texturecolor * color;
}
In the example above, an Image is passed to the effect shader, I'm trying to figure out how I can get the dimensions of that texture without passing them to the shader as an extern. I'm pretty new to shaders so please go easy on me. Also, any information regarding shaders and how to use them in love would be nice too!

Also, are there any special things I should know about the Image data type, I really want to learn anything you guys have to teach! =)
User avatar
raidho36
Party member
Posts: 2063
Joined: Mon Jun 17, 2013 12:00 pm

Re: How to get the dimensions of an Image passed to a shader?

Post by raidho36 »

Code: Select all

ivec2 textureSize ( sampler2D )
Note that unless you use dedicated texture for each sprite (as opposed to sprite sheets and atlases) it's pretty useless. And you shouldn't care about exact dimensions, either.
MasterLee
Party member
Posts: 141
Joined: Tue Mar 07, 2017 4:03 pm
Contact:

Re: How to get the dimensions of an Image passed to a shader?

Post by MasterLee »

love2d uses GLSL 1.20, but textureSize is only available at version 1.30 and above.
Also texelFetch is only available in version 1.30.
Post Reply

Who is online

Users browsing this forum: No registered users and 77 guests