Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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!

share|improve this question

1 Answer 1

up vote 1 down vote accepted

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).

share|improve this answer
    
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/… –  Miguel P Feb 12 '13 at 20:52
    
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 –  Josh Petrie Feb 12 '13 at 20:55

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.