【D3D Review】3
来源:互联网 发布:淘宝店铺大码模特招聘 编辑:程序博客网 时间:2024/05/29 11:05
色彩:
D3D中存储颜色的数据结构:
1.D3DCOLOR:
定义: typedef DWORD D3DCOLOR;
就是说D3DCOLOR就是一个DWORD;所以要用宏把颜色分量转化成DWORD。
例如:
而D3DCOLOR_XRGB宏就是把高字节设为ff:
2.D3DCOLORVALUE:
定义:
可见能够表示的颜色数更多了,而每个颜色的数据量也大了,4个字,是D3DCOLOR的4倍。
3.D3DXCOLOR:
增加了运算,用起来更为方便。
定义:
注意:顶点颜色只能是D3DCOLOR(固定管线),D3DXCOLOR不允许进行点积和叉积运算。
光:
D3D中有三种光:
1.Ambient Light【环境光】
2.Diffuse Light【漫射光】
3.Specular Light【镜面光】
光用D3DCOLORVALUE或D3DXCOLOR结构来描述:
D3DXCOLOR用于描述光时,alpha值是忽略的。
材质:
Diffuse:指定表面反射漫射光的数量;
Ambient:指定表面反射环境光的数量;
Specular:指定表面反射镜面光的数量;
Emissive:This component is used to add to the overall color of the surface, making it appear brighter like its giving off its own light.
Power:指定镜面高光的锐利程度,值越大高光越锐利。
可用于一个红色物体的材质:
通过设置材质的值来控制反射每种灯光的数量来表现物体的颜色。
固定管线的顶点没有材质属性,需要调用IDirect3DDevice9::SetMaterial(CONST D3DMATERIAL9* pMaterial)方法来设置顶点的材质。
类似OpenGL的状态机
顶点法线:
带法线的顶点结构示例:
单一多边形可以用面法线来代替顶点法线,下面是计算面法线的示例函数:
如果一个顶点被多个多边形共享,那么就不可以简单的用其中一个多边形的面法线来代替顶点法线,可以用所有面法线的均值来近似:
Vn = (n0 +n1 + n2+ ...+n(m-1))/m
光源:
点光源:
方向光源:
聚光灯:内外两个光锥,
D3D中初始化光源的方法:
创建一个平行于x轴正向的方向光
D3D中存储颜色的数据结构:
1.D3DCOLOR:
定义: typedef DWORD D3DCOLOR;
就是说D3DCOLOR就是一个DWORD;所以要用宏把颜色分量转化成DWORD。
例如:
- D3DCOLOR brightRed = D3DCOLOR_ARGB(255, 255, 0, 0);
- D3DCOLOR someColor = D3DCOLOR_ARGB(255, 144, 87, 201);
- #define D3DCOLOR_XRGB(r,g,b) D3DCOLOR_ARGB(0xff,r,g,b)
定义:
- typedef struct _D3DCOLORVALUE {
- float r; // the red component, range 0.0-1.0
- float g; // the green component, range 0.0-1.0
- float b; // the blue component, range 0.0-1.0
- float a; // the alpha component, range 0.0-1.0
- } D3DCOLORVALUE;
3.D3DXCOLOR:
增加了运算,用起来更为方便。
定义:
- typedef struct D3DXCOLOR
- {
- #ifdef __cplusplus
- public:
- D3DXCOLOR() {}
- D3DXCOLOR( DWORD argb );
- D3DXCOLOR( CONST FLOAT * );
- D3DXCOLOR( CONST D3DXFLOAT16 * );
- D3DXCOLOR( CONST D3DCOLORVALUE& );
- D3DXCOLOR( FLOAT r, FLOAT g, FLOAT b, FLOAT a );
- // casting
- operator DWORD () const;
- operator FLOAT* ();
- operator CONST FLOAT* () const;
- operator D3DCOLORVALUE* ();
- operator CONST D3DCOLORVALUE* () const;
- operator D3DCOLORVALUE& ();
- operator CONST D3DCOLORVALUE& () const;
- // assignment operators
- D3DXCOLOR& operator += ( CONST D3DXCOLOR& );
- D3DXCOLOR& operator -= ( CONST D3DXCOLOR& );
- D3DXCOLOR& operator *= ( FLOAT );
- D3DXCOLOR& operator /= ( FLOAT );
- // unary operators
- D3DXCOLOR operator + () const;
- D3DXCOLOR operator - () const;
- // binary operators
- D3DXCOLOR operator + ( CONST D3DXCOLOR& ) const;
- D3DXCOLOR operator - ( CONST D3DXCOLOR& ) const;
- D3DXCOLOR operator * ( FLOAT ) const;
- D3DXCOLOR operator / ( FLOAT ) const;
- friend D3DXCOLOR operator * (FLOAT, CONST D3DXCOLOR& );
- BOOL operator == ( CONST D3DXCOLOR& ) const;
- BOOL operator != ( CONST D3DXCOLOR& ) const;
- #endif //__cplusplus
- FLOAT r, g, b, a;
- } D3DXCOLOR, *LPD3DXCOLOR;
光:
D3D中有三种光:
1.Ambient Light【环境光】
2.Diffuse Light【漫射光】
3.Specular Light【镜面光】
- // 打开镜面光
- Device->SetRenderState(D3DRS_SPECULARENABLE, true);
- D3DXCOLOR redAmbient(1.0f, 0.0f, 0.0f, 1.0f);
- D3DXCOLOR blueDiffuse(0.0f, 0.0f, 1.0f, 1.0f);
- D3DXCOLOR whiteSpecular(1.0f, 1.0f, 1.0f, 1.0f);
材质:
- typedef struct _D3DMATERIAL9 {
- D3DCOLORVALUE Diffuse, Ambient, Specular, Emissive;
- float Power;
- } D3DMATERIAL9;
Ambient:指定表面反射环境光的数量;
Specular:指定表面反射镜面光的数量;
Emissive:This component is used to add to the overall color of the surface, making it appear brighter like its giving off its own light.
Power:指定镜面高光的锐利程度,值越大高光越锐利。
可用于一个红色物体的材质:
- D3DMATERIAL9 red;
- ::ZeroMemory(&red, sizeof(red));
- red.Diffuse = D3DXCOLOR(1.0f, 0.0f, 0.0f, 1.0f); // red
- red.Ambient = D3DXCOLOR(1.0f, 0.0f, 0.0f, 1.0f); // red
- red.Specular = D3DXCOLOR(1.0f, 0.0f, 0.0f, 1.0f); // red
- red.Emissive = D3DXCOLOR(0.0f, 0.0f, 0.0f, 1.0f); // no emission
- red.Power = 5.0f;
固定管线的顶点没有材质属性,需要调用IDirect3DDevice9::SetMaterial(CONST D3DMATERIAL9* pMaterial)方法来设置顶点的材质。
- D3DMATERIAL9 blueMaterial, redMaterial;
- ...// set up material structures
- Device->SetMaterial(&blueMaterial);
- drawSphere(); // blue sphere
- Device->SetMaterial(&redMaterial);
- drawSphere(); // red sphere
顶点法线:
带法线的顶点结构示例:
- struct Vertex
- {
- float _x, _y, _z;
- float _nx, _ny, _nz;
- static const DWORD FVF;
- }
- const DWORD Vertex::FVF = D3DFVF_XYZ | D3DFVF_NORMAL;
- void ComputeNormal(D3DXVECTOR3* p0,
- D3DXVECTOR3* p1,
- D3DXVECTOR3* p2,
- D3DXVECTOR3* out)
- {
- D3DXVECTOR3 u = *p1 - *p0;
- D3DXVECTOR3 v = *p2 - *p0;
- D3DXVec3Cross(out, &u, &v);
- D3DXVec3Normalize(out, out);
- }
Vn = (n0 +n1 + n2+ ...+n(m-1))/m
光源:
点光源:
方向光源:
聚光灯:内外两个光锥,
- typedef struct _D3DLIGHT9 {
- D3DLIGHTTYPE Type; // 指定光源类型,D3DLIGHT_POINT, D3DLIGHT_SPOT,
- // D3DLIGHT_DIRECTIONAL
- D3DCOLORVALUE Diffuse; // 此光源发出的漫射光颜色
- D3DCOLORVALUE Specular;
- D3DCOLORVALUE Ambient; // 此光源发出的环境光颜色
- D3DVECTOR Position; // 光源坐标,对方向光无意义
- D3DVECTOR Direction; // 光源在世界坐标系的照射方向,对点光源无意义
- float Range; // 照射的距离,对方向光无意义
- float Falloff; // 只用于聚光灯,内锥到外锥的强度衰减,通常为1.0f
- float Attenuation0; // 常量衰减,光强的传播距离衰减,不适用于方向光
- float Attenuation1; // 线性衰减
- float Attenuation2; // 二次衰减
- float Theta; // 内锥角度,单位弧度
- float Phi; // 外锥角度,单位弧度
- } D3DLIGHT9;
- namespace d3d
- {
- .
- .
- .
- D3DLIGHT9 InitDirectionalLight(D3DXVECTOR3* direction,D3DXCOLOR* color);
- D3DLIGHT9 InitPointLight(D3DXVECTOR3* position,D3DXCOLOR* color);
- D3DLIGHT9 InitSpotLight(D3DXVECTOR3* position,D3DXVECTOR3* direction,D3DXCOLOR* color);
- }
- D3DXVECTOR3 dir(1.0f, 0.0f, 0.0f);
- D3DXCOLOR c = d3d::WHITE;
- D3DLIGHT9 dirLight = d3d::InitDirectionalLight(&dir, &c);
- Device->SetLight(
- 0, // element in the light list to set, range is 0-maxlights
- &light);// address of the D3DLIGHT9 structure to set
- Device->LightEnable(
- 0, // the element in the light list to enable/disable
- true); // true = enable, false = disable
- 【D3D Review】3
- 【D3D Review】4 纹理
- 【D3D Review】Blending 混合
- 【D3D Review】D3DX基础数学知识
- 3d3d
- D3D
- D3D
- d3d
- D3D
- Device Kit review 3
- code review手记3
- 3rd review
- Complex analysis review 3
- Review
- Review
- review
- review
- review
- Delphi第三方控件大比拼(收费篇)
- [转载]优化程序
- ABAP/4 报表编程模板
- ABAP报表的事件
- DNS负载均衡技术
- 【D3D Review】3
- shell脚本迅速获取access日志中的某个参数
- ABAP:参数输入屏幕SELECTION-SCREEN中的事件
- 引用Microsoft.Office.Interop.Excel出现的问题
- DNS负载均衡与负载均衡器两种方案的选择
- ABAP-报表的事件
- 电子支付行业大洗牌:央行发10张牌照
- [转载]abap面试题
- 下学期主要任务