Wednesday, March 9, 2016

directx - 2D Line drawing with Pixel Shaders


Recently I asked a question, what is the fastest way to render 2D lines using DirectX, and one of the answers mentioned this paper on Fast Prefiltered Lines which uses Pixel Shaders to accomplish wireframe drawing. This paper draws quads per line segment then uses a pixel shader to draw a line by computing distance from the pixel to the line down the centre of the quad before filling with line-color or transparent.


So, I'm wondering how can this be done? I wasn't aware the pixel shader can get knowledge of the input geometry (e.g. the quad) that creates it. Is the following possible? Ideally in DirectX9 but DX10 or OpenGL solutions also appreciated!


enter image description here


EDIT


Turns out I don't draw the quad like that, but like this. So the question is: How can I get information about x1y1 x2y2 into the pixel shader so I can compute distance to line edge & get a nice antialiased line segment?


enter image description here




No comments:

Post a Comment

Simple past, Present perfect Past perfect

Can you tell me which form of the following sentences is the correct one please? Imagine two friends discussing the gym... I was in a good s...