Jump to content

  • Log In with Google      Sign In   
  • Create Account


Outlines with vertex shader


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
2 replies to this topic

#1 nacmacneedle   Members   -  Reputation: 101

Like
0Likes
Like

Posted 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?

Sponsor:

#2 C0lumbo   Crossbones+   -  Reputation: 2106

Like
0Likes
Like

Posted 20 March 2013 - 11:37 AM

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 :)



#3 nacmacneedle   Members   -  Reputation: 101

Like
0Likes
Like

Posted 20 March 2013 - 11:53 AM

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...




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS