gl_TexCoord[0] deprecated on BGE 2.78?

gl_TexCoord[0] used to work at 2.76. I then decided to update the BGE of my game project to 2.78 and behold, glsl 4.0 changed a lot, so it no longer have gl_TexCoord[0] among other things.

Long ago I had this custom cartoon outline filter I had some work to adapt, since gl_TexCoord[0] no longer works I cannot do an initial texture2D(bgl_RenderedTexture, texcoord), thus the rest of the code no longer works. As always I looked up a lot on the internet but all I saw was “oh, now you have to pass the texture coordinates from the vertex shader to the fragment shader”, the thing is the 2D Filter controller seems to be just for fragment shaders. It is rare, but I am having some trouble with this issue even after researching.

I had a backup plan of using shader.setSource() on the objects I wanted the outline, but I do not believe it would work, as many outline shaders operate on the entire screen not on single objects. Also, I do not believe I could render all the desired objects colored as normals, render an outline based on that and apply to another render (a normal one) to only then display on BGE either.

Duplicate animated objects, so one is bigger and black and the other the normal one was never an option.

I would really appreciate help regarding this.

Here is a toon shader that I use for the post processing addon, it works in 2.78c. Might be useful as a reference.

/** * Toon Lines shader by Jose I. Romero (cyborg_ar)
 *
 * Based on blender's built-in "prewitt" filter which is free software
 * released under the terms of the GNU General Public License version 2
 * 
 * The original code is (c) Blender Foundation.
 */
uniform sampler2D bgl_RenderedTexture;
uniform vec2 bgl_TextureCoordinateOffset[9];


uniform float line_size;


void main(void)
{
    vec4 sample[9];
    vec4 border;
    vec4 texcol = texture2D(bgl_RenderedTexture, gl_TexCoord[0].st);


    for (int i = 0; i < 9; i++)
    {
        sample[i] = texture2D(bgl_RenderedTexture, 
                              gl_TexCoord[0].st + bgl_TextureCoordinateOffset[i]);
    }


    vec4 horizEdge = sample[2] + sample[5] + sample[8] -
                     (sample[0] + sample[3] + sample[6]);


    vec4 vertEdge = sample[0] + sample[1] + sample[2] -
                    (sample[6] + sample[7] + sample[8]);


    border.rgb = sqrt((horizEdge.rgb * horizEdge.rgb) + 
                            (vertEdge.rgb * vertEdge.rgb));


       if (border.r > (1.0-line_size)||border.g > (1.0-line_size)||border.b > (1.0-line_size)){
        gl_FragColor.r = 0.0;
        gl_FragColor.g = 0.0;
        gl_FragColor.b = 0.0;
        gl_FragColor.a = 1.0;
    }else{
        gl_FragColor.rgb = texcol.rgb;
        gl_FragColor.a = 1.0;
    }
}

Thanks for helping out Thatimster :wink:

Actually I got my fragment shader working after taking a look the one you presented. For that I had to at my original fragment shader:
1 - Not setting the glsl version to 400, not setting it, or set it to 120. (#version 120)
2 - Strangely the following no longer worked (main error)

abs(colDifForce) > (sample[4] * baseThresh) / near ? gl_FragColor = vec4(vec3(texcol * edgeForce), 1.0) : gl_FragColor = vec4(texcol);

but now only the following does:

if (abs(colDifForce) > (sample[4] * baseThresh) / near){
gl_FragColor = vec4(vec3(texcol * edgeForce), 1.0);
}else{
gl_FragColor = vec4(texcol);
}

As the code content is the same, what is going on with number 1 since it worked before and now it does not? Searching in the web such problem at another software, it was a bug. :confused:

The compiler will compile them to the same, and the second is much clearer what is going on. Why would you use the first?

Sorry, that wasn’t very useful. It probably should work.

Good night sdfgeoff,

The compiler will compile them to the same, and the second is much clearer what is going on.

If both options should compile the same (because as I said before the content is the same), then the issue is the compiler? Because as I said, the first option no longer works(which means it did before), my game freezes and closes, but option 2 works. Not sure if this is a platform problem, because I do not recall having it on Linux Opensuse, currently I stopped using Linux and am using windows 10, but again, I changed from BGE 2.76 to 2.78 too.

Why would you use the first

I thought using the first would give a small improvement either in execution speed or file size/shader loading time, but using as reference your opinion, perhaps it does not matter. If it does not matter, then I will keep option 2 because of readibility as you said (which I value too if it does not interfere with other things).

Sorry, that wasn’t very useful. It probably should work.

I must apologize, but I did understood well this part (perhaps my english is getting worse after learning japanese :confused:). If you meant not useful in clarifying why option 1 no longer works while option 2 works; then do not worry, I am already happy because you granted me your time by commenting. Also, by probably work you mean option 1? If yes, it did not as I said before.

My original issue was already solved with the help of Thatimster, but what was the nature of the game crashing problem with option 1 is still not clear.