Original Post
I have a 100*100 texture with format D3DFMT_R32F, now i want to calculate the max value of the datas stored in this texture. How can i do this job in gpu shader and return the max value to cpu for some following work. Thank you very much! The following code is what i have try, but it seems not work! float4 CalMaxValue() : POSITION { half a1; int i, j; float2 coord; for(i = 1; i < W - 1; i++) { for(j = 1; j < H - 1; j++) { coord = float2(1.0f * i / W, 1.0f * j / H); a1 = abs(tex2D(RTextureSampler, coord).x); maxValue = max(a1, maxValue); } } return float4(0, 0, 0, 1); } technique MainLoop_CalMaxValue { pass P0 { VertexShader = compile vs_2_0 CalMaxValue(); PixelShader = NULL; } } The PTextureSampler is a sampler and maxValue is a global float.(W and H are contants) In my d3d9 program i try to render a single vertex to startup this vertex shader, and later i use ID3DXEffect::GetFloat() to get back the max value, but i get always the same value 0.0f (that is the init value)?