private void ControllerDraw(Controller3D mc, ulong unused) { // System.Diagnostics.Debug.WriteLine("Draw eye " + gl3dcontroller.MatrixCalc.EyePosition + " to " + gl3dcontroller.Pos.Current); GLMatrixCalcUniformBlock mcub = (GLMatrixCalcUniformBlock)items.UB("MCUB"); mcub.Set(gl3dcontroller.MatrixCalc); countbuffer.ZeroBuffer(); rObjects.Render(glwfc.RenderState, gl3dcontroller.MatrixCalc); GLMemoryBarrier.Vertex(); int count = countbuffer.ReadInt(0); Vector4[] d = rejectedbuffer.ReadVector4s(0, count); for (int i = 0; i < count; i++) { System.Diagnostics.Debug.WriteLine(i + " = " + d[i]); } redraw.DrawCount = count; // render passed back ones using red from vecoutbuffer rObjects2.Render(glwfc.RenderState, gl3dcontroller.MatrixCalc); }
private void ControllerDraw(Controller3D mc, ulong unused) { ((GLMatrixCalcUniformBlock)items.UB("MCUB")).Set(gl3dcontroller.MatrixCalc); // set the matrix unform block to the controller 3d matrix calc. IGLRenderableItem i = rObjects["DYNGRIDRENDER"]; DynamicGridVertexShader s = items.PLShader("PLGRIDVertShader") as DynamicGridVertexShader; if (Math.Abs(lasteyedistance - gl3dcontroller.MatrixCalc.EyeDistance) > 10) // a little histerisis { i.InstanceCount = s.ComputeGridSize(gl3dcontroller.MatrixCalc.EyeDistance, out lastgridwidth); lasteyedistance = gl3dcontroller.MatrixCalc.EyeDistance; } s.SetUniforms(gl3dcontroller.MatrixCalc.LookAt, lastgridwidth, i.InstanceCount); DynamicGridCoordVertexShader bs = items.PLShader("PLGRIDBitmapVertShader") as DynamicGridCoordVertexShader; bs.ComputeUniforms(lastgridwidth, gl3dcontroller.MatrixCalc, gl3dcontroller.PosCamera.CameraDirection, Color.Yellow, Color.Transparent); solmarker.Position = gl3dcontroller.MatrixCalc.LookAt; solmarker.Scale = gl3dcontroller.MatrixCalc.EyeDistance / 20; rObjects.Render(glwfc.RenderState, gl3dcontroller.MatrixCalc); this.Text = "Looking at " + gl3dcontroller.MatrixCalc.LookAt + " eye@ " + gl3dcontroller.MatrixCalc.EyePosition + " dir " + gl3dcontroller.PosCamera.CameraDirection + " Dist " + gl3dcontroller.MatrixCalc.EyeDistance + " Zoom " + gl3dcontroller.PosCamera.ZoomFactor; }
private void ControllerDraw(Controller3D mc, ulong unused) { //System.Diagnostics.Debug.WriteLine("Draw"); GLMatrixCalcUniformBlock mcub = (GLMatrixCalcUniformBlock)items.UB("MCUB"); mcub.SetFull(gl3dcontroller.MatrixCalc); rObjects.Render(glwfc.RenderState, gl3dcontroller.MatrixCalc); var azel = gl3dcontroller.PosCamera.EyePosition.AzEl(gl3dcontroller.PosCamera.LookAt, true); this.Text = "Looking at " + gl3dcontroller.MatrixCalc.LookAt + " from " + gl3dcontroller.MatrixCalc.EyePosition + " cdir " + gl3dcontroller.PosCamera.CameraDirection + " azel " + azel + " zoom " + gl3dcontroller.PosCamera.ZoomFactor + " dist " + gl3dcontroller.MatrixCalc.EyeDistance + " FOV " + gl3dcontroller.MatrixCalc.FovDeg; //GL.MemoryBarrier(MemoryBarrierFlags.AllBarrierBits); //Vector4[] databack = dataoutbuffer.ReadVector4(0, 4); //for (int i = 0; i < databack.Length; i += 1) //{ // // databack[i] = databack[i] / databack[i].W; // // databack[i].X = databack[i].X * gl3dcontroller.glControl.Width / 2 + gl3dcontroller.glControl.Width/2; // // databack[i].Y = gl3dcontroller.glControl.Height - databack[i].Y * gl3dcontroller.glControl.Height; // System.Diagnostics.Debug.WriteLine("{0}={1}", i, databack[i].ToStringVec(true)); //} //GLStatics.Check(); }
private void ControllerDraw(Controller3D mc, ulong unused) { GLMatrixCalcUniformBlock mcub = (GLMatrixCalcUniformBlock)items.UB("MCUB"); mcub.Set(gl3dcontroller.MatrixCalc); rObjects.Render(glwfc.RenderState, gl3dcontroller.MatrixCalc); }
private void ControllerDraw(Controller3D mc, ulong time) { // System.Diagnostics.Debug.WriteLine("Draw eye " + gl3dcontroller.MatrixCalc.EyePosition + " to " + gl3dcontroller.Pos.Current); float zeroone10s = ((float)(time % 10000)) / 10000.0f; float zeroone5s = ((float)(time % 5000)) / 5000.0f; float zerotwo5s = ((float)(time % 5000)) / 2500.0f; float degrees = zeroone10s * 360; // matrixbuffer.Write(Matrix4.CreateTranslation(new Vector3(zeroone * 20, 50, 0)),0,true); if (items.Contains("ShaderPos")) { ((GLMultipleTexturedBlended)items.Shader("ShaderPos")).CommonTransform.YRotDegrees = degrees; ((GLMultipleTexturedBlended)items.Shader("ShaderPos")).Blend = zerotwo5s; } if (items.Contains("ShaderMat")) { ((GLMultipleTexturedBlended)items.Shader("ShaderMat")).CommonTransform.ZRotDegrees = degrees; ((GLMultipleTexturedBlended)items.Shader("ShaderMat")).Blend = zerotwo5s; } GLMatrixCalcUniformBlock mcub = (GLMatrixCalcUniformBlock)items.UB("MCUB"); mcub.Set(gl3dcontroller.MatrixCalc); rObjects.Render(glwfc.RenderState, gl3dcontroller.MatrixCalc); this.Text = "Looking at " + gl3dcontroller.MatrixCalc.LookAt + " dir " + gl3dcontroller.PosCamera.CameraDirection + " Dist " + gl3dcontroller.MatrixCalc.EyeDistance; }
private void ControllerDraw(Controller3D mc, ulong unused) { GLMatrixCalcUniformBlock mcub = (GLMatrixCalcUniformBlock)items.UB("MCUB"); mcub.Set(gl3dcontroller.MatrixCalc); vecoutbuffer.ZeroBuffer(); rObjects.Render(glwfc.RenderState, gl3dcontroller.MatrixCalc); int count = vecoutbuffer.ReadInt(0); if (count > 0) { float[] values = vecoutbuffer.ReadFloats(4, Math.Min(2000, count), true); System.Diagnostics.Debug.WriteLine("Count " + count + " min " + values.Min() + " max " + values.Max()); for (int i = 0; i < count; i = i + 4) { Vector3 pos = new Vector3(values[i], values[i + 1], values[i + 2]); System.Diagnostics.Debug.Write(" " + i / 4 + " = " + pos + " : " + values[i + 3]); Vector3 up = new Vector3(0, 1, 0); float value = Vector3.Dot(up, pos); value = 0.0f + value; System.Diagnostics.Debug.WriteLine(" -> dotp" + value); } } this.Text = "Looking at " + gl3dcontroller.MatrixCalc.LookAt + " dir " + gl3dcontroller.PosCamera.CameraDirection + " Dist " + gl3dcontroller.MatrixCalc.EyeDistance; }
private void ControllerDraw(Controller3D mc, ulong time) { // System.Diagnostics.Debug.WriteLine("Draw eye " + gl3dcontroller.MatrixCalc.EyePosition + " to " + gl3dcontroller.Pos.Current); float zeroone10000s = ((float)(time % 10000000)) / 10000000.0f; float zeroone5000s = ((float)(time % 5000000)) / 5000000.0f; float zeroone1000s = ((float)(time % 1000000)) / 1000000.0f; float zeroone500s = ((float)(time % 500000)) / 500000.0f; float zeroone100s = ((float)(time % 100000)) / 100000.0f; float zeroone10s = ((float)(time % 10000)) / 10000.0f; float zeroone5s = ((float)(time % 5000)) / 5000.0f; float zerotwo5s = ((float)(time % 5000)) / 2500.0f; float timediv10s = (float)time / 10000.0f; float timediv100s = (float)time / 100000.0f; if (items.Contains("STAR")) { int vid = items.Shader("STAR").GetShader(OpenTK.Graphics.OpenGL4.ShaderType.FragmentShader).Id; ((GLRenderDataTranslationRotation)(rObjects["sun"].RenderData)).RotationDegrees = new Vector3(0, -zeroone100s * 360, 0); var stellarsurfaceshader = (GLPLStarSurfaceFragmentShader)items.Shader("STAR").GetShader(OpenTK.Graphics.OpenGL4.ShaderType.FragmentShader); stellarsurfaceshader.TimeDeltaSpots = zeroone500s; stellarsurfaceshader.TimeDeltaSurface = timediv100s; } if (items.Contains("STAR-M2")) { var vid = items.Shader("STAR-M2").GetShader(OpenTK.Graphics.OpenGL4.ShaderType.VertexShader); ((GLPLVertexShaderModelCoordWorldAutoscale)vid).ModelTranslation = Matrix4.CreateRotationY((float)(-zeroone10s * Math.PI * 2)); var stellarsurfaceshader = (GLPLStarSurfaceFragmentShader)items.Shader("STAR-M2").GetShader(OpenTK.Graphics.OpenGL4.ShaderType.FragmentShader); stellarsurfaceshader.TimeDeltaSpots = zeroone500s; stellarsurfaceshader.TimeDeltaSurface = timediv100s; } if (items.Contains("STAR-M3")) { var vid = items.Shader("STAR-M3").GetShader(OpenTK.Graphics.OpenGL4.ShaderType.VertexShader); ((GLPLVertexShaderModelCoordWorldAutoscale)vid).ModelTranslation = Matrix4.CreateRotationY((float)(-zeroone10s * Math.PI * 2)); var stellarsurfaceshader = (GLPLStarSurfaceFragmentShader)items.Shader("STAR-M3").GetShader(OpenTK.Graphics.OpenGL4.ShaderType.FragmentShader); stellarsurfaceshader.TimeDeltaSpots = zeroone500s; stellarsurfaceshader.TimeDeltaSurface = timediv100s; } if (items.Contains("CORONA")) { ((GLShaderStarCorona)items.Shader("CORONA")).TimeDelta = (float)time / 100000f; } GLMatrixCalcUniformBlock mcub = (GLMatrixCalcUniformBlock)items.UB("MCUB"); mcub.Set(gl3dcontroller.MatrixCalc); rObjects.Render(glwfc.RenderState, gl3dcontroller.MatrixCalc); GL.MemoryBarrier(MemoryBarrierFlags.AllBarrierBits); this.Text = //"Freq " + frequency.ToString("#.#########") + " unRadius " + unRadius + " scutoff" + scutoff + " BD " + blackdeepness + " CE " + concentrationequator " Looking at " + gl3dcontroller.MatrixCalc.LookAt + " dir " + gl3dcontroller.PosCamera.CameraDirection + " Dist " + gl3dcontroller.MatrixCalc.EyeDistance; }
private void Controller3dDraw(Controller3D mc, ulong unused) { ((GLMatrixCalcUniformBlock)items.UB("MCUB")).SetFull(gl3dcontroller.MatrixCalc); // set the matrix unform block to the controller 3d matrix calc. rObjects.Render(glwfc.RenderState, gl3dcontroller.MatrixCalc); this.Text = "Looking at " + gl3dcontroller.MatrixCalc.LookAt + " eye@ " + gl3dcontroller.MatrixCalc.EyePosition + " dir " + gl3dcontroller.PosCamera.CameraDirection + " Dist " + gl3dcontroller.MatrixCalc.EyeDistance + " Zoom " + gl3dcontroller.PosCamera.ZoomFactor; }
private void ControllerDraw(Controller3D mc, long time) { ((GLMatrixCalcUniformBlock)items.UB("MCUB")).Set(gl3dcontroller.MatrixCalc); // set the matrix unform block to the controller 3d matrix calc. rObjects.Render(gl3dcontroller.MatrixCalc); this.Text = "Looking at " + gl3dcontroller.MatrixCalc.TargetPosition + " dir " + gl3dcontroller.Pos.CameraDirection + " eye@ " + gl3dcontroller.MatrixCalc.EyePosition + " Dist " + gl3dcontroller.MatrixCalc.EyeDistance; }
private void ControllerDraw(Controller3D mc, ulong unused) { GLMatrixCalcUniformBlock mcub = (GLMatrixCalcUniformBlock)items.UB("MCUB"); mcub.Set(gl3dcontroller.MatrixCalc); rObjects.Render(glwfc.RenderState, gl3dcontroller.MatrixCalc); GL.MemoryBarrier(MemoryBarrierFlags.VertexAttribArrayBarrierBit); }
// called on Paint of scene private void Draw(object mc, ulong unused) { //System.Diagnostics.Debug.WriteLine("Draw"); GLMatrixCalcUniformBlock mcub = (GLMatrixCalcUniformBlock)items.UB("MCUB"); mcub.SetFull(matrixcalc); // need to store the matrixcalc information into the uniform block rObjects.Render(glwfc.RenderState, matrixcalc); // execute render }
private void ControllerDraw(Controller3D mc, ulong unused) { GLMatrixCalcUniformBlock mcub = (GLMatrixCalcUniformBlock)items.UB("MCUB"); mcub.Set(gl3dcontroller.MatrixCalc); rObjects.Render(glwfc.RenderState, gl3dcontroller.MatrixCalc); this.Text = "Looking at " + gl3dcontroller.MatrixCalc.LookAt + " dir " + gl3dcontroller.PosCamera.CameraDirection + " Dist " + gl3dcontroller.MatrixCalc.EyeDistance; }
private void ControllerDraw(Controller3D mc, ulong time) { float degrees = ((float)time / 5000.0f * 360.0f) % 360f; float degreesd2 = ((float)time / 10000.0f * 360.0f) % 360f; GLMatrixCalcUniformBlock mcub = (GLMatrixCalcUniformBlock)items.UB("MCUB"); mcub.Set(gl3dcontroller.MatrixCalc); System.Diagnostics.Debug.WriteLine("Draw eye " + gl3dcontroller.MatrixCalc.EyePosition + " to " + gl3dcontroller.PosCamera.LookAt); rObjects.Render(glwfc.RenderState, gl3dcontroller.MatrixCalc); }
private void ControllerDraw(Controller3D mc, ulong unused) { ((GLMatrixCalcUniformBlock)items.UB("MCUB")).Set(gl3dcontroller.MatrixCalc); // set the matrix unform block to the controller 3d matrix calc. pointblock.StartWrite(0, pointblock.Length); float minzv = float.MaxValue, maxzv = float.MinValue; for (int i = 0; i < 8; i++) { Vector4 p = Vector4.Transform(boundingbox[i], mc.MatrixCalc.ModelMatrix); if (p.Z < minzv) { minzv = p.Z; } if (p.Z > maxzv) { maxzv = p.Z; } pointblock.Write(p); } pointblock.Write(minzv); pointblock.Write(maxzv); pointblock.Write(Vector4.Transform(new Vector4(mc.MatrixCalc.EyePosition, 0), mc.MatrixCalc.ModelMatrix)); float slicedist = (maxzv - minzv) / (float)slices; float slicestart = (maxzv - minzv) / ((float)slices * 2); pointblock.Write(slicestart); //slicestart pointblock.Write(slicedist); //slicedist // System.Diagnostics.Debug.WriteLine("slice start {0} dist {1}", slicestart, slicedist); // for (int ic = 0; ic < slices; ic++) // System.Diagnostics.Debug.WriteLine("slice {0} {1} {2}", minzv, maxzv, minzv + slicestart + slicedist * ic); pointblock.StopReadWrite(); dataoutbuffer.ZeroBuffer(); atomicbuffer.ZeroBuffer(); rObjects.Render(glwfc.RenderState, gl3dcontroller.MatrixCalc); GL.MemoryBarrier(MemoryBarrierFlags.AllBarrierBits); Vector4[] databack = dataoutbuffer.ReadVector4s(0, 5); // System.Diagnostics.Debug.WriteLine("avg {0} txtavg {1}", databack[0].ToStringVec(), databack[1].ToStringVec()); for (int i = 0; i < databack.Length; i += 1) { // System.Diagnostics.Debug.WriteLine("db "+databack[i].ToStringVec()); } this.Text = "Looking at " + gl3dcontroller.MatrixCalc.LookAt + " dir " + gl3dcontroller.PosCamera.CameraDirection + " eye@ " + gl3dcontroller.MatrixCalc.EyePosition + " Dist " + gl3dcontroller.MatrixCalc.EyeDistance; }
private void ControllerDraw(Controller3D mc, ulong unused) { ((GLMatrixCalcUniformBlock)items.UB("MCUB")).Set(gl3dcontroller.MatrixCalc); // set the matrix unform block to the controller 3d matrix calc. if (galaxy != null) { galaxy.InstanceCount = volumetricblock.Set(gl3dcontroller.MatrixCalc, boundingbox, 10.0f); // set up the volumentric uniform } rObjects.Render(glwfc.RenderState, gl3dcontroller.MatrixCalc); this.Text = "Looking at " + gl3dcontroller.MatrixCalc.LookAt + " eye@ " + gl3dcontroller.MatrixCalc.EyePosition + " dir " + gl3dcontroller.PosCamera.CameraDirection + " Dist " + gl3dcontroller.MatrixCalc.EyeDistance + " Zoom " + gl3dcontroller.PosCamera.ZoomFactor; }
private void ControllerDraw(Controller3D mc, ulong unused) { //System.Diagnostics.Debug.WriteLine("Draw"); GLMatrixCalcUniformBlock mcub = (GLMatrixCalcUniformBlock)items.UB("MCUB"); mcub.SetFull(gl3dcontroller.MatrixCalc); rObjects.Render(glwfc.RenderState, gl3dcontroller.MatrixCalc); var azel = gl3dcontroller.PosCamera.EyePosition.AzEl(gl3dcontroller.PosCamera.LookAt, true); this.Text = "Main Window Looking at " + gl3dcontroller.MatrixCalc.LookAt + " from " + gl3dcontroller.MatrixCalc.EyePosition + " cdir " + gl3dcontroller.PosCamera.CameraDirection + " azel " + azel + " zoom " + gl3dcontroller.PosCamera.ZoomFactor + " dist " + gl3dcontroller.MatrixCalc.EyeDistance + " FOV " + gl3dcontroller.MatrixCalc.FovDeg; }
private void ControllerDraw(Controller3Dd mc, ulong time) { // System.Diagnostics.Debug.WriteLine("Controller Draw"); GLMatrixCalcUniformBlock mcub = (GLMatrixCalcUniformBlock)items.UB("MCUB"); mcub.SetFull(gl3dcontroller.MatrixCalc); rObjects.Render(glwfc.RenderState, gl3dcontroller.MatrixCalc, false); rBodyObjects.Render(glwfc.RenderState, gl3dcontroller.MatrixCalc, false); if (jdscaling != 0 && lasttime != ulong.MaxValue) { var diff = time - lasttime; // ms between calls currentjd += diff / (60.0 * 60 * 24 * 1000) * jdscaling; // convert ms delta to days, with scaling } lasttime = time; }
private void ControllerDraw(Controller3D c3d, ulong unused) { ((GLMatrixCalcUniformBlock)items.UB("MCUB")).Set(gl3dcontroller.MatrixCalc); // set the matrix unform block to the controller 3d matrix calc. IGLRenderableItem i = rObjects["DYNGRIDRENDER"]; DynamicGridVertexShader s = items.PLShader("PLGRIDVertShader") as DynamicGridVertexShader; if (Math.Abs(lasteyedistance - gl3dcontroller.MatrixCalc.EyeDistance) > 10) // a little histerisis { i.InstanceCount = s.ComputeGridSize(gl3dcontroller.MatrixCalc.EyeDistance, out lastgridwidth); lasteyedistance = gl3dcontroller.MatrixCalc.EyeDistance; } s.SetUniforms(gl3dcontroller.MatrixCalc.LookAt, lastgridwidth, i.InstanceCount); float dist = c3d.MatrixCalc.EyeDistance; float d1 = dist - lastgridwidth; float suc = d1 / (9.0f * lastgridwidth); float cf = 1.0f - suc.Clamp(0f, 1f); float a = 0.7f * cf; float coordfade = lastgridwidth == 10000 ? (0.7f - (c3d.MatrixCalc.EyeDistance / 20000).Clamp(0.0f, 0.7f)) : 0.7f; Color coordscol = Color.FromArgb(coordfade < 0.05 ? 0 : 150, Color.Cyan); System.Diagnostics.Debug.WriteLine("Dist {0} grid {1} suc {2} cf {3} a {4} coord {5} {6}", dist, lastgridwidth, suc, cf, a, coordfade, coordscol); DynamicGridCoordVertexShader bs = items.PLShader("PLGRIDBitmapVertShader") as DynamicGridCoordVertexShader; bs.ComputeUniforms(lastgridwidth, gl3dcontroller.MatrixCalc, gl3dcontroller.PosCamera.CameraDirection, coordscol, Color.Transparent); if (galaxy != null) { galaxy.InstanceCount = volumetricblock.Set(gl3dcontroller.MatrixCalc, boundingbox, 50.0f); // set up the volumentric uniform IGLProgramShader p = items.Shader("Galaxy"); var fsgalaxy = p.GetShader(OpenTK.Graphics.OpenGL4.ShaderType.FragmentShader) as GalaxyFragmentPipeline; fsgalaxy.SetFader(c3d.MatrixCalc.EyeDistance); } rObjects.Render(glwfc.RenderState, gl3dcontroller.MatrixCalc); this.Text = "Looking at " + gl3dcontroller.MatrixCalc.LookAt + " eye@ " + gl3dcontroller.MatrixCalc.EyePosition + " dir " + gl3dcontroller.PosCamera.CameraDirection + " Dist " + gl3dcontroller.MatrixCalc.EyeDistance + " Zoom " + gl3dcontroller.PosCamera.ZoomFactor; }
private void ControllerDraw(Controller3D mc, ulong unused) { ((GLMatrixCalcUniformBlock)items.UB("MCUB")).Set(gl3dcontroller.MatrixCalc); // set the matrix unform block to the controller 3d matrix calc. dataoutbuffer.ZeroBuffer(); atomicbuffer.ZeroBuffer(); rObjects.Render(glwfc.RenderState, gl3dcontroller.MatrixCalc); GL.MemoryBarrier(MemoryBarrierFlags.AllBarrierBits); Vector4[] databack = dataoutbuffer.ReadVector4s(0, 2); for (int i = 0; i < databack.Length; i++) { System.Diagnostics.Debug.WriteLine(i + " = " + databack[i].ToString()); } this.Text = "Looking at " + gl3dcontroller.MatrixCalc.LookAt + " dir " + gl3dcontroller.PosCamera.CameraDirection + " eye@ " + gl3dcontroller.MatrixCalc.EyePosition + " Dist " + gl3dcontroller.MatrixCalc.EyeDistance; }
private void ControllerDraw(Controller3D mc, ulong time) { //System.Diagnostics.Debug.WriteLine("Draw"); GLMatrixCalcUniformBlock mcub = (GLMatrixCalcUniformBlock)items.UB("MCUB"); mcub.SetFull(gl3dcontroller.MatrixCalc); rObjects.Render(glwfc.RenderState, gl3dcontroller.MatrixCalc, false); if (jdscaling != 0 && lasttime != ulong.MaxValue) { var diff = time - lasttime; // ms between calls currentjd += diff / (60.0 * 60 * 24 * 1000) * jdscaling; // convert ms delta to days, with scaling } lasttime = time; var azel = gl3dcontroller.PosCamera.EyePosition.AzEl(gl3dcontroller.PosCamera.LookAt, true); this.Text = "Looking at " + gl3dcontroller.MatrixCalc.LookAt + " from " + gl3dcontroller.MatrixCalc.EyePosition + " cdir " + gl3dcontroller.PosCamera.CameraDirection + " azel " + azel + " zoom " + gl3dcontroller.PosCamera.ZoomFactor + " dist " + gl3dcontroller.MatrixCalc.EyeDistance + " FOV " + gl3dcontroller.MatrixCalc.FovDeg; }
private void ControllerDraw(Controller3D mc, ulong unused) { ((GLMatrixCalcUniformBlock)items.UB("MCUB")).Set(gl3dcontroller.MatrixCalc); // set the matrix unform block to the controller 3d matrix calc. galaxy.InstanceCount = volumetricblock.Set(gl3dcontroller.MatrixCalc, boundingbox, 100); // set up the volumentric uniform dataoutbuffer.ZeroBuffer(); atomicbuffer.ZeroBuffer(); rObjects.Render(glwfc.RenderState, gl3dcontroller.MatrixCalc); GL.MemoryBarrier(MemoryBarrierFlags.AllBarrierBits); Vector4[] databack = dataoutbuffer.ReadVector4s(0, 10); //System.Diagnostics.Debug.WriteLine("avg {0} txtavg {1}", databack[0].ToStringVec(), databack[1].ToStringVec()); for (int i = 0; i < databack.Length; i += 1) { System.Diagnostics.Debug.WriteLine("db " + databack[i].ToStringVec()); } this.Text = "Looking at " + gl3dcontroller.MatrixCalc.LookAt + " eye@ " + gl3dcontroller.MatrixCalc.EyePosition + " dir " + gl3dcontroller.PosCamera.CameraDirection + " Dist " + gl3dcontroller.MatrixCalc.EyeDistance + " Zoom " + gl3dcontroller.PosCamera.ZoomFactor; }
private void ControllerDraw(Controller3D mc, ulong unused) { ((GLMatrixCalcUniformBlock)items.UB("MCUB")).Set(gl3dcontroller.MatrixCalc); // set the matrix unform block to the controller 3d matrix calc. Vector4[] modelboundingbox = boundingbox.Transform(gl3dcontroller.MatrixCalc.ModelMatrix); for (int i = 0; i < boundingbox.Length; i++) { System.Diagnostics.Debug.WriteLine(i + " = " + modelboundingbox[i].ToStringVec()); } modelboundingbox.MinMaxZ(out int minz, out int maxz); System.Diagnostics.Debug.WriteLine("min " + minz + " max " + maxz); indicatorlinebuffer.StartWrite(0, sizeof(float) * 4 * 2); indicatorlinebuffer.Write(boundingbox[minz]); indicatorlinebuffer.Write(boundingbox[maxz]); indicatorlinebuffer.StopReadWrite(); float percent = 0.2f; float zdist = modelboundingbox[maxz].Z - modelboundingbox[minz].Z; { float zpoint = modelboundingbox[maxz].Z - zdist * percent; //System.Diagnostics.Debug.WriteLine("Zpoint is" + zpoint); Vector4[] intercepts = new Vector4[6]; int count = 0; modelboundingbox[0].FindVectorFromZ(modelboundingbox[1], ref intercepts, ref count, zpoint); modelboundingbox[1].FindVectorFromZ(modelboundingbox[2], ref intercepts, ref count, zpoint); modelboundingbox[2].FindVectorFromZ(modelboundingbox[3], ref intercepts, ref count, zpoint); modelboundingbox[3].FindVectorFromZ(modelboundingbox[0], ref intercepts, ref count, zpoint); modelboundingbox[4].FindVectorFromZ(modelboundingbox[5], ref intercepts, ref count, zpoint); modelboundingbox[5].FindVectorFromZ(modelboundingbox[6], ref intercepts, ref count, zpoint); modelboundingbox[6].FindVectorFromZ(modelboundingbox[7], ref intercepts, ref count, zpoint); modelboundingbox[7].FindVectorFromZ(modelboundingbox[4], ref intercepts, ref count, zpoint); modelboundingbox[0].FindVectorFromZ(modelboundingbox[4], ref intercepts, ref count, zpoint); modelboundingbox[1].FindVectorFromZ(modelboundingbox[5], ref intercepts, ref count, zpoint); modelboundingbox[2].FindVectorFromZ(modelboundingbox[6], ref intercepts, ref count, zpoint); modelboundingbox[3].FindVectorFromZ(modelboundingbox[7], ref intercepts, ref count, zpoint); // texturecoords can be worked out by zpercent and knowing its direction (x,y,z).. if (count >= 3) { Vector4 avg = intercepts.Average(); float[] angles = new float[6]; for (int i = 0; i < count; i++) { angles[i] = -(float)Math.Atan2(intercepts[i].Y - avg.Y, intercepts[i].X - avg.X); // all on the same z plane, so x/y only need be considered System.Diagnostics.Debug.WriteLine("C" + intercepts[i].ToStringVec() + " " + angles[i].Degrees()); } Array.Sort(angles, intercepts, 0, count); // sort by angles, sorting intercepts, from 0 to count for (int i = 0; i < count; i++) { // System.Diagnostics.Debug.WriteLine(intercepts[i].ToStringVec() + " " + angles[i].Degrees()); } interceptpointbuffer.StartWrite(0, sizeof(float) * 4 * count); int ji = 0; for (; ji < count; ji++) { interceptpointbuffer.Write(intercepts[ji]); } interceptpointbuffer.StopReadWrite(); interceptri.DrawCount = count; surfacebuffer.StartWrite(0, sizeof(float) * 4 * (2 + count)); surfacebuffer.Write(avg); for (ji = 0; ji < count; ji++) { surfacebuffer.Write(intercepts[ji]); } surfacebuffer.Write(intercepts[0]); surfacebuffer.StopReadWrite(); surfaceri.DrawCount = count + 2; } } rObjects.Render(glwfc.RenderState, gl3dcontroller.MatrixCalc); this.Text = "Looking at " + gl3dcontroller.MatrixCalc.LookAt + " dir " + gl3dcontroller.PosCamera.CameraDirection + " eye@ " + gl3dcontroller.MatrixCalc.EyePosition + " Dist " + gl3dcontroller.MatrixCalc.EyeDistance; }
private void Controller3DDraw(Controller3D c3d, ulong time) { long t1 = hptimer.ElapsedTicks; //TBD // GL.Finish(); // use GL finish to ensure last frame is done - if we are operating above sys tick rate, this will be small time. If we are rendering too much, it will stall long t2 = hptimer.ElapsedTicks; GLMatrixCalcUniformBlock mcb = ((GLMatrixCalcUniformBlock)items.UB("MCUB")); mcb.SetFull(gl3dcontroller.MatrixCalc); // set the matrix unform block to the controller 3d matrix calc. // set up the grid shader size if (gridrenderable != null) { gridrenderable.InstanceCount = gridvertshader.ComputeGridSize(gl3dcontroller.MatrixCalc.EyeDistance, out lastgridwidth); lasteyedistance = gl3dcontroller.MatrixCalc.EyeDistance; gridvertshader.SetUniforms(gl3dcontroller.MatrixCalc.LookAt, lastgridwidth, gridrenderable.InstanceCount); } if (gridbitmapvertshader != null) { float coordfade = lastgridwidth == 10000 ? (0.7f - (c3d.MatrixCalc.EyeDistance / 20000).Clamp(0.0f, 0.7f)) : 0.7f; Color coordscol = Color.FromArgb(coordfade < 0.05 ? 0 : 150, Color.Cyan); gridbitmapvertshader.ComputeUniforms(lastgridwidth, gl3dcontroller.MatrixCalc, gl3dcontroller.PosCamera.CameraDirection, coordscol, Color.Transparent); } if (edsmgalmapregions != null) { edsmgalmapregions.SetY(gl3dcontroller.PosCamera.LookAt.Y); } if (elitemapregions != null) { elitemapregions.SetY(gl3dcontroller.PosCamera.LookAt.Y); } // set the coords fader // set the galaxy volumetric block if (galaxyrenderable != null) { galaxyrenderable.InstanceCount = volumetricblock.Set(gl3dcontroller.MatrixCalc, volumetricboundingbox, gl3dcontroller.MatrixCalc.InPerspectiveMode ? 50.0f : 0); // set up the volumentric uniform //System.Diagnostics.Debug.WriteLine("GI {0}", galaxyrendererable.InstanceCount); galaxyshader.SetDistance(gl3dcontroller.MatrixCalc.InPerspectiveMode ? c3d.MatrixCalc.EyeDistance : -1f); } long t3 = hptimer.ElapsedTicks; if (travelpath != null) { travelpath.Update(time, gl3dcontroller.MatrixCalc.EyeDistance); } if (galmapobjects != null) { galmapobjects.Update(time, gl3dcontroller.MatrixCalc.EyeDistance); } if (galaxystars != null) { galaxystars.Update(time, gl3dcontroller.MatrixCalc.EyeDistance); } if (galaxystars != null && gl3dcontroller.MatrixCalc.EyeDistance < 400) { galaxystars.Request9BoxConditional(gl3dcontroller.PosCamera.LookAt); } long t4 = hptimer.ElapsedTicks; //int[] queryID = new int[2]; //GL.GenQueries(2, queryID); //GL.QueryCounter(queryID[0], QueryCounterTarget.Timestamp); var tmr1 = new GLOperationQueryTimeStamp(); var tmr2 = new GLOperationQueryTimeStamp(); tmr1.Execute(null); rObjects.Render(glwfc.RenderState, gl3dcontroller.MatrixCalc, verbose: false); tmr2.Execute(null); // GL.QueryCounter(queryID[1], QueryCounterTarget.Timestamp); // GL.Flush(); // ensure everything is in the grapghics pipeline //while (tmr2.IsAvailable() == false) // ; long a = tmr1.GetCounter(); long b = tmr2.GetCounter(); //int done = 0; //while (done == 0) //{ // GL.GetQueryObject(queryID[1], GetQueryObjectParam.QueryResultAvailable, out done); //} //GL.GetQueryObject(queryID[0], GetQueryObjectParam.QueryResult, out long a); //GL.GetQueryObject(queryID[1], GetQueryObjectParam.QueryResult, out long b); //System.Diagnostics.Debug.WriteLine($"timer {a} {b} {b-a}" ); long t5 = hptimer.ElapsedTicks; if (debugbuffer != null) { GLMemoryBarrier.All(); Vector4[] debugout = debugbuffer.ReadVector4s(0, 4); System.Diagnostics.Debug.WriteLine("{0},{1},{2},{3}", debugout[0], debugout[1], debugout[2], debugout[3]); } long t = hptimer.ElapsedMilliseconds; long diff = t - lastms; for (int i = frametimes.Length - 1; i > 0; i--) { frametimes[i] = frametimes[i - 1]; } frametimes[0] = diff; lastms = t; double fps = (1000.0 / diff); if (fpsavg <= 1) { fpsavg = fps; } else { fpsavg = (fpsavg * 0.95) + fps * 0.05; } tmr1.Dispose(); tmr2.Dispose(); if (diff > 0) { // System.Diagnostics.Debug.Write($"Frame {hptimer.ElapsedMilliseconds,6} {diff,3} fps {fpsavg:#.0} frames {frametimes[0],3} {frametimes[1],3} {frametimes[2],3} {frametimes[3],3} {frametimes[4],3} {frametimes[5],3} sec {galaxystars.Sectors,3}"); // System.Diagnostics.Debug.WriteLine($" finish {(t2 - t1) * 1000000 / Stopwatch.Frequency,5} t3 {(t3 - t2) * 1000000 / Stopwatch.Frequency,4} t4 {(t4 - t3) * 1000000 / Stopwatch.Frequency,4} render {(t5 - t4) * 1000000 / Stopwatch.Frequency,5} tot {(t5 - t1) * 1000000 / Stopwatch.Frequency,5}"); } // this.Text = "FPS " + fpsavg.ToString("N0") + " Looking at " + gl3dcontroller.MatrixCalc.TargetPosition + " eye@ " + gl3dcontroller.MatrixCalc.EyePosition + " dir " + gl3dcontroller.Pos.CameraDirection + " Dist " + gl3dcontroller.MatrixCalc.EyeDistance + " Zoom " + gl3dcontroller.Pos.ZoomFactor; }