Ddx and ddy not available?
by Bil Simser · in Torque Game Engine Advanced · 07/16/2004 (5:46 am) · 18 replies
I was trying to do a shader (a competely procedural checkerboard, no textures) with this hlsl call in it:
However TSE blew its head off and couldn't figure out how to do it. ddx and ddy are Intrinsics so are they not supported or is there something special I have to do to use them? (be gentle, I'm still getting my head around this stuff).
float3 d = max(abs(ddx(IN.TexCoord)), abs(ddy(IN.TexCoord)));
However TSE blew its head off and couldn't figure out how to do it. ddx and ddy are Intrinsics so are they not supported or is there something special I have to do to use them? (be gentle, I'm still getting my head around this stuff).
#2
Chack here for what functions are supported in what versions:
HLSL Intrinsic Functions
07/16/2004 (10:07 am)
Ddx & ddy are only available in ps_2_x pixel shaders and greater. If your card doesn't support this then the 'complaints' would be correct.Chack here for what functions are supported in what versions:
HLSL Intrinsic Functions
#3
07/16/2004 (12:04 pm)
Bill posted in another thread that he has a FX5700 (which supports ps_2_x) so that shouldn't be the issue. Mayhap he is trying to use the funcs in a shaders defined as less than ps_2_x? What sort of errors would that give?
#4
07/16/2004 (12:17 pm)
Betcha whatever errors he's getting. :P
#5
07/16/2004 (2:26 pm)
Back home now so I'll give it another try. I might have done something stupid like set the pixel shader version to 1.1 in the .cs file (either that or I was distracted by yet another Torque project butterfly that flew by).
#6
Here's the error message I'm getting:
That line refers to code I posted above. I broke the call down to individual functions and it bombs on the ddy() call so it got past ddx().
Here's the output from the log so I know I have pixel (and vertex) 2.0 support:
So now the event you've all been waiting for. Here's the shaders. Maybe someone can point out an obvious flaw in what I'm trying to do.
Vertex shader:
And the pixel shader:
Let me know if anyone sees anything. Thanks.
07/16/2004 (2:56 pm)
Okay, this probably should be in the shader forum but I can't seem to see why this doesn't work.Here's the error message I'm getting:
Quote:
D:\torque\games\tse\shaders\testP.hlsl(24): error X4532: cannot map expression to pixel shader instruction set
That line refers to code I posted above. I broke the call down to individual functions and it bombs on the ddy() call so it got past ddx().
Here's the output from the log so I know I have pixel (and vertex) 2.0 support:
Quote:
Direct 3D device found
Cur. D3DDevice ref count=1
Pix version detected: 2.000000
Vert version detected: 2.000000
Initializing GFXCardProfiler (D3D9)
o Vendor : 'ASUSTek'
o Card : 'GeForce FX 5700'
o Version: '56.72'
- Scanning card capabilities...
GFXCardProfiler (D3D9) - Setting capability 'autoMipMapLevel' to true.
- Loading card profiles...
- Exec'ing profile/D3D9.cs
- No profile/D3D9.ASUSTek.cs
- No profile/D3D9.ASUSTek.GeForceFX5700.cs
- No profile/D3D9.ASUSTek.GeForceFX5700.5672.cs
Loading compiled script common/ui/defaultProfiles.cs.
Loading compiled script common/ui/GuiEditorGui.gui.
Texture Manager
- Approx. Available VRAM: 134217728
- Threshold VRAM: 68157440
- Quality mode: high
So now the event you've all been waiting for. Here's the shaders. Maybe someone can point out an obvious flaw in what I'm trying to do.
Vertex shader:
//*****************************************************************************
// Test Shader
//*****************************************************************************
#define IN_HLSL
#include "shdrConsts.h"
//-----------------------------------------------------------------------------
// Constants
//-----------------------------------------------------------------------------
struct Appdata
{
float3 Position : POSITION;
float4 UV : TEXCOORD0;
float4 Normal : NORMAL;
};
struct Conn
{
float4 HPosition : POSITION;
float3 TexCoord : TEXCOORD0;
};
//-----------------------------------------------------------------------------
// Main
//-----------------------------------------------------------------------------
Conn main(
Appdata IN,
uniform float4x4 modelview : register(VC_WORLD_PROJ)
)
{
Conn OUT;
OUT.HPosition = mul(modelview, IN.Position);
OUT.TexCoord = IN.Position * 5.0;
return OUT;
}And the pixel shader:
//-----------------------------------------------------------------------------
// Structures
//-----------------------------------------------------------------------------
struct AppData
{
float4 HPosition : POSITION;
float3 TexCoord : TEXCOORD0;
};
struct Fragout
{
float4 col : COLOR0;
};
//-----------------------------------------------------------------------------
// Main
//-----------------------------------------------------------------------------
Fragout main(
AppData IN
)
{
Fragout OUT;
float3 d = max(abs(ddx(IN.TexCoord)), abs(ddy(IN.TexCoord)));
float Blur = 1.0;
d *= Blur;
d = smoothstep(0.25 - d, 0.25 + d, abs(frac(IN.TexCoord) - 0.5));
float check = d.x;
check = lerp(check, 1.0 - check, d.y);
check = lerp(check, 1.0 - check, d.z);
float4 WhiteColor = {1.0, 1.0, 1.0, 1.0};
float4 BlackColor = {0.0, 0.0, 0.0, 1.0};
OUT.col = lerp(WhiteColor, BlackColor, check);
return OUT;
}Let me know if anyone sees anything. Thanks.
#7
Have you tried looking at the results of running your shader through the standalone DX HLSL compiler? Comes with the SDK...
07/16/2004 (8:40 pm)
Your card reports its vendor as ASUSTek? That is _really_ lame... Wow. :(Have you tried looking at the results of running your shader through the standalone DX HLSL compiler? Comes with the SDK...
#8
I tried it out in FX Composer and works fine.
07/17/2004 (4:56 am)
*sigh* it is an ASUSTek card so Torque's doing it's job (hey, don't knock it, it still works great).I tried it out in FX Composer and works fine.
#9
As for the ASUSTek thing, it's just a bit of a headache because if we have NVidia specific version checking it won't know that an ASUSTek card is from NVidia... :-/
07/17/2004 (8:12 am)
Try running the standalone HLSL compiler. Also, what does the material/custommaterial datablock look like?As for the ASUSTek thing, it's just a bit of a headache because if we have NVidia specific version checking it won't know that an ASUSTek card is from NVidia... :-/
#10
The shader/material datablocks are just a stock one that I use for testing:
Then I just map the material to a test material (for now, OrcSkin) and view it in the show tool.
07/17/2004 (9:38 am)
I ran it through the compiler and got the error:D:\torque\games\tse\shaders\checkerboardP.hlsl(23): error X4532: cannot map expr ession to pixel shader instruction setWhich indicates that more instruction slots are used than available. I guess a shortcoming of my card? What's puzzling is that I can load up the same script into FX Composer and it works. Very odd.
The shader/material datablocks are just a stock one that I use for testing:
datablock ShaderData( TestShader )
{
DXVertexShaderFile = "shaders/testV.hlsl";
DXPixelShaderFile = "shaders/testP.hlsl";
pixVersion = 2.0;
};datablock CustomMaterial(TestMaterial)
{
shader = TestShader;
pixVersion = 2.0;
};Then I just map the material to a test material (for now, OrcSkin) and view it in the show tool.
#11
07/17/2004 (10:48 am)
Very mysterious. Don't see why off hand. Maybe someone else can have some ideas. You might also try searching DirectXDev for that error.
#12
You might want to stay away from those instructions anyway since there could be compatibility problems, and you probably don't want to have to write the shader multiple times for multiple hardware.
07/17/2004 (3:17 pm)
Bil, I would recommend breaking up that line of code to make sure it is in fact the ddx/ddy instructions causing the problem. There's an awful lot going on in that line.You might want to stay away from those instructions anyway since there could be compatibility problems, and you probably don't want to have to write the shader multiple times for multiple hardware.
#13
In any case, doesn't really matter. I was just trying the functions out based on a sample I found. It was to build a checkerboard shader without using any texture files. There haven't been any examples I've seen that use the ddx/ddy calls so this was a spike experiment (which obviously has gone horribly wrong, back to writing basic shaders now ;)
Lesson learned here: Don't use ddx() and ddy()
07/17/2004 (3:27 pm)
@Brian: I did break it up (1 call per line) and it does fail on the ddy call for sure.In any case, doesn't really matter. I was just trying the functions out based on a sample I found. It was to build a checkerboard shader without using any texture files. There haven't been any examples I've seen that use the ddx/ddy calls so this was a spike experiment (which obviously has gone horribly wrong, back to writing basic shaders now ;)
Lesson learned here: Don't use ddx() and ddy()
#14
07/17/2004 (11:02 pm)
@Brian - but look up tables suck... Ok, I'll do that.
#15
07/18/2004 (8:38 pm)
I don't have a link handy but nvidia has a list of all of their device ids on their site, I think ATI does too. Device/Vendor IDs are definitely the way to go.
#17
http://developer.nvidia.com/object/device_ids.html
Partial ATI:
http://www.ati.com/support/identify/graphicschart.html
07/20/2004 (6:54 am)
Official link:http://developer.nvidia.com/object/device_ids.html
Partial ATI:
http://www.ati.com/support/identify/graphicschart.html
#18
07/20/2004 (7:57 am)
Ah, handy links, Ken. Thanks.
Associate Kyle Carter