Some help for outlining an object
by Frank Bignone · in Torque Game Engine Advanced · 11/23/2004 (10:11 am) · 6 replies
I'm currently writing a toon shader, but I need to have some help or answer on the following:
- it seems eyePos is expressed in world coordinates (obj transform is applied on it) ?
- so if I want to compute dot product betwwen eyeVector and model normal, I should multiply vertex position by obj transform (and same for normal) and then compute the dot product of (eye-pos).normal ? This dot product should tell me if The eyeVector is tangent with model surface and then if I need to draw a silhouette.
It seems to not work, so I must do something wrong. Can someone tell me what is wrong?
Regards
- it seems eyePos is expressed in world coordinates (obj transform is applied on it) ?
- so if I want to compute dot product betwwen eyeVector and model normal, I should multiply vertex position by obj transform (and same for normal) and then compute the dot product of (eye-pos).normal ? This dot product should tell me if The eyeVector is tangent with model surface and then if I need to draw a silhouette.
It seems to not work, so I must do something wrong. Can someone tell me what is wrong?
Regards
About the author
Real programmers don't waste time recompiling; they patch the binary files... ... Real programmers don't waste time patching binary files; they patch memory.
#2
I think "EyePos, is expressed according to model coordinates" is true.
I find dot(N,EyeVec)is is not Work well with Dts of Orc in Vertex or in Pixel.
05/13/2009 (2:21 am)
I have the same questions,too.I think "EyePos, is expressed according to model coordinates" is true.
I find dot(N,EyeVec)is is not Work well with Dts of Orc in Vertex or in Pixel.
#3
Anyway, this isn't the best way to render outlines. You can get geoemtry outlines without engine changes by exporting your model with a duplicate mesh, with normals reversed and using a black texture. Then assign a customMaterial for that black texture and have it's vertex shader offset the vertex position in the negative normal direction by a certain amount (based on distance from eye to the vertex).
05/13/2009 (8:57 am)
Try passing the normal and the eyevec from VS to PS, and in the PS normalize both it and perform the dot product there. Do not do the dot product on the VS, and remember to normalize in PS.Anyway, this isn't the best way to render outlines. You can get geoemtry outlines without engine changes by exporting your model with a duplicate mesh, with normals reversed and using a black texture. Then assign a customMaterial for that black texture and have it's vertex shader offset the vertex position in the negative normal direction by a certain amount (based on distance from eye to the vertex).
#4
That's one way to do it. Then you can add fancier shaders ontop of that.
05/13/2009 (3:06 pm)
Draw the shape a second time (this is simply doing a second ShapeInstance::render () call in ShapeBase), but this time setting CullMode to CCW. Then scale the object slightly and give it whatever color you need.That's one way to do it. Then you can add fancier shaders ontop of that.
#5
05/14/2009 (8:26 am)
Scaling only works for convex stuff. Human shapes are far from convex. You need to "fatten" the model, and displacing the vertices along their (smoothed) normals is a way to do it.
#6
05/14/2009 (11:51 am)
Not saying you're wrong, but it works on our end - that's characters included. YMMV.
Torque 3D Owner Frank Bignone
Darkhand Studio
- EyePos, is expressed according to model coordinates (true?)
- so Normal, Position, and lightVec are all in same coordinate frame.
My problem is that my model is very low poly, so I have some artefact when trying to find edges (dot(N,EyeVec)) which result in no so good looking outlines for the model.
On the other side, the toon shading works well. I need definitaly to find something else for the outline, maybe a two-pass method.