Sign in to follow this  
SAE Superman

Problem with book code: "Programming Vertex and Pixel Shaders" : **SOLVED**

Recommended Posts

I just bought "Programming Vertex and Pixel Shaders" last weekend and I'm having trouble setting up Visual Studio 2003 and compiling and running the first program. Here is a link to another thread started last summer about this from someone else: Other thread I have two problems...problem #1: I can't run the precompiled executables. When I run the programs, I get a dialog box that says something like "Make sure DirectX is installed correctly". I downloaded the latest DirectX SDK (April 2006) and installed it. No change. Do I need to completely uninstall DirectX and then install the latest? Problem #2: The book is horrible about directing you on how to set up Visual Studio to compile and debug shaders. I was wondering if anyone could give me a quick rundown on how to set it up and compile a simple .fx file. I'm not at my home computer right now so I can't give details on how far I get or the exact errors but I'll post them as soon as I can. Any links to resources would be greatly appreciated too since google is no help on this (and I found stuff on gamdev.net about it but it was written by the same author as this book, Wolfgang Engel, and it doesn't explain how to set up VS any better). Thanks in advance... [Edited by - SAE Superman on April 19, 2006 11:56:03 AM]

Share this post


Link to post
Share on other sites
I have that book too but have not cracked it yet. However, I don't think it is an intro book. To start out take a look at some of the HLSL samples in the DirectX SDK (most of the other samples in the SDK also use HLSL). You can use the D3DXCreateEffectFromFile function to compile an effect (.fx) file at runtime. There are similar functions for doing vertex and pixel shaders separately.

I think the executibles should work though. Since DX uses COM it supports the older interfaces even if you are developing with the later ones. Try uninstalling the current DX SDK and installing the newer ones being sure to install the runtime and debug stuff. The Introduction chapter in the book shows how VS should be setup. You need VS 2002 or later for it to work.

Share this post


Link to post
Share on other sites
Thanks for replying...here's what I did so far:

Uninstalled every version of DirectX SDK I had installed. Then installed the latest DirectX SDK (April 2006). I then tried to run the precompiled executable and got this message in a dialog box: "Could not find required media. Ensure that the DirectX SDK is correctly installed."

As for the problem #2:
Here's a link to a pdf of the sample first chapter: Sample First Chapter

My problem is page 6 and 7 (I'm new to shaders and custom build steps in VS so bear with me). I can bring up the properties page but what exactly do I type where? You can't read the entire line in the figure on page 6, and page 7 doesn't tell you what to type where. Do I type what page 7 says word for word? I tried typing it in the "Command Line" portion but then I right click on the .fx file and the compile option is greyed out (until I put something into "Outputs", which I'm assuming I have to put something but what?) If I go on and look at the bottom of page 9 "Compile and Debug a Shader", it doesn't tell you everything to get you started in Visual Studio. Also, on page 11, how do I "Confirm that the shaders are compiled with debug information by setting flags..."?

I just need to get this first project to compile and then I can proceed with the learning and the expanding of knowledge [grin]

Thanks for the help!

Share this post


Link to post
Share on other sites
Hey just came across your post. The best thing you can do is install the same SDK that comes with the CD. Microsoft changed the DirectX framework quite a lot in the last couple of years and only the framework version on the CD should work without hazzle.
Hope this helps,
- Wolf

Share this post


Link to post
Share on other sites
I had that same dialog box for the precompiled demos. You need to find the UI folder in the Media folder of your installed SDK. Then, place the UI folder in the Media folder provided by the CD. That should let you run the sample programs.

Share this post


Link to post
Share on other sites
Quote:
Original post by DirectXFreak
I had that same dialog box for the precompiled demos. You need to find the UI folder in the Media folder of your installed SDK. Then, place the UI folder in the Media folder provided by the CD. That should let you run the sample programs.


Thanks, that worked great!!!

Now I just need help compiling in Visual Studio (remember I'm a noob at custom build steps in VS [grin])

Thanks again!

Share this post


Link to post
Share on other sites
Quote:
Original post by wolf
Hey just came across your post. The best thing you can do is install the same SDK that comes with the CD. Microsoft changed the DirectX framework quite a lot in the last couple of years and only the framework version on the CD should work without hazzle.
Hope this helps,
- Wolf


I'll probably try this if I have any more problems after I get the compiling thing figured out. Can you clarify my issues with the pages I've stated above?

BTW, the precompiled exe's look amazing!

Share this post


Link to post
Share on other sites
Hey,
check out figure 1.2. It shows you what you need to type in. Verify this with the HLSL compiler command line on page 6 and 7. You can also check out the DirectX SDK documentation to look at some command line parameters.
It is not really necessary to do it this way, but it is quite handy :-)

Have fun,
- Wolf

Share this post


Link to post
Share on other sites
Quote:
Original post by wolf
Hey,
check out figure 1.2. It shows you what you need to type in. Verify this with the HLSL compiler command line on page 6 and 7. You can also check out the DirectX SDK documentation to look at some command line parameters.
It is not really necessary to do it this way, but it is quite handy :-)

Have fun,
- Wolf


That's my problem...figure 1.2 cuts off the command in "Command Line." Plus the project in the figure isn't the same as the first project Ambient, so it makes it hard for me to correlate what I put where. So can you tell me exactly what goes in "Command Line" and "Outputs" for the Ambient project? For instance, what is the PS.txt in the figure? Do I type the $(InputName).fx exactly or do I have to replace that with the input .fx file name? Is that the end of the command line? Do I put "vs.fxo" in the Outputs every time or does that correspond to something? The only sentence I can find that says anything about the "Outputs" field is page 7: "The entry field labeled Output stores the name of the output file." So what is the name of the output file supposed to be?

Plus, just telling the reader to check the SDK and here's a list of options without explaining any of them or how to use them or when to use them doesn't help the noob at debugging shaders (i.e. me). Having at least one very noob literal step by step "type this exactly here and there," would help a ton. After I see how it works once, I can apply that to the rest of the projects...

Thanks for the help guys :)

[Edited by - SAE Superman on April 18, 2006 12:01:31 PM]

Share this post


Link to post
Share on other sites
... this is a general problem I can see more and more.
I assumed that people who want to program vertex and pixel shaderes are working usually for some time in the industry or at least with DirectX. After you programmed DirectX for some time, all these things are not an issue for you, because you are used to the IDE ... the question is how far would you like to explain the usage of Visual C++ in a book on shader programming.

The next version of the book will be clearly marked for intermediate programmers.
I am sorry about the confusion here. I would like to suggest you look into a tutorial on how to use the Visual C++ IDE first.
Ok here is an example command line that should work

fxc.exe /T ps_2_0 /E PSProjTexture /Fc $(InputName).txt $(InputName).fx

This one compiles a pixel shader with the name PSProjTexture for ps_2_0 and outputs an assembly listing.

If you write that into your command line, it should work. I hope this helps.

Have a great day,
- Wolf



Share this post


Link to post
Share on other sites
OK, so here's where I am now. I installed the SDK that was included on the CD (only one on my computer now). I typed in exactly what you said in the command line but when I right click on the .fx, the compile option is greyed out. I then add the vs.fxo to the "Outputs" line just like it is in Figure 1.2. I then right click the Ambient.fx file and click "compile." It then gives me this error:

error X3501: 'PSProjTexture': entrypoint not found

error PRJ0019: A tool returned an error code from "Performing Custom Build Step"

What am I missing / doing wrong now?

Thanks for all the help :) I'm really looking forward to learning from this book.

Share this post


Link to post
Share on other sites
PSProjTexture is the name of the pixel shader in this example. I do not know which name your pixel shader has.
Check out the documentation for a flag that lets you compile the vertex and the pixel shader at the same time ... I believe it was fx_2_0. Than you should be able to run

fxc.exe /T fx_2_0 /Fc $(InputName).txt $(InputName).fx

Hope it helps,
- Wolf

Share this post


Link to post
Share on other sites
You need to compile them with debug data ... I think there is a #define in the example program that just sets this flag.

Share this post


Link to post
Share on other sites
Haha, I had those uncommented earlier but switched back to what was on the CD [grin] Everything works great now, thanks a ton! One last question about when I turn on the debug...is it supposed to run at 1-2 frames per second? I have a NVidia 6600 GT and I get a dialog that states "Switching to the reference rasterizer, a device that implements the entire Direct3D feature set, but runs very slowly."

Thanks again for all the help Wolf! I'm really looking forward to diving into your book [grin]

Share this post


Link to post
Share on other sites
that should not happen on most of the examples :-) ... I believe the vertex texture example might have such a behaviour.
Other than this the text should highlight, if an example is hardware specific ... I really can not remember anymore which example might be hardware-specific. It is now more than 2 years ago that I finished the book and I am currently thinking about a re-write with a couple of people.

Share this post


Link to post
Share on other sites
.... wait a second. It might be that the old SDK did not support a few features the hardware had ...

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