////////////////////////////////////////////////////////////////////////////
//
// File: diffuse.txt
//
// Author: Frank Luna (C) All Rights Reserved
//
// System: AMD Athlon 1800+ XP, 512 DDR, Geforce 3, Windows XP, MSVC++ 7.0
//
// Desc: Vertex shader that does diffuse lighting.
//
////////////////////////////////////////////////////////////////////////////
//
// Global variables we use to hold the view matrix, projection matrix,
// ambient material, diffuse material, and the light vector that describes
// the direction to the light source. These variables are initialized from
// the application.
//
matrix ViewMatrix;
matrix ViewProjMatrix;
vector AmbientMtrl;
vector DiffuseMtrl;
vector LightDirection;
//
// Global variables used to hold the ambient light intensity (ambient
// light the light source emits) and the diffuse light intensity (diffuse
// light the light source emits). These variables are initialized here
// in the shader.
//
vector DiffuseLightIntensity = {0.0f, 0.0f, 1.0f, 1.0f};
vector AmbientLightIntensity = {0.0f, 0.0f, 0.2f, 1.0f};
//
// Input and Output structures.
//
struct VS_INPUT
{
vector position : POSITION;
vector normal : NORMAL;
};
struct VS_OUTPUT
{
vector position : POSITION;
vector diffuse : COLOR;
};
//
// Main
//
VS_OUTPUT Main(VS_INPUT input)
{
// zero out all members of the output instance.
VS_OUTPUT output = (VS_OUTPUT)0;
//
// Transform position to homogeneous clip space
// and store in the output.position member.
//
output.position = mul(input.position, ViewProjMatrix);
//
// Transform lights and normals to view space. Set w
// componentes to zero since we're transforming vectors
// here and not points.
//
LightDirection.w = 0.0f;
input.normal.w = 0.0f;
LightDirection = mul(LightDirection, ViewMatrix);
input.normal = mul(input.normal, ViewMatrix);
//
// Compute cosine of the angle between light and normal.
//
float s = dot(LightDirection, input.normal);
//
// Recall that if the angle between the surface and light
// is greater than 90 degrees the surface recieves no light.
// Thus, if the angle is greater than 90 degrees we set
// s to zero so that the surface will not be lit.
//
if( s < 0.0f )
s = 0.0f;
//
// Ambient light reflected is computed by performing a
// component wise multiplication with the ambient material
// vector and the ambient light intensity vector.
//
// Diffuse light reflected is computed by performing a
// component wise multiplication with the diffuse material
// vector and the diffuse light intensity vector. Further
// we scale each component by the shading scalar s, which
// shades the color based on how much light the vertex received
// from the light source.
//
// The sum of both the ambient and diffuse components gives
// us our final vertex color.
//
output.diffuse = (AmbientMtrl * AmbientLightIntensity) +
(s * (DiffuseLightIntensity * DiffuseMtrl));
return output;
}
没有合适的资源?快使用搜索试试~ 我知道了~
Directx9 3D 游戏编程 实例
共261个文件
cpp:100个
h:62个
jpg:53个
3星 · 超过75%的资源 需积分: 10 35 下载量 9 浏览量
2009-04-26
18:24:09
上传
评论
收藏 4.69MB RAR 举报
温馨提示
Directx9 3D 游戏编程 实例源代码 Introduction to Directx9 3D Game Programming
资源推荐
资源详情
资源评论
收起资源包目录
Directx9 3D 游戏编程 实例 (261个子文件)
desert.bmp 768KB
ice.bmp 768KB
ice.bmp 768KB
ice.bmp 768KB
desert.bmp 768KB
desert.bmp 768KB
desert.bmp 768KB
desert.bmp 768KB
grass.bmp 768KB
text.bmp 192KB
crate.bmp 192KB
alphachannel.bmp 65KB
dx5_logo.bmp 65KB
dx5_logo.bmp 65KB
spotlight.bmp 65KB
toonshade.bmp 48KB
toonshade.bmp 48KB
toonshade.bmp 48KB
block.bmp 17KB
snowball.bmp 17KB
block.bmp 17KB
flare.bmp 17KB
flare.bmp 17KB
dxutil.cpp 37KB
dxutil.cpp 35KB
d3dfont.cpp 26KB
d3dutil.cpp 25KB
d3dfont.cpp 23KB
d3dutil.cpp 20KB
stencilmirrorshadow.cpp 13KB
terrain.cpp 13KB
terrain.cpp 13KB
d3dxcreatemeshfvf.cpp 12KB
pSystem.cpp 11KB
pSystem.cpp 11KB
pSystem.cpp 11KB
stencilmirror.cpp 11KB
silhouetteEdges.cpp 10KB
stencilshadow.cpp 10KB
d3dUtility.cpp 10KB
d3dUtility.cpp 10KB
d3dUtility.cpp 10KB
d3dUtility.cpp 10KB
d3dUtility.cpp 10KB
d3dUtility.cpp 10KB
d3dUtility.cpp 10KB
d3dUtility.cpp 10KB
d3dUtility.cpp 10KB
d3dUtility.cpp 10KB
d3dUtility.cpp 10KB
d3dUtility.cpp 10KB
toon.cpp 9KB
d3dUtility.cpp 9KB
d3dUtility.cpp 9KB
ps_multitex.cpp 8KB
boundingvolumes.cpp 8KB
pmesh.cpp 7KB
toon.cpp 6KB
tooneffect.cpp 6KB
pickSample.cpp 6KB
light_tex_effect.cpp 6KB
mtrlAlpha.cpp 6KB
d3dUtility.cpp 6KB
d3dUtility.cpp 6KB
d3dUtility.cpp 6KB
d3dUtility.cpp 6KB
d3dUtility.cpp 6KB
d3dUtility.cpp 6KB
d3dUtility.cpp 6KB
d3dUtility.cpp 6KB
d3dUtility.cpp 6KB
d3dUtility.cpp 6KB
d3dUtility.cpp 6KB
d3dUtility.cpp 6KB
d3dUtility.cpp 6KB
d3dUtility.cpp 6KB
d3dUtility.cpp 6KB
d3dUtility.cpp 6KB
d3dUtility.cpp 6KB
d3dUtility.cpp 6KB
d3dUtility.cpp 6KB
vs_diffuse.cpp 5KB
hello.cpp 5KB
d3dxcreate.cpp 5KB
cube.cpp 5KB
texAlpha.cpp 5KB
litPyramid.cpp 5KB
xfile.cpp 5KB
addressModes.cpp 5KB
fog.cpp 5KB
transform.cpp 5KB
spotLight.cpp 5KB
pointLight.cpp 4KB
directionalLight.cpp 4KB
d3dxcreatetext.cpp 4KB
d3dUtility.cpp 4KB
d3dUtility.cpp 4KB
d3dUtility.cpp 4KB
d3dUtility.cpp 4KB
d3dUtility.cpp 4KB
共 261 条
- 1
- 2
- 3
资源评论
- 连江点点萍引2015-04-07运行出来的效果还不错的
- kekok2014-08-11写的较好,赞一个!有一些帮助,希望再详细一点
- fnoi09lyming2013-10-27写的较好,赞一个!有一些帮助,希望再详细一点
- fgdgtz2011-10-06感谢你的共享,但只有代码且没什么注释,而且也没讲解,阅读起来会很吃力呀
shangguanyi
- 粉丝: 0
- 资源: 5
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- Linux知识体系复习
- 东华深度学习课后习题全部
- 基于STM32+ESP8266+OneNET平台的环境监测报警系统设计.rar
- 基于Django+Django -Rest-Framework实现的在线考试系统
- mt7628 breed 固件
- 基于STM32F103+ESP8266+机智云的室内室外各种环境监测系统设计
- 基于STM32+MPU9250的小型四轴飞行器设计-毕设开题报告&PPT&部分回答问题.rar
- 基于STM32+NB-IOT的风机环境监控系统设计
- STM32单片机FPGA毕设电路原理论文报告一种基于单片机的节能断电保护电路设计
- 基于python+django+vue开发的外卖点餐系统
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功