winform 用Directx 做模型的光源问题

.Net技术 码拜 8年前 (2016-05-29) 1567次浏览
目前做在.net winform引用Directx 做了一个3d模型,数据是从数据库中读到的三维坐标。用的是平行光源。方向是从上往下斜着照射的。问题是模型看上去光是从中心原点发出的,而且看上去有点暗,假如把环境光调高,模型又会变的惨白。
下面的图是材质和光源的设置。另外顶点缓冲也设置了顶点法向量。
//材质设置
material = new Material();
material.Ambient = Color.FromArgb(0, 40, 40, 40);//设置环境光
material.Diffuse = Color.FromArgb(1, 250, 250, 250);//设置漫反射
material.Emissive = Color.FromArgb(0, 0, 0, 0);//设置自发光
material.Specular = Color.FromArgb(0, 200, 200, 200);//设置镜面反射光
material.SpecularSharpness = 200;//反射高光清晰度
device.Material = material;
//光源设置
//填充模式
device.RenderState.FillMode = FillMode.Solid;
//开启场景光源
device.RenderState.Lighting = true;
device.RenderState.SpecularEnable = true;
//设置光源类型,Point为点光源,Directional为平行光源,Spot为聚光灯(散射型)
device.Lights[0].Type = LightType.Directional;

device.Lights[0].Direction = new Vector3(1,1,-10);
device.Lights[0].Direction = new Vector3(0, 0, -10);
//        //漫射光
device.Lights[0].Diffuse = Color.FromArgb(0, 250, 250, 250);
//      //环境光
device.Lights[0].Ambient = Color.FromArgb(0, 40, 40, 40);
//镜面光
device.Lights[0].Specular = Color.FromArgb(0, 200, 200, 200);
//   //开启
device.Lights[0].Enabled = true;
winform 用Directx 做模型的光源问题

解决方案

20

               device.Lights[0].Direction = new Vector3(1,1,-10);
device.Lights[0].Direction = new Vector3(0, 0, -10);
这样最后不还是水平光吗?

20

不清楚了,本人去掉高光、环境光,显示的色彩亮度是正常的
有高光:
winform 用Directx 做模型的光源问题
无高光:
winform 用Directx 做模型的光源问题

CodeBye 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权 , 转载请注明winform 用Directx 做模型的光源问题
喜欢 (0)
[1034331897@qq.com]
分享 (0)