Skip to main content
GameDev.net gamedev.net
🔒 Locked

Performance question regarding Pixel Shading

Started by RPTD Jan 16, 2005 at 4:42 PM 4 replies 750+ views
Original Post
RPTD
RPTD
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.
Life's like a Hydra... cut off one problem just to have two more popping out.
Leader and Coder: Project Epsylon | Drag[en]gine Game Engine
_the_phantom_
_the_phantom_
1 will be better on most current hardware, 2 might well gain you something on SM3.0 cards
Sages
Sages
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.
RPTD
RPTD
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 ^_^
Life's like a Hydra... cut off one problem just to have two more popping out.
Leader and Coder: Project Epsylon | Drag[en]gine Game Engine
emosoft05
emosoft05
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.
RPTD
RPTD
hm... i tried using a shader. looks like this:


how would you fake this flashlight? just using a billboard would look crappy i think.
Life's like a Hydra... cut off one problem just to have two more popping out.
Leader and Coder: Project Epsylon | Drag[en]gine Game Engine

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.