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

📄 dot3_directional.nvv

📁 游戏编程精华02-含有几十个游戏编程例子
💻 NVV
字号:
; This shader does the per-vertex dot3 work.
; It transforms the light vector by the basis vectors
; passed into the shader.
; The basis vectors only need to change if the model's
; shape changes.
; The output vector is stored in the diffuse channel
; (use the menu to look at the generated light vector)
#include "dot3.h"

#define V_POSITION v0
#define V_NORMAL v1
#define V_DIFFUSE v2
#define V_TEXTURE v3
#define V_SxT v4
#define V_S v5
#define V_T v6
#define S_WORLD r0
#define T_WORLD r1
#define SxT_WORLD r2
#define LIGHT_LOCAL r3

vs.1.0

; Transform position to clip space and output it
dp4 oPos.x, V_POSITION, c[CV_WORLDVIEWPROJ_0]
dp4 oPos.y, V_POSITION, c[CV_WORLDVIEWPROJ_1]
dp4 oPos.z, V_POSITION, c[CV_WORLDVIEWPROJ_2]
dp4 oPos.w, V_POSITION, c[CV_WORLDVIEWPROJ_3]

; Transform basis vectors to world space
dp3 S_WORLD.x, V_S, c[CV_WORLD_0]
dp3 S_WORLD.y, V_S, c[CV_WORLD_1]
dp3 S_WORLD.z, V_S, c[CV_WORLD_2]

dp3 T_WORLD.x, V_T, c[CV_WORLD_0]
dp3 T_WORLD.y, V_T, c[CV_WORLD_1]
dp3 T_WORLD.z, V_T, c[CV_WORLD_2]

dp3 SxT_WORLD.x, V_NORMAL, c[CV_WORLD_0]
dp3 SxT_WORLD.y, V_NORMAL, c[CV_WORLD_1]
dp3 SxT_WORLD.z, V_NORMAL, c[CV_WORLD_2]

; transform light by basis vectors to put it
; into texture space
dp3 LIGHT_LOCAL.x, S_WORLD.xyz, c[CV_LIGHT_DIRECTION]
dp3 LIGHT_LOCAL.y, T_WORLD.xyz, c[CV_LIGHT_DIRECTION]
dp3 LIGHT_LOCAL.z, SxT_WORLD.xyz, c[CV_LIGHT_DIRECTION]

; Normalize the light vector
dp3 LIGHT_LOCAL.w, LIGHT_LOCAL, LIGHT_LOCAL
rsq LIGHT_LOCAL.w, LIGHT_LOCAL.w
mul LIGHT_LOCAL, LIGHT_LOCAL, LIGHT_LOCAL.w

; Scale to 0-1
add LIGHT_LOCAL, LIGHT_LOCAL, c[CV_ONE]
mul oD0, LIGHT_LOCAL, c[CV_HALF]

; Set alpha to 1
mov oD0.w, c[CV_ONE].w

; output tex coords
mov oT0, V_TEXTURE
mov oT1, V_TEXTURE









⌨️ 快捷键说明

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