Archived

This topic is now archived and is closed to further replies.

angrytofu

is ANYONE working with DX9 HLSL?

Recommended Posts

I''m trying to get them to work also.. It gets confusing when they separate the Declarations from the shaders. I haven''t quite gotten into HLSL quite yet, I''m still trying to get my shader vs.1.1 to work with the separate declarations! I''m really confused because my program uses multiple custom vertex shaders along with a couple drawings with the fixed function pipeline, and now that we have to pay attention to SetFVF and SetVertexDeclaration along with SetVertexShader, I''m baffled at how to tell the program what is the current declaration. I thought I had it right in that whenever I set the vertex shader, go ahead and set the declaration for it now too, and when I''m using the fixed function pipeline, use SetFVF to tell it the vertex format. But I get the error "Vertex stride in stream 0 is less than in the declaration, DrawIndexedPrimitive failed." So I''m guessing in some places I have to worry about setting the declaration to NULL when using the fixed function pipeline? I dunno, has anyone else gotten a complex system of custom and fixed shaders working with DX9, if even the HLSL?

Share this post


Link to post
Share on other sites
You best bet right now is Cg compiler toolkit just release for DirectX 9. developer.nvidia.com. If anyone has write any substantial HLSL scripts please share the info. We need to booststrap ourself.

Share this post


Link to post
Share on other sites
well i hope at some point there will be a 3dsmax plug in to view shaders or some tool to help create them for the mathmatically handicapped

eventually a tutorial will come out to help us all get started I think

Share this post


Link to post
Share on other sites
I just did my first HLSL pixel shader yesterday

So, maybe this helps ... note, following code is for the Managed DirectX9 ... shouldn''t be too hard to port to C++ (Hint: Use D3DXCompileShaderFromFile instead of the ShaderLoader):

OK, example shader is this:

float4 main() : COLOR
{
// return red for every pixel
return float4 (1, 0, 0, 1);
}

It just draws everything red ... simple, no? Here''s something which interprets the texture coordinate passed into the function as the color:

float4 main(float3 worldPos : TEXCOORD0) : COLOR
{
return float4 (worldPos.x, worldPos.y, worldPos.z, 1.0f);
}

I haven''t gotten around to trying other stuff ... as there is something called christmas. Especially texture sampling is on my ''try next'' list. OK, now with C# and Managed DX9 you create a PixelShader object like so:

GraphicsStream code = ShaderLoader.CompileShaderFromFile("myfile.hlsl", "main", null, "ps_2_0", 0);
PixelShader mHLSLPixelShader = new PixelShader(mDevice, code);
code.Close();

With CompileShaderFromFile() you always have to specify the entry point function (in both examples ''main'') and which pixel shader version you want to target ("ps_2_0"). Now, you set the pixel shader like so:

mDevice.PixelShader = mHLSLPixelShader;

Then you render your geometry. I haven''t done a whole lot more with it, but it seems nice. I''ll write something more interesting in the next days. Maybe also try it for vertex shaders, but I like to do stuff at the pixel level right now much more ... I just got my Radeon 9700

Merry Christmas,
Marco

Share this post


Link to post
Share on other sites
I think you need to use D3DXCompileShaderFromFile(). Then I think you need to run D3DXAssembleShader() since the output from compile shader would be asm, right? Yesterday, I wrote a dx9 vertex shader using asm and float color passed in as constant. Can''t get the right color out with fixed function pixel pipe, I''m on gf2 and don''t want to use ref rast. because it''s slow. So it renders a black quad, for a while it rendered nothing until I cleared to red color. It''s always good to clear to some other color than black, could have saved some time instead of trouble shooting my shader setup code.

Share this post


Link to post
Share on other sites
Well got my asm vertex shader working since I made a stupid mistake of doing this D3DRS_COLORWRITEENABLE(TRUE) instead of D3DRS_COLORWRITEENABLE(~0) stupid, stupid, stupid... I was pulling my hair out

Share this post


Link to post
Share on other sites
so how do imagine shaders being used for your games? will you use them on all objects? will shaders exist like textures in that people will make and collect them ? eventually will applying the shaders be done in 3ds max mainly?

Share this post


Link to post
Share on other sites
I don''t think vertex shaders will completely replace fixed function. Tools use it a lot. I still read devs using cpu for animations because of flexibility and ease of use. Pixel shaders on the other hand most likely will replace texture stages because of greater flexiblity offered by shaders. In due time when hw gets faster and less restrictive hlsl will replace asm. The asm might still be there for speed ups but I don''t think devs are going to be writing 1000 line shaders. Possibly what will happen is the shader is first written in hlsl then the output in asm is scrutinized for any optimizations.

I browse the cgshaders.com forum but people don''t post that much there so I don''t know if cg shaders are being used much. Most engines are still using lightmaps and fixed function pipeline. New doom3 like engines might utilize shaders more but I don''t think they''re must have today. NOLF looked nice on my gf2, down to the Kate''s coat sleve fur hairs. Lots of life left in the old fixed function pipe.

Aren''t those shaders in 3dsmax just texture layers that are then blended? If so they''re like quake3 texture shaders which are done with texture stages. The pixel shaders I refer to are complex math formulas that manipulate light vectors and such. Like reflectance vectors for terminator2 type looks. Better light falloff functions that are not encoded in texture maps, displacement maps, etc.

Share this post


Link to post
Share on other sites
i sued to read cshaders.org
that is the biggest (and only) site I can find dedicated to shaders.. if I was good enough I would open the first HLSL web site!

hopefulyl someone will someday with simple tutorials to help people get started with them

Share this post


Link to post
Share on other sites
I wrote a simple vertex dx9 hlsl shader compiled from memory, here is link:

http://www.gamedev.net/community/forums/topic.asp?topic_id=130376

I used dx9 docs hlsl section + Nvidia''s CG manual to figure stuff out. Not sure if you can use the CG toolkit with dx9. Anyways the hlsl code should work with gf1/radeon and up. Have gf2 myself and it works.

I also browse cgshaders site but it''s not frequented too often compared to gamedev.net site. It has some nice cg shaders samples that might be useful with dx9 hlsl. Btw, I''m starting to like hlsl Two things that I don''t like about asm shaders and that is counting instructions and their restrictions. With hlsl you can almost forget about them and concentrate on the algo at hand rather than meddle with registers. God, did that bring back memories

Share this post


Link to post
Share on other sites
I think that soon vertex shaders will come into common use because:
a) They run very fast, even in software.
b) They let you do more optimization than fixed-function would allow.
c) You can use multiple lights at a very high frame rate.

------------------------------
BASIC programmers don''t die, they just GOSUB and don''t return.

Share this post


Link to post
Share on other sites