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

📄 objectspace.nvf

📁 游戏编程精华02-含有几十个游戏编程例子
💻 NVF
字号:
vs.1.0

#include "constants.h"

// *** Object space code ***
// A fragment to create an object-space eye vector
#beginfragment create_objectspace_eyevector_local_viewer
add r_objectspace_eyevector, FIXED_POSITION, -c_objectspace_eyeposition
dp3 r_objectspace_eyevector.w, r_objectspace_eyevector, r_objectspace_eyevector
rsq r_eye_distance_rcp.w, r_objectspace_eyevector.w		
mul r_objectspace_eyevector, -r_objectspace_eyevector, r_eye_distance_rcp.w
#endfragment

// *** Texgen code
// A fragment to implement CAMERASPACEREFLECTION in DX7 wording
// Calculate E - 2*(E dot N)*N
#beginfragment calculate_objectspace_reflection
dp3 r_dot2, -r_objectspace_eyevector, v_normal
add r_dot2, r_dot2, r_dot2
mul r_dot2, v_normal, r_dot2
add r_eyereflection_vector, -r_objectspace_eyevector, -r_dot2
#endfragment

// *** Directional light code
// Dot normal with light vector
#beginfragment calculate_objectspace_directionallight_diffuse_intensity
dp3 r_intensity, v_normal, c_dirlight_direction++
#endfragment

// Generate normalized half vector
#beginfragment calculate_objectspace_directionallight_diffuse_and_specular_intensity_localviewer
dp3 r_intensity.x, v_normal, c_dirlight_direction  // diffuse intensity caclulation
add r_halfvector, r_objectspace_eyevector, c_dirlight_direction++ // half-vector calculation
dp3 r_halfvector.w, r_halfvector, r_halfvector
rsq r_halfvector.w, r_halfvector.w
mul r_halfvector, r_halfvector, r_halfvector.w
dp3 r_intensity.yz, v_normal, r_halfvector // specular intensity calculation
#endfragment

#beginfragment calculate_objectspace_directionallight_diffuse_and_specular_intensity_nonlocalviewer
dp3 r_intensity.x, v_normal, c_dirlight_direction++		// diffuse intensity caclulation
dp3 r_intensity.yz, v_normal, c_dirlight_halfvector++	// specular intensity calculation
#endfragment

#beginfragment calculate_objectspace_directionallight_diffuse_and_specular_intensity_rdotl
dp3 r_intensity.x, v_normal, c_dirlight_direction						// diffuse intensity caclulation
dp3 r_intensity.yz, r_eyereflection_vector, c_dirlight_direction++  	// specular intensity calculation
#endfragment

// *** Point light code
// Generate the vertex to light vector
#beginfragment calculate_objectspace_pointlight_vector
add r_vertex_to_pointlight, c_pointlight_position++,-FIXED_POSITION
dp3 r_vertex_to_pointlight.w, r_vertex_to_pointlight, r_vertex_to_pointlight	
rsq r_vertex_to_pointlight.w, r_vertex_to_pointlight.w
mul r_vertex_to_pointlight, r_vertex_to_pointlight, r_vertex_to_pointlight.w
#endfragment

// Generate the diffuse intensity
#beginfragment calculate_objectspace_pointlight_diffuse_intensity
dp3 r_intensity, v_normal, r_vertex_to_pointlight
#endfragment

// Generate normalized half vector
#beginfragment calculate_objectspace_pointlight_diffuse_and_specular_intensity_localviewer
dp3 r_intensity.x, v_normal, r_vertex_to_pointlight
add r_halfvector, r_objectspace_eyevector, r_vertex_to_pointlight
dp3 r_halfvector.w, r_halfvector, r_halfvector
rsq r_halfvector.w, r_halfvector.w
mul r_halfvector, r_halfvector, r_halfvector.w
dp3 r_intensity.yz, v_normal, r_halfvector
#endfragment

#beginfragment calculate_objectspace_pointlight_diffuse_and_specular_intensity_nonlocalviewer
dp3 r_intensity.x, v_normal, r_vertex_to_pointlight
add r_halfvector, c_objectspace_eyevector, r_vertex_to_pointlight
dp3 r_halfvector.w, r_halfvector, r_halfvector
rsq r_halfvector.w, r_halfvector.w
mul r_halfvector, r_halfvector, r_halfvector.w
dp3 r_intensity.yz, v_normal, r_halfvector
#endfragment

#beginfragment calculate_objectspace_pointlight_diffuse_and_specular_intensity_rdotl
dp3 r_intensity.x, v_normal, r_vertex_to_pointlight						// diffuse intensity caclulation
dp3 r_intensity.yz, r_eyereflection_vector, r_vertex_to_pointlight  	// specular intensity calculation
#endfragment


⌨️ 快捷键说明

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