Jump to content
  • Advertisement

Archived

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

angrytofu

is ANYONE working with DX9 HLSL?

This topic is 5772 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I can not find a web page or ANYTHING dealing with shaders. I know about the web page for CG shaders. So is there some more examples or anything out there?

Share this post


Link to post
Share on other sites
Advertisement
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

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!