/// <summary> /// Draw. /// </summary> /// <param name="gt">The gt.</param> /// <param name="obj">The obj.</param> /// <param name="render">The render.</param> /// <param name="camera">The camera.</param> /// <param name="lights">The lights.</param> protected override void Draw(GameTime gt, IObject obj, RenderHelper render, ICamera camera, IList <ILight> lights) { IModelo modelo = obj.Modelo; IdParameter.SetValue(shaderId); SpecularIntensityParameter.SetValue(specularIntensity); SpecularPowerParameter.SetValue(specularPower); ViewProjectionParameter.SetValue(camera.ViewProjection); for (int i = 0; i < modelo.MeshNumber; i++) { BatchInformation[] bi = modelo.GetBatchInformation(i); for (int j = 0; j < bi.Count(); j++) { if (useAmbientCubeMap) { render.Textures[4] = modelo.GetCubeTexture(TextureType.AMBIENT_CUBE_MAP, i, j); //PAmbientCubeTexture.SetValue(modelo.GetCubeTexture(TextureType.AMBIENT_CUBE_MAP, i, j)); PAmbientCubeMapScale.SetValue(AmbientCubeMapScale); } render.Textures[0] = modelo.getTexture(TextureType.DIFFUSE, i, j); //TextureParameter.SetValue(modelo.getTexture(TextureType.DIFFUSE,i,j)); WorldParameter.SetValue(bi[j].ModelLocalTransformation * obj.WorldMatrix); render.RenderBatch(bi[j], _shader); } } }
/// <summary> /// Draw /// </summary> /// <param name="gt">The gt.</param> /// <param name="obj">The obj.</param> /// <param name="render">The render.</param> /// <param name="cam">The cam.</param> /// <param name="lights">The lights.</param> public void iDraw(GameTime gt, IObject obj, RenderHelper render, ICamera cam, IList <ILight> lights) { if (OcclusionQuery != null) { while (OcclusionQuery.Tag == null && OcclusionQuery.IsComplete == false) { } if ((OcclusionQuery.Tag == null && OcclusionQuery.PixelCount > 0) || obj.PhysicObject.BoundingBox == null) { PixelsRendered = OcclusionQuery.PixelCount; //Enable rendering to screen. //Enable or disable writing to depth buffer (depends on whether the object is translucent or opaque). //Render the object itself. OcclusionQuery.Begin(); this.Draw(gt, obj, render, cam, lights); OcclusionQuery.End(); } else { //Disable rendering to screen. //Disable writing to depth buffer. //"Render" the object's bounding box. PixelsRendered = 0; OcclusionQuery.Begin(); render.PushBlendState(BlendState); render.PushDepthStencilState(DepthStencilState.DepthRead); BoundingBox BoundingBox = obj.PhysicObject.BoundingBox.Value; BasicEffect.View = cam.View; BasicEffect.Projection = cam.Projection; Vector3 centerPos = obj.PhysicObject.Position; Vector3 scale = BoundingBox.Max - BoundingBox.Min; Matrix world = Matrix.CreateScale(scale); world.Translation = centerPos; BasicEffect.World = world; render.RenderBatch(Modelo.GetBatchInformation(0)[0], BasicEffect); OcclusionQuery.End(); render.PopDepthStencilState(); render.PopBlendState(); OcclusionQuery.Tag = null; } } else { PixelsRendered = 0; this.Draw(gt, obj, render, cam, lights); } }
public override void Draw(Texture2D ImageToProcess, RenderHelper rHelper, Microsoft.Xna.Framework.GameTime gt, PloobsEngine.Engine.GraphicInfo GraphicInfo, IWorld world, bool useFloatBuffer) { rHelper.PushRenderTarget(target); rHelper.Clear(Color.Black); effectdistorcion.Parameters["halfPixel"].SetValue(GraphicInfo.HalfPixel); effectdistorcion.Parameters["DEPTH"].SetValue(rHelper[PrincipalConstants.DephRT]); effectdistorcion.Parameters["DistortionScale"].SetValue(Distortion); rHelper.PushDepthStencilState(DepthStencilState.None); foreach (var obj in objs) { IModelo modelo = obj.Modelo; for (int i = 0; i < modelo.MeshNumber; i++) { BatchInformation[] bi = modelo.GetBatchInformation(i); for (int j = 0; j < bi.Count(); j++) { Matrix w = bi[j].ModelLocalTransformation * obj.WorldMatrix; effectdistorcion.Parameters["WorldViewProjection"].SetValue(w * world.CameraManager.ActiveCamera.View * world.CameraManager.ActiveCamera.Projection); effectdistorcion.Parameters["WorldView"].SetValue(w * world.CameraManager.ActiveCamera.View); rHelper.RenderBatch(bi[j], effectdistorcion); } } } rHelper.PopDepthStencilState(); x = rHelper.PopRenderTargetAsSingleRenderTarget2D(); rHelper.Clear(Color.Black); effect.Parameters["SceneTexture"].SetValue(ImageToProcess); effect.Parameters["DistortionMap"].SetValue(x); //effect.Parameters["halfPixel"].SetValue(GraphicInfo.HalfPixel); rHelper.RenderTextureToFullScreenSpriteBatch(ImageToProcess, effect, GraphicInfo.FullScreenRectangle); }
/// <summary> /// Helper to get the vertex and index List from the model. /// </summary> /// <param name="vert">The vert.</param> /// <param name="ind">The ind.</param> /// <param name="model">The model.</param> private void ExtractData(ref Vector3[] vert, ref int[] ind, IModelo model) { List <Vector3> vertices = new List <Vector3>(); List <int> indices = new List <int>(); for (int i = 0; i < model.MeshNumber; i++) { BatchInformation[] bi = model.GetBatchInformation(i); for (int j = 0; j < bi.Length; j++) { BatchInformation info = bi[j]; int offset = vertices.Count; Vector3[] a = new Vector3[info.NumVertices]; // Read the format of the vertex buffer VertexDeclaration declaration = bi[j].VertexBuffer.VertexDeclaration; VertexElement[] vertexElements = declaration.GetVertexElements(); // Find the element that holds the position VertexElement vertexPosition = new VertexElement(); foreach (VertexElement elem in vertexElements) { if (elem.VertexElementUsage == VertexElementUsage.Position && elem.VertexElementFormat == VertexElementFormat.Vector3) { vertexPosition = elem; // There should only be one break; } } // Check the position element found is valid if (vertexPosition == null || vertexPosition.VertexElementUsage != VertexElementUsage.Position || vertexPosition.VertexElementFormat != VertexElementFormat.Vector3) { throw new Exception("Model uses unsupported vertex format!"); } // This where we store the vertices until transformed // Read the vertices from the buffer in to the array bi[j].VertexBuffer.GetData <Vector3>( bi[j].BaseVertex * declaration.VertexStride + vertexPosition.Offset, a, 0, bi[j].NumVertices, declaration.VertexStride); for (int k = 0; k != a.Length; ++k) { Vector3.Transform(ref a[k], ref info.ModelLocalTransformation, out a[k]); } vertices.AddRange(a); if (info.IndexBuffer.IndexElementSize != IndexElementSize.SixteenBits) { int[] s = new int[info.PrimitiveCount * 3]; info.IndexBuffer.GetData <int>(info.StartIndex * 2, s, 0, info.PrimitiveCount * 3); for (int k = 0; k != info.PrimitiveCount; ++k) { indices.Add(s[k * 3 + 2] + offset); indices.Add(s[k * 3 + 1] + offset); indices.Add(s[k * 3 + 0] + offset); } } else { short[] s = new short[info.PrimitiveCount * 3]; info.IndexBuffer.GetData <short>(info.StartIndex * 2, s, 0, info.PrimitiveCount * 3); for (int k = 0; k != info.PrimitiveCount; ++k) { indices.Add(s[k * 3 + 2] + offset); indices.Add(s[k * 3 + 1] + offset); indices.Add(s[k * 3 + 0] + offset); } } } } ind = indices.ToArray(); vert = vertices.ToArray(); }