GLSL Nearest filter?

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
retrotails
Party member
Posts: 212
Joined: Wed Apr 18, 2012 12:37 am

GLSL Nearest filter?

Post by retrotails »

So just to do it, I started a tile renderer in GLSL. Problem is, the filtering fucks everything up. I tried

Code: Select all

texture2D(map, floor((pixel_coords)/size)/size)
it's the closest I could get but it's still blurry before scaling it up with a broken nearest filter.
At the moment, it just adds color to the fragment so I can just test if I can scale up with a nearest neighbor filter.
I'd much rather send a table, but that seems difficult from what I've read.
User avatar
monsieur_h
Citizen
Posts: 65
Joined: Tue Oct 30, 2012 4:43 pm

Re: GLSL Nearest filter?

Post by monsieur_h »

Your .love doesn't seem to work. I get an error on line 1365 "cannot compile shader".

Details are:

Code: Select all

Line 10: implicit cast from float to vec2
line 11: implicit cast from vec4 to vec3
User avatar
retrotails
Party member
Posts: 212
Joined: Wed Apr 18, 2012 12:37 am

Re: GLSL Nearest filter?

Post by retrotails »

monsieur_h wrote:Your .love doesn't seem to work. I get an error on line 1365 "cannot compile shader".

Details are:

Code: Select all

Line 10: implicit cast from float to vec2
line 11: implicit cast from vec4 to vec3
Odd, works for me. But thanks for posting the error, could be related.
edit: I see, your card apparently can't convert one vector to another. I can fix the first issue but I don't know how to fix the second.
User avatar
Boolsheet
Inner party member
Posts: 780
Joined: Wed Dec 29, 2010 4:57 am
Location: Switzerland

Re: GLSL Nearest filter?

Post by Boolsheet »

It's actually GLSL 1.2 that doesn't specify such implicit casts. Only int to float is allowed, I think. Your driver is more lenient and lets it go by.

Can't you use the .rgb (or .xyz, they're identical) swizzler for the second texture2D call too?
Shallow indentations.
User avatar
retrotails
Party member
Posts: 212
Joined: Wed Apr 18, 2012 12:37 am

Re: GLSL Nearest filter?

Post by retrotails »

Boolsheet wrote:It's actually GLSL 1.2 that doesn't specify such implicit casts. Only int to float is allowed, I think. Your driver is more lenient and lets it go by.

Can't you use the .rgb (or .xyz, they're identical) swizzler for the second texture2D call too?
Ah, so vec3(0,0,0) + 1 doesn't equal vec3(1,1,1), I have to say vec3(0,0,0) + vec3(1,1,1) to be correct?
If so many people can't play like anything with shaders I've made.
I could add the .xyz, but I wasn't sure if that'd fix it since I have no way of testing for it.
By the way, does the video driver compile shaders?

edit: While this topic is up, why does this spit out

Code: Select all

Line 16: error: Undeclared Identifier: col
I'm just trying this shader as a test to see if I can get conditionals working at ALL.

Code: Select all

[[
            uniform sampler2D tex0;
            vec4 effect(vec4 color, Image texture, vec2 texture_coords, vec2 pixel_coords)
            {
                vec2 uv = vec2(
                    texture_coords.x,
                    1 - texture_coords.y
                );
                if (1 == 1) {
                    vec4 col = vec4(0,0,0,1);
                } else {
                    vec4 col = vec4(1,0,0,1);
                }
             return vec4(col);
            }
        ]]
User avatar
Boolsheet
Inner party member
Posts: 780
Joined: Wed Dec 29, 2010 4:57 am
Location: Switzerland

Re: GLSL Nearest filter?

Post by Boolsheet »

GLSL 1.2 has special rules for arithmetic operators. See '5.9 Expressions' in the GLSL 1.2 specification. This part is relevant to your question:
One operand is a scalar, and the other is a vector or matrix. In this case, the scalar operation is
applied independently to each component of the vector or matrix, resulting in the same size vector
or matrix.
I can't find anything on type promoting, so I guess arithmetic with different size vectors (like vec4 + vec3) is invalid, but the drivers do it anyway.
retrotails wrote:By the way, does the video driver compile shaders?
Correct. You can assume that every vendor has their own compiler in their OpenGL implementation and they all have their own little quirks.

Regarding your new problem, it looks like you have some issues with the scope there. Your code would look like this in Lua.

Code: Select all

function effect()
    if (1 == 1) then
        local col = {0,0,0,1}
    else
        local col = {1,0,0,1}
    end
    return col
end
See the problem? Declare the vec4 variable above the if statement so the code inside it can assign the value to that.
Shallow indentations.
User avatar
retrotails
Party member
Posts: 212
Joined: Wed Apr 18, 2012 12:37 am

Re: GLSL Nearest filter?

Post by retrotails »

Boolsheet wrote: See the problem? Declare the vec4 variable above the if statement so the code inside it can assign the value to that.
Well it gives me some redefinition error. Fortunately I don't have to use a conditional anymore, I have some complex mod() do it instead.
User avatar
Boolsheet
Inner party member
Posts: 780
Joined: Wed Dec 29, 2010 4:57 am
Location: Switzerland

Re: GLSL Nearest filter?

Post by Boolsheet »

Here's what I hinted at in actual GLSL.

Code: Select all

vec4 col;
if (1 == 1) {
    col = vec4(0,0,0,1);
} else {
    col = vec4(1,0,0,1);
}
return col;
Shallow indentations.
Post Reply

Who is online

Users browsing this forum: No registered users and 230 guests