I wrote a shader combining 3 bump maps and 3 color maps together distributed by a splat map. While I cannot do these calculations in one pass due to an instruction exceeding I splitted these in two passes (one calculates the bump/lighting and the second pass calculates the color). In order to get correct lighting, I blend the second color pass in a multiplicative way with the first pass by using “Blend DstColor Zero”.
The problem that occurs when doing it that way is that the fog isn’t being calculated correctly. The fog now fades to black the further the cam is away from the surface instead of fading to the fog color defined in the unity settings.
Any suggestions to fix this issue?
I tried that, but it doesn’t fix it. I also tried to compute fog manually and disabling the unity fog. But that doesn’t work either. If I manually compute the fog term, the fogged objects appear to be a little darker than the unity fogged objects.
I noted that if I’m using no blend mode in the second pass, everything renders fine. But why does the multiply blend mode influence the fog computation?
potentially due to the blend to zero on the first blend
why do you blend there at all actually if you just want to draw it? (you can just not specify a blend in that pass for example)
I set the blend mode to multiply in the second pass, because I’m doing all the lighting in the first pass. As you know to get the final color of a surface you multiply the color map by the lighting term, thus I have to set a blend mode. If I don’t set it, the surface isn’t lit correctly and is rendered much too bright due to a simple add of the lighting term and the surface color.
Too bright should not happen as you do the lighting calc in only one of the passes, which likely normally is the bump pass as you need to calculate all the stuff there already anyway.
normally you would likely use no blend setup in pass one (and none set globally) and then set the second one additive.
Though with all that said, I’m not sure if your setup here is the best at all.
I personally would have gone the same way as the terrain goes:
do up to 2 combined bump+color splats per pass and X passes to handle up to 2*x such splats (thats how terrain works too with up to 4 color splats per pass)
that way you don’t get strange interactions between passes that never should have been seperated in passes at all.
from your need of 2 passes I guess each of the 3 combos has an own splat map right? otherwise you don’t need 2 passes anyway, as it would only be 7 textures, and up to 8 are supported unless you want to support ati 9800 or older or geforce4 actually
Yeah, I have 3 normal maps which are distributed to a splatmap (each color channel for one normal map) and I have a global bump map which fades in if the cam is further away from the surface. Secondly I have 3 color maps which are also blended based on the same splat map. So I have a total ammount of 8 textures. According to your statement, I can use these all in one pass. If I write a simple shader with 8 texture accesses where all color values of the textures gets for example multiplied or added, everything works fine. But if I’m doing a little bit of math in the shader, the instruction limit of 12 (on ATI HD 2400) is exceeded.
I think I should set the shader model to 3.0 to increase the number of instruction and get rid of this error. Thanks very much.