Jump to content

  • Log In with Google      Sign In   
  • Create Account


nacmacneedle

Member Since 20 Mar 2013
Offline Last Active Mar 20 2013 12:06 PM
-----

Topics I've Started

Outlines with vertex shader

20 March 2013 - 11:30 AM

Hi community!

I'm currently writing a cel shaded game. The cel shading itself works quite well, but drawing outlines seems to be a bit harder.
At the moment I'm solving this by loading my model two times, enlarging one copy by 1% and then rendering the back faces black to get the outline.
But since the game is aimed at handheld devices and I have to do deformation operations which will scale O(n^2 ) or even worse I can't take the costs of doubling the vertices.

I wanted to render the back faces black and let the vertex shader enlarge them in direction of their surface normals, which I read is a common method.

So I created the following vertex shader and combined it with a fragment shader which returns only black.

attribute vec4 a_position; // given by model loaderattribute vec3 a_normal;   // uniform mat4 u_matrix;     // combined matrixuniform float u_thickness; // outline thicknessvoid main() {	vec4 position = a_position + normalize( vec4( a_normal, 0.0 ) ) * u_thickness;	gl_Position = u_matrix * a_position;}

When I only use the outline shader I get the black back faces, but when I draw the cel shaded model over the outlines, it has exactly the same size, so I don't get any outlines.
Why doesn't my shader resize the back faces?

Attached is (hopefully) a screenshot of the rendered with the cel-shader and the outline-shader next to each other as well and with my current workaround which produces the desired effect.

I apologize for the formatting... somehow my line breaks seem to get removed upon posting?

PARTNERS