質問

In my engine I have lots of shaders that handles specified combination of textures, for example DiffTexShader, NoTexShader, DiffTexNormalMapShader, DiffTexLightmapShader etc.

Now I want do add shadow mapping effect. What is better to do? Is it better to do shadow mapping in separate pass and then combine original scene with shadow-only scene? Or it is better to duplicate all my shaders and make them able to use shadowmap to clculate shadows?

I think first approach is better to maintain (only one extra shader for rendering shadows), but much slower than second approach.

役に立ちましたか?

解決

That's a general problem with the shaders: have one, huge uber-shader and just set the flags: - enableTexturing, enableNormalMap, enableLights and then in the code

if (enableTexturing) {

}
if (enableLights) {

}

Or have separated shaders like in your case. I would not go into a separate pass because it can hurt the performance much.

In glsl you can implement shadowing inside a function and attach this function as another shader to the program. That way it will be visible by other shaders in the program.

here are another similar questions:

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top