Question

I am trying to write a set of shaders to be able to draw the edges of surfaces (not polygons!), like in the game Echochrome.

From what I can remember from graphics programming, the technique for doing this is to make a multi-pass render. The first pass should encode face normal vectors and depths as RGBA colors and draw these to a texture. The second pass should look up values in the texture and draw an edge if the normal or depth information at the current fragment varies significantly from the surrounding texels' normals or depths.

(Note: If there is an easier way to do this, please tell me, especially if it's easy to do in Flash. However, my specific question is as follows.)

I have hit a snag in programming the first pass. From what I've read in Introduction to 3D Game Programming with DirectX 9.0c: A Shader Approach by Frank D. Luna, the correct way to "interpolate" a normal vector is to average the normal vectors for the triangle's vertices, then use that value for every fragment on the surface. However, my fragment shader is interpolating the normal vector instead, which results in drawing a gradient instead of solid colors for the surfaces.

How can I get AGAL to do the necessary averaging instead of interpolating?

Was it helpful?

Solution

I think you will need to duplicate your vertices, so that each triangle has it's own three vertices, not shared with any other triangle. The normal for each vertex of the triangle should be the averaged normal: All three normals for a triangle will be the same, so that the interpolated value will not change. I know that this is not ideal, but I don't of any other solutions.

In OpenGL, you can calculate the averaged normals in a geometry shader or use the "flat" qualifier so that the normals are not interpolated, but I don't think you can do either of these in AGAL.

See this question/answer for some more info.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top