EDIT EDITI’m using a script for toonshading, but the way it works is that ALL the object I assign in the objlist MUST ALL be shown in the Current scene, so when only one of those object I want to be shaded is deleted from the scene or just not in the scene, all the other object stop being toon shaded. But with my NEW modified script I FINALY found a way!!! here’s the new toonshaders script:
from math import *
import GameLogic as g
scene = g.getCurrentScene()
own = g.getCurrentController().getOwner()
objlist = scene.getObjectList()
g.setLogicTicRate(60.0)
# -------------------------------------
ShaderObjects = objlist
MaterialIndexList = [0]
GlobalAmbient = [0.39,0.35,0.32,1]
AmbF = 0.5
# -------------------------------------
VertexShader = """
varying vec2 texCoords;
varying vec3 vNormal;
varying vec3 vVertex;
void main() {
gl_Position = ftransform();
vVertex = vec3(gl_ModelViewMatrix * gl_Vertex);
vNormal = normalize(gl_NormalMatrix * gl_Normal);
texCoords = gl_MultiTexCoord0.st;
}
"""
FragmentShader = """
varying vec2 texCoords;
varying vec3 vNormal;
varying vec3 vVertex;
uniform float silhouetteThreshold;
uniform sampler2D texture;
#define shininess 20.0
void main() {
//vec4 materialColor = gl_FrontMaterial.diffuse;
//vec4 materialColor = vec4(1.0,1.0,1.0,1.0);
//vec4 materialColor = gl_Color;
vec4 materialColor = texture2D(texture,texCoords);
vec4 silhouetteColor = vec4(0.0,0.0,0.0,1.0);
vec4 specularColor = gl_FrontMaterial.specular;
vec3 eyePos = normalize(-vVertex);
vec3 lightPos = gl_LightSource[0].position.xyz;
vec3 Normal = vNormal;
vec3 EyeVert = normalize(eyePos - vVertex);
vec3 LightVert = normalize(lightPos - vVertex);
vec3 EyeLight = normalize(LightVert+EyeVert);
float sil = max(dot(Normal,EyeVert), 0.0);
if(sil < silhouetteThreshold)
gl_FragColor = silhouetteColor;
else
{
gl_FragColor = materialColor;
float spec = pow(max(dot(Normal,EyeLight),0.0), shininess);
if(spec < 0.2)
gl_FragColor *= 0.98;
else
gl_FragColor = materialColor+specularColor*.5;
float diffuse = max(dot(Normal,LightVert),0.0);
if( diffuse < 0.5)
gl_FragColor *= 0.9;
}
}
"""
def MainLoop ():
# for each object
for obj in ShaderObjects:
mesh_index = 0
mesh = own.getMesh(mesh_index)
while mesh != None:
for mat in mesh.materials:
# regular TexFace materials do NOT have this function
if not hasattr(mat, "getMaterialIndex"):
return
mat_index = mat.getMaterialIndex()
# find an index
found = 0
for i in range(len(MaterialIndexList)):
if mat_index == MaterialIndexList[i]:
found=1
break
if not found: continue
shader = mat.getShader()
if shader != None:
if not shader.isValid():
shader.setSource(VertexShader, FragmentShader,1)
shader.setUniform1f('silhouetteThreshold',0.25)
shader.setSampler('texture',0)
mesh_index += 1
mesh = own.getMesh(mesh_index)
# -------------------------------------
MainLoop()
# -------------------------------------
now with this, you dont have to type all the object you want to be shaded with all the side effects like ‘‘if one is not in all is not toonshaded anymore’’
you just assign the script in the logic bricks of the object you want to be shaded and … TADAA!!! it works and work indepentently from other tonnshaded object