[HLSL] Depth Edge Detection

Started by
6 comments, last by MJP 12 years, 9 months ago
Hello,

I'm trying to add edge detection post process which I tried to base off different demos, but I can't seem get it to work.
I try to compile shader with "ps_4_0_level_9_1" (have to keep it DX9 compatible) but it throws: "error X4532: cannot map expression to pixel shader instruction set" at line 11, but on other hand it works with "ps_4_0".

Here's my shader:
#define threshold 0.04
SamplerState texSampler : register(s0);
Texture2D<float> depthTex : register(t0);

float4 EdgeDetectionPS(float4 position : SV_POSITION, float2 texcoord : TEXCOORD0) : SV_TARGET {
float fCenter = depthTex.Sample(texSampler, texcoord);
float4 fEdges = {
depthTex.Sample(texSampler, texcoord, int2(-1, 0)),
depthTex.Sample(texSampler, texcoord, int2(0, -1)),
depthTex.Sample(texSampler, texcoord, int2(1, 0)),
depthTex.Sample(texSampler, texcoord, int2(0, 1)) // Line 11
};

float4 delta = abs(fCenter.xxxx - fEdges);
float4 edges = step(threshold / 10.0, delta);

if (dot(edges, 1.0) == 0.0)
discard;

return edges;}



Anyone knows why this error happens, or how to fix it?

Thank you.


P.S. It doesn't work with "ps_4_0_level_9_3" either, but I don't know what's the difference
Advertisement
Just a wild guess : D3D 9 level hardware has problems with the integer offsets? Try disabling them and then recompiling.

Cheers!

Just a wild guess : D3D 9 level hardware has problems with the integer offsets? Try disabling them and then recompiling.

Cheers!


http://msdn.microsof...5(v=vs.85).aspx

According to MSDN only integer arguments are supported, but I tried float2 it's same error. However if I remove offsets it's fine
Yes I read the MSDN doc too and you are right that only integer arguments are supported.

I think that you'll need to modify your texcoord in the D3D 9 version by +-1.0f / texture width/height

Good luck!

Yes I read the MSDN doc too and you are right that only integer arguments are supported.

I think that you'll need to modify your texcoord in the D3D 9 version by +-1.0f / texture width/height

Good luck!


Well I had that in mind as workaround, but I hoped there's easier way. =(
You can't use texel offsets in that feature level. That was added as part of SM4.0.

You can't use texel offsets in that feature level. That was added as part of SM4.0.


Ahh that makes sense, thank you. Guess I'll have to do it hard way
I usually end up doing the offset manually anyway for cross-platform reasons, and also ever since I hit an Nvidia driver bug where using the offset with SampleCmp caused my app to crash. The offsets also have to be hard-coded, which means you can't use them in a dynamic loop or have the offset based on some other calculation which limits its usefulness.

This topic is closed to new replies.

Advertisement