TEXCOORD0 in my HLSL shader always points to (0,0) - directx

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.

Related

Convert DXBC to DXIL (DirectX Bytecode to DirectX Intermediate Language)

Microsoft's open source DirectX Shader Compiler describes the format of a new intermediate language (IL) for HLSL shaders called DXIL.
The documentation makes reference to a converter from the previous HLSL IL, called DXBC, to the new DXIL: https://github.com/Microsoft/DirectXShaderCompiler/blob/master/docs/DXIL.rst.
However, I am unable to find the referenced dxbc2dxil tool, or any other way to convert DXBC to DXIL. I have tried passing DXBC files to the various tools in the DirectX Shader Compiler project, but none have accepted plain DXBC as input.
Is there currently a way to obtain DXIL from old DXBC?
My understanding of this documentation is that Microsoft will take charge of only providing DXIR to the vendor's drivers in the future. The DXBC2DXIL is a Microsoft internal only module.
To my knowledge, nothing in the DirectX Shader Compiler repository has the capability to translate a DXBC IL to a DXIL.
See this project for a working hack: https://github.com/Nukem9/Dxbc2Dxil
They use "dxilconv.dll" from win10 to create an instance of the undocumented DXBC->DXIL converter.

Delphi DX11 Direct3D Vertex and Pixel Shader Issues

I'm attempting to translate some C++ DX11 Direct3d height-map code into Delphi. I'm at at a stage where I have almost the entire code translated across without any compile errors or run-time errors however I cannot for the life of me get anything to render on-screen - which I believe may be a vertex/pixel shader issue.
The code I'm translating across is here:
http://www.rastertek.com/tertut02.html
And I'm using the JSB DirectX11 interface libraries from here:
http://www.jsbmedical.co.uk/DirectXForDelphi/
I know that the Direct3D subsystem is working correctly as I am able to alter the color of the background of the render surface however, I just do not get any polygons rendered on the display.
There is quite a lot of code which I'm unable to upload here so for convenience, here's a copy of my source (without any object files/binaries)
https://www.dropbox.com/s/r90jbl6vz9gb3s7/Delphi%20Height%20Map.zip?dl=0
Unfortunately, there doesn't appear to be many Delphi DX11 or D3D examples on the internet so I have nothing to benchmark the code against.
I'd be eternally grateful if anyone could offer any pointers as to what may be the issue. Like I say, the code compiles and runs without any errors but just nothing is rendered.
Thanks in advance,
Kevin
You can look here on how to do basic rendering with D3D11 using Delphi - https://github.com/AntonAngeloff/DX11_Examples
These examples use another headers translations, though.

DirectX CreateGeometryShader fails with E_INVALIDARG

I am using a geometry shader in my DirectX application which is compiled using shader model 4.0 (gs_4_0). The shader works correctly on my development pc with a DirectX 11 card but fails on two client PCs with DirectX 10.1 cards. The application fails when it calls CreateGeometryShader using the compiled bytecode with a return result of E_INVALIDARG.
I assume that the client PC graphics cards or drivers do not support some feature I am making use of in the geometry shader.
The client machines do not have the DirectX SDK installed so I can't get a more detailed error message.
How can I investigate this issue further?
Is there a list of likely causes of this problem which I can run through?

Tool for pixel and vertex shader

Is there any tool for testing pixel and vertex shaders?
nVidia FX Composer (There was also AMD (formerly ATI) RenderMonkey, but it looks like that's been shelved.)
Finally, you may find PIX useful for testing shaders as they are used in your application. It is included in the DirectX SDK.
For HLSL Effects that you can use in XNA (PS 2.0-3.0) you can try:
3DPee (Tridipy) player and shader editor (dead link)
It operates on images and video.
It supports multi pass technique, vertext shader, and has a nice editor with error message reporting on compile.
It's an alpha version i have developed but it can be useful.
Screenshot:
You need to have a Mac to use it, but Apple's OpenGL Shader Builder is pretty nice. You can literally type in shaders and run them live, outside of your application.
A nice one here for WebGL: http://glsl.heroku.com

Hooks for Direct3D 6.1 to replace EMBM with shaders

I am writing Windows Hooks for DirectX 6.1. I want to intercept calls for EMBM (Environment Mapped Bump Mapping) and pass the data to own bump shader, so application which depend on EMBM will work correctly. The only problem is that DX 6.1 don't allow shaders at all. I can't simple replace Direct3DDevice3 with class from newer SDK, because it's methods uses different sets of arguments and application that use my hooked dll will crash. I do not know how to workaround through. I am not so good at DirectX (maybe there is more effective way to implement bump in DX 6.1 that will work on modern hardware?) Maybe it is possible to query some interface in D3Device that will allow me to use shaders?
Anything that could point me in right direction would be much appreciated.
Each Direct 3D device derives directly from IUnknown so no you cannot QI from a v6 device to a v9 device.
The only way you can do what you want (above driver level) is to implement the entire v6 device and translate all calls to their v9 equivalents. Of course you then have a problem if the game implements embm via v7 or v8 ...

Resources