...
The shaders have access to some _uniforms _ (see shaders for more info on shaders and uniforms) that are set by the game: the area flags, the world time, ... and the one we will use in this tutorial areaGlobalWind which contains the global wind vector for the area.
¿Why this uniform? because this uniform can be changed in a per player basis, so we can change the value of _areaGlobalWind _ for only one player. There are sureley other uniforms that can be used but, as we will see, this one allows an easy way for the shader to detect we want to apply a specific effect without affecting, at least noticeably, the wind effects in the area.
...
| Code Block | ||||||||
|---|---|---|---|---|---|---|---|---|
| ||||||||
#include "nwnx_area"
const float SM_WIND_SHADER_NONE = 0.00;
const float SM_WIND_SHADER_ETHEREAL = 0.01;
const float SM_WIND_SHADER_ULTRAVISION = 0.02;
void SetWindShader(object oPlayer, float fWindShader=SM_WIND_SHADER_NONE);
void SetWindShader(object oPlayer, float fWindShader=SM_WIND_SHADER_NONE)
{
object oArea = GetArea(oPlayer);
// I'm using the default game vector, a normalized vector (length 1) would be "easier", but I have not tested it
vector vDirection = Vector(1.0, 1.0, 0.0);
int nWindPower = NWNX_Area_GetWindPower(oArea);
float fYaw, fPitch;
switch(nWindPower)
{
case 0:
fYaw = 0.0;
fPitch = 0.0;
break;
case 1:
fYaw = 100.0;
fPitch = 3.0;
break;
case 2:
fYaw = 150.0;
fPitch = 5.0;
break;
}
// We will work with the squared modulus to avoid the use of sqrt() operation in the shader
float fSqModulus = IntToFloat(2*nWindPower*nWindPower);
//We want the shader to see fSqModulus + fWindShader
fSqModulus+=fWindShader;
// From the desired result, calculate the magnitude we will use for the NWNX_Player_UpdateWind function
float fMagnitude = fSqModulus/2.0; // 2.0 is the squared modulus of vDirection
fMagnitude = sqrt(fMagnitude);
// Apply it to the player
NWNX_AreaPlayer_UpdateWind(oPlayer, vDirection, fMagnitude, fYaw, fPitch);
} |
...