How to draw a single-pixel width line in Stage3D

140 views Asked by At

I'm working on a 3D game set in space. I'm currently adding orbit-lines of the planets.
Ideally I'd like to draw the orbit lines at 1 pixel width, irrespective of the line's distance from the camera. Does anyone know of the way to do that?
Currently I'm using a plane mesh scaled and rotated to match the orbit of a planet. In the fragment shader I use the U and V coordinates to figure out if a pixel should be drawn at a given pixel:

// subtract 0.5 from UV coordintes of this pixel
"sub ft0, v1, fc4 \n" + // fc4 is a vector of 0.5 values
// double it, so values range from -1...1
"mul ft0, ft0, fc2 \n" + // fc2 is a vector of 2 values
// square x component
"mul ft1.x, ft0.x, ft0,x \n" +
// square y component
"mul ft1.y, ft0.y, ft0.y \n" +
// set others to 0
"mov ft1.w, fc0.w \n" + // fc0 is a vector of 0s
"mov ft1.z, fc0.w \n" +
// add and square root to get distance from centre...
"add ft1.xyzw, ft1.xxxx, ft1.yyyy \n" +
"sqt ft1, ft1 \n" +

So ft1 ends up being the distance of the current fragment from the centre of the plane mesh. I can use the sge and slt op codes to compare this value to '1', but HOW do I have the resulting line always drawn only 1 pixel width? The result I'm getting is distorted by perspective and also if the camera is near-to level with the plane.
I've tried scaling the width by the current fragment's distance from camera, but that seems an ugly work-around - and it's still affected by 'flattening' if the camera happens to be level with the plane of the orbit.
What's the solution? Surely it's possible to draw a non-perspective 1-pixel width line...

0

There are 0 answers