Sign in to follow this  

Performance question regarding Pixel Shading

This topic is 4719 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've got now two ways how i can deal with per-pixel-lighting and i'm not sure yet which version is better. 1) use a pixel shader for each individual light type: directional, point, spot. this needs switching shader program for each scene element i render and for each light affecting it. 2) use one pixel shader which has some if-else statements inside but covers all three light types. needs no changing of shader program for each scene element and light but has if-else statements.

Share this post


Link to post
Share on other sites
Quote:
Original post by _the_phantom_
1 will be better on most current hardware, 2 might well gain you something on SM3.0 cards


Yes, I'll have to agree with _the_phantom on this one. Most graphics enthusiasts and researches are leaning towards large, generic 'uber' shaders for next gen hardware. Having one shader to render nearly every type of mesh in your scene will not be uncommon. However, this approach would be inefficient and inpractical on all but the newest graphics hardware. I tend to lean towards designing for the future, so I would use method two. However, if you don't provide a fallback then you'll be limiting yourself because the large majority of the market won't have next generation hardware for quite some time.

At any rate, good luck with your decision and let me know if I can be of further assistance.

Share this post


Link to post
Share on other sites
i'll do version 1 for the moment. my engine architecture is anyways scalable enough to be made to use newest hardware with a finger-snip without impacting whatever is there already. i just have read once somewhere that if-else in shaders below 3.0 are rather slow... but i also read that switching fragment programs a lot is slow too... guess it depends in the end on the hardware it runs on ^_^

Share this post


Link to post
Share on other sites
you could probably get away with using lightmaps for directional lights. or since there is usually only one directional light (the sun), just make a seperate shader for directional lights. you could even combine this with a zfill pass i suppose.

then you could do some clever clipping with user clip planes to simulate spotlights. if you use squared distance instead of actual distance it will already look spotlight-ish anyway. you can probably use one shader for all the dynamic lights then. effectively, the only per pixel lights would be point lights. in the shader code you just have to use small if statements that can expanded.

IMO spotlights only look good if you simulate beams or cones of light. usually cleverly placed billboards can fake this quite well. just think of a street light, far away it'll look like a cone. the closer you get, the more it seems like a point light. i'm cheap and only simulate nearby lights. maybe its just me.

Share this post


Link to post
Share on other sites
hm... i tried using a shader. looks like this:


how would you fake this flashlight? just using a billboard would look crappy i think.

Share this post


Link to post
Share on other sites

This topic is 4719 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this