Advertisement Jump to content
Sign in to follow this  
Metus

Shader management

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

How does one keep track of pixel- and vertexshaders in a game? Let's say my character has a weapon, and when fired, I want it to cast perpixel lighting on the geometry surrounding it. Should I assign the perpixel light shader to the weapon itself or should they be stored in a "pool" of global lightsources? And what if a secondary character arrives, with the same kind of perpixel-light casting weaponry? Do I need a separate pixelshader for each number of active lights per scene - one shader for 1 lighrsource, 1 shader for 2 lightsources... etc

Share this post


Link to post
Share on other sites
Advertisement
Quote:
Original post by Metus
Let's say my character has a weapon, and when fired, I want it to cast perpixel lighting on the geometry surrounding it. Should I assign the perpixel light shader to the weapon itself or should they be stored in a "pool" of global lightsources?

You should add a new light to light pool whenever weapon is fired (and of course, remove it after a while). Every mesh in your game should have a shader assigned to it, and these shaders can use light pool to get info about nearest lights.

Quote:
And what if a secondary character arrives, with the same kind of perpixel-light casting weaponry? Do I need a separate pixelshader for each number of active lights per scene - one shader for 1 lighrsource, 1 shader for 2 lightsources... etc

There are two commonly used methods:
1) Render one pass per light. That is, render all geometry in light's range once for every light, using additive blending to combine results together.

2) Handle multiple lights in one shader. You can write a shader that computes lighting from, let's say, 3 light sources. At runtime, you collect nearest 3 lights for each mesh and pass their properties as shader constants.

Share this post


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

  • 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!