我正在使用 SharpDX d3d9 制作具有灯光效果的球体。
所以,我尝试了下面的代码。
var direct3D = new Direct3D();
var device = new SharpDX.Direct3D9.Device(direct3D, 0, SharpDX.Direct3D9.DeviceType.Hardware, this.Handle, CreateFlags.HardwareVertexProcessing,
new PresentParameters(this.ClientSize.Width, this.ClientSize.Height));
Light light = new Light();
light.Type = LightType.Point;
light.Diffuse.Red = 1.0f;
light.Diffuse.Green = 1.0f;
light.Diffuse.Blue = 1.0f;
light.Diffuse.Alpha = 0.7f;
light.Position = new Vector3(-10, -10, -10);
light.Range = 200.0f;
light.Attenuation0 = 0.1f;
device.SetRenderState(RenderState.Lighting, true);
device.SetRenderState(RenderState.Ambient, new Color4(0.5f, 0.5f, 0.5f, 0.5f).ToRgba());
device.SetLight(0, ref light);
device.EnableLight(0, true);
Material met = new Material();
met.Diffuse = new Color4(1, 1, 1, 1);
met.Ambient = new Color4(1, 1, 1, 1);
met.Specular = new Color4(1, 1, 0, 1);
met.Emissive = new Color4(0, 0, 0, 1);
met.Diffuse.Alpha = 0.7f;
met.Power = 5.0f;
device.Material = met;
但是,什么都没有改变。
图像:http : //cfile24.uf.tistory.com/image/156A994C5103547E273035
(颜色是我输入的值。)
渲染代码是
RenderLoop.Run(this, () => {
var time = clock.ElapsedMilliseconds / 1000.0f;
device.Clear(ClearFlags.Target | ClearFlags.ZBuffer, Color.Black, 1.0f, 0);
device.BeginScene();
effect.Technique = technique;
effect.Begin();
effect.BeginPass(0);
var worldViewProj = Matrix.RotationX(time) * Matrix.RotationY(time * 2) * Matrix.RotationZ(time * .7f) * viewProj;
effect.SetValue("worldViewProj", worldViewProj);
//effect.SetValue("worldViewProj", viewProj);
//device.DrawPrimitives(PrimitiveType.LineList, 0, counts / 2);
device.DrawPrimitives(PrimitiveType.TriangleList, 0, counts / 3);
effect.EndPass();
effect.End();
device.EndScene();
device.Present();
});
如何将光应用于我的应用程序?
和,
var effect = Effect.FromFile(device, "MiniCube.fx", ShaderFlags.None);
什么剂量是什么意思?但是我不想要任何效果..(它来自 SharpDX 示例源。MiniCube.csproj)