0
\$\begingroup\$

I'm working on a deferred shader, and I want to use instancing to draw point lights.

From what I understand, I can send the instance data through the vertex shader and pass it through unchanged to the pixel shader. Is this the correct way to do it, or can I send the instance data straight to the pixel shader somehow?

\$\endgroup\$

1 Answer 1

1
\$\begingroup\$

can I send the instance data straight to the pixel shader somehow?

What would that mean, exactly? The values your fragment (or pixel if you insist) shader gets are per-vertex values interpolated across the face of the primitive, and constant uniform values that do not change within a draw call.

There is no way to magic a vertex stage input into a vertex stage output. There must be a vertex shader and it must write that input into the output.

I want to use instancing to draw point lights.

You probably do not. Instancing usually isn't a performance win unless you're talking about thousands of instances. If you only have 20 point lights, it's not going to be worthwhile.

At the very least, you should profile it before committing to it.

\$\endgroup\$
3
  • \$\begingroup\$ I'm thinking thousands of lights, yeah. \$\endgroup\$ Jul 20, 2012 at 6:43
  • 1
    \$\begingroup\$ @Rei: If you're using thousands of lights, it would be better to have a fragment shader that loops over some number of lights, rather than using instancing to pass parameters. That way, the fixed per-sample cost is reduced (reverse transforming back into eye-space). For example, you might have shaders that do 1, 5, 10, 25, and 100 lights, or whatever fits in the shader. \$\endgroup\$ Jul 20, 2012 at 7:08
  • \$\begingroup\$ Oh I see, that would also make it so that I don't have to worry about choosing a size for the vertex buffer holding all the lights. Thanks! \$\endgroup\$ Jul 20, 2012 at 8:38

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .