Вопрос

I'm creating a fog feature in my Effect file.. in the pixel shader, I calculate the distance from the camera position and the input's position, as so:

    float x = distance(_in.pos3d, CameraPosition);
float fd;
if(Fog)
{
    if(x > FogDistance)
        fd = ((x-FogDistance) * FogIntensity > 100) ? 100 : ((x-FogDistance) * FogIntensity);
    //_in.color = ???;
}

Where: x is the distance from the camera position and vertex position, fd is the percentage of fog color, FogDistance is the distance where objects won't be affected by fog, and FogIntensity is how intense the fog is.

What I'm trying to get is a color that contains (fd %) of the fog color. For example, if the fog color was orange, the input was white, and fd was 25%, the color generated would be white + 25% orange.

EDIT: By the way, sorry for the unmaintainable setting code.

EDIT 2: I noticed that having two transparent layers have a transparent outcome, so I cleaned up the question a bit. There's no percentage for the vertex input.

Это было полезно?

Решение

You want the lerp function (MSDN). That is the "linear interpolation" function.

Colours in pixel shaders are essentially the same thing as vectors, so you can use any vector functions on them.

Rather than a percentage (in the range 0 to 100), the lerp function takes a value between 0 and 1.

So your code will probably look something like the following:

_in.color = lerp(_in.color, someOtherColor, fogAmount);
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top