• Create Account

Banner advertising on our site currently available from just \$5!

### #ActualHodgman

Posted 29 May 2013 - 10:53 PM

I post this topic just to verify what it the right way to output the non-linear z/w depth if not use depth-stencil target. Shader Version 1 or Version 2 ? Because so many shader online use version 1 while others use version 2.

PS: we can also use type qualifier to control the interpolation method,  See  Interpolation Modifier  in HLSL.

Shader model 1 doesn't even have pixel shaders  If you're using D3D11, then you'll be using SM 2, 4 or 5 (depending if you use the 9, 10 or 11 feature level). Perspective correct interpolation works the same in every shader model, except that in 4/5 you can use the modifiers that you mention.

In SM 2/3, without these modifiers, I guess that if you want to get per-pixel interpolated(z)/interpolated(w), you'd output z*w and w in the vertex shader:

VS output:
pos = float4(x,y,z,w);
o   = float2(z*w, w);

Interpolator performs per pixel:
o.x = interpolate(z*w/w)/interpolate(1/w) == interpolate(z)/interpolate(1/w)
o.y = interpolate(w/w)/interpolate(1/w) == 1/interpolate(1/w)

Ps code:
float depthBuf = o.x / o.y / o.y;
// depthBuf == interpolate(z)/interpolate(1/w) / (1/interpolate(1/w)) / (1/interpolate(1/w))
// depthBuf == interpolate(z)/interpolate(1/w) * interpolate(1/w) * interpolate(1/w)
// depthBuf == interpolate(z) * interpolate(1/w)

This is confusing though, I might have made a mistake

Why not just use a depth buffer?

### #3Hodgman

Posted 29 May 2013 - 10:52 PM

I post this topic just to verify what it the right way to output the non-linear z/w depth if not use depth-stencil target. Shader Version 1 or Version 2 ? Because so many shader online use version 1 while others use version 2.

PS: we can also use type qualifier to control the interpolation method,  See  Interpolation Modifier  in HLSL.

Shader model 1 doesn't even have pixel shaders  If you're using D3D11, then you'll be using SM 2 4 or 5 (depending if you use the 9, 10 or 11 feature level). Perspective correct interpolation works the same in every shader model, except that in 4/5 you can use the modifiers that you mention.

In SM 2/3, without these modifiers, I guess that if you want to get per-pixel interpolated(z)/interpolated(w), you'd output z*w and w in the vertex shader:

VS output:
pos = float4(x,y,z,w);
o   = float2(z*w, w);

Interpolator performs per pixel:
o.x = interpolate(z*w/w)/interpolate(1/w) == interpolate(z)/interpolate(1/w)
o.y = interpolate(w/w)/interpolate(1/w) == 1/interpolate(1/w)

Ps code:
float depthBuf = o.x / o.y / o.y;
// depthBuf == interpolate(z)/interpolate(1/w) / (1/interpolate(1/w)) / (1/interpolate(1/w))
// depthBuf == interpolate(z)/interpolate(1/w) * interpolate(1/w) * interpolate(1/w)
// depthBuf == interpolate(z) * interpolate(1/w)

This is confusing though, I might have made a mistake

### #2Hodgman

Posted 29 May 2013 - 10:51 PM

I post this topic just to verify what it the right way to output the non-linear z/w depth if not use depth-stencil target. Shader Version 1 or Version 2 ? Because so many shader online use version 1 while others use version 2.

PS: we can also use type qualifier to control the interpolation method,  See  Interpolation Modifier  in HLSL.

Shader model 1 doesn't even have pixel shaders  If you're using D3D11, then you'll be using SM 2 4 or 5 (depending if you use the 9, 10 or 11 feature level). Perspective correct interpolation works the same in every shader model, except that in 4/5 you can use the modifiers that you mention.

In SM 2/3, without these modifiers, I guess that if you want to get per-pixel interpolated(z)/interpolated(w), you'd output z*w and w in the vertex shader:

VS output:
pos = float4(x,y,z,w);
o   = float2(z*w, w);

Interpolator performs per pixel:
o.x = interpolate(z*w/w)/interpolate(1/w) == interpolate(z)/interpolate(1/w)
o.y = interpolate(w/w)/interpolate(1/w) == 1/interpolate(1/w)

Ps code:
float depthBuf = o.x / o.y / o.y;
// depthBuf == interpolate(z)/interpolate(1/w) / (1/interpolate(1/w)) / (1/interpolate(1/w))
// depthBuf == interpolate(z)/interpolate(1/w) * interpolate(1/w) * interpolate(1/w)
// depthBuf == interpolate(z) * interpolate(1/w)

### #1Hodgman

Posted 29 May 2013 - 10:43 PM

I post this topic just to verify what it the right way to output the non-linear z/w depth if not use depth-stencil target. Shader Version 1 or Version 2 ? Because so many shader online use version 1 while others use version 2.

PS: we can also use type qualifier to control the interpolation method,  See  Interpolation Modifier  in HLSL.

Shader model 1 doesn't even have pixel shaders  If you're using D3D11, then you'll be using SM 2 4 or 5 (depending if you use the 9, 10 or 11 feature level). Perspective correct interpolation works the same in every shader model, except that in 4/5 you can use the modifiers that you mention.

In SM 2/3, without these modifiers, I guess that if you want to get per-pixel interpolated(z)/interpolated(w), you'd output z*w and w in the vertex shader:

VS output:
pos = float4(x,y,z,w);
o   = float2(z*w, w);

Interpolator performs per pixel:
o.x = interpolate(z*w/w)*interpolate(w) == interpolate(z)*interpolate(w)
o.y = interpolate(w/w)*interpolate(w) == interpolate(w)

Ps code:
float depthBuf = o.x / o.y / o.y;
// depthBuf == interpolate(z)*interpolate(w) / interpolate(w) / interpolate(w)
// depthBuf == interpolate(z) / interpolate(w)

PARTNERS