i'm working on directx9 and i'm trying to get my hand on shaders, here is my shader:
sampler texLastPass : register( s0 );
float4 main(in float2 t : TEXCOORD0) : COLOR
{
float4 color = tex2D(texLastPass, t);
return float4(color.rgb, 1.0f);
}
In theory there should be no change with it, but instead my whole objects is filled with pixel that exists on position (0, 0) in texture.
So why provided pixel coordinates to shader are wrong?
Your shader code has a sampler, but where is the texture? From Microsoft Docs:
Three things are required to sample a texture:
* A texture
* A sampler (with sampler state)
* A sampling instruction
Since you are missing the binding to the texture, Direct3D 9 is going to provide you a value of 0,0,0 for all texture references.
texture tex0 : register( t0 );
Without this it still builds because it implicitly assumes you mean
t0
.
You are using 'explicit binding' in this shader, which is perfectly fine and recommended if you are avoiding the use of the legacy Effects system. That said, Direct3D 9 developer education materials and samples were heavily based on Effects which uses a slightly different syntax, and therefore a source of confusion.
You don't show your C/C++ code, so it could be related to your binding code as well.
Note that if writing Direct3D 9 code these days, a few important things to keep in mind:
The DirectX SDK is deprecated and legacy, and it's use is strongly discouraged. See Microsoft Docs. It has a number of known issues and is challenging to even install.
The core headers for Direct3D 9 are part of the Windows SDK, so they are already part of Visual Studio 2012 or later. You don't need the DirectX SDK to build Direct3D 9 code.
The D3DX9 utility library is also deprecated, but is really the only way to get Direct3D 9 support code. As of earlier this year, you can now consume it from NuGet with a simple side-by-side redistribution rather than rely on the legacy DirectX SDK or the legacy DirectX End-User Runtime Redist. See this blog post.
The Direct3D 9 Debug Device is not supported on Windows 8, Windows 8.1, or Windows 10.
All the samples for Direct3D 9 from the legacy DirectX SDK can be found on GitHub.
You should take a look at DirectX 11 as a better starting point which has much better debugging support, tools support, and open source libraries. See this blog post.