public ComputeBallsScene() { int instancesAxis = 10; int instances = instancesAxis * instancesAxis * instancesAxis; var ballInfo = Object3dInfo.LoadFromObjSingle(Media.Get("star3d.obj")); // var cb = Object3dGenerator.CreateCube(new Vector3(1000, 1000, 1000), new Vector2(1, 1)); // cb.FlipFaces(); // var sky = new Mesh3d(cb, new GenericMaterial(Color.Black)); // Add(sky); ballInfo.Normalize(); var instanced = new InstancedMesh3d(ballInfo, new GenericMaterial(new Vector4(0, 1, 0, 1))); var instanced2 = new InstancedMesh3d(ballInfo, new GenericMaterial(Color.Green)); //var model = Object3dInfo.LoadFromObjSingle(Media.Get("monkey.obj")); //var vrts = model.GetOrderedVertices(); //vrts = vrts.Distinct().ToList(); var bts3 = new List<Vector4>(); for(int x = 0; x < 20; x++) for(int y = 60; y > 0; y--) { bts3.Add(new Vector4(x, y, 0, 1)); } instanced2.UpdateMatrix(); Add(instanced2); instanced.Instances = instances; var SBuffer = new ShaderStorageBuffer(); var VBuffer = new ShaderStorageBuffer(); var PBuffer = new ShaderStorageBuffer(); GLThread.Invoke(() => { var cshader = new ComputeShader("AIPathFollower.compute.glsl"); var bts = new List<Vector4>(); var bts2 = new List<Vector4>(); var rand = new Random(); PBuffer.MapData(bts3.ToArray()); for(int x = 0; x < 12; x++) { for(int y = 0; y < 90; y++) { for(int z = 0; z < 12; z++) { instanced.Transformations.Add(new TransformationManager(new Vector3(x * 5, y + 300, z * 5), Quaternion.Identity, 1.5f)); bts.Add(new Vector4(x * 5, y + 300, z * 5, 1)); bts2.Add(new Vector4(0, 0, 0, 1)); } } } SBuffer.MapData(bts.ToArray()); VBuffer.MapData(bts2.ToArray()); instanced.UpdateMatrix(); GLThread.OnBeforeDraw += (o, e) => { cshader.Use(); instanced.ModelMatricesBuffer.Use(0); SBuffer.Use(1); VBuffer.Use(2); PBuffer.Use(3); cshader.SetUniform("BallsCount", instances); cshader.SetUniform("PathPointsCount", bts3.Count); cshader.SetUniform("Time", (float)(DateTime.Now - GLThread.StartTime).TotalMilliseconds / 1000); cshader.Dispatch(12, 90, 12); }; }); Add(instanced); }
public void Use() { if(!Compiled) Compile(); GL.UseProgram(Handle); Current = this; }
public static FreeCamera SetUpFreeCamera() { CameraSavedViews = new Dictionary<int, TransformationManager>(); float aspect = Game.Resolution.Height > Game.Resolution.Width ? Game.Resolution.Height / Game.Resolution.Width : Game.Resolution.Width / Game.Resolution.Height; var freeCamera = new FreeCamera((float)Game.Resolution.Width / (float)Game.Resolution.Height, MathHelper.PiOver3 / 1); FreeCam = freeCamera; PickingResult = new ShaderStorageBuffer(); MousePicker = new ComputeShader("MousePicker.compute.glsl"); return freeCamera; }
public PostProcessing(int initialWidth, int initialHeight) { //FullScene3DTexture = new Texture3D(new Vector3(64, 64, 64)); TestBuffer = new ShaderStorageBuffer(); NumbersTexture = new Texture(Media.Get("numbers.png")); CShader = new ComputeShader("Blur.compute.glsl"); GLThread.Invoke(() => { TestBuffer.MapData(new Vector3[4]{ new Vector3(1, 0.25f, 1), new Vector3(0, 0.55f, 0.75f), new Vector3(1, 0.25f, 0), new Vector3(0.55f, 0, 0.75f) }); }); Width = initialWidth; Height = initialHeight; MSAAResolvingFrameBuffer = new Framebuffer(initialWidth, initialHeight); MSAAResolvingFrameBuffer.SetMultiSample(true); MRT = new MRTFramebuffer(initialWidth, initialHeight); BackMRT = new MRTFramebuffer(initialWidth / 4, initialHeight / 4); Pass1FrameBuffer = new Framebuffer(initialWidth, initialHeight); Pass2FrameBuffer = new Framebuffer(initialWidth, initialHeight); LightPointsFrameBuffer = new Framebuffer(initialWidth / 6, initialHeight / 6); BloomFrameBuffer = new Framebuffer(initialWidth / 4, initialHeight / 4); FogFramebuffer = new Framebuffer(initialWidth, initialHeight); SmallFrameBuffer = new Framebuffer(initialWidth / 10, initialHeight / 10); LastWorldPositionFramebuffer = new Framebuffer(initialWidth / 1, initialHeight / 1); RSMFramebuffer = new Framebuffer(initialWidth / 1, initialHeight / 1); SSReflectionsFramebuffer = new Framebuffer(initialWidth / 1, initialHeight / 1); VDAOFramebuffer = new Framebuffer(initialWidth / 1, initialHeight / 1); GlobalIlluminationFrameBuffer = new Framebuffer(initialWidth, initialHeight); //GlobalIlluminationFrameBuffer.ColorInternalFormat = PixelInternalFormat.R8; //GlobalIlluminationFrameBuffer.ColorPixelFormat = PixelFormat.Red; //GlobalIlluminationFrameBuffer.ColorPixelType = PixelType.UnsignedByte; GlobalIlluminationFrameBuffer.Use(); //BackDiffuseFrameBuffer = new Framebuffer(initialWidth / 2, initialHeight / 2); //BackNormalsFrameBuffer = new Framebuffer(initialWidth / 2, initialHeight / 2); ScreenSpaceNormalsWriterShader = ShaderProgram.Compile("Generic.vertex.glsl", "ScreenSpaceNormalsWriter.fragment.glsl"); BackDepthWriterShader = ShaderProgram.Compile("Generic.vertex.glsl", "BackDepthWriter.fragment.glsl"); BloomShader = ShaderProgram.Compile("PostProcess.vertex.glsl", "Bloom.fragment.glsl"); MSAAShader = ShaderProgram.Compile("PostProcess.vertex.glsl", "MSAA.fragment.glsl"); SSAOShader = ShaderProgram.Compile("PostProcess.vertex.glsl", "SSAO.fragment.glsl"); FogShader = ShaderProgram.Compile("PostProcess.vertex.glsl", "Fog.fragment.glsl"); LightPointsShader = ShaderProgram.Compile("PostProcess.vertex.glsl", "LightPoints.fragment.glsl"); LensBlurShader = ShaderProgram.Compile("PostProcess.vertex.glsl", "LensBlur.fragment.glsl"); HDRShader = ShaderProgram.Compile("PostProcess.vertex.glsl", "HDR.fragment.glsl"); BlitShader = ShaderProgram.Compile("PostProcess.vertex.glsl", "Blit.fragment.glsl"); DeferredShader = ShaderProgram.Compile("PostProcess.vertex.glsl", "Deferred.fragment.glsl"); CombinerShader = ShaderProgram.Compile("PostProcess.vertex.glsl", "Combiner.fragment.glsl"); PathTracerOutputShader = ShaderProgram.Compile("PostProcess.vertex.glsl", "Output.fragment.glsl"); GlobalIlluminationShaderX = ShaderProgram.Compile("PostProcess.vertex.glsl", "GlobalIllumination.fragment.glsl"); GlobalIlluminationShaderX.SetGlobal("SEED", "gl_FragCoord.x"); GlobalIlluminationShaderY = ShaderProgram.Compile("PostProcess.vertex.glsl", "GlobalIllumination.fragment.glsl"); GlobalIlluminationShaderY.SetGlobal("SEED", "gl_FragCoord.y"); RSMShader = ShaderProgram.Compile("PostProcess.vertex.glsl", "RSM.fragment.glsl"); SSReflectionsShader = ShaderProgram.Compile("PostProcess.vertex.glsl", "SSReflections.fragment.glsl"); VDAOShader = ShaderProgram.Compile("PostProcess.vertex.glsl", "VDAO.fragment.glsl"); //ReflectShader = ShaderProgram.Compile(Media.ReadAllText("PostProcess.vertex.glsl"), Media.ReadAllText("Reflect.fragment.glsl")); Object3dInfo postPlane3dInfo = new Object3dInfo(postProcessingPlaneVertices, postProcessingPlaneIndices); PostProcessingMesh = new Mesh3d(postPlane3dInfo, new GenericMaterial(Color.Pink)); }
public Voxel3dTextureWriter(int gridsizeX, int gridsizeY, int gridsizeZ, Vector3 boxsize, Vector3 staticPosition) { GridSizeX = gridsizeX; GridSizeY = gridsizeY; GridSizeZ = gridsizeZ; MapPosition = staticPosition; BoxSize = boxsize; TextureResolverShader = new ComputeShader("Texture3DResolve.compute.glsl"); //TextureResolverNormalShader = new ComputeShader("Texture3DResolveNormal.compute.glsl"); TextureMipmapShader = new ComputeShader("Texture3DMipmap.compute.glsl"); TextureRed = new Texture3D(gridsizeX, gridsizeY, gridsizeZ); TextureGreen = new Texture3D(gridsizeX, gridsizeY, gridsizeZ); TextureBlue = new Texture3D(gridsizeX, gridsizeY, gridsizeZ); /* * TextureNormalX = new Texture3D(gridsize, gridsize, gridsize) * { * ColorInternalFormat = PixelInternalFormat.R32i, * ColorPixelFormat = PixelFormat.RedInteger, * ColorPixelType = PixelType.Int * }; * TextureNormalY = new Texture3D(gridsize, gridsize, gridsize) * { * ColorInternalFormat = PixelInternalFormat.R32i, * ColorPixelFormat = PixelFormat.RedInteger, * ColorPixelType = PixelType.Int * }; * TextureNormalZ = new Texture3D(gridsize, gridsize, gridsize) * { * ColorInternalFormat = PixelInternalFormat.R32i, * ColorPixelFormat = PixelFormat.RedInteger, * ColorPixelType = PixelType.Int * }; * TextureNormalResolved = new Texture3D(gridsize, gridsize, gridsize) * { * ColorInternalFormat = PixelInternalFormat.Rgba16f, * ColorPixelFormat = PixelFormat.Rgba, * ColorPixelType = PixelType.HalfFloat * }; */ TextureCount = new Texture3D(gridsizeX, gridsizeY, gridsizeZ); /* * TEXTURE LAYOUT: * 1 - Initial - RES / 1 - 256 * 2 - Blurred 2 PX 1 res / 2 128 * 3 - Blurred 2 PX 2 res / 2 64 * 4 - Blurred 2 PX 3 res / 2 32 */ TextureResolvedMipMaps = new List <Texture3D>(); int szx = gridsizeX; int szy = gridsizeY; int szz = gridsizeZ; //while(szx > 8 && szy > 8 && szz > 8) for (int i = 0; i < 4; i++) { TextureResolvedMipMaps.Add(new Texture3D(szx, szy, szz) { ColorInternalFormat = PixelInternalFormat.Rgba16f, ColorPixelFormat = PixelFormat.Rgba, ColorPixelType = PixelType.HalfFloat }); szx = szx / 2; szy = szy / 2; szz = szz / 2; } FBO = new Framebuffer(512, 512, true) { }; XForward = Matrix4.LookAt(Vector3.Zero, Vector3.UnitX, Vector3.UnitY).ExtractRotation(); YForward = Matrix4.LookAt(Vector3.Zero, Vector3.UnitY, Vector3.UnitZ).ExtractRotation(); ZForward = Matrix4.LookAt(Vector3.Zero, Vector3.UnitZ, Vector3.UnitY).ExtractRotation(); Vector3 boxhalf = boxsize * 0.5f; RenderingCameraX = new Camera(); RenderingCameraX.UpdatePerspectiveOrtho(-boxhalf.X, boxhalf.X, -boxhalf.Y, boxhalf.Y, boxhalf.Z, -boxhalf.Z); RenderingCameraX.SetOrientation(XForward); RenderingCameraX.SetPosition(MapPosition); RenderingCameraX.Update(); RenderingCameraY = new Camera(); RenderingCameraY.UpdatePerspectiveOrtho(-boxhalf.X, boxhalf.X, -boxhalf.Z, boxhalf.Z, boxhalf.Y, -boxhalf.Y); RenderingCameraY.SetOrientation(YForward); RenderingCameraY.SetPosition(MapPosition); RenderingCameraY.Update(); RenderingCameraZ = new Camera(); RenderingCameraZ.UpdatePerspectiveOrtho(-boxhalf.X, boxhalf.X, -boxhalf.Y, boxhalf.Y, boxhalf.Z, -boxhalf.Z); RenderingCameraZ.SetOrientation(ZForward); RenderingCameraZ.SetPosition(MapPosition); RenderingCameraZ.Update(); Shader = new ShaderPool.ShaderPack("Voxel3dTextureWriter.fragment.glsl"); }