Sign in to follow this  
nacmacneedle

Outlines with vertex shader

Recommended Posts

nacmacneedle    101
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?

Share this post


Link to post
Share on other sites
C0lumbo    4411

You're adding on the normal to create a new position called 'position', you're then not using it, in the next line you use 'a_position' instead.

 

Very silly mistake and one that I have done countless times :)

Share this post


Link to post
Share on other sites
nacmacneedle    101
Uhm. Well. I... uh... fixed it but of course it was not such a stupid thing... *whistles innocently* ;-) *lol* Thanks... I wouln't have spotted that in a hundred years. I must say, the workaround looked better, at least with a simple box...

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this