Three.js outlines

后端 未结 3 1374
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-01-20 00:20

Is it possible to have an black outline on my 3d models with three.js?

I would have graphics which looks like Borderlands 2. (toon shading + black outlines)

3条回答
  •  爱一瞬间的悲伤
    2021-01-20 00:37

    Its a old question but here is what i did.

    I created a Outlined Cel-shader for my CG course. Unfortunately it takes 3 rendering passes. Im currently trying to figure out how to remove one pass.

    Here's the idea: 1) Render NormalDepth image to texture.

    In vertex shader you do what you normally do, position to screen space and normal to screen space.

    In fragment shader you calculate the depth of the pixel and then create the normal color with the depth as the alpha value

    float ndcDepth = (2.0 * gl_FragCoord.z - gl_DepthRange.near - gl_DepthRange.far) / (gl_DepthRange.far - gl_DepthRange.near);
    float clipDepth = ndcDepth / gl_FragCoord.w;
    

    2) Render the scene on to a texture with cel-shading. I changed the scene override material.

    3)Make quad and render both textures on the quad and have a orto camera look at it. Cel-shaded texture is just renderd on quad but the normaldepth shaded on that you use some edge detection and then with that you know when the pixel needs to be black(edge).

提交回复
热议问题