public MaterialManager(string toonDir = @"D:\Documents\MMD\PmxEditor_0222\_data\toon") { BGColor = new Color4(0.3f, 0.3f, 0.3f); Light = new SlimDX.Direct3D9.Light { Type = LightType.Directional, Diffuse = Color.White, Ambient = Color.GhostWhite, Direction = new Vector3(0.0f, -1.0f, 0.0f) }; this.toonDir = toonDir; DicObjTex = new Dictionary <string, Texture>(); DicSphTex = new Dictionary <string, Texture>(); DicToonTex = new Dictionary <string, Texture>(); }
public override void Begin() { SDX_Display mDisplay = (SDX_Display)AgateLib.DisplayLib.Display.Impl; Set2DDrawState(); mDisplay.D3D_Device.Device.SetRenderState(RenderState.Lighting, true); mDisplay.D3D_Device.Device.SetRenderState(RenderState.Ambient, AmbientLight.ToArgb()); mDisplay.D3D_Device.Device.SetRenderState(RenderState.ColorVertex, true); TextureArgument arg0 = (TextureArgument)mDisplay.D3D_Device.Device.GetTextureStageState(0, TextureStage.ColorArg0); TextureArgument arg1 = (TextureArgument)mDisplay.D3D_Device.Device.GetTextureStageState(0, TextureStage.ColorArg1); TextureArgument arg2 = (TextureArgument)mDisplay.D3D_Device.Device.GetTextureStageState(0, TextureStage.ColorArg2); TextureOperation op = (TextureOperation)mDisplay.D3D_Device.Device.GetTextureStageState(0, TextureStage.ColorOperation); mDisplay.D3D_Device.Device.SetTextureStageState(0, TextureStage.ColorArg0, TextureArgument.Current); mDisplay.D3D_Device.Device.SetTextureStageState(0, TextureStage.ColorArg1, TextureArgument.Texture); mDisplay.D3D_Device.Device.SetTextureStageState(0, TextureStage.ColorArg2, TextureArgument.Current); mDisplay.D3D_Device.Device.SetTextureStageState(0, TextureStage.ColorOperation, TextureOperation.Modulate); mDisplay.D3D_Device.Device.SetRenderState(RenderState.DiffuseMaterialSource, ColorSource.Color1); mDisplay.D3D_Device.Device.SetRenderState(RenderState.AmbientMaterialSource, ColorSource.Color1); Material material = new Material(); material.Diffuse = new SlimDX.Color4(Color.White.ToArgb()); material.Ambient = new SlimDX.Color4(Color.White.ToArgb()); mDisplay.D3D_Device.Device.Material = material; int index = 0; for (int i = 0; i < Lights.Count; i++) { var agateLight = Lights[i]; if (agateLight == null) { continue; } if (agateLight.Enabled == false) { continue; } SlimDX.Direct3D9.Light l = new SlimDX.Direct3D9.Light(); l.Ambient = new SlimDX.Color4(agateLight.AmbientColor.ToArgb()); l.Attenuation0 = agateLight.AttenuationConstant; l.Attenuation1 = agateLight.AttenuationLinear; l.Attenuation2 = agateLight.AttenuationQuadratic; l.Diffuse = new SlimDX.Color4(agateLight.DiffuseColor.ToArgb()); l.Type = LightType.Point; l.Direction = new SlimDX.Vector3(0, 0, 1); l.Range = 100; Vector3 pos = agateLight.Position; l.Position = new SlimDX.Vector3(pos.X, pos.Y, pos.Z); mDisplay.D3D_Device.Device.SetLight(index, l); mDisplay.D3D_Device.Device.EnableLight(index, true); index++; } }
public override void Begin() { int index = 0; mDisplay.D3D_Device.Device.SetTransform( TransformState.Projection, GeoHelper.TransformAgateMatrix(mProjection.Transpose())); mDisplay.D3D_Device.Device.SetTransform( TransformState.View, GeoHelper.TransformAgateMatrix(mView.Transpose())); mDisplay.D3D_Device.Device.SetTransform( TransformState.World, GeoHelper.TransformAgateMatrix(mWorld.Transpose())); if (EnableLighting == false) { mDisplay.D3D_Device.Device.SetRenderState(RenderState.Lighting, false); return; } mDisplay.D3D_Device.Device.SetRenderState(RenderState.Lighting, true); mDisplay.D3D_Device.Device.SetRenderState(RenderState.Ambient, mAmbientLight.ToArgb()); Material material = new Material(); material.Diffuse = new SlimDX.Color4(Color.White.ToArgb()); material.Ambient = new SlimDX.Color4(Color.White.ToArgb()); mDisplay.D3D_Device.Device.Material = material; for (int i = 0; i < Lights.Length; i++) { var agateLight = Lights[i]; if (agateLight == null) { continue; } if (agateLight.Enabled == false) { continue; } SlimDX.Direct3D9.Light l = new SlimDX.Direct3D9.Light(); l.Ambient = new SlimDX.Color4(agateLight.AmbientColor.ToArgb()); l.Attenuation0 = agateLight.AttenuationConstant; l.Attenuation1 = agateLight.AttenuationLinear; l.Attenuation2 = agateLight.AttenuationQuadratic; l.Diffuse = new SlimDX.Color4(agateLight.DiffuseColor.ToArgb()); l.Type = LightType.Point; l.Direction = new SlimDX.Vector3(0, 0, 1); l.Range = 100; Vector3 pos = agateLight.Position; l.Position = new SlimDX.Vector3(pos.X, pos.Y, pos.Z); mDisplay.D3D_Device.Device.SetLight(index, l); mDisplay.D3D_Device.Device.EnableLight(index, true); index++; } }