Jump to content

  • Log In with Google      Sign In   
  • Create Account

Awesome job so far everyone! Please give us your feedback on how our article efforts are going. We still need more finished articles for our May contest theme: Remake the Classics

[HLSL] Depth Edge Detection


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
7 replies to this topic

#1 Ripiz   Members   -  Reputation: 521

Like
0Likes
Like

Posted 22 July 2011 - 05:30 AM

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

Sponsor:

#2 kauna   Members   -  Reputation: 1133

Like
0Likes
Like

Posted 22 July 2011 - 07:33 AM

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

Cheers!

#3 Ripiz   Members   -  Reputation: 521

Like
0Likes
Like

Posted 22 July 2011 - 08:04 AM

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

#4 kauna   Members   -  Reputation: 1133

Like
1Likes
Like

Posted 22 July 2011 - 09:05 AM

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!

#5 Ripiz   Members   -  Reputation: 521

Like
0Likes
Like

Posted 22 July 2011 - 09:24 AM

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. =(

#6 MJP   Moderators   -  Reputation: 5428

Like
1Likes
Like

Posted 22 July 2011 - 11:24 AM

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

#7 Ripiz   Members   -  Reputation: 521

Like
0Likes
Like

Posted 22 July 2011 - 12:36 PM

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

#8 MJP   Moderators   -  Reputation: 5428

Like
0Likes
Like

Posted 22 July 2011 - 11:26 PM

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.




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS