Jump to content
  • Advertisement


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

Fluid FX

vertex/pixel shaders

This topic is 5946 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 have the book "Real time rendering ..." and it teaches you lightning per pixel for example. But now, it might be silly but, how do i use 2 lights for example? one light is simple, load the shader set the shader-values each render, and draw your scene but when you use 2 lights, should you load the shader 2 times, like an array of "shader buffers" or? GreetSZZ!!!!

Share this post

Link to post
Share on other sites
If you want 2 lights you need a new shader(*). Same calculations as for 1 light (but for 2 lights instead) and output colour is the results of your 2 lights put together.

pseuso code:

do light calculation for light 1
put output colour in r50
do light calculation for light 2
put output colour in r60
add r50 and r60 and put in output colour.

The only way to have a flexible system this way is to do the above for as many lights as you MIGHT need and make any inactive ones black (NOTE this is FLEXIBLE not EFFICIENT).

* NVidia (and possibly ATI (I haven''t checked)) have their own vs compilers which allow for #defines so that vs code can be generated as needed. This means writing just 1 complicated shader with a lot of ifdefs to add extra code. Download CG viewer to see what i mean (I''ve never used it - plain old MS for me)



Share this post

Link to post
Share on other sites
Check out:
nVidia NVLink or ATI ATILLA - those can be used to link fragments of shaders together at run time so your shaders resemble collections of macros and get converted to various combinations of shaders.

Wait for:
HLSL, Cg (out now), shader version 2.0, there are things in each of those to simplify this problem.

Simon O''Connor
Creative Asylum Ltd

Share this post

Link to post
Share on other sites
thanks for your reply i have to look more into shaders i guess :-)

you know what? why not wait for shader version 2.0...

cause i am so rich that i can just buy 100 of new cards every day!! ;-)


Share this post

Link to post
Share on other sites
For the vertex shader examples, it''s fairly easy to add more lights to the shader. See the nVidia effectsbrowser for an example of where they placed several lights in a shader by basically repeating the instructions for each light.

Per-pixel lights require a bit more work. You''ll have to build the lights into both the vertex shader and the pixel shader. Depending on the number of lights you and what type, you might have to get very creative with the textures themselves.

To start, look at the nVidia sample. You''ll see that it is essentially a shader with many repeated instructions for each light.

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!