6
\$\begingroup\$

I use blender game engine and blender uses OpenGL for graphics. How can I draw lines around all 3D objects? Would this be a job for a filter? Mainly, I want my end result to look drawn.

I found this:

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 = 9050;  

   vec4 sub = vec4(fac*intensity,fac*intensity,fac*intensity,0);
   
   gl_FragColor = texture2D( bgl_RenderedTexture, gl_TexCoord[0].xy ) - sub;
}

#change float intensity

here and that seems to work, but I need it to look more sketched. So I would like some noise influence. Maybe it's called sinus displacement? Is there a way to do that?

I draw and I want the style to look like this. Thanks.

Disclaimer: I do hang out on BSE and this is not a question they are prepared to answer or is it necessarily on-topic for them, since it is about OpenGL.

\$\endgroup\$
2
  • \$\begingroup\$ What you want to Google is "NPR Shaders". \$\endgroup\$ – Yousef Amar Dec 10 '15 at 22:10
  • \$\begingroup\$ The sample of what you want it to look like now "doesn't exist or is provate". \$\endgroup\$ – doppelgreener Jan 23 at 15:47
0
\$\begingroup\$

Here's some code that hopefully gives you the effect you are looking for. It works similar to your original code, but has some added code to help get a brighter pop.

uniform sampler2D bgl_RenderedTexture;
uniform sampler2D bgl_DepthTexture;
uniform vec2 bgl_TextureCoordinateOffset[9];

const float near = 0.1;
const float far = 100.0;

float depth(in vec2 coo)
{
 vec4 depth =  texture2D(bgl_DepthTexture, coo);
 return -near / (-1.0+float(depth) * ((far-near)/far));
}

void main(void)
{


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



    for (int i = 0; i < 9; i++)
    {
        sample[i] = vec4(depth(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));

       if (border.r > 0.8||border.g > 0.8||border.b > 0.8){
        gl_FragColor = vec4(0.0, 0.0, 0.0, 1.0);
    }else{
  gl_FragColor.rgb = texcol.rgb;
        gl_FragColor.a = 1.0;
    }
}
\$\endgroup\$
1
  • 3
    \$\begingroup\$ It would be worth talking about what this code does, and why it's doing that. \$\endgroup\$ – doppelgreener Jan 23 at 15:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.