Sign in to follow this  
belfegor

[DX9] Array of samplers

Recommended Posts

belfegor    2834
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);

Share this post


Link to post
Share on other sites
belfegor    2834
3rd question

First example:

// Vertex shader
// here Depth is float
OUT.Depth = (OUT.Position.z / OUT.Position.w);
//Pixel shader
OUT.Color = float4(IN.Depth, 1.0f, 1.0f, 1.0f);


Second:

// Vertex shader
// here Depth is float2
OUT.Depth.xy = OUT.Position.zw;
//Pixel shader
OUT.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?

Share this post


Link to post
Share on other sites
Nik02    4348
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.

Share this post


Link to post
Share on other sites
MJP    19753
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.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this