sombreador de fragmentos unity3d: ¿distancia del píxel al vértice?

I'm trying to create a star field fragment shader in which the vertices of a mesh are treated as stars. I want the color of the pixel to go between 0,0,0,1 and 1,1,1,1 as the distance from the pixel (interpolated from the position output of the vertex shader) to the vertex (output from the vertex shader in some way that will prevent it from getting interpolated) goes between some value to 0. I want the value to be calculated based on the z value of the vertex.

Is this possible? How can it be done?

I'm having trouble coming up with the distance from the interpolated vertex position to the non-interpolated one in the fragment shader. Maybe it could be done by somehow getting the screen coordinate of the vertex in the vertex shader, and passing that as a color value or something? Because I seem to be able to access the screen coordinates for a fragment, but not the world coordinates. (If I try to use anything that has position semantics in the fragment shader, I get an error, as I guess you'd expect.)

Additionally, I'd really like to also pass a (star) color value and size value along with a vertex, from the vertex shader, and have those affect the output of the fragment shader.

preguntado el 22 de septiembre de 13 a las 22:09

0 Respuestas

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.