Archived

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

BrianH

questions about vertex shaders

Recommended Posts

Hello, I am just starting to learn vertex shaders and I have some general questions.. 1. Since vertex shaders take over the transformation and lighting pipeline, I have to do all the lighting calculations myself. This means, I will no longer use the Direct3D SetLight or SetMaterial functions. Rather, I will load the lighting and material data into the constant registers. Is this correct? 2. Is there anyway to mix programmable vertex shaders and the fixed function pipeline (e.g. use it for transformation but leave lighting alone) or is it pretty much all or nothing? 3. If I cannot still use D3D lighting with vertex shaders, how do I go about supporting ambient, point, and directional lights? I guess I would just have to define a set of constants that I consistenly use for lighting data so that each shader I would write (that uses lighting) would know where this data is. 4. to disable lighting without having to write another version of each shader, I would just have to supply 0''s for the constant lighting data? As you can see, I have many questions regarding lighting with vertex shaders... so any help in this area would be greatly appreciated. I hope these questions made sense... Thanks, BH

Share this post


Link to post
Share on other sites
Okay, I''m relatively new to vertex shaders myself, so I might be wrong about some things...

1. Yep, you don''t need to worry about SetLight or SetMaterial. You can make your own function for it if it would make it easier to setup the constant registers.

2. From what I understand, it is all or nothing, you can''t mix and match.

3. Yep, just define a set of constants that will always hold certain data for the lights. There are a number of sources about how to calculate the lighting as well, just search the web. There are several tutorials here that are good too.

4. If you set the lighting data to zero, you would get complete darkness, i.e. all the lights would be off. If you want to shut off lighting, meaning, you don''t want any lighting done, but you still want to see the scene normally, then just put zero in for all the point, directional, and spotlights, and then just turn amibient lighting on to full. If you actually want to black out the scene, then setting everything to zero will work fine.

________________________
Grab your sword, and get prepared for the SolidSteel RPG engine, coming soon...(i.e. when it''s done)

Share this post


Link to post
Share on other sites
1. Yes
2. No (Yes, it is all or nothing)
3. You must write your own lighting functions that can use constants as lighting values.
4. Yes

For help, take a look at nVidia''s developer site, ATI''s site, the book shaderX, or my book listed below. Shaders look hard at first, but they are not too bad and they give you a lot of control.

Author, "Real Time Rendering Tricks and Techniques in DirectX", "Focus on Curves and Surfaces"

Share this post


Link to post
Share on other sites
Have a look at the vertex/pixel shader series of articles which were posted on gamedev. Wolfgang F. Engel nicely introduces the vertex and pixel shaders. He shows you how to use vertex shaders to achieve standard vertex lighting (point and directional lights) and later moves on to per-pixel lighting methods using pixel shaders.

Vertex shaders have really matured. There are lots of available contant registers and also you can use a whole lot of instruction in one vertex shader. This means you can process multiple lights in one pass.

Pixel shaders have got a long way to go though (ps 1.4 is already heaps better but I don''t think it is available on any of the current nVidia cards.) I''m using p.s 1.1 and the limit on the number of instructions is quite annoying. Never the less, a VERY powerful tool.

Share this post


Link to post
Share on other sites
Can I add a couple of questions?

1) I have seen different versions metioned for vertex and pixel shaders. Everyone says you really don''t need hardware support for vertex shaders since the software version is also fast, but you do for pixel shaders. Does the user only need to update their DX or video drivers to use the different versions?

I am a little confused on the relatioship between the versions and what the user must have setup on their computer.

Thanks!

Share this post


Link to post
Share on other sites
Hmmm you''ve got me a bit confused too now . Basically a later pixel or vertex shader version allows more registers, and more a advanced instruction set. In order for you to use a certain version though, both the API you are using AND the video card chip must support it. Note that if your video card and API allows say ps1.4, then you can use all the previous versions too (ie 1.0, 1.1, 1.2, 1.3) You just set it at the beginning of the shader code.

The ''software version'' which you are talking about is not really a version, as identified with the numbers above. DirectX provides a "software emulation" which runs the shader in software if the video card doesn''t support it. It doesn''t have a particular version number

Look at the articles which I mentioned in my previous post. They explain all the version issues.

Hope that helps

Share this post


Link to post
Share on other sites
Thanks for all the replies! You all have really cleared some things up for me.

I have another question though If I want to do full character skinning using vertex shaders, I will put all of the bone transforms into the constant registers before the geometry is drawn. However, I am limited to 96 constant registers (on my video card at least). Now since each bone transform is 4 vectors... that leaves me with a max of only 24 bones. Now, of course I have to take some of those away because a few need to be used for lighting and such (my first post). That leaves me with probably around 16 bones... This seems very restrictive. Any ideas?


Thanks again for all the replies

-BH

Share this post


Link to post
Share on other sites
In a CG program (see developer.nevidia.com), the skinning vertex shader program uses:
uniform float4x4 WorldViewProj,const uniform float3x4 Bones[29],uniform float3 LightVec
as an input which is a good deal more than 96 but you mentioned it was your graphic card.
Coundn''t you split the model and send the top and bottom body seperatly and set the constants to just a limited number of bones?

Share this post


Link to post
Share on other sites