0
\$\begingroup\$

Right now I'm facing the issue of rendering the same objects more than once in Directx 11, as the object has:

  • A diffuse shader
  • A directional lighting shader
  • A texture shader

Now the final color should be all of them somehow put together, maybe something like this:

  • Render Diffuse
  • Render Texture
  • Render Directional
  • Final Color = (Diffuse + Texture) * Lighting // Not sure about this though

But how can this be archieved? Without the EFFECTS FRAMEWORK!

\$\endgroup\$

1 Answer 1

1
\$\begingroup\$

You don't need the effects framework to use shaders, you can still just write a shader and create/bind it directly (for example, using this function for vertex shaders and VS's built-in HLSL compiler or D3DCompileFromFile).

You can achieve this by literally rendering the object multiple times, changing the shader that is bound each time, and setting the blending mode to do additive blending if that's what you want. However, that seems costly.

You could also just write a single shader that performs the appropriate computations for the diffuse term, direction lighting term, and reads the color from the read and modulates it by the lighting terms. This way you avoid the overhead of repeatedly rendering and changing shaders, and you get a bit more control over the way your color terms are combined (blending with the framebuffer isn't fully programmable, you can only pick from a pre-defined set of options, so that limits you somewhat).

\$\endgroup\$
2
  • \$\begingroup\$ I think I will try to write single shaders for different cases, but this also really helped me to anyone who's reading this: msdn.microsoft.com/en-us/library/windows/desktop/… \$\endgroup\$
    – Miguel P
    Commented Feb 12, 2013 at 20:52
  • \$\begingroup\$ You may be underestimating the impact that would have long-term. If your reason for having separate shaders for each component of the final color term is to aid in the modularity of your shader code, you may want to consider a "SuperShader"-like approach where you combine the individual fragments for diffuse/directional/et cetera as a pre-processing step so you can avoid the redraw overhead. graphics.cs.brown.edu/games/SuperShader/index.html \$\endgroup\$
    – user1430
    Commented Feb 12, 2013 at 20:55

You must log in to answer this question.

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