Sign in to follow this  
Ripiz

[HLSL] Depth Edge Detection

Recommended Posts

Ripiz    539
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:
[code]#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;}[/code]


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

Share this post


Link to post
Share on other sites
kauna    2922
Just a wild guess : D3D 9 level hardware has problems with the integer offsets? Try disabling them and then recompiling.

Cheers!

Share this post


Link to post
Share on other sites
Ripiz    539
[quote name='kauna' timestamp='1311341591' post='4838889']
Just a wild guess : D3D 9 level hardware has problems with the integer offsets? Try disabling them and then recompiling.

Cheers!
[/quote]

[url="http://msdn.microsoft.com/en-us/library/bb509695(v=vs.85).aspx"]http://msdn.microsof...5(v=vs.85).aspx[/url]

According to MSDN only integer arguments are supported, but I tried float2 it's same error. However if I remove offsets it's fine

Share this post


Link to post
Share on other sites
kauna    2922
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!

Share this post


Link to post
Share on other sites
Ripiz    539
[quote name='kauna' timestamp='1311347139' post='4838952']
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!
[/quote]

Well I had that in mind as workaround, but I hoped there's easier way. =(

Share this post


Link to post
Share on other sites
Ripiz    539
[quote name='MJP' timestamp='1311355451' post='4839031']
You can't use texel offsets in that feature level. That was added as part of SM4.0.
[/quote]

Ahh that makes sense, thank you. Guess I'll have to do it hard way

Share this post


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

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