⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 fog.vp

📁 OpeNGL超级宝典源代码. OpeNGL超级宝典源代码.
💻 VP
字号:
!!ARBvp1.0

# fog.vp
#
# Generic vertex transformation,
# diffuse and specular lighting,
# based on one white light

ATTRIB iPos = vertex.position;             # input position
ATTRIB iPrC = vertex.color.primary;        # input primary color
ATTRIB iNrm = vertex.normal;               # input normal

OUTPUT oPos = result.position;             # output position
OUTPUT oPrC = result.color.primary;        # output primary color

PARAM mvp[4] = { state.matrix.mvp };       # model-view * proj matrix
PARAM mv[4] =  { state.matrix.modelview }; # model-view matrix
# inverse transpose of model-view matrix:
PARAM mvIT[4] = { state.matrix.modelview.invtrans }; 

PARAM lightPos = program.local[0];         # light pos in eye space
PARAM density = program.local[1];          # fog density
PARAM fogColor = {0.5, 0.8, 0.5, 1.0};     # fog color
PARAM e = {2.71828, 0, 0, 0};

TEMP N, V, L, H, NdotL, NdotH;             # temporary registers
TEMP diffuse, specular, fogFactor, litColor;

DP4 oPos.x, iPos, mvp[0];                  # xform input pos by MVP
DP4 oPos.y, iPos, mvp[1];
DP4 oPos.z, iPos, mvp[2];
DP4 oPos.w, iPos, mvp[3];

DP4 V.x, iPos, mv[0];                      # xform input pos by MV
DP4 V.y, iPos, mv[1];
DP4 V.z, iPos, mv[2];
DP4 V.w, iPos, mv[3];

SUB L, lightPos, V;                        # vertex to light vector

DP3 N.x, iNrm, mvIT[0];                    # xform norm to eye space
DP3 N.y, iNrm, mvIT[1];
DP3 N.z, iNrm, mvIT[2];

DP3 N.w, N, N;                             # normalize normal
RSQ N.w, N.w;
MUL N, N, N.w;

DP3 L.w, L, L;                             # normalize light vector
RSQ L.w, L.w;
MUL L, L, L.w;

ADD H.xyz, L, {0, 0, 1};

DP3 H.w, H, H;                             # normalize half-angle
RSQ H.w, H.w;
MUL H, H, H.w;

DP3 NdotL, N, L;                           # N . L
MAX NdotL, NdotL, 0.0;
MUL diffuse, iPrC, NdotL;

DP3 NdotH, N, H;                           # N . H
MAX NdotH, NdotH, 0.0;
POW specular, NdotH.x, 128.0.x;            # 128 is specular exponent

ADD litColor, diffuse, specular;           # sum the colors
MAX litColor, litColor, 0.0;               # clamp to [0,1]
MIN litColor, litColor, 1.0;

# fogFactor = clamp(e^(-(d*|Ve|)^2))
DP4 fogFactor.x, V, V;                     
POW fogFactor.x, fogFactor.x, 0.5.x;
MUL fogFactor.x, fogFactor.x, density.x;
MUL fogFactor.x, fogFactor.x, fogFactor.x;
POW fogFactor.x, e.x, -fogFactor.x;
MAX fogFactor.x, fogFactor.x, 0.0;         # clamp to [0,1]
MIN fogFactor.x, fogFactor.x, 1.0;

SUB litColor, litColor, fogColor;          # blend lit and fog colors
MAD oPrC, fogFactor.x, litColor, fogColor;

END

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -