Why Won't This GLSL .blend Game Work?

Hi,

I wanna learn from this bge .blend file (CC-BY license :slight_smile: :

But when I simulate it, the objects are completely white.
I tried changing the viewport (e.g. texture or solid), and both the embedded and standalone game players, with no luck.

I noticed that GLSL in general never seems to work on my computer.

Andā€¦ GLSL seems unfriendly for noobs to learn :expressionless:

How can I get GLSL to work?

Or alternatively: how can I get cartoony black outlines in BGE? Freestyle doesnā€™t seem to work.

Credits to http://www.blendswap.com/user/BsDev
P.S. BsDevā€™s recent activity dates back to 2014. I figure ppl here are more active.

Outline Filter.blend (582 KB)

are you in textured view?

Yeah. Still just white. Does it work for u?

P.s. i have integrated graphics on a cheap laptop, if thatā€™s relevant. Once tried updating stuff on OpenGLā€™s site, but that site was confusingā€¦

The shader work for me.

Do you have a error message in the console? (When you are on windows you can open it in the blender menu ā€œWindow/Toggle system consoleā€)

Maybe it is a driver problem. Do you have the last graphic driver installed? It would be good to know what graphic chip your laptop have.

By coincidence I was just working on something like this today. Is this something like what you want?


GLSL is not easy becouse the documentation for the BGE specifics is hard to find, and worse since you donā€™t have python wrappers most of the time you have to guess the correct values of the uniforms. But no worry! This is solved on my UPBGEā€™s Community Addon, where by the way the filter is included and can be easy activated with a button.

As for the filter itself, if you donā€™t want to use my addon, here is the code (of course you bind the appropiate uniforms as object properties):


/**
 * Toon Lines 2 shader by Robert Planas (elmeunick9)
 * Based on Toon Lines 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 brightness; // = 1.0;
uniform float mode; // = 1;
uniform float threshold; // = 0.2;
uniform vec4  border_color; // = Vec4(0.0);

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

    /* Detect border */
    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));

    /*Line Color & Smooth*/
    float intensity = 0.2;
    float alpha = 0.0;
    
    float cho;
    if (mode)    cho = (3-border.r-border.g-border.b)/3;
    else        cho = (border.r > threshold || border.g > threshold || border.b > threshold) ? 0.0 : 1.0;
    
    vec3 cLine = mix(border_color.rgb, texcol.rgb, alpha + border_color.a);
    vec3 cElse = texcol.rgb * vec3(brightness);
    
    gl_FragColor.rgb = mix(cLine, cElse, cho);
    gl_FragColor.a = 1.0;
}

Thanks for your replies, people!

So far, problems with either using python, or UPBGE + Community Addon.

@Maujoe
CPU-Z says I have IntelĀ® HD Graphics.

A program from Intel says I have the latest drivers.

I attached my console errors (see last two screenshots, plz. Theyā€™re in reverse order, sry). Dunno what they mean!

@elmeunick9
Yes! Your ā€œDefaultā€ pic is exactly what I wanna do! (Alt pic looks cool, too).

But UPBGE wonā€™t let me start a new game project :frowning: (see 1st screenshot, plz). I tried uninstalling both normal and UPBGE blenders, and then reinstalling UPBGE only, but no luck.

Once I get UPBGE working, looks like Iā€™ll use class core.glsl.ToonLine(**kw).

Attachments




Try this: go to the menu -> help -> save system info. Also in the first image you are on a flat shading, switch to meterial.

the console error cannot convert const int to float, refers to the 300 on this line


float intensity = 300; // syntax error
float intensity = 300.0; // use this

Thanks everybody for your support!

@guramarx
Thanks! Now I see the outlines!
But the colours arenā€™t showing
(using materials, texture, or whatever doesnā€™t work,
not even in the standalone player).

But at least I can add a 3rd-person camera! :slight_smile:
But so slowā€¦ And the lines are pixelated. Hmmā€¦

This might be a long learning journey.

@Akira_San
Thanks! And here I was, using 5x subsurface modifierā€¦
Smooth shading renders so much faster!
P.S. the yellow sphere now has hair.

EDIT: Attached pdf of system info for UPBGE no-new-game-project issue.

P.S. This user pref & console screenshot might be relevant to the new-game-project issue.

I noticed the user pref message when installing community add-on.

Attachments


system-info for UPBGE failing to start new game project.pdf (42.3 KB)

You have OGL 2.1. And for the errors the upbge devs have to see them, so you could ask them. You could switch between 2.78a and upbge for comparison.
Try this file: https://drive.google.com/file/d/0B6yNvVGWiWysV0pvb2N4YlJTclE/view Its a cell shaded anime char.

@sdhy

That was a bug I introduced on one of the previous builds (just after adding the ToneLine effetct). It is bug on the build system, the files werenā€™t packed correctly so the installation fails (and the addon canā€™t find the correct files when creating a new game). Should be fixed now.

Try downloading the addon again, but before you install it go to: %appdata%/Blender Foundation/Blender/2.78 and delete it, it will clean you UPBGE of any addon thatā€™s not build-in.

Sorry for the inconvenience.

P.S: You can use the 2D Filter menu when using the addon if you only want to test them, changing uniforms on realtime and so on will requiere Python but if itā€™s just for testing the UIList is fine:


PS2: Iā€™m adding documentation for the game project menu, the export options, and the packge internals. Hopefully if I make a bug like this again reading the documentation people will know how to work arround it.

UPBGE has modernized the code (both C++ and OpenGL Shaders), that means Blender will not work properly on old GPUs anymore. Upgrade your computer or get an older version of regular Blenderā€¦

Thanks for the support everybody.

UPBGE + community addon works now (thanks, elmeunick9)
But the default project wonā€™t simulate, not even if I wait 15 minutes. My laptopā€™s too slow.
(Yeah, youā€™re right, TwisterGE. I should upgrade).

Can any skills I apply to normal BGE be used for UPBGE and vice versa?
Iā€™m guessing yes, unless itā€™s using some kind of UPBGE-only feature.

@Akira_San
The .blend file works!
But itā€™s 1.5 fps,
and it lags my computer a lot.
Yet CPU and RAM usage are very low.
Does this mean the game-simulation is burdening my integrated graphics?
i.e. add dedicated GPU to my buy-list?

Is it possible / practical if I smoothen the toon-lines in the future?
At least it looks cartoony, though!

@anyone
Will turning off toon-lines :frowning: improve performance?

Again, thanks everybody for your support. Much appreciated. Dunno howā€™d Iā€™d fix this myself.

@sdhy

The same blend runs at 80fps on my laptop, all thanks to the AMD driver.
The default project of the addon may contain some 2DFilters enabled by default, at what fps does it run with them removed?
That aside, you definitively need an integrated graphics card to play modern 3D games, can you play those on your computer?

By the way, the toon-line on the Community addon does smooth the lines. You can disable that by changing the ā€œmodeā€ to 0.

Ops, my mistake. The blend file is from a non-bge file. Its an example of toon shading + toon edge filter. The subsurf modifier need to be removed. Modifiers should be removed for the bge.
Try this: https://drive.google.com/open?id=0B6yNvVGWiWysTk04U2h6MnFqMlU

The old one works on UPBGE, not as well as it should, but works nonetheless.

@elmeunick9
The default project had no 2Dfilters on by default.
I tried turning off all shading,
and then doing full render baking
But the simulation still wouldnā€™t start in UPBGE.
It works under normal blender, though, but the toon-line filter wonā€™t show.

@Akira_San
The new .blend didnā€™t change fps
But I did notice that fps is a little faster when I use the embedded player.
Funky green coloured clothes. haha.

A blender game from this forum worked:

  • Yo Frankie (tho one level lagged a bit)
    ā€¦ Otherwise havenā€™t played games in a while. (yet I wanna make one. Ha.)

Iā€™m thinking of buying a thunderbolt 3 laptop, and an eGPU enclosure (when I really need it).

And for now, Iā€™ll focus on making animation only,
and on making the actual game
(Iā€™ll worry about toon shading later).

Again, thanks for your support!

@sdhy

Are you using MAC? There arenā€™t any MAC devolopers for UPBGE that I know, your errors could be becouse of the lack of testing. If you try the shader code I posted, without using the addon, on normal BGE, it should work, at wich speed I donā€™t know.

In any case if you are gonna make games, consider buying a Windows Machine, wich should also be cheaper by the way.

@elmeunick9

No, Iā€™m not using Mac. Iā€™m using Windows 7.
(though a long time ago, I had Mac and thus was missing out on a lot).

I pasted your code into a text in game logic mode
and then made sure the comments were actually comments
(by using #'s. So the actual code starts at uniform sampler2Dā€¦).

But thereā€™s no toon lines when I run the simulation.

(Do I have to rename something in the code?)

Thanks again for your support and your timely responses!

@sdhy

Comments in C,C++ and GLSL are done with ā€œ//ā€ (line) or ā€œ/""/ā€ (paragraph). If youā€™re using ā€œ#ā€ like in Python it should not compile, if it does then thatā€™s some wierd hack the BF did there. Usually ā€œ#ā€ in C/C++/GLSL means ā€œMACROā€ wich for the most part you should not worry about it but remeber that it is executable code, e.j: ā€œ#define VAR 10ā€ means that any place in the code where thereā€™s ā€œVARā€ will be replaced by ā€œ10ā€ before compiling.

If you are ever gonna try implementing another shader, you must know that uniforms need to be initialized or otherwise they are initialized to 0 by default. The initialization (~= aka binding) can be done in multiple ways, the most common in BGE is create a game property with the name of the uniform and itā€™s value. So, for example:

uniform float brightness; // = 1.0;

Means that you need to create a game property named ā€œbrightnessā€ of float type with the value 1.0. In this shader the only exception is the border_color uniform, wich is of type vec4 and you donā€™t have that type in the UI of object properties. It should not be a problem since its default value is already 0 (black), but if you want to change it you will need Python.

However, you may not need all of that since it seems the problem you had with UPBGE has been solved (download it from here): https://blenderartists.org/forum/showthread.php?387752-A-new-fork-of-the-engine/page43. Also the Community Addon uses UPBGE 1.0 wich should not have that bug (hopefully), you can try that too as a last resource.

P.S: Iā€™ve seen shaders compile with uniforms initialized like this ā€œuniform float variable = 1.0;ā€. If it works, it would be easier than creating the game properties. You can also modify that into ā€œconst float variable = 1.0;ā€ wich should work too.

P.S: The syntax coloring of the BF Blender text editor only works for Python, even if you input normal text or GLSL, maybe thatā€™s why you were confused with the comments?