[DX9] Array of samplers

Started by
3 comments, last by Nik02 14 years, 1 month ago
1st question Current code:

sampler samp0 : register(s0) = sampler_state
{
    ...//set filtering, address modes...
};

sampler samp1 : register(s1) = sampler_state
{
    ...//set filtering, address modes...
};
...and so on
Is it possible and how to do that with array of samplers?

sampler arrSamp[4];
2nd question Is this the correct way to clear 4 render targets:

dev->SetRenderTarget(0, rt0);
dev->SetRenderTarget(1, rt1);
dev->SetRenderTarget(2, rt2);
dev->SetRenderTarget(3, rt3);// all rts are of the same size
D3DRECT rcs[4];
rcs[0].x1 = 0;
rcs[0].x2 = rtSize;
rcs[0].y1 = 0;
rcs[0].y2 = rtSize;
rcs[1].x1 = 0;
rcs[1].x2 = rtSize;
rcs[1].y1 = 0;
rcs[1].y2 = rtSize;
rcs[2].x1 = 0;
rcs[2].x2 = rtSize;
rcs[2].y1 = 0;
rcs[2].y2 = rtSize;
rcs[3].x1 = 0;
rcs[3].x2 = rtSize;
rcs[3].y1 = 0;
rcs[3].y2 = rtSize;
HRESULT hr = dev->Clear(4, rcs, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0x00FFFFFF, 1.0f, 0L);
Advertisement
3rd question

First example:
// Vertex shader// here Depth is floatOUT.Depth              = (OUT.Position.z / OUT.Position.w);//Pixel shaderOUT.Color = float4(IN.Depth, 1.0f, 1.0f, 1.0f);


Second:
// Vertex shader// here Depth is float2OUT.Depth.xy            = OUT.Position.zw;//Pixel shaderOUT.Color = float4(IN.Depth.x / IN.Depth.y, 1.0f, 1.0f, 1.0f);


Does it make it any difference, except that pixel shader is
"called" more times then vertex?
1: No (assuming D3D9).

2: If you want to clear the whole area of all set render targets, you can call Clear without specifying any rectangles. The rectangles have nothing to do with individual render targets - they just specify which rectangular areas of the render target to clear.

Niko Suni

For your third question, the first method will give you incorrect depth values. This is because the homogeneous divide is a non-linear operation, which means you can't do it before interpolation. You instead have to interpolate first and then perform the divide in the pixel shader.
Note that the hardware can automatically apply perspective correction to texture coordinates.

Niko Suni

This topic is closed to new replies.

Advertisement