• Advertisement
Sign in to follow this  

Pixel Shader

This topic is 4731 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

When doing pixel lighting with DirectX9 PixelShaders, how do you, in the fastest way possible, apply more than one light? Do you draw the primitive more than once and blend the results? Or could you, somehow, send more data to the pixelshader than only about 8 registers?

Share this post


Link to post
Share on other sites
Advertisement
Quote:
Original post by henksgu
When doing pixel lighting with DirectX9 PixelShaders, how do you, in the fastest way possible, apply more than one light? Do you draw the primitive more than once and blend the results? Or could you, somehow, send more data to the pixelshader than only about 8 registers?

There are two general strategies to follow here...

Firstly, use multi-pass rendering. Render the entire scene using the shader configured for light-1, then render the entire scene again using the shader configured for light-2 and use the ADDITIVE blending operations. It's very simple to implement, but obviously has a few performance issues if you're not careful.

Secondly, write a longer and more complex version of your shader so that it can do multiple lights in one pass. You may find that you need the higher-end shader models to achieve this (ps_2_0_b or ps_3_0). The guys behind CryEngine (used in FarCry) released their v1.2 patch with one of the primary additions was supporting multiple lights in a single pass using sm3 shaders.

hth
Jack

Share this post


Link to post
Share on other sites
Another method is to use interfaces - although this only applies to CG. You then loop through all the lights in the scene, and then blend these results together.

Share this post


Link to post
Share on other sites
What ís sm3 shaders? How do they work and do I have to download some patch? I am currently writing with v 1.4 (if that is the same)

Share this post


Link to post
Share on other sites
Quote:
Original post by henksgu
What ís sm3 shaders? How do they work and do I have to download some patch? I am currently writing with v 1.4 (if that is the same)

"SM" = Shader Model. It's the all-encompassing term for pixel/vertex shaders of any major version.

Currently we have:
SM1 - all the 1.x versions (GeForce 3's, Radeon 8500->9200)
SM2 - all the 2.x versions (GeForceFX's, Radeon 9500->X850)
SM3 - all the 3.x versions (GeForce 6x00's only)

You do need supporting software - in particular, the latest DirectX runtime (9.0c) in order to use the latest and greatest; however it is predominantly dependent on the underlying hardware.

If you don't have one of the high end cards, then you may not want to take my suggestion of using the higher shader models to perform the operation in a single pass.

hth
Jack

Share this post


Link to post
Share on other sites
I do have a radeon 9600, so the version 2.0 would work nicely right?

You would use the rep, and loop commands right? But how do you pass the lights' positions and color etc.

I only want to have the simple positional lights to start with, and then multiply them with some already finished lightmaps.

But my problem is that I want to have an infinite number of lights, but I don't know how to do that in a pixel shader, you know pass all the info to the GPU

Share this post


Link to post
Share on other sites
If I'm not completely wrong, is it not a restriction of how many constants you can write (about 8) to the pixelshader and they can only hold a value between
-1 and 1 right?

So how can you give the ps the amount of data that is required for about 25 lights?

Share this post


Link to post
Share on other sites
Quote:
Original post by henksgu
So how can you give the ps the amount of data that is required for about 25 lights?

You wouldn't [smile]. At least, my current understanding of the technologies wouldn't allow you to do that - in fact, pretty much everything I've read about complex realtime lighting would suggest less than 10 active (dynamic) sources per rendered frame if you want a decent frame rate.

My original suggestion of using shaders to perform multiple lighting calculations in a single pass could easily be combined with the pure multi-pass approach.

If you can write a shader that'll do 5 light calculations in a single pass, then you could just do 5 passes - each with a new set of lights...

hth
Jack

Share this post


Link to post
Share on other sites
ok but how do pass in a single light then? You need at least to pass in a position and a light range. But with pixel shader you can only pass in a small value between -1 and 1 (or something), so how do pass the position and range? And how do I know the world position of the pixel?

Sorry for beeing such a ass ;)

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement