I wanna learn from this bge .blend file (CC-BY license :
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
How can I get GLSL to work?
Or alternatively: how can I get cartoony black outlines in BGE? Freestyle doesnāt seem to work.
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;
}
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 (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).
@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!
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.
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.
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ā¦
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 improve performance?
Again, thanks everybody for your support. Much appreciated. Dunno howād Iād fix this myself.
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
@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).
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.
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!
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.
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?