📄 dot3_point.nvv
字号:
; Per-Pixel attenuated point lights with bumps
; This shader does the per-vertex dot3 work.
; It transforms the light vector by the basis vectors
; passed into the shader. This sample is different to
; the directional shader because it calculates a local light
; vector for the point light.
; The basis vectors only need to change if the model's
; shape changes.
; The output vector is stored in texture coordinates
; which look into a cubemap per pixel to get a normalized
; per pixel local light vector.
; (use the menus to see the various stages)
#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
#define POSITION_WORLD r4
#define LIGHT_DIRECTION r5
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 position to world space
dp4 POSITION_WORLD.x, V_POSITION, c[CV_WORLD_0]
dp4 POSITION_WORLD.y, V_POSITION, c[CV_WORLD_1]
dp4 POSITION_WORLD.z, V_POSITION, c[CV_WORLD_2]
dp4 POSITION_WORLD.w, V_POSITION, c[CV_WORLD_3]
; Calculate the vector to the light from the world vertex
add LIGHT_DIRECTION, -POSITION_WORLD, c[CV_LIGHT_POSITION]
; 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, LIGHT_DIRECTION
dp3 LIGHT_LOCAL.y, T_WORLD.xyz, LIGHT_DIRECTION
dp3 LIGHT_LOCAL.z, SxT_WORLD.xyz, 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 oT1, LIGHT_LOCAL, c[CV_HALF]
mov oT1.w, c[CV_ONE]
; Set alpha to 1
mov oD0.w, c[CV_ONE].w
; output tex coords
mov oT0.xy, V_TEXTURE
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -