fast python scripts

my best blend:

destroyer (vertex management)
/uploads/default/original/4X/6/3/0/63034c117e43c768f99ff5d534f1c25fd439582d.blendd=1329083857

artillery trajectory (math)
/uploads/default/original/3X/f/6/f6aa76bd4b07bf965a953d816a12487cc3e4035a.blendd=1331053740

AI (python,class)
/uploads/default/original/3X/4/b/4bbca2ebde12844b50b1cff8eba2bbf1e491abe3.blendd=1336539303


# IMPUT KEYBOARD
"""
0= key not press
1= key just press
2= key press
3= key release

list of key:
print(dir(bge.events))
ONEKEY TWOKEY WKEY DKEY PAD1 PAD8
SPACEKEY LEFTSHIFTKEY LEFTCTRLKEY (...)
code example->
"""



import bge

c=bge.logic.getCurrentController()
ob=c.owner
key=bge.logic.keyboard.events


if key[bge.events.UPARROWKEY]==2:
    ob.applyMovement([+1,0,0],1)

if key[bge.events.PAD2]      ==2:
    ob.applyMovement([-1,0,0],1)



# IMPUT MOUSE
"""
0= button not press
1= button just press
2= button press
3= button release

list of button:
print(dir(bge.events))
LEFTMOUSE MIDDLEMOUSE RIGHTMOUSE
WHEELUPMOUSE WHEELDOWNMOUSE
code example->
"""



import bge

c=bge.logic.getCurrentController()
ob=c.owner
mou=bge.logic.mouse.events


if mou[bge.events.WHEELUPMOUSE]  ==2:
    ob.applyMovement([+1,0,0],1)

if mou[bge.events.WHEELDOWNMOUSE]==2:
    ob.applyMovement([-1,0,0],1)
    

check the power of your CPU
what the number of loop without LAG ?(60 time at second)
MY PC->number of loop = 250981


def testCPU():
    from time import time as TIM
    timeTotal   =   0
    n           =   1000
    while timeTotal < 0.016:
        n = int(n*1.1)
        timeA = float(TIM())
        for i in range(n):
            if 2+2 != 4: 
                print("O_O")
                return
        timeB               =   float(TIM())
        timeTotal           =   timeB-timeA
    print("number of loop   =", n)
    print("time amount      =", timeTotal)
    
testCPU()

SUPER SHORT SCRIPT

nearTarget(by agoose77)


obs = scene.objects
targets = sorted([i for i in obs if "enemy" in i], key=lambda o : own.getDistanceTo(o))
if len(targets) > 0 :
    target = targets[0]

mouselook with tap:


import bge

def mslk(cont):
    own = cont.owner
    x   = 0.5-bge.logic.mouse.position[0]
    y   = 0.5-bge.logic.mouse.position[1]
    
    if not "init" in own:
        own["init"]=1
        x, y = 0, 0
        
    if abs(x)>0.001:  own.applyRotation((0, 0, x), 0)    

    if abs(y)>0.001:
        zz = own.worldOrientation[2][2]
        if   zz > -0.9 and y>0:  own.applyRotation((y, 0, 0), 1)
        elif zz < +0.9 and y<0:  own.applyRotation((y, 0, 0), 1)
            
            
    bge.logic.mouse.position = 0.5, 0.5

wsad



import bge

def wsad(cont) :
    own = cont.owner
    
    key=bge.logic.keyboard.events
    llv = own.localLinearVelocity

    if   key[ord("w")]:   llv[1] =  5
    elif key[ord("s")]:   llv[1] = -2
    if   key[ord("a")]:   own.applyRotation((0, 0, +0.1), 1)
    elif key[ord("d")]:   own.applyRotation((0, 0, -0.1), 1)


----- magic vector -----

----- magic quaternion -----

----- COLLISION FOR NOCOLLISION OBJ -----

ok, update , this is very well done

collision obj/obj between children/parent
that simulate (or try) a obj dynamic (without rotation…no rigid body)
with a mesh

still a little error with low speed, when the sphere is on the edge , and know also where is the error.
as FPS not there confront with bullet (10 time more slow,more noticeable with big mesh)
lack totally a real optimization

the good part is which is extremely easy to use , this script must run on the sphere obj(the children)
while the mesh target is(on default) the parent.

why make all this mess?
because the “static-bug” give very annoyng and the physic constraints is full of bug.



import bge
from mathutils import geometry as geo ,Matrix


class ClassCollisionMesh(object):
    def __init__(self,own, meshCollision, radius=1.0, bounce=0.5, margin=2.0):
        self.owner      = own
        self.velocity   = own.worldPosition * 0
        self.radius = radius
        self.bounce = bounce
        self.margin = margin  
        
        
        try:
            self.target = meshCollision
            mesh = self.target.meshes[0]
        except:
            self.mapMesh = None
            print( "wrong something")
            own.endObject()
            return
        
        
        tar=self.target 
        D={}
        trisList=[]
        for face in range(mesh.numPolygons):
            
            def Mapping(vertexOrder):
                L=[]
                for vertexFace in vertexOrder: 
                    vertID   = mesh.getPolygon(face).getVertexIndex(vertexFace)
                    vertPos  = mesh.getVertex(0,vertID).getXYZ()
                    L.append( vertPos.copy() )
                trisList.append(L)
                    
            trisOrQuad = mesh.getPolygon(face).getNumVertex()
            if   trisOrQuad==3: Mapping((0,1,2))
            elif trisOrQuad==4: 
                Mapping((0,1,2))
                Mapping((0,2,3))
                
        triN = -1
        for tri in trisList:
            triN += 1
            
            a,b,c = tri
            
            
            # decompose triangle
            mab = (a-b).magnitude
            mbc = (b-c).magnitude
            mca = (c-a).magnitude
            if   mab >= max(mbc,mca): tri = a, b, c
            elif mbc >= max(mca,mab): tri = b, c, a
            elif mca >= max(mab,mbc): tri = c, a, b
            
            
            
            faceDir = geo.normal(a,b,c)
            mAB, mBC, mCA = (a+b)/2, (b+c)/2, (c+a)/2
            n = faceDir
            cAB,cBC,cCA = n.cross((b-a).normalized()), n.cross((c-b).normalized()), n.cross((a-c).normalized())
            tot = ((a-b).magnitude + (b-c).magnitude + (c-a).magnitude)*10
            
            
            
            
            def MaxDistance(point):
                dA=(point- a).magnitude
                dB=(point- b).magnitude
                dC=(point- c).magnitude
                return max(dA,dB,dC)
            
            def SetSensor(var):
                L=[]
                L.append(var)
                L.append(MaxDistance(var))
                sensorList.append(L)
            
            
            intersect = geo.intersect_line_line(mBC,mBC+cBC, mCA,mCA+cCA)[0]
            M = Matrix().to_3x3()
            vx = (b-a).normalized()
            vz = n
            vy = n.cross(vx)
            M.col[0]=vx
            M.col[1]=vy
            M.col[2]=vz
            intLoc = (intersect - a) * M
            if intLoc.y>0:
                faceCenter = intersect
            else:
                faceCenter = mAB
            
            sensorList=[]
            
            v = faceCenter;                              SetSensor(v)#center
            v = faceCenter  - (faceDir * (tot));         SetSensor(v)#sensDW
            v = faceCenter  + (faceDir * (tot+margin));  SetSensor(v)#sensUP
            v = mAB         + (cAB           *  tot);    SetSensor(v)#sensEdge
            v = mBC         + (cBC           *  tot);    SetSensor(v)#sensEdge
            v = mCA         + (cCA           *  tot);    SetSensor(v)#sensEdge
            
            D[triN]={
                    "vertex"    : (a,b,c),
                    "faceDir"   : faceDir,
                    "faceCenter": faceCenter,
                    "sensors"   : sensorList, 
                    }
                    
        self.mapMesh = D
        return
    
    
    
    
    
    def Update(self):
        
        if self.target.invalid: #or not "mapMesh" in dir(self):
            self.owner.endObject()
            return
        
        
        #################################
        def Globaldraw(pointList, refWP, refWO):
            for i in range(len(pointList)-1):
                p0 = refWP + refWO * pointList[i]
                p1 = refWP + refWO * pointList[i+1]
                bge.render.drawLine(p0, p1, [1,0,0])
            
            
        mesh    = self.target
        meshWP  = mesh.worldPosition
        meshWO  = mesh.worldOrientation
        radius  = self.radius
        bounce  = self.bounce
        
        velocity     = self.velocity * 0.9999999
        velocity[2] -= 0.016
        WP           = self.owner.worldPosition + velocity
        
        
        OLP = (WP - meshWP) * meshWO
        
        
        for triN in self.mapMesh:
            check = 1
            tri = self.mapMesh[triN]
            for s in tri["sensors"]:
                dist = (s[0]-OLP).magnitude
                if dist > (s[1] + radius):
                    check = 0
                    break
        
            if check == 1 :
                faceNormal = meshWO * tri["faceDir"]
                oldDir = velocity.normalized()
                newVel = velocity.reflect(faceNormal)
                newDir = newVel.normalized()
                dirDif = ((newDir-oldDir).magnitude)/2
                bounce2  = 1-(dirDif*(1-bounce))
                velocity = newVel*bounce2#2*bounce
                
                draw=bge.render.drawLine
                a,b,c= tri["vertex"]
                faceCenter,faceDir=tri["faceCenter"],tri["faceDir"]
                
                ########
                Globaldraw((a,b,c,a), meshWP, meshWO)
                Globaldraw((faceCenter,faceCenter+faceDir*10), meshWP, meshWO)
       
                break
            
        self.velocity = velocity
        self.owner.worldPosition += velocity
        
        



def main(cont):
    own = cont.owner
    
    if not "init" in own:
        own["init"]=1 ####################( own, meshCollision, radius=1.0, bounce=0.5, margin=2.0)
        own["ClassCollisionMesh"]=ClassCollisionMesh(own ,own.parent)
        own.removeParent()
        return
        
    own["ClassCollisionMesh"].Update()


Attachments

trigono13.blend (233 KB)

DOCUMENTATION LACK…

own.playAction(“action”, framestart, frameend, layer=0, priority=0, blendin=0, play_mode=bge.logic.KX_ACTION_MODE_LOOP, layer_weight=0.0, ipo_flags=0, speed=1.0)

update: :D, short version(you can use also a number instead of KX… bla blah!)


own.playAction("action", framestart, frameend, play_mode=2)

– MESH HELPER –

joint all vertex joint as single vertex
and use global coordinate read/write

notes:
1 - use the position to know if a vertex is joint ( can be inaccurate… )
2 - not keep in count the material, so work only for a mesh with one single material
3 - vertex.worldPosition not work exactly as should …vertex.worldPosition.x+= 0.5 not work


from mathutils import Vector
import random


class MegaVertex:
    def __init__(self, mesh, pos, verts):
        self.mesh = mesh
        self._position = Vector(pos)
        self.verts = verts
    
    @property
    def position(self):
        return self._position
    
    @position.setter
    def position(self, vec):
        for i in self.verts:
            i.XYZ = Vector(vec)
        self._position = Vector(vec)
    
    @property
    def worldPosition(self):
        return Vector(self.mesh.worldTransform * self._position)
    
    @worldPosition.setter
    def worldPosition(self, vec):
        pos = Vector(self.mesh.worldTransform.inverted() * vec)
        for i in self.verts:
            i.XYZ = pos
        self._position = pos
        
        
        


class Mesh:
    def __init__(self, meshObject):
        self.meshObject = meshObject
        
        mesh = self.meshObject.meshes[0]
        D = {}
        for vN in range(mesh.getVertexArrayLength(0)):
            vertex = mesh.getVertex(0, vN)
            vPos = tuple(vertex.XYZ)
            if not vPos in D:
                D[vPos] = []
            D[vPos].append(vertex)
        
        self.vertsJoint = D #not used
        
        self.megaVerts = []
        for i in D:
            meshOwner, position, verts = meshObject, Vector(i), D[i]
            self.megaVerts.append(MegaVertex(meshOwner, position, verts))
        
        
        
        
        
def main(cont):
    own = cont.owner
    if not "Mesh" in own:
        own["Mesh"] = Mesh(own)
        
    
    otherObject = own.scene.objects["Sphere"]
    mesh = own["Mesh"]
    
    if own.getDistanceTo(otherObject) < 15:
        for mv in mesh.megaVerts:
            dist, vec, vec2 = otherObject.getVectTo(mv.worldPosition)
            if dist < 10.0:
                mv.worldPosition +=  vec * 0.08

  • UV stuff -
    change the UV of the mesh by rayCast() from a camera obj (the script must run from a camera obj)
    (mesh must have material ,texture and a property “menu”)

import bge

cont = bge.logic.getCurrentController()

own = cont.owner

sens = cont.sensors
MLB = sens["mlb"] 
MRB = sens["mrb"]
if MLB.status == 1 or MRB.status == 1 :
    
    x, y = bge.logic.mouse.position
    vec = own.getScreenVect(x,y) * -1
    
    p1 = own.worldPosition
    p2 = p1 + vec
    #         rayCast(objto, objfrom, dist, prop,   face, xray, poly)
    ray = own.rayCast(p2,    p1,      100,  "menu", 1,    1,    5)
    
    
    poly = ray[3] 
    
    
    if ray[0] != None :
        
    
        mesh = ray[0].meshes[0]
        
        
        polyId = poly
        L=[]
        for i in range( polyId.getNumVertex() ):
            vN = polyId.getVertexIndex( i )
            v = mesh.getVertex( 0, vN )
            L.append(v)
        
        if MLB.positive : uv = 0.1, 0.1 #move the texture in the left place (invisible)
        if MRB.positive : uv = 0.9, 0.9 #move the texture in the right place (visible)
        
        
        for v in L:
            v.v, v.u = uv

Attachments

menu.blend (248 KB)

AUTO RIGGED … hair system (amazing)

this required all my skill with python and matrices, this joint rigidBody chain on an armature empty!

later i guess post also one blend , for now post the script
really avesome :smiley:


import bge
from mathutils import Matrix,Quaternion,Vector


def main(cont):
    own = cont.owner
    
    if not "init" in own:
        if not "initTimer" in own:
            own["initTimer"]=0
        own["initTimer"]+=1
        if own["initTimer"]<10:
            return
        
        own["init"] = 1
        own["bones"] = []
        bMaster = [i for i in own.channels if "SSS" in i.name]
        meshStatic = [i for i in own.children if "headCollision" in i][0]
        armWT = own.worldTransform.copy()
        scene=bge.logic.getCurrentScene()
        obs=scene.objects
        
        def setCs(bone, ob2, pivotPos=True):
            new = scene.addObject("din",own)
            new["reference"] = ob2
            new.worldTransform = armWT * bone.arm_mat
            if pivotPos == True :
                x,y,z = (new.worldTransform.inverted() * ob2.worldTransform).translation
            else :
                x,y,z = 0.0, 0.0, 0.0
            cs = bge.constraints.createConstraint(new.getPhysicsId(),ob2.getPhysicsId(),12,x,y,z,0,0,0,128)
            v = 0.2
            cs.setParam(3, -v, v)
            cs.setParam(4,  0,0)
            cs.setParam(5, -v, v)
            own["bones"].append(list((own.channels[str(bone)], new)))
            return new
        
        for i in bMaster :
            b = i.bone
            old = setCs(b, meshStatic, False)
            while b.children :
                b = b.children[0]
                old = setCs(b, old)
    
    armWT = own.worldTransform
    for i in own["bones"] :
        b, target = i
        TQL = (armWT.inverted() * target.worldTransform).to_quaternion()
        b.rotation_quaternion   = Quaternion(b.rotation_quaternion) * b.pose_matrix.to_quaternion().rotation_difference(TQL)
                
        
        
        
def hair(cont) :
    own=cont.owner
    if own["reference"].invalid:
        own.endObject()

BASIC PYTHON GAME

movement for character(python)
WSAD+JUMP

  • FRICTION(on X)
  • ACCELLERATION
  • MAXSPEED

Attachments

FiniteMovementMachine.blend (61.6 KB)

– CRAZY PATH –




""" on the right track.... """


D = {
    0:[0,1],
    1:[1,0,2,3],
    2:[2,1],
    3:[3,1],
    }
    
DD = {}


for key in D:
    pats = [[key]]
    n = 1
    while n == 1 :
        n = 0
        for path in pats:
            for nn in D[path[-1]]:
                if not nn in path:
                    n=1
                    pt = path.copy();pt.append(nn);pats.append(pt)
            if n == 1:
                pats.remove(path)
                break
    DD[key] = pats
    
DD


…FINALLY…(…or almost)


def get_path(start, end):
    if start == end:
        return [start, end]
    paths_old = [[start]]
    paths_new = [[]]
    marked = set()
    marked.add(start)
    while paths_new:
        paths_new = []
        for path_old in paths_old:
            c = path_old[-1]
            for nc in c.nears:
                if not nc in marked:
                    path_new = path_old+[nc]
                    marked.add(nc)
                    paths_new.append(path_new)
                if nc == end:
                    return path_old+[nc]
        paths_old = paths_new
    return []


class Cell:
    def __init__(self):
        self.nears = []

c1,c2,c3 = Cell(),Cell(),Cell()
c1.nears.append(c2)
c2.nears.append(c1)
path = get_path(c1,c2)
path = get_path(c1,c3)

-MOUSELOOOOKss-

– MOUSELLOK (ONLY WHEEL) –


"""
CAMERA VOYAGER
for explore big environment


how use it : move mouse + WHEEL press to move, tunr wheel for zoom, move mouse for turn
setup : sensors always (with True Pulse) + controller[module]


9-4-2013
blender 2.64a
"""




ROT_VEL = 0.0001  # speed or rotation
MOV_VEL = 0.0001 # speed of movement 




import bge
from mathutils import Vector


def main(cont):
    own = cont.owner
    
    
    if own is not bge.logic.getCurrentScene().active_camera:
        return
    
    if not "init" in own :
        own["init"] = 1
        own["vel"] = Vector()
        own["rotX"]=0.0
        own["rotY"]=0.0
        bge.logic.mouse.position = 0.5, 0.5
        return
    
    
    w, h = bge.render.getWindowWidth(), bge.render.getWindowHeight()
    xn, yn = bge.logic.mouse.position
    x, y = (0.5-xn) * w, (0.5-yn) * h
    
    ev = bge.events
    mouEv = bge.logic.mouse.events
    
    if max(abs(x), abs(y)) > 0.6 :
        if mouEv[ev.MIDDLEMOUSE] :  
            own["vel"].xy += Vector((-x * MOV_VEL, y * MOV_VEL))
            if   mouEv[ev.MIDDLEMOUSE] == 3: 
                bge.logic.mouse.position = 0.5, 0.5
        
        else:
            bge.logic.mouse.position = 0.5, 0.5
            own["rotX"] += x * ROT_VEL
            own["rotY"] += y * ROT_VEL
            
            
            
    if   mouEv[ev.WHEELUPMOUSE]   :  own["vel"].z  -= MOV_VEL * 2000 # zoom IN
    elif mouEv[ev.WHEELDOWNMOUSE] :  own["vel"].z  += MOV_VEL * 2000 # zoom OUT
    
    own.applyMovement(own["vel"], 1)
    own["vel"] *= 0.96
    
    own.applyRotation((0, 0, own["rotX"]), 0)
    own.applyRotation((own["rotY"], 0, 0), 1)
    own["rotX"] *= 0.96
    own["rotY"] *= 0.96

— CRAP – (above :D)

MOUSELOOK AS BLENDEREDIT - ORBITING


import bge, mathutils


class MouseLookAsBlenderEdit:
    def __init__(self, cam):
        self.MAT = mathutils.Matrix; self.GEO = mathutils.geometry; self.owner = cam; self.ROT_SPEED = 2.2; self.ZOM_SPEED = 0.1; self.mouse = bge.logic.mouse; self.ev = bge.events; self.dist = 10.0; self.focusOri = self.wo.copy(); self.focusPos = self.wp - self.wo.col[2] * self.dist; self.mouseXY = 0.5, 0.5
    @property
    def wp(self): return self.owner.worldPosition
    @property
    def wo(self): return self.owner.worldOrientation
    def update(s):
        mou = s.mouse.events; ev = s.ev; mlb, mmb, mwup, mwdw = mou[ev.LEFTMOUSE], mou[ev.MIDDLEMOUSE], mou[ev.WHEELUPMOUSE],  mou[ev.WHEELDOWNMOUSE]
        if   mmb and mmb == 1   : s.focusOri = s.wo.copy(); s.focusPos = s.wp - s.wo.col[2] * s.dist; s.mouseXY = s.mouse.position
        elif mmb and mmb != 1   : x0, y0 = s.mouseXY; x, y = s.mouse.position; x, y = x-x0, y-y0; rot = s.MAT.Rotation; m3 = rot(-x * s.ROT_SPEED, 3, "Z") * s.focusOri * rot(-y * s.ROT_SPEED, 3, "X"); s.owner.worldOrientation = m3; s.owner.worldPosition = s.focusPos + m3.col[2] * s.dist
        elif mwup               : s.dist *= 1.0 - s.ZOM_SPEED; s.owner.worldPosition = s.focusPos + s.wo.col[2] * s.dist
        elif mwdw               : s.dist *= 1.0 + s.ZOM_SPEED; s.owner.worldPosition = s.focusPos + s.wo.col[2] * s.dist
        elif mlb == 1           : x, y = s.mouse.position; plane_co = s.wp - s.wo.col[2] * s.dist; plane_no = s.wo.col[2]; s.focusPos = s.GEO.intersect_line_plane(s.wp, s.wp + s.owner.getScreenVect(x, y)*-1, plane_co, plane_no); s.owner.worldPosition = s.focusPos + plane_no * s.dist
        
def main(cont):
    own = cont.owner
    if own.scene.active_camera != own : return
    if not "MouseLookAsBlenderEdit" in own: bge.render.showMouse(1); own.worldOrientation = own.worldOrientation.col[2].to_track_quat("Z","Y"); own["MouseLookAsBlenderEdit"] = MouseLookAsBlenderEdit(own) 
    own["MouseLookAsBlenderEdit"].update()


    

– MOUSELOOK FPS –
more complex than expected


"""
writtten by MarcoIT 4/7/2013
blender version 2.65
otherObject is the obj that turn left - right 
usually the parent , but can be parent.parent in a character
"""


import bge


CAP = 0.5
SENS = 0.002


class MouseLook_FPS:
    def __init__(self, cam, otherObject=None):
        self.cam = cam
        par = cam.parent; cam.removeParent(); cam.setParent(par) # clean the matrices bugged 
        if not otherObject:
            otherObject = cam.parent
        self.otherObject = otherObject
        self.xStart = cam.localOrientation.to_euler()[0]
        self.x = 0.0
        bge.logic.mouse.position = 0.5, 0.5
    
    def update(self):
        w = bge.render.getWindowWidth()  // 2
        h = bge.render.getWindowHeight() // 2
        x, y = bge.logic.mouse.position
        mx = int((0.5 - x) * w) * SENS
        my = int((0.5 - y) * h) * SENS
        if mx or my:
            self.x += my
            self.x  = min(max(self.x, -CAP), CAP)
            self.cam.localOrientation = self.x + self.xStart, 0.0, 0.0
            self.otherObject.applyRotation((0, 0, mx), 0)
            bge.render.setMousePosition(w, h)
            
            
def mouseLook_FPS(cont):
    own = cont.owner
    
    if not "MouseLook_FPS" in own:
        own["MouseLook_FPS"] = MouseLook_FPS(own, own.parent)
        return
    
    own["MouseLook_FPS"].update()
    

– GAMEOBJECT EXTENSION –
(function that mantain the same standard of other function that already exist in KX_GameObject)

torqueTo(otherObj, factor) ##=> really should be “torqeAs()” i guess
forceTo(otherObj, factor)


"""written by MarcoIT 15/7/2013 ......feel free to use""" 




import bge
from mathutils import Vector
from bge.logic import getCurrentController




def torqueTo(ob2 , force=50.0):
    ob1 = getCurrentController().owner
    m1  = ob1.worldOrientation
    m2  = ob2.worldOrientation
    dif = Vector((m2 * m1.inverted()).to_euler())
    ob1.applyTorque(dif * force, 0)
    
def forceTo(ob2, force=50.0) :
    ob1 = getCurrentController().owner
    p1  = ob1.worldPosition
    p2  = ob2.worldPosition
    dif = p2 - p1
    ob1.applyForce(dif * force, 0)
    




def main(cont):
    own = cont.owner
    target = own.scene.objects["hook1"]
    forceTo(target,  150.0)
    torqueTo(target, 150.0)
    

blend below

Attachments

torqueTo.blend (263 KB)

  • MATRIX HELPER -
    play with the cube to see in real time how work matrices
    (see blend for control):wink:MatrixHelper.blend (101 KB)

Attachments


------2D FILTER-----


//TOONS/CEELS-SHADING ( tanks to superflip and someother )


uniform sampler2D bgl_RenderedTexture;
uniform sampler2D bgl_DepthTexture;
void main()
{
   float depth = texture2D( bgl_DepthTexture, gl_TexCoord[0].xy).r;
   float depth2 = texture2D( bgl_DepthTexture, gl_TexCoord[0].xy + vec2(0,0.002)).r;
   float depth3 = texture2D( bgl_DepthTexture, gl_TexCoord[0].xy + vec2(0.002,0)).r;
   
   float fac = abs(depth-depth2) + abs(depth-depth3);
   
   float intensity = 1000;
   vec4 sub = vec4( fac*intensity,  fac*intensity,  fac*intensity, 0);
   
   gl_FragColor = texture2D( bgl_RenderedTexture, gl_TexCoord[0].xy ) - sub;
}




//CHANGE FLOAT INTENSITY FOR LINE THICKNESS

…empty…

…empty…

…empty…

…empty