Reputation: 269
I'm using SharpDX d3d9 to make sphere with lighting effect.
so, I tryed below code.
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;
but, nothing changed.
img : http://cfile24.uf.tistory.com/image/156A994C5103547E273035
(the colors are I inputed values.)
rendering code is
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();
});
How can I apply light to my application?
and,
var effect = Effect.FromFile(device, "MiniCube.fx", ShaderFlags.None);
What dose it mean Effect? I don't want any effect however..(It comes SharpDX sample source. MiniCube.csproj)
Upvotes: 1
Views: 2672
Reputation: 13286
If you want to use lighting, your vertex format should include VertexFormat.Normal
. If there is no normal, lighting can not be computed by DirectX.
Upvotes: 0
Reputation: 1751
I'm not familiar with SharpDX myself aside from the fact that it is a DX wrapper for C#. While a cool concept, I'd warn against using it if you are not first familiar with how DirectX works. As far as I understand it the SharpDX guys intentionally provide very little documentation due to the fact that DirectX itself has a monumental amount of examples and docs already.
To touch on effects, they are objects that handle Shader logic. Shaders are 'mini-programs' that interface directly with the GPU. Most everything in modern games is written, displayed, skewed, morphed, changed, or even moved via shaders, including lighting! HLSL (or High Level Shader language) is the standard language for DirectX interfaces. Ironically it can be rather difficult to find simple shader tutorials or examples, while the more intricate details are rather well mapped out.
Although these may not be particularly useful for your immediate needs, here are my two favorite resources for HLSL material.
DXTutorial is amazing for learning DX via C++ with virtually no dependencies except for the D3DX library that Microsoft recently declared deprecated (bastards). It also has a nominal $50 fee for the premium content (I believe that includes shaders) but trust me when I say that he's selling himself short at $50.
JaJDoo's tutorials are excellent in their own right, however they target the Ogre graphics framework so you'll need to do some alterations to the code as Ogre uses a custom shader pipeline which alters the way you define and call techniques and passes, not a huge deal to figure out IMO.
That being said I realize I haven't actually answered your question. However I would urge you to step back from SharpDX and learn the fundamentals. There may be others who disagree with my opinion but it just seems a little backwards to me. At any rate, good luck!
Upvotes: 1