Sign in to follow this  
Mathy

[SlimDX] Stroke around a sphere?

Recommended Posts

How do I make a stroke (a line around) a sphere that I have the mesh of, and have already drawn onto the device? [Edited by - Mathy on March 15, 2010 9:04:46 AM]

Share this post


Link to post
Share on other sites
You could rotate a transparent(apart from the Stroke) square around the sphere (with a common centre) and make the pixel shader draw non transparently where the distance from the centre = the radius of the sphere.

P.S. As an optimisation Square the radius and compare the squared distance.

Share this post


Link to post
Share on other sites
Another way, since a sphere is convex, you can draw all the edges where one neighboring face is facing the camera, and the other isn't. This will give you exactly the silhouette of the sphere.

Share this post


Link to post
Share on other sites
Here is a slightly modified quote from "The Orange Book":
A technique for drawing silhouette edges for simple objects requires drawing the geometry twice. First, we draw just the front-facing polygons using filled polygons and the depth comparison mode set to LESS. Then, we draw the back-facing polygons as lines with the depth comparison mode set to LESS OR EQUAL. This has the effect of drawing lines such that a front-facing polygon shares an edge with a back-facing polygon

Share this post


Link to post
Share on other sites
Quote:
Original post by Decibit
Here is a slightly modified quote from "The Orange Book":
A technique for drawing silhouette edges for simple objects requires drawing the geometry twice. First, we draw just the front-facing polygons using filled polygons and the depth comparison mode set to LESS. Then, we draw the back-facing polygons as lines with the depth comparison mode set to LESS OR EQUAL. This has the effect of drawing lines such that a front-facing polygon shares an edge with a back-facing polygon


This is extremely interesting. I'm using SlimDX.

Are there any code examples? Could you show me how, somehow?

Share this post


Link to post
Share on other sites
Moving to graphics programming.

The technique you're looking for is often called "silhouette rendering". There are a lot of example techniques out there -- but do note that you're generally not going to be able to just lift somebody else's shader code and have it work in your own projects. You'll have to read about the technique and understand how it works. The same is true of your other query about glow shaders.

Share this post


Link to post
Share on other sites
It works exactly the same as in native code. You create an Effect object using the shader code (probably with Effect.FromFile or Effect.FromString) and render with it.

You will also need to do any CPU-side computation required to implement the visual technique desired and pass any appropriate parameters to the effect. Exactly how you do that CPU-side work and what you pass to the shader depends on how the rest of your rendering pipeline is structured.

Share this post


Link to post
Share on other sites
Quote:
Original post by Mathy
Quote:
Original post by Decibit
Here is a slightly modified quote from "The Orange Book":
A technique for drawing silhouette edges for simple objects requires drawing the geometry twice. First, we draw just the front-facing polygons using filled polygons and the depth comparison mode set to LESS. Then, we draw the back-facing polygons as lines with the depth comparison mode set to LESS OR EQUAL. This has the effect of drawing lines such that a front-facing polygon shares an edge with a back-facing polygon


This is extremely interesting. I'm using SlimDX.

Are there any code examples? Could you show me how, somehow?

The book web site 3D Shaders contains the examples. Of course the are written using the OpenGL. However the technique is quite straightforward and can be implemented using any kind of 3D-API. The silhouette edges require no use of shaders and can be done even with the legacy hardware.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this