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

📄 reflect_and_refract.nvv

📁 游戏编程精华02-含有几十个游戏编程例子
💻 NVV
字号:
; This shader generates the camera space reflection coordinates in T0, and
; a reasonable approximation of refraction coordinates in T1. The approximation 
; for refraction is set up by shortening the vertex normal and passing it 
; through the standard reflection calculation.

#include "reflect_and_refract.h"


#define R_WORLDSPACE_NORMAL r9
#define R_WORLDSPACE_NORMAL_REFRACT r7
#define R_EYE_VECTOR r3
#define R_DOT2 r4 

#define R_TEMP r1 

vs.1.0

; Transform position
dp4 oPos.x, v0, c[CV_WORLDVIEWPROJ_0]
dp4 oPos.y, v0, c[CV_WORLDVIEWPROJ_1]
dp4 oPos.z, v0, c[CV_WORLDVIEWPROJ_2]
dp4 oPos.w, v0, c[CV_WORLDVIEWPROJ_3]

; Get world space vertex position
dp4 r0.x, v0, c[CV_WORLD_0]
dp4 r0.y, v0, c[CV_WORLD_1]
dp4 r0.z, v0, c[CV_WORLD_2]
dp4 r0.w, v0, c[CV_WORLD_3]

; Transform normal to world space
dp3 R_WORLDSPACE_NORMAL.x, v1, c[CV_WORLD_0]
dp3 R_WORLDSPACE_NORMAL.y, v1, c[CV_WORLD_1]
dp3 R_WORLDSPACE_NORMAL.z, v1, c[CV_WORLD_2]

; Need to re-normalize normal
dp3 R_WORLDSPACE_NORMAL.w, R_WORLDSPACE_NORMAL, R_WORLDSPACE_NORMAL
rsq R_WORLDSPACE_NORMAL.w, R_WORLDSPACE_NORMAL.w
mul R_WORLDSPACE_NORMAL, R_WORLDSPACE_NORMAL, R_WORLDSPACE_NORMAL.w

; Get vector from eye to vertex
sub R_TEMP, r0, c[CV_WORLDEYEPOS]
dp3 R_EYE_VECTOR.w, R_TEMP, R_TEMP
rsq R_EYE_VECTOR.w, R_EYE_VECTOR.w		
mul R_EYE_VECTOR, R_TEMP, R_EYE_VECTOR.w

; Calculate E - 2*(E dot N)*N 
dp3 R_DOT2, R_EYE_VECTOR, R_WORLDSPACE_NORMAL
add R_DOT2, R_DOT2, R_DOT2
mad oT0.xyz,R_WORLDSPACE_NORMAL, -R_DOT2, R_EYE_VECTOR
mov oT0.w, c[CV_ONE].x

; Get refraction normal
mul R_WORLDSPACE_NORMAL_REFRACT.xyz, R_WORLDSPACE_NORMAL, c[CV_REFRACT]

; Calculate E - 2*(E dot N)*N 
dp3 R_DOT2, R_EYE_VECTOR, R_WORLDSPACE_NORMAL_REFRACT
add R_DOT2, R_DOT2, R_DOT2
mad oT1.xyz,R_WORLDSPACE_NORMAL_REFRACT, -R_DOT2, R_EYE_VECTOR
mov oT1.w, c[CV_ONE].x






⌨️ 快捷键说明

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