semblance

08-13-2007, 02:04 PM

Hi, I'm trying to implement a very specialized sphere shader which draws a properly lit sphere on a quad.

I've managed to draw a circle on the quad, but I'm having extreme difficulties with changing the fragments' depths.

Does anyone know how to "pull" a fragment an exact distance in world coordinates?

Here's what I have done so far in order to draw a circle:

- draw all four vertices at the center of the sphere

- for each vertex, send two attributes named 'x' and 'y' which each have values of -1 or 1.

- in the vertex shader, push each vertex out in the x and y directions based on the 'x' and 'y' attributes. Also, copy the 'x' and 'y' attributes to varying variables, which will provide the fragment shader with positional information for its lighting calculations.

- in the fragment shader use the varying 'x' and 'y' variables to draw the circle (disposing fragments that are outside of the circle), calculate lighting and depth.

Again, I can't seem to figure out how to correlate fragment depth with the world coordinate system.

I've managed to draw a circle on the quad, but I'm having extreme difficulties with changing the fragments' depths.

Does anyone know how to "pull" a fragment an exact distance in world coordinates?

Here's what I have done so far in order to draw a circle:

- draw all four vertices at the center of the sphere

- for each vertex, send two attributes named 'x' and 'y' which each have values of -1 or 1.

- in the vertex shader, push each vertex out in the x and y directions based on the 'x' and 'y' attributes. Also, copy the 'x' and 'y' attributes to varying variables, which will provide the fragment shader with positional information for its lighting calculations.

- in the fragment shader use the varying 'x' and 'y' variables to draw the circle (disposing fragments that are outside of the circle), calculate lighting and depth.

Again, I can't seem to figure out how to correlate fragment depth with the world coordinate system.