Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Nein01

macrumors 6502
Original poster
Dec 1, 2009
307
1
Germany
Hopefully this is the right place for me to post this topic..

I can't get any custom 2d filter scripts to work in the blender game engine and it's driving me crazy. I need a toon outline filter for the game I'm working on. The uploader of this filter says it works fine on his windows machine.

I don't know if there could be a problem with the code as I don't know python, but the script is as follows and I've been told there is nothing wrong with it:

Code:
 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 = 300;

       vec4 sub = vec4(fac*intensity,fac*intensity,fac*intensity,0);
       
       gl_FragColor = texture2D( bgl_RenderedTexture, gl_TexCoord[0].xy ) - sub;
    }
I would like to ask someone with a little knowledge of blender (you'll have to set up a tiny bit of game logic) who maybe has access to a PC and a Mac to try this filter and tell me if it is working on OS X or not.

I get no outline when I play the game engine.
 
This appears to be C, not Python.

Further, the API looks like straight up OpenGL, with nothing unique to Blender.

Having said that, I'm not familiar enough with OpenGL or Blender to actually help you.
 
I figured it out. GLSL on Mac OS tends to be strict. If you declare a float you must assign a float. There are two instances where the author declared float, but assigned an integer. The author is lazy.

This is the correct code:

Code:
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, 0.002)).r;
  float depth3 = texture2D( bgl_DepthTexture, gl_TexCoord[0].xy + vec2(0.002, 0.0)).r;

  float fac = abs(depth-depth2) + abs(depth-depth3);

  float intensity = 300.0;

  vec4 sub = vec4(fac*intensity, fac*intensity, fac*intensity, 0.0);

  gl_FragColor = texture2D( bgl_RenderedTexture, gl_TexCoord[0].xy ) - sub;
}
 
Last edited:
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.