private CubemapDataProvider GetCubemapDataProvider(Bitmap totalBmp) { int width = totalBmp.Width / 4, height = totalBmp.Height / 3; var top = new Bitmap(width, height); using (var g = Graphics.FromImage(top)) { g.DrawImage(totalBmp, new Rectangle(0, 0, width, height), new Rectangle(width, 0, width, height), GraphicsUnit.Pixel); } top.RotateFlip(RotateFlipType.Rotate180FlipNone); // apparently it doesnt like aligning the top so we have to do this bullshit var left = new Bitmap(width, height); using (var g = Graphics.FromImage(left)) { g.DrawImage(totalBmp, new Rectangle(0, 0, width, height), new Rectangle(0, height, width, height), GraphicsUnit.Pixel); } var front = new Bitmap(width, height); using (var g = Graphics.FromImage(front)) { g.DrawImage(totalBmp, new Rectangle(0, 0, width, height), new Rectangle(width, height, width, height), GraphicsUnit.Pixel); } var right = new Bitmap(width, height); using (var g = Graphics.FromImage(right)) { g.DrawImage(totalBmp, new Rectangle(0, 0, width, height), new Rectangle(width * 2, height, width, height), GraphicsUnit.Pixel); } var back = new Bitmap(width, height); using (var g = Graphics.FromImage(back)) { g.DrawImage(totalBmp, new Rectangle(0, 0, width, height), new Rectangle(width * 3, height, width, height), GraphicsUnit.Pixel); } var bottom = new Bitmap(width, height); using (var g = Graphics.FromImage(bottom)) { g.DrawImage(totalBmp, new Rectangle(0, 0, width, height), new Rectangle(width, height * 2, width, height), GraphicsUnit.Pixel); } var flip = RotateFlipType.Rotate180FlipY; right.RotateFlip(flip); left.RotateFlip(flip); top.RotateFlip(flip); bottom.RotateFlip(RotateFlipType.Rotate180FlipX); back.RotateFlip(flip); front.RotateFlip(flip); #if SKYBOX_SAVE right.Save("right.png"); left.Save("left.png"); top.Save("top.png"); bottom.Save("bottom.png"); back.Save("back.png"); front.Save("front.png"); #endif var result = new CubemapDataProvider(right, left, top, bottom, back, front); return(result); }
// pbr: create an irradiance cubemap. private Texture LoadIrradianceMap() { var dataProvider = new CubemapDataProvider(null, null, null, null, null, null); var storage = new CubemapTexImage2D(GL.GL_RGB16F, 32, 32, GL.GL_RGB, GL.GL_FLOAT, dataProvider); var envCubeMap = new Texture(storage, new TexParameteri(TexParameter.PropertyName.TextureWrapS, (int)GL.GL_CLAMP_TO_EDGE), new TexParameteri(TexParameter.PropertyName.TextureWrapT, (int)GL.GL_CLAMP_TO_EDGE), new TexParameteri(TexParameter.PropertyName.TextureWrapR, (int)GL.GL_CLAMP_TO_EDGE), new TexParameteri(TexParameter.PropertyName.TextureMinFilter, (int)GL.GL_LINEAR), new TexParameteri(TexParameter.PropertyName.TextureMagFilter, (int)GL.GL_LINEAR)); envCubeMap.Initialize(); return(envCubeMap); }
private Texture LoadPrefliterMap() { var dataProvider = new CubemapDataProvider(null, null, null, null, null, null); var storage = new CubemapTexImage2D(GL.GL_RGB16F, 128, 128, GL.GL_RGB, GL.GL_FLOAT, dataProvider, 6); var prefliterMap = new Texture(storage, new MipmapBuilder(), new TexParameteri(TexParameter.PropertyName.TextureWrapS, (int)GL.GL_CLAMP_TO_EDGE), new TexParameteri(TexParameter.PropertyName.TextureWrapT, (int)GL.GL_CLAMP_TO_EDGE), new TexParameteri(TexParameter.PropertyName.TextureWrapR, (int)GL.GL_CLAMP_TO_EDGE), new TexParameteri(TexParameter.PropertyName.TextureMinFilter, (int)GL.GL_LINEAR_MIPMAP_LINEAR), new TexParameteri(TexParameter.PropertyName.TextureMagFilter, (int)GL.GL_LINEAR)); prefliterMap.Initialize(); return(prefliterMap); }
// pbr: setup cubemap to render to and attach to framebuffer private Texture LoadEnvCubeMap() { var dataProvider = new CubemapDataProvider(null, null, null, null, null, null); var storage = new CubemapTexImage2D(GL.GL_RGB16F, 512, 512, GL.GL_RGB, GL.GL_FLOAT, dataProvider); var envCubeMap = new Texture(storage, new MipmapBuilder(), // This is can also be done inside CubemapNode.DoInitialize(). new TexParameteri(TexParameter.PropertyName.TextureWrapS, (int)GL.GL_CLAMP_TO_EDGE), new TexParameteri(TexParameter.PropertyName.TextureWrapT, (int)GL.GL_CLAMP_TO_EDGE), new TexParameteri(TexParameter.PropertyName.TextureWrapR, (int)GL.GL_CLAMP_TO_EDGE), new TexParameteri(TexParameter.PropertyName.TextureMinFilter, (int)GL.GL_LINEAR_MIPMAP_LINEAR), new TexParameteri(TexParameter.PropertyName.TextureMagFilter, (int)GL.GL_LINEAR)); envCubeMap.Initialize(); return(envCubeMap); }
private Texture GetCubemapTexture(Bitmap[] bitmaps) { var dataProvider = new CubemapDataProvider( bitmaps[0], bitmaps[1], bitmaps[2], bitmaps[3], bitmaps[4], bitmaps[5]); var storage = new CubemapTexImage2D((int)GL.GL_RGBA, bitmaps[0].Width, bitmaps[0].Height, 0, GL.GL_BGRA, GL.GL_UNSIGNED_BYTE, dataProvider); var texture = new Texture(TextureTarget.TextureCubeMap, storage, new TexParameteri(TexParameter.PropertyName.TextureMagFilter, (int)GL.GL_LINEAR), new TexParameteri(TexParameter.PropertyName.TextureMinFilter, (int)GL.GL_LINEAR), new TexParameteri(TexParameter.PropertyName.TextureWrapS, (int)GL.GL_CLAMP_TO_EDGE), new TexParameteri(TexParameter.PropertyName.TextureWrapT, (int)GL.GL_CLAMP_TO_EDGE), new TexParameteri(TexParameter.PropertyName.TextureWrapR, (int)GL.GL_CLAMP_TO_EDGE)); texture.Initialize(); return(texture); }
// pbr: create a pre-filter cubemap. private Texture LoadPrefilterMap() { var dataProvider = new CubemapDataProvider(null, null, null, null, null, null); var storage = new CubemapTexImage2D(GL.GL_RGB16F, 128, 128, GL.GL_RGB, GL.GL_FLOAT, dataProvider); var envCubeMap = new Texture(storage, // generate mipmaps for the cubemap so OpenGL automatically allocates the required memory. new MipmapBuilder(), new TexParameteri(TexParameter.PropertyName.TextureWrapS, (int)GL.GL_CLAMP_TO_EDGE), new TexParameteri(TexParameter.PropertyName.TextureWrapT, (int)GL.GL_CLAMP_TO_EDGE), new TexParameteri(TexParameter.PropertyName.TextureWrapR, (int)GL.GL_CLAMP_TO_EDGE), // be sure to set minifcation filter to mip_linear new TexParameteri(TexParameter.PropertyName.TextureMinFilter, (int)GL.GL_LINEAR_MIPMAP_LINEAR), new TexParameteri(TexParameter.PropertyName.TextureMagFilter, (int)GL.GL_LINEAR)); envCubeMap.Initialize(); return(envCubeMap); }