public Pass(Pass copyFrom) { this.input = copyFrom.input; this.output = copyFrom.output; this.clearColor = copyFrom.clearColor; this.clearDepth = copyFrom.clearDepth; this.clearFlags = copyFrom.clearFlags; this.matrixMode = copyFrom.matrixMode; this.visibilityMask = copyFrom.visibilityMask; this.MakeAvailable(); }
public ParticleEmitter() { NewParticlesPerSecond = int.MaxValue; InitialScale = Vector2.One; ColorStart = Colors.White; ColorEnd = Colors.Transparent; DrawParticlesOffScreen = true; IsVisible = true; IsEnabled = true; NewParticlesPerSecond = DEFAULT_PARTICLES_PER_SECOND; InitialScale = Vector2.One; ParticlesAmount = DEFAULT_PARTICLES; TimeToLive = DEFAULT_TTL; VisibilityGroup = VisibilityFlag.Group0; }
public void QueryVisibleRenderers(DrawDevice device, RawList <ICmpRenderer> visibleRenderers) { int activeCount = this.cullingInfo.Count; CullingInfo[] cullingData = this.cullingInfo.Data; ICmpRenderer[] rendererData = this.cullingRenderers.Data; visibleRenderers.Clear(); visibleRenderers.Reserve(activeCount); ICmpRenderer[] visibleRendererData = visibleRenderers.Data; int visibleCount = 0; VisibilityFlag mask = device.VisibilityMask; for (int i = 0; i < activeCount; i++) { // Check group and overlay / world visibility if ((cullingData[i].Visibility & VisibilityFlag.AllGroups & mask) == VisibilityFlag.None) { continue; } if ((cullingData[i].Visibility & VisibilityFlag.ScreenOverlay) != (mask & VisibilityFlag.ScreenOverlay)) { continue; } // Check spatial visibility if (!device.IsSphereInView(cullingData[i].Position, cullingData[i].Radius)) { continue; } // Add renderer to visible result list visibleRendererData[visibleCount] = rendererData[i]; visibleCount++; } visibleRenderers.Count = visibleCount; }
/// <summary> /// Renders a picking map of the current <see cref="Duality.Resources.Scene"/>. /// This method needs to be called each frame a picking operation is to be performed. /// </summary> /// <param name="viewportSize">Size of the viewport area to which will be rendered.</param> /// <param name="renderOverlay">Whether or not to render screen overlay renderers onto the picking target.</param> public void RenderPickingMap(Point2 viewportSize, bool renderOverlay) { Profile.TimeVisualPicking.BeginMeasure(); // Render picking map { this.MakeAvailable(); this.UpdateDeviceConfig(); this.SetupPickingRT(viewportSize); if (this.pickingMap == null) this.pickingMap = new List<ICmpRenderer>(); this.pickingMap.Clear(); // Setup DrawDevice this.drawDevice.PickingIndex = 1; this.drawDevice.Target = this.pickingRT; this.drawDevice.ViewportRect = new Rect(this.pickingTex.PixelWidth, this.pickingTex.PixelHeight); // Render the world { this.drawDevice.VisibilityMask = this.visibilityMask & VisibilityFlag.AllGroups; this.drawDevice.RenderMode = RenderMatrix.PerspectiveWorld; this.drawDevice.PrepareForDrawcalls(); this.CollectDrawcalls(); this.drawDevice.Render(ClearFlag.All, ColorRgba.Black, 1.0f); } // Render screen overlays if (renderOverlay) { this.drawDevice.VisibilityMask = this.visibilityMask; this.drawDevice.RenderMode = RenderMatrix.OrthoScreen; this.drawDevice.PrepareForDrawcalls(); this.CollectDrawcalls(); this.drawDevice.Render(ClearFlag.None, ColorRgba.Black, 1.0f); } this.drawDevice.PickingIndex = 0; } // Move data to local buffer int pxNum = this.pickingTex.PixelWidth * this.pickingTex.PixelHeight; int pxByteNum = pxNum * 4; if (this.pickingBuffer == null) this.pickingBuffer = new byte[pxByteNum]; else if (pxByteNum > this.pickingBuffer.Length) Array.Resize(ref this.pickingBuffer, Math.Max(this.pickingBuffer.Length * 2, pxByteNum)); this.pickingRT.GetPixelData(this.pickingBuffer); PixelData test = this.pickingRT.GetPixelData(); Profile.TimeVisualPicking.EndMeasure(); }
/// <summary> /// Renders the current <see cref="Duality.Resources.Scene"/>. /// </summary> /// <param name="viewportRect">The viewport area to which will be rendered.</param> public void Render(Rect viewportRect) { this.MakeAvailable(); this.UpdateDeviceConfig(); string counterName = PathOp.Combine("Cameras", this.gameobj.Name); Profile.BeginMeasure(counterName); Profile.TimeRender.BeginMeasure(); foreach (Pass t in this.passes) { this.RenderSinglePass(viewportRect, t); } this.drawDevice.VisibilityMask = this.visibilityMask; this.drawDevice.RenderMode = RenderMatrix.PerspectiveWorld; this.drawDevice.UpdateMatrices(); // Reset matrices for projection calculations during update Profile.TimeRender.EndMeasure(); Profile.EndMeasure(counterName); }
//[InlineMethod.Inline] public static bool IsFaceVisible(this VoxelDefinition current, VoxelDefinition neighbor, VisibilityFlag neighborFace, VisibilityFlag currentFace) => current.IsBlock && ((neighbor.CoverFlags & neighborFace) == 0 || (current.CoverFlags & currentFace) == 0);
public BlockDefinitionBuilder WithCoverFlags(VisibilityFlag value) { _coverFlags = value; return(this); }
public BlockDefinitionBuilder WithHue(VisibilityFlag value) { _hueFaces = value; return(this); }
public SolidFaceInfo(int offset, int count, FaceBuildInfo buildInfo, VisibilityFlag direction) { Offset = offset; BuildInfo = buildInfo; Direction = direction; }
/// <summary> /// Renders a picking map of the current <see cref="Duality.Resources.Scene"/>. /// If picking is required, this will be (automatically) done each frame a picking operation needs to /// be performed. /// </summary> /// <param name="viewportSize">Sife of the viewport area to which will be rendered.</param> /// <returns>True, if the picking map has been rendered. False, if this frames cached version is used.</returns> public bool RenderPickingMap(Vector2 viewportSize) { if (this.pickingLast == Time.FrameCount) return false; this.pickingLast = Time.FrameCount; Profile.TimeVisualPicking.BeginMeasure(); // Render picking map { this.MakeAvailable(); this.UpdateDeviceConfig(); this.SetupPickingRT(viewportSize); // Setup DrawDevice this.drawDevice.PickingIndex = 1; this.drawDevice.Target = this.pickingRT; this.drawDevice.VisibilityMask = this.visibilityMask & VisibilityFlag.AllGroups; this.drawDevice.RenderMode = RenderMatrix.PerspectiveWorld; this.drawDevice.ViewportRect = new Rect(this.pickingTex.PixelWidth, this.pickingTex.PixelHeight); // Render Scene this.drawDevice.BeginRendering(ClearFlag.All, ColorRgba.Black, 1.0f); this.CollectDrawcalls(); this.drawDevice.EndRendering(); this.drawDevice.PickingIndex = 0; GL.Finish(); RenderTarget.Bind(RenderTarget.None); } // Move data to local buffer int pxNum = this.pickingTex.PixelWidth * this.pickingTex.PixelHeight; int pxByteNum = pxNum * 4; if (pxByteNum > this.pickingBuffer.Length) Array.Resize(ref this.pickingBuffer, Math.Max(this.pickingBuffer.Length * 2, pxByteNum)); ContentRef<RenderTarget> lastTex = RenderTarget.BoundRT; RenderTarget.Bind(this.pickingRT); GL.ReadBuffer(ReadBufferMode.ColorAttachment0); GL.ReadPixels(0, 0, this.pickingTex.PixelWidth, this.pickingTex.PixelHeight, PixelFormat.Rgba, PixelType.UnsignedByte, this.pickingBuffer); RenderTarget.Bind(lastTex); GL.ReadBuffer(ReadBufferMode.Back); Profile.TimeVisualPicking.EndMeasure(); return true; }
protected override void OnRenderPointOfView(Scene scene, DrawDevice drawDevice, Rect viewportRect, Vector2 imageSize) { // Set up the picking render target to match the proper size if (this.pickingTex == null) { this.pickingTex = new Texture( (int)viewportRect.W, (int)viewportRect.H, TextureSizeMode.Default, TextureMagFilter.Nearest, TextureMinFilter.Nearest); } if (this.pickingRT == null) { this.pickingRT = new RenderTarget( AAQuality.Off, true, this.pickingTex); this.pickingRT.DepthBuffer = true; } this.ResizeRenderTarget(this.pickingRT, (Point2)viewportRect.Size); ContentRef <RenderTarget> oldDeviceTarget = drawDevice.Target; ProjectionMode oldDeviceProjection = drawDevice.Projection; VisibilityFlag oldDeviceMask = drawDevice.VisibilityMask; drawDevice.PickingIndex = 1; drawDevice.ClearColor = ColorRgba.Black; drawDevice.ClearDepth = 1.0f; drawDevice.Target = this.pickingRT; drawDevice.TargetSize = imageSize; drawDevice.ViewportRect = new Rect(this.pickingRT.Size); if (this.pickingMap == null) { this.pickingMap = new List <ICmpRenderer>(); } this.pickingMap.Clear(); // Render the world { drawDevice.VisibilityMask = oldDeviceMask & VisibilityFlag.AllGroups; drawDevice.Projection = oldDeviceProjection; drawDevice.ClearFlags = ClearFlag.All; drawDevice.PrepareForDrawcalls(); this.CollectRendererDrawcalls(scene, drawDevice); drawDevice.Render(); } // Render screen overlays if (this.renderOverlay) { drawDevice.VisibilityMask = oldDeviceMask; drawDevice.Projection = ProjectionMode.Screen; drawDevice.ClearFlags = ClearFlag.None; drawDevice.PrepareForDrawcalls(); this.CollectRendererDrawcalls(scene, drawDevice); drawDevice.Render(); } drawDevice.PickingIndex = 0; drawDevice.VisibilityMask = oldDeviceMask; drawDevice.Projection = oldDeviceProjection; drawDevice.Target = oldDeviceTarget; // Move data to local buffer int pxNum = this.pickingTex.ContentWidth * this.pickingTex.ContentHeight; int pxByteNum = pxNum * 4; if (this.pickingBuffer == null) { this.pickingBuffer = new byte[pxByteNum]; } else if (pxByteNum > this.pickingBuffer.Length) { Array.Resize(ref this.pickingBuffer, Math.Max(this.pickingBuffer.Length * 2, pxByteNum)); } this.pickingRT.GetPixelData(this.pickingBuffer); }
/// <summary> /// Renders a picking map of the current <see cref="Duality.Resources.Scene"/>. /// If picking is required, this will be (automatically) done each frame a picking operation needs to /// be performed. /// </summary> /// <param name="viewportSize">Sife of the viewport area to which will be rendered.</param> /// <returns>True, if the picking map has been rendered. False, if this frames cached version is used.</returns> public bool RenderPickingMap(Vector2 viewportSize) { if (this.pickingLast == Time.FrameCount) return false; this.pickingLast = Time.FrameCount; Profile.TimeVisualPicking.BeginMeasure(); // Render picking map { this.MakeAvailable(); this.UpdateDeviceConfig(); this.SetupPickingRT(viewportSize); // Setup DrawDevice this.drawDevice.PickingIndex = 1; this.drawDevice.Target = this.pickingRT; this.drawDevice.VisibilityMask = this.visibilityMask & VisibilityFlag.AllGroups; this.drawDevice.RenderMode = RenderMatrix.PerspectiveWorld; this.drawDevice.ViewportRect = new Rect(this.pickingTex.PixelWidth, this.pickingTex.PixelHeight); // Render Scene this.drawDevice.PrepareForDrawcalls(); this.CollectDrawcalls(); this.drawDevice.Render(ClearFlag.All, ColorRgba.Black, 1.0f); this.drawDevice.PickingIndex = 0; } // Move data to local buffer int pxNum = this.pickingTex.PixelWidth * this.pickingTex.PixelHeight; int pxByteNum = pxNum * 4; if (pxByteNum > this.pickingBuffer.Length) Array.Resize(ref this.pickingBuffer, Math.Max(this.pickingBuffer.Length * 2, pxByteNum)); this.pickingRT.GetPixelData(this.pickingBuffer); Profile.TimeVisualPicking.EndMeasure(); return true; }
public EnvironmentRenderer() { visibilityGroup = VisibilityFlag.Group0; }
private void RenderSinglePass(Rect viewportRect, Pass p) { this.drawDevice.VisibilityMask = this.visibilityMask & p.VisibilityMask; this.drawDevice.RenderMode = p.MatrixMode; this.drawDevice.Target = p.Output; this.drawDevice.ViewportRect = p.Output.IsAvailable ? new Rect(p.Output.Res.Width, p.Output.Res.Height) : viewportRect; if (p.Input == null) { // Render Scene this.drawDevice.BeginRendering(p.ClearFlags, p.ClearColor, p.ClearDepth, p.Output.IsAvailable ? false : UseViewportScaling); try { this.CollectDrawcalls(); p.NotifyCollectDrawcalls(this.drawDevice); } catch (Exception e) { Log.Core.WriteError("There was an error while {0} was collecting drawcalls: {1}", this.ToString(), Log.Exception(e)); } this.drawDevice.EndRendering(); } else { Profile.TimePostProcessing.BeginMeasure(); this.drawDevice.BeginRendering(p.ClearFlags, p.ClearColor, p.ClearDepth, !p.Output.IsAvailable && UseViewportScaling); Texture mainTex = p.Input.MainTexture.Res; Vector2 uvRatio = mainTex != null ? mainTex.UVRatio : Vector2.One; Rect targetRect = new Rect(this.drawDevice.TargetSize); IDrawDevice device = this.drawDevice; device.AddVertices(p.Input, VertexMode.Quads, new VertexC1P3T2(targetRect.MinimumX, targetRect.MinimumY, 0.0f, 0.0f, 0.0f), new VertexC1P3T2(targetRect.MaximumX, targetRect.MinimumY, 0.0f, uvRatio.X, 0.0f), new VertexC1P3T2(targetRect.MaximumX, targetRect.MaximumY, 0.0f, uvRatio.X, uvRatio.Y), new VertexC1P3T2(targetRect.MinimumX, targetRect.MaximumY, 0.0f, 0.0f, uvRatio.Y)); this.drawDevice.EndRendering(); Profile.TimePostProcessing.EndMeasure(); } }
public static VisibilityFlag GetOpposite(this VisibilityFlag flag) => OppositeMapping[flag];
private void RenderSinglePass(Rect viewportRect, Pass p) { this.drawDevice.VisibilityMask = this.visibilityMask & p.VisibilityMask; this.drawDevice.RenderMode = p.MatrixMode; this.drawDevice.Target = p.Output; this.drawDevice.ViewportRect = p.Output.IsAvailable ? new Rect(p.Output.Res.Width, p.Output.Res.Height) : viewportRect; if (p.Input == null) { // Render Scene this.drawDevice.PrepareForDrawcalls(); try { this.CollectDrawcalls(); p.NotifyCollectDrawcalls(this.drawDevice); } catch (Exception e) { Log.Core.WriteError("There was an error while {0} was collecting drawcalls: {1}", this.ToString(), Log.Exception(e)); } this.drawDevice.Render(p.ClearFlags, p.ClearColor, p.ClearDepth); } else { Profile.TimePostProcessing.BeginMeasure(); this.drawDevice.PrepareForDrawcalls(); Texture mainTex = p.Input.MainTexture.Res; Vector2 uvRatio = mainTex != null ? mainTex.UVRatio : Vector2.One; Vector2 inputSize = mainTex != null ? new Vector2(mainTex.PixelWidth, mainTex.PixelHeight) : Vector2.One; Rect targetRect; if (DualityApp.ExecEnvironment == DualityApp.ExecutionEnvironment.Editor && !this.drawDevice.Target.IsAvailable) targetRect = Rect.Align(Alignment.Center, this.drawDevice.TargetSize.X * 0.5f, this.drawDevice.TargetSize.Y * 0.5f, inputSize.X, inputSize.Y); else targetRect = new Rect(this.drawDevice.TargetSize); IDrawDevice device = this.drawDevice; { VertexC1P3T2[] vertices = new VertexC1P3T2[4]; vertices[0].Pos = new Vector3(targetRect.LeftX, targetRect.TopY, 0.0f); vertices[1].Pos = new Vector3(targetRect.RightX, targetRect.TopY, 0.0f); vertices[2].Pos = new Vector3(targetRect.RightX, targetRect.BottomY, 0.0f); vertices[3].Pos = new Vector3(targetRect.LeftX, targetRect.BottomY, 0.0f); vertices[0].TexCoord = new Vector2(0.0f, 0.0f); vertices[1].TexCoord = new Vector2(uvRatio.X, 0.0f); vertices[2].TexCoord = new Vector2(uvRatio.X, uvRatio.Y); vertices[3].TexCoord = new Vector2(0.0f, uvRatio.Y); vertices[0].Color = ColorRgba.White; vertices[1].Color = ColorRgba.White; vertices[2].Color = ColorRgba.White; vertices[3].Color = ColorRgba.White; device.AddVertices(p.Input, VertexMode.Quads, vertices); } this.drawDevice.Render(p.ClearFlags, p.ClearColor, p.ClearDepth); Profile.TimePostProcessing.EndMeasure(); } }
public Pass(Pass copyFrom, BatchInfo inputOverride) { this.input = inputOverride; this.output = copyFrom.output; this.clearColor = copyFrom.clearColor; this.clearDepth = copyFrom.clearDepth; this.clearFlags = copyFrom.clearFlags; this.matrixMode = copyFrom.matrixMode; this.visibilityMask = copyFrom.visibilityMask; this.MakeAvailable(); }
/// <summary> /// Performs the specified <see cref="RenderStep"/>. This method will do some basic, localized configuration on /// the drawing device and then invoke <see cref="OnRenderSingleStep"/> for running the actual rendering operations. /// </summary> /// <param name="step"></param> /// <param name="scene"></param> /// <param name="drawDevice"></param> /// <param name="viewportRect"></param> /// <param name="imageSize"></param> /// <param name="outputTargetRect"></param> protected void RenderSingleStep(RenderStep step, Scene scene, DrawDevice drawDevice, Rect viewportRect, Vector2 imageSize) { // Memorize old draw device settings to reset them later VisibilityFlag oldDeviceMask = drawDevice.VisibilityMask; ColorRgba oldDeviceClearColor = drawDevice.ClearColor; ContentRef <RenderTarget> oldDeviceTarget = drawDevice.Target; Rect localViewport; Vector2 localTargetSize; ContentRef <RenderTarget> renderTarget; // If this step is using a custom render target, override image and viewport sizes if (step.Output.IsAvailable) { renderTarget = step.Output; localTargetSize = step.Output.Res.Size; localViewport = new Rect(step.Output.Res.Size); } // Otherwise, use the provided parameter values else { renderTarget = oldDeviceTarget; localTargetSize = imageSize; localViewport = viewportRect; } // Regardless of rendering targets, adjust the local render size and viewport // according to the rendering step target rect localViewport.Pos += localViewport.Size * step.TargetRect.Pos; localViewport.Size *= step.TargetRect.Size; localTargetSize *= step.TargetRect.Size; // Set up the draw device with rendering step settings drawDevice.RenderMode = step.MatrixMode; drawDevice.Target = renderTarget; drawDevice.TargetSize = localTargetSize; drawDevice.ViewportRect = localViewport; drawDevice.ClearFlags = step.ClearFlags; drawDevice.ClearColor = step.DefaultClearColor ? oldDeviceClearColor : step.ClearColor; drawDevice.ClearDepth = step.ClearDepth; // ScreenOverlay is a special flag that is set on a per-rendering-step basis // and that shouldn't be affected by overall device settings. Keep it separate. drawDevice.VisibilityMask = (drawDevice.VisibilityMask & step.VisibilityMask & ~VisibilityFlag.ScreenOverlay) | (step.VisibilityMask & VisibilityFlag.ScreenOverlay); try { this.OnRenderSingleStep(step, scene, drawDevice); } catch (Exception e) { Console.WriteLine("There was an error while {0} was processing rendering step '{1}': {2}", this, step.Id, /*LogFormat.Exception(*/ e /*)*/); } // Restore old draw device state drawDevice.VisibilityMask = oldDeviceMask; drawDevice.ClearColor = oldDeviceClearColor; drawDevice.Target = oldDeviceTarget; }