public Sole() { model = new Model("MEDIA//Sfera5.x", 0); EffectPool pool = new EffectPool(); effect = Effect.FromFile(LogiX_Engine.Device, "MEDIA//Sun.fx", null, ShaderFlags.None, pool); effectHandles = new EffectHandle[5]; effectHandles[0] = effect.GetTechnique("t0"); effectHandles[1] = effect.GetParameter(null, "matViewProjection"); effectHandles[2] = effect.GetParameter(null, "Time"); effectHandles[3] = effect.GetParameter(null, "Texture"); effectHandles[4] = effect.GetParameter(null, "TexDimension"); baseTexture = TextureLoader.FromFile(LogiX_Engine.Device, "MEDIA//N030.jpg"); Alone = new XMaterial(Color.White, Color.White, Color.Black, 1); light = new DirectionalLight(VertexData.Empty, Color.FromArgb(60, 10, 0), Color.FromArgb(255, 170, 100), Color.FromArgb(250, 250, 250)); }
public void RenderizzaAtmosfera(float time, float RaggioAtmosferaRispettoPianeta, XMaterial mat, LogiX_Engine lxe) { lxe.SetAlphaMode(); lxe.SetCullMode(CullMode.Clockwise); lxe.AmbientLight = Color.FromArgb(255, 255, 255); lxe.SetLightMode(true, true); XTexture.ResetTextures(); TransformAtm(time, RaggioAtmosferaRispettoPianeta); mat.SetMaterial(); model.DrawSubset(0); XMaterial.ResetMaterials(); RestoreWorld(); lxe.AmbientLight = Color.FromArgb(0, 0, 0); lxe.SetCullMode(CullMode.CounterClockwise); lxe.UnSetAlphaMode(); lxe.SetLightMode(true, false); }
/// <summary> /// Inizializza un Triangolo con un materiale applicato /// </summary> /// <param name="Vertex1"></param> /// <param name="Vertex2"></param> /// <param name="Vertex3"></param> /// <param name="Material"></param> public Triangle(VertexData Vertex1, VertexData Vertex2, VertexData Vertex3, XMaterial Material) { try { mat = Material; my_vertex_buffer = new VertexBuffer(typeof(CustomVertex.PositionNormalColored), 3, device, 0, CustomVertex.PositionNormalColored.Format, Pool.Default); CustomVertex.PositionNormalColored[] verts = (CustomVertex.PositionNormalColored[])my_vertex_buffer.Lock(0, 0); verts[0].X = Vertex1.X; verts[0].Y = Vertex1.Y; verts[0].Z = Vertex1.Z; verts[0].Color = Material.Ambient.ToArgb(); verts[1].X = Vertex2.X; verts[1].Y = Vertex2.Y; verts[1].Z = Vertex2.Z; verts[1].Color = Material.Ambient.ToArgb(); ; verts[2].X = Vertex3.X; verts[2].Y = Vertex3.Y; verts[2].Z = Vertex3.Z; verts[2].Color = Material.Ambient.ToArgb(); my_vertex_buffer.Unlock(); correct = true; textured = false; } catch { Error("OnCreateObject"); } }
/// <summary> /// Attiva l'effetto base PerPixelDirectionalLight /// </summary> /// <param name="cam"></param> /// <param name="LightDirection"></param> /// <param name="mat"></param> /// <returns></returns> public bool BeginPerPixelDirectionalLightEffect(Camera cam, VertexData LightDirection, XMaterial mat) { try { Effect.Begin(FX.None); matrix = LogiX_Engine.Device.Transform.View * LogiX_Engine.Device.Transform.Projection; Matrix.TransposeMatrix(matrix); Effect.SetValue(EffectHandles[0], matrix); matrix = LogiX_Engine.Device.Transform.World; Matrix.TransposeMatrix(matrix); Effect.SetValue(EffectHandles[1], matrix); Effect.SetValue(EffectHandles[2], new float[3] { -LightDirection.X, -LightDirection.Y, -LightDirection.Z }); Effect.SetValue(EffectHandles[3], new float[3] { cam.Position.X, cam.Position.Y, cam.Position.Z }); Effect.SetValue(EffectHandles[4], BaseTextures[0]); Effect.SetValue(EffectHandles[5], new float[4] { mat.Specular.R / 255, mat.Specular.G / 255, mat.Specular.B / 255, mat.Specular.A / 255 }); Effect.SetValue(EffectHandles[6], new float[4] { mat.Diffuse.R / 255, mat.Diffuse.G / 255, mat.Diffuse.B / 255, mat.Diffuse.A / 255 }); Effect.SetValue(EffectHandles[7], mat.SpecularSharpness); Effect.CommitChanges(); Effect.BeginPass(0); return true; } catch { if (AmICorrect == true) Error("OnBeginEffect"); return false; } }
/// <summary> /// Renderizza il Modello con un Materiale applicato, calcolando le Trasformazioni Geometriche, quali traslazioni, rotazioni e dilatazioni. (Tiene conto delle proprietà Position, Rotation, Rotation Axis e Scaling dell'oggetto stesso) /// </summary> /// <param name="XMaterial"></param> /// <param name="SubsetStart"></param> /// <returns></returns> public bool RenderMe(XMaterial XMaterial, int SubsetStart) { try { for (int i = SubsetStart; i < meshMaterial.Length; i++) { SetModelMatrices(); device.SetTexture(0, null); device.Material = XMaterial.DXMaterial; mesh.DrawSubset(i); UnSetModelMatrices(); } return true; } catch { if (AmICorrect == true) Error("RenderingObject"); return false; } }