public void SetUniforms(Renderer renderer, ShaderPool.ShaderPack pack) { for (int i = 0; i < pack.ProgramsList.Length; i++) { var shader = pack.ProgramsList[i]; if (!shader.Compiled) { continue; } shader.Use(); shader.SetUniform("VPMatrix", Camera.Current.GetVPMatrix()); Camera.Current.SetUniforms(); shader.SetUniform("Time", (float)(DateTime.Now - Game.StartTime).TotalMilliseconds / 1000); shader.SetUniform("resolution", new Vector2(renderer.Width, renderer.Height)); shader.SetUniform("CameraPosition", Camera.Current.Transformation.GetPosition()); shader.SetUniform("CameraDirection", Camera.Current.Transformation.GetOrientation().ToDirection()); shader.SetUniform("CameraTangentUp", Camera.Current.Transformation.GetOrientation().GetTangent(MathExtensions.TangentDirection.Up)); shader.SetUniform("CameraTangentLeft", Camera.Current.Transformation.GetOrientation().GetTangent(MathExtensions.TangentDirection.Left)); } }
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"); }