protected override void OnLoad(EventArgs e) { base.OnLoad(e); Closed += ShaderTest_Closed; gl3dcontroller = new Controller3D(); gl3dcontroller.PaintObjects = ControllerDraw; gl3dcontroller.MatrixCalc.PerspectiveNearZDistance = 0.1f; gl3dcontroller.ZoomDistance = 40F; gl3dcontroller.MouseRotateAmountPerPixel = 0.05f; gl3dcontroller.Start(glwfc, new Vector3(0, 0, 0), new Vector3(135, 0, 0), 1F); gl3dcontroller.KeyboardTravelSpeed = (ms, eyedist) => { return((float)ms / 100.0f); }; items.Add(new GLColorShaderWorld(), "COSW"); GLRenderState rl1 = GLRenderState.Lines(1); { rObjects.Add(items.Shader("COSW"), "L1", // horizontal GLRenderableItem.CreateVector4Color4(items, PrimitiveType.Lines, rl1, GLShapeObjectFactory.CreateLines(new Vector3(-100, 0, -100), new Vector3(-100, 0, 100), new Vector3(10, 0, 0), 21), new Color4[] { Color.Gray }) ); rObjects.Add(items.Shader("COSW"), // vertical GLRenderableItem.CreateVector4Color4(items, PrimitiveType.Lines, rl1, GLShapeObjectFactory.CreateLines(new Vector3(-100, 0, -100), new Vector3(100, 0, -100), new Vector3(0, 0, 10), 21), new Color4[] { Color.Gray }) ); } // Number markers using instancing and 2d arrays, each with its own transform { Bitmap[] numbers = new Bitmap[20]; Matrix4[] numberpos = new Matrix4[20]; Font fnt = new Font("Arial", 44); for (int i = 0; i < numbers.Length; i++) { int v = -100 + i * 10; numbers[i] = new Bitmap(100, 100); GLOFC.Utils.BitMapHelpers.DrawTextCentreIntoBitmap(ref numbers[i], v.ToString(), fnt, System.Drawing.Text.TextRenderingHint.ClearTypeGridFit, Color.Red, Color.AliceBlue); numberpos[i] = Matrix4.CreateScale(1); numberpos[i] *= Matrix4.CreateRotationX(-80f.Radians()); numberpos[i] *= Matrix4.CreateTranslation(new Vector3(20, 0, v)); } GLTexture2DArray array = new GLTexture2DArray(numbers, SizedInternalFormat.Rgba8, ownbmp: true); items.Add(array, "Nums"); items.Add(new GLShaderPipeline(new GLPLVertexShaderModelMatrixTexture(), new GLPLFragmentShaderTexture2DIndexed(0)), "IC-2"); GLRenderState rq = GLRenderState.Quads(cullface: false); GLRenderDataTexture rt = new GLRenderDataTexture(items.Tex("Nums")); rObjects.Add(items.Shader("IC-2"), "1-b", GLRenderableItem.CreateVector4Vector2Matrix4(items, PrimitiveType.Quads, rq, GLShapeObjectFactory.CreateQuad(1.0f), GLShapeObjectFactory.TexQuadCW, numberpos, rt, numberpos.Length)); } { int left = -40, right = 40, bottom = -20, top = +20, front = -40, back = 40; Vector4[] lines2 = new Vector4[] { new Vector4(left, bottom, front, 1), new Vector4(left, top, front, 1), new Vector4(left, top, front, 1), new Vector4(right, top, front, 1), new Vector4(right, top, front, 1), new Vector4(right, bottom, front, 1), new Vector4(right, bottom, front, 1), new Vector4(left, bottom, front, 1), new Vector4(left, bottom, back, 1), new Vector4(left, top, back, 1), new Vector4(left, top, back, 1), new Vector4(right, top, back, 1), new Vector4(right, top, back, 1), new Vector4(right, bottom, back, 1), new Vector4(right, bottom, back, 1), new Vector4(left, bottom, back, 1), new Vector4(left, bottom, front, 1), new Vector4(left, bottom, back, 1), new Vector4(left, top, front, 1), new Vector4(left, top, back, 1), new Vector4(right, bottom, front, 1), new Vector4(right, bottom, back, 1), new Vector4(right, top, front, 1), new Vector4(right, top, back, 1), }; items.Add(new GLFixedShader(System.Drawing.Color.Yellow), "LINEYELLOW"); rObjects.Add(items.Shader("LINEYELLOW"), GLRenderableItem.CreateVector4(items, PrimitiveType.Lines, rl1, lines2)); } items.Add(new ShaderV2(), "V2"); Vector4[] points = new Vector4[] { new Vector4(-40, -20, -40, 1), new Vector4(+40, +20, +40, 1), }; GLRenderState rltot = GLRenderState.Tri(); rObjects.Add(items.Shader("V2"), GLRenderableItem.CreateVector4(items, PrimitiveType.Lines, rltot, points, ic: 1)); items.Add(new GLMatrixCalcUniformBlock(), "MCUB"); // create a matrix uniform block dataoutbuffer = items.NewStorageBlock(5); dataoutbuffer.AllocateBytes(sizeof(float) * 4 * 32, OpenTK.Graphics.OpenGL4.BufferUsageHint.DynamicRead); // 32 vec4 back atomicbuffer = items.NewAtomicBlock(6); atomicbuffer.AllocateBytes(sizeof(float) * 32, OpenTK.Graphics.OpenGL4.BufferUsageHint.DynamicCopy); }
protected override void OnLoad(EventArgs e) { base.OnLoad(e); Closed += ShaderTest_Closed; gl3dcontroller = new Controller3D(); gl3dcontroller.PaintObjects = ControllerDraw; gl3dcontroller.MatrixCalc.PerspectiveNearZDistance = 0.1f; gl3dcontroller.ZoomDistance = 40F; gl3dcontroller.Start(glwfc, new Vector3(30, 0, 0), new Vector3(135f, 0, 0), 1F); gl3dcontroller.KeyboardTravelSpeed = (ms, eyedist) => { return((float)ms / 100.0f); }; items.Add(new GLColorShaderWorld(), "COSW"); GLRenderState rl1 = GLRenderState.Lines(1); { rObjects.Add(items.Shader("COSW"), "L1", // horizontal GLRenderableItem.CreateVector4Color4(items, PrimitiveType.Lines, rl1, GLShapeObjectFactory.CreateLines(new Vector3(-100, 0, -100), new Vector3(-100, 0, 100), new Vector3(10, 0, 0), 21), new Color4[] { Color.Gray }) ); rObjects.Add(items.Shader("COSW"), // vertical GLRenderableItem.CreateVector4Color4(items, PrimitiveType.Lines, rl1, GLShapeObjectFactory.CreateLines(new Vector3(-100, 0, -100), new Vector3(100, 0, -100), new Vector3(0, 0, 10), 21), new Color4[] { Color.Gray }) ); } // New geo shader Vector4[] points = new Vector4[] { new Vector4(20, -5, -10, 1), //PT1 new Vector4(40, +5, +10, 1), //PT7 }; items.Add(new ShaderV2(), "V2"); GLRenderState rltot = GLRenderState.Tri(); rObjects.Add(items.Shader("V2"), GLRenderableItem.CreateVector4(items, PrimitiveType.Lines, rltot, points, ic: 9)); // ic select number of slices int left = 20, right = 40, bottom = -5, top = +5, front = -10, back = 10; Vector4[] lines2 = new Vector4[] { new Vector4(left, bottom, front, 1), new Vector4(left, top, front, 1), new Vector4(left, top, front, 1), new Vector4(right, top, front, 1), new Vector4(right, top, front, 1), new Vector4(right, bottom, front, 1), new Vector4(right, bottom, front, 1), new Vector4(left, bottom, front, 1), new Vector4(left, bottom, back, 1), new Vector4(left, top, back, 1), new Vector4(left, top, back, 1), new Vector4(right, top, back, 1), new Vector4(right, top, back, 1), new Vector4(right, bottom, back, 1), new Vector4(right, bottom, back, 1), new Vector4(left, bottom, back, 1), new Vector4(left, bottom, front, 1), new Vector4(left, bottom, back, 1), new Vector4(left, top, front, 1), new Vector4(left, top, back, 1), new Vector4(right, bottom, front, 1), new Vector4(right, bottom, back, 1), new Vector4(right, top, front, 1), new Vector4(right, top, back, 1), }; items.Add(new GLFixedShader(System.Drawing.Color.Yellow), "LINEYELLOW"); rObjects.Add(items.Shader("LINEYELLOW"), GLRenderableItem.CreateVector4(items, PrimitiveType.Lines, rl1, lines2)); dataoutbuffer = items.NewStorageBlock(5); dataoutbuffer.AllocateBytes(sizeof(float) * 4 * 32, OpenTK.Graphics.OpenGL4.BufferUsageHint.DynamicRead); atomicbuffer = items.NewAtomicBlock(6); atomicbuffer.AllocateBytes(sizeof(float) * 32, OpenTK.Graphics.OpenGL4.BufferUsageHint.DynamicCopy); items.Add(new GLMatrixCalcUniformBlock(), "MCUB"); // create a matrix uniform block }
protected override void OnLoad(EventArgs e) { base.OnLoad(e); Closed += ShaderTest_Closed; //GLStatics.EnableDebug(DebugProc); gl3dcontroller = new Controller3D(); gl3dcontroller.PaintObjects = ControllerDraw; gl3dcontroller.MatrixCalc.PerspectiveNearZDistance = 1f; gl3dcontroller.MatrixCalc.PerspectiveFarZDistance = 500000f; gl3dcontroller.ZoomDistance = 5000F; gl3dcontroller.YHoldMovement = true; gl3dcontroller.KeyboardTravelSpeed = (ms, eyedist) => { return((float)ms * 10.0f); }; gl3dcontroller.MatrixCalc.InPerspectiveMode = true; gl3dcontroller.Start(glwfc, new Vector3(0, 0, -35000), new Vector3(135f, 0, 0), 0.31622F); items.Add(new GLColorShaderWorld(), "COSW"); GLRenderState rl1 = GLRenderState.Lines(1); float h = -1; if (h != -1) { Color cr = Color.FromArgb(60, Color.Gray); rObjects.Add(items.Shader("COS-1L"), // horizontal GLRenderableItem.CreateVector4Color4(items, PrimitiveType.Lines, rl1, GLShapeObjectFactory.CreateLines(new Vector3(-35000, h, -35000), new Vector3(-35000, h, 35000), new Vector3(1000, 0, 0), 70), new Color4[] { cr }) ); rObjects.Add(items.Shader("COS-1L"), GLRenderableItem.CreateVector4Color4(items, PrimitiveType.Lines, rl1, GLShapeObjectFactory.CreateLines(new Vector3(-35000, h, -35000), new Vector3(35000, h, -35000), new Vector3(0, 0, 1000), 70), new Color4[] { cr }) ); } int hsize = 35000, vsize = 2000, zsize = 35000; { int left = -hsize, right = hsize, bottom = -vsize, top = +vsize, front = -zsize, back = zsize; Vector4[] lines2 = new Vector4[] { new Vector4(left, bottom, front, 1), new Vector4(left, top, front, 1), new Vector4(left, top, front, 1), new Vector4(right, top, front, 1), new Vector4(right, top, front, 1), new Vector4(right, bottom, front, 1), new Vector4(right, bottom, front, 1), new Vector4(left, bottom, front, 1), new Vector4(left, bottom, back, 1), new Vector4(left, top, back, 1), new Vector4(left, top, back, 1), new Vector4(right, top, back, 1), new Vector4(right, top, back, 1), new Vector4(right, bottom, back, 1), new Vector4(right, bottom, back, 1), new Vector4(left, bottom, back, 1), new Vector4(left, bottom, front, 1), new Vector4(left, bottom, back, 1), new Vector4(left, top, front, 1), new Vector4(left, top, back, 1), new Vector4(right, bottom, front, 1), new Vector4(right, bottom, back, 1), new Vector4(right, top, front, 1), new Vector4(right, top, back, 1), }; items.Add(new GLFixedShader(System.Drawing.Color.Yellow), "LINEYELLOW"); rObjects.Add(items.Shader("LINEYELLOW"), GLRenderableItem.CreateVector4(items, PrimitiveType.Lines, rl1, lines2)); } // bounding box boundingbox = new Vector4[] { new Vector4(-hsize, -vsize, -zsize, 1), new Vector4(-hsize, vsize, -zsize, 1), new Vector4(hsize, vsize, -zsize, 1), new Vector4(hsize, -vsize, -zsize, 1), new Vector4(-hsize, -vsize, zsize, 1), new Vector4(-hsize, vsize, zsize, 1), new Vector4(hsize, vsize, zsize, 1), new Vector4(hsize, -vsize, zsize, 1), }; items.Add(new GLMatrixCalcUniformBlock(), "MCUB"); // create a matrix uniform block dataoutbuffer = items.NewStorageBlock(5); dataoutbuffer.AllocateBytes(sizeof(float) * 4 * 32, OpenTK.Graphics.OpenGL4.BufferUsageHint.DynamicRead); // 32 vec4 back atomicbuffer = items.NewAtomicBlock(6); atomicbuffer.AllocateBytes(sizeof(float) * 32, OpenTK.Graphics.OpenGL4.BufferUsageHint.DynamicCopy); dataoutbuffer = items.NewStorageBlock(5); dataoutbuffer.AllocateBytes(sizeof(float) * 4 * 256, OpenTK.Graphics.OpenGL4.BufferUsageHint.DynamicRead); // 32 vec4 back volumetricblock = new GLVolumetricUniformBlock(); items.Add(volumetricblock, "VB"); { Bitmap[] numbers = new Bitmap[70]; Matrix4[] numberpos = new Matrix4[numbers.Length]; Matrix4[] numberpos2 = new Matrix4[numbers.Length]; Font fnt = new Font("Arial", 20); for (int i = 0; i < numbers.Length; i++) { int v = -35000 + i * 1000; numbers[i] = new Bitmap(100, 100); GLOFC.Utils.BitMapHelpers.DrawTextCentreIntoBitmap(ref numbers[i], v.ToString(), fnt, System.Drawing.Text.TextRenderingHint.ClearTypeGridFit, Color.Red, Color.AliceBlue); numberpos[i] = Matrix4.CreateScale(1); numberpos[i] *= Matrix4.CreateRotationX(-25f.Radians()); numberpos[i] *= Matrix4.CreateTranslation(new Vector3(35500, 0, v)); numberpos2[i] = Matrix4.CreateScale(1); numberpos2[i] *= Matrix4.CreateRotationX(-25f.Radians()); numberpos2[i] *= Matrix4.CreateTranslation(new Vector3(v, 0, -35500)); } GLTexture2DArray array = new GLTexture2DArray(numbers, SizedInternalFormat.Rgba8, ownbmp: true); items.Add(array, "Nums"); items.Add(new GLShaderPipeline(new GLPLVertexShaderModelMatrixTexture(), new GLPLFragmentShaderTexture2DIndexed(0)), "IC-2"); GLRenderState rq = GLRenderState.Quads(cullface: false); GLRenderDataTexture rt = new GLRenderDataTexture(items.Tex("Nums")); rObjects.Add(items.Shader("IC-2"), "1-b", GLRenderableItem.CreateVector4Vector2Matrix4(items, PrimitiveType.Quads, rq, GLShapeObjectFactory.CreateQuad(500.0f), GLShapeObjectFactory.TexQuadCW, numberpos, rt, numberpos.Length)); rObjects.Add(items.Shader("IC-2"), "1-b2", GLRenderableItem.CreateVector4Vector2Matrix4(items, PrimitiveType.Quads, rq, GLShapeObjectFactory.CreateQuad(500.0f), GLShapeObjectFactory.TexQuadCW, numberpos2, rt, numberpos.Length)); } GLTexture3D noise3d = new GLTexture3D(1024, 64, 1024, OpenTK.Graphics.OpenGL4.SizedInternalFormat.R32f); // red channel only //{ // shows program fill // for (int ly = 0; ly < noise3d.Depth; ly++) // { // float[] fd = new float[noise3d.Width * noise3d.Height]; // float[] fdi = new float[noise3d.Width * noise3d.Height]; // for (int x = 0; x < noise3d.Width; x++) // { // for (int y = 0; y < noise3d.Height; y++) // { // int p = (y * noise3d.Width + x) * 1; // float xv = (float)x / (float)noise3d.Width; // float yv = (float)y / (float)noise3d.Height; // var c = ((Math.Sin(2 * Math.PI * xv) / 2) + 0.5); // c += ((Math.Cos(2 * Math.PI * yv) / 2) + 0.5); // c /= 2; // fd[p + 0] = (float)(c); // fdi[p + 0] = 1.0f-(float)(c); // } // } // noise3d.StoreZPlane(ly, 0, 0, noise3d.Width, noise3d.Height, fd, OpenTK.Graphics.OpenGL4.PixelFormat.Red); // only a single float per pixel, stored in RED // } //} ShaderNoiseDisplay ns = new ShaderNoiseDisplay(); ns.StartAction += (a, m) => { noise3d.Bind(3); }; items.Add(ns, "NS"); GLRenderState rv = GLRenderState.Tri(); noisebox = GLRenderableItem.CreateNullVertex(OpenTK.Graphics.OpenGL4.PrimitiveType.Points, rv); // no vertexes, all data from bound volumetric uniform, no instances as yet rObjects.Add(items.Shader("NS"), noisebox); // make a compute shader noise and run it, to fill up noise3d buffer ComputeShaderNoise csn = new ComputeShaderNoise(noise3d.Width, noise3d.Height, noise3d.Depth, 32, 4, 32); // must be a multiple of localgroupsize in csn csn.StartAction += (A, m) => { noise3d.BindImage(3); }; items.Add(csn, "CE1"); GLComputeShaderList p = new GLComputeShaderList(); // demonstrate a render list holding a compute shader. p.Add(csn); p.Run(); // run the shader to compute into the noise3d block the noise. }
protected override void OnLoad(EventArgs e) { base.OnLoad(e); Closed += ShaderTest_Closed; //GLStatics.EnableDebug(DebugProc); gl3dcontroller = new Controller3D(); gl3dcontroller.PaintObjects = ControllerDraw; gl3dcontroller.MatrixCalc.PerspectiveNearZDistance = 1f; gl3dcontroller.MatrixCalc.PerspectiveFarZDistance = 500000f; gl3dcontroller.ZoomDistance = 500F; gl3dcontroller.KeyboardTravelSpeed = (ms, eyedist) => { return((float)ms * 20.0f); }; //gl3dcontroller.MatrixCalc.InPerspectiveMode = false; gl3dcontroller.Start(glwfc, new Vector3(0, 0, 0), new Vector3(135f, 0, 0), 0.01F); items.Add(new GLColorShaderWorld(), "COSW"); GLRenderState rl1 = GLRenderState.Lines(1); float h = 0; { rObjects.Add(items.Shader("COSW"), // horizontal GLRenderableItem.CreateVector4Color4(items, PrimitiveType.Lines, rl1, GLShapeObjectFactory.CreateLines(new Vector3(-35000, h, -35000), new Vector3(-35000, h, 35000), new Vector3(1000, 0, 0), 70), new Color4[] { Color.Gray }) ); rObjects.Add(items.Shader("COSW"), GLRenderableItem.CreateVector4Color4(items, PrimitiveType.Lines, rl1, GLShapeObjectFactory.CreateLines(new Vector3(-35000, h, -35000), new Vector3(35000, h, -35000), new Vector3(0, 0, 1000), 70), new Color4[] { Color.Gray }) ); } int hsize = 35000, vsize = 2000, zsize = 35000; { int left = -hsize, right = hsize, bottom = -vsize, top = +vsize, front = -zsize, back = zsize; Vector4[] lines2 = new Vector4[] { new Vector4(left, bottom, front, 1), new Vector4(left, top, front, 1), new Vector4(left, top, front, 1), new Vector4(right, top, front, 1), new Vector4(right, top, front, 1), new Vector4(right, bottom, front, 1), new Vector4(right, bottom, front, 1), new Vector4(left, bottom, front, 1), new Vector4(left, bottom, back, 1), new Vector4(left, top, back, 1), new Vector4(left, top, back, 1), new Vector4(right, top, back, 1), new Vector4(right, top, back, 1), new Vector4(right, bottom, back, 1), new Vector4(right, bottom, back, 1), new Vector4(left, bottom, back, 1), new Vector4(left, bottom, front, 1), new Vector4(left, bottom, back, 1), new Vector4(left, top, front, 1), new Vector4(left, top, back, 1), new Vector4(right, bottom, front, 1), new Vector4(right, bottom, back, 1), new Vector4(right, top, front, 1), new Vector4(right, top, back, 1), }; items.Add(new GLFixedShader(System.Drawing.Color.Yellow), "LINEYELLOW"); rObjects.Add(items.Shader("LINEYELLOW"), GLRenderableItem.CreateVector4(items, PrimitiveType.Lines, rl1, lines2)); } { Bitmap[] numbers = new Bitmap[70]; Matrix4[] numberpos = new Matrix4[numbers.Length]; Font fnt = new Font("Arial", 20); for (int i = 0; i < numbers.Length; i++) { int v = -35000 + i * 1000; numbers[i] = new Bitmap(100, 100); GLOFC.Utils.BitMapHelpers.DrawTextCentreIntoBitmap(ref numbers[i], v.ToString(), fnt, System.Drawing.Text.TextRenderingHint.ClearTypeGridFit, Color.Red, Color.AliceBlue); numberpos[i] = Matrix4.CreateScale(1); numberpos[i] *= Matrix4.CreateRotationX(-25f.Radians()); numberpos[i] *= Matrix4.CreateTranslation(new Vector3(35500, 0, v)); } GLTexture2DArray array = new GLTexture2DArray(numbers, SizedInternalFormat.Rgba8, ownbmp: true); items.Add(array, "Nums"); items.Add(new GLShaderPipeline(new GLPLVertexShaderModelMatrixTexture(), new GLPLFragmentShaderTexture2DIndexed(0)), "IC-2"); items.Shader("IC-2").StartAction += (s, m) => { items.Tex("Nums").Bind(1); GL.Disable(EnableCap.CullFace); }; items.Shader("IC-2").FinishAction += (s) => { GL.Enable(EnableCap.CullFace); }; // investigate why its wrapping when we asked for it TexQUAD 1 which should interpolate over surface.. GLRenderState rq = GLRenderState.Quads(cullface: false); GLRenderDataTexture rt = new GLRenderDataTexture(items.Tex("Nums")); rObjects.Add(items.Shader("IC-2"), "1-b", GLRenderableItem.CreateVector4Vector2Matrix4(items, PrimitiveType.Quads, rq, GLShapeObjectFactory.CreateQuad(500.0f), GLShapeObjectFactory.TexQuadCW, numberpos, rt, numberpos.Length)); } // bounding box boundingbox = new Vector4[] { new Vector4(-hsize, -vsize, -zsize, 1), new Vector4(-hsize, vsize, -zsize, 1), new Vector4(hsize, vsize, -zsize, 1), new Vector4(hsize, -vsize, -zsize, 1), new Vector4(-hsize, -vsize, zsize, 1), new Vector4(-hsize, vsize, zsize, 1), new Vector4(hsize, vsize, zsize, 1), new Vector4(hsize, -vsize, zsize, 1), }; items.Add(new ShaderV2(), "V2"); GLRenderState rv = GLRenderState.Tri(); galaxy = GLRenderableItem.CreateNullVertex(PrimitiveType.Points, rv); // no vertexes, all data from bound volumetric uniform, no instances as yet rObjects.Add(items.Shader("V2"), galaxy); dataoutbuffer = items.NewStorageBlock(5); dataoutbuffer.AllocateBytes(sizeof(float) * 4 * 32, OpenTK.Graphics.OpenGL4.BufferUsageHint.DynamicRead); // 32 vec4 back atomicbuffer = items.NewAtomicBlock(6); atomicbuffer.AllocateBytes(sizeof(float) * 32, OpenTK.Graphics.OpenGL4.BufferUsageHint.DynamicCopy); dataoutbuffer = items.NewStorageBlock(5); dataoutbuffer.AllocateBytes(sizeof(float) * 4 * 256, OpenTK.Graphics.OpenGL4.BufferUsageHint.DynamicRead); // 32 vec4 back volumetricblock = new GLVolumetricUniformBlock(); items.Add(volumetricblock, "VB"); items.Add(new GLMatrixCalcUniformBlock(), "MCUB"); // create a matrix uniform block }