   Shaders Sharing Shazbot
  For reasons that can not be questioned I am not using the effects framework.Is it possible to share data between a vertex shader and a pixel shader?Additionally, what is the deal with preshaders?  The documentation says they only work with effects, but that is clearly mistaken, since you can precompute matrices and send them to pixel shaders and vertex shaders before executing them.Thank you,Yogurt Emperor   
  I am not sure what you mean with share in this context. Can you describe your use case?Precompute stuff in your own code and set it as shader constant is not exactly the same as a  “preshaders”. A preshader is a part in your shader code that depends only on effect parameters. The compiler can separate such code and execute it once on the CPU instead of multiple times (every vertex/pixel) on the GPU. ;  Sharing: I set a value for g_mWorldViewProj in the vertex shader and the value is also applied to the linked pixel shader.“Linked” is the same mechanism as in OpenGL, in which shaders can be linked to a program object.Perhaps my question is really about whether or not you can link shaders together to create program objects, since that would certainly imply that globals between them would be shared and thus need to be set only once between them.Since precomputing only exists in effect files it stands to reason that this cannot be done.Yogurt Emperor   ;  The vertex shader can return a struct that the Pixel shader uses as input. You can pass any data you want from the vertex shader to the pixel shader, so long as you define the struct to support it.Does that help you?   ;  Well maybe I got lost in a maze of a million thoughts due to the huge task I am about to undergo.Maybe my question is meaningless.I was specifically thinking about global matrices that may be used in both a vertex and a pixel shader, and seeking a way to set the values only once instead of once for the vertex shader and once for the pixel shader.But in my maze of thoughts, maybe I missed the possibility that there is never a need for a vertex shader and a pixel shader to have the same globals.But surely that can’t always be the case.There must be some case where I will want to have a global (a matrix probably) with the same name in both shaders and so my question is, is there a way to link the global in the pixel shader to the global in the vertex shader so that when I update the value in the vertex shader it is automatically updated in the pixel shader?L. Spiro   ;  The solution I've gone for is to define a number of constant buffers in header files and include these where they are required in shaders.   ;  For DX9 the shader constants are complete separated. If you need values for both shaders you need to set them to both shader stages.   ;Quote:Original post by DemirugFor DX9 the shader constants are complete separated. If you need values for both shaders you need to set them to both shader stages.That's true also for DX10/11 - you can use the same constant buffers in multiple locations, but they need to be individually set.   ;  But what about when using the Effects Framework?That allows you to create shared pools and basically do exactly what I am asking right?So the only way to match OpenGL in this aspect is to use effect files.Yogurt Emperor   ;  The effect framework just manages the separate shader stages for you - behind the scenes, if you have two shaders that require the same constant buffer, then the same buffer is just set into the two different stages.  Again this is for DX10/11, but I am fairly sure that DX9 is the same way.  The effect framework source code for DX11 is distributed with the SDK if you are interested in seeing how it actually works.   