Shader data flow questions
1. Is there any decent way to get a small chunk of data (4-8
bytes) from a vertex shader back to the CPU? I would only
do this in direct response to a mouse click, so it need not be fast,
just possible.
2. The MSDN reference materialhere would suggest that a variable declaredstatic
could carry information from one shader invocation to the next, so that
one could, for example, calculate a running min, max, or average of
some property over all vertices. But in practice it seems that my
static variable is zeroed afresh for every vertex.
Below are the bones of my test case. The CPU program is providing
each vertex with the "extra" variable, of which extra.x is a unique id
for each vertex, starting with 0.0 for the first, counting by 1.0 each
time. This information is demonstrably getting through.
However, reading the documentation would suggest that the line labelled
"HERE'S THE ACTION" should give me all vertices red. In fact, I
get only one red vertex, namely the first, suggesting that pickd is NOT
retaining a value.
Am I missing something really obvious? Should I be reading a
different reference? Is there one document somewhere that is The
Definitive Reference for HLSL?
[using DirectX 9 (June SDK), 6800
Ultra graphics card, Windows XP Pro, using D3DXCreateEffectFromFile to
set up the shader.] OutputVS MyDemoVS(float3 posL : POSITION0, float2 extra : TEXCOORD0) { static float pickd = 0; if (extra.x == 0) pickd = 100; // reset picking algorithm, once per frame OutputVS outVS = (OutputVS)0; outVS.color.y = extra.x / 4000.0; // visually demonstrates that the ID is getting through // Transform to homogeneous clip space: outVS.posH = mul(float4(posL, 1.0f), gWVP); return outVS; }
uniform extern float4x4 gWVP;
if (pickd == 100) outVS.color = red; // HERE'S THE ACTION

