private void Render() { if (CubeBasedPostProcessing != null) { if (cubeTarget == null) { cubeTarget = renderer.RenderFactory.CreateCubeRenderTexture(new RenderParameters(false), 1024, 1024); cubeTarget.CreateViewport(camera, RelativeRectangle.FromScale(0, 0, 1, 1)); } renderer.Render(cubeTarget); CubeBasedPostProcessing.Input = cubeTarget.Targets[0]; ITextureCubemap cm = (ITextureCubemap)cubeTarget.Targets[0]; /* * for (int i = 0; i < 6; i++) * { * cm.ToBitmap((CubeFace)i).Save(string.Format(@"d:\test-{0}.png", i), ImageFormat.Png); * * } */ //execute the post processing and output its result to the window renderer.Execute(CubeBasedPostProcessing, window); } else { renderer.Render(window); } }
public void Draw(ITextureCubemap gltextureCubemap, CameraFrame cameraFrame, float fieldOfView, float aspectRatio) { glContext.States.DepthStencil.DepthTestEnable.Set(false); glContext.States.DepthStencil.DepthMask.Set(false); // todo: to ObjectGL glContext.GL.Enable((int)All.TextureCubeMapSeamless); glContext.Bindings.Program.Set(shaderProgram); glContext.Bindings.VertexArray.Set(vao); var simplifiedViewFrame = new CameraFrame(Vector3.Zero, cameraFrame.Forward, cameraFrame.Up, cameraFrame.Right); var viewMat = simplifiedViewFrame.GetViewMat(); var projMat = Matrix4x4.PerspectiveFovDx(fieldOfView, aspectRatio, 0.1f, 100f); cameraUb.SetData(viewMat * projMat); cameraUb.Bind(glContext, 0); glContext.Bindings.Textures.ActiveUnit.Set(0); glContext.Bindings.Textures.Units[0].Set(gltextureCubemap); glContext.Bindings.Samplers[0].Set(sampler); glContext.States.Rasterizer.CullFaceEnable.Set(false); glContext.Actions.Draw.Elements(BeginMode.Triangles, 36, DrawElementsType.UnsignedInt, 0); }
public unsafe ITextureCubemap GetGlTextureCubemap() { if (!isDirty) { return(glTexture); } var width = skybox.Width; if (glTexture == null || glTexture.Width != width) { glTexture?.Dispose(); var mipCount = GraphicsHelper.TextureMipCount(width); glTexture = infra.GlContext.Create.TextureCubemap(width, mipCount, Format.Srgb8Alpha8); } for (var i = 0; i < FacesInOglOrder.Length; i++) { var data = skybox.GetRawData(FacesInOglOrder[i]); fixed(byte *pData = data) glTexture.SetData(0, i, (IntPtr)pData, FormatColor.Bgra, FormatType.UnsignedByte); } glTexture.GenerateMipmap(); isDirty = false; return(glTexture); }
public static void Run() { try { // ExStart:RenderSceneIntoCubemapwithsixfaces //load the scene Scene scene = new Scene(RunExamples.GetDataFilePath("VirtualCity.glb")); //create a camera for capturing the cube map Camera cam = new Camera(ProjectionType.Perspective) { NearPlane = 0.1, FarPlane = 200, RotationMode = RotationMode.FixedDirection }; scene.RootNode.CreateChildNode(cam).Transform.Translation = new Vector3(5, 6, 0); //create two lights to illuminate the scene scene.RootNode.CreateChildNode(new Light() { LightType = LightType.Point }).Transform.Translation = new Vector3(-10, 7, -10); scene.RootNode.CreateChildNode(new Light() { Color = new Vector3(Color.CadetBlue) }).Transform.Translation = new Vector3(49, 0, 49); //create a renderer using (var renderer = Renderer.CreateRenderer()) { //create a cube map render target with depth texture, depth is required when rendering a scene. IRenderTexture rt = renderer.RenderFactory.CreateCubeRenderTexture(new RenderParameters(false), 512, 512); //a viewport is required on the render target rt.CreateViewport(cam, RelativeRectangle.FromScale(0, 0, 1, 1)); renderer.Render(rt); //now lets get the cubemap texture ITextureCubemap cubemap = rt.Targets[0] as ITextureCubemap; //we can directly save each face to disk by specifing the file name CubeFaceData <string> fileNames = new CubeFaceData <string>() { Right = RunExamples.GetOutputFilePath("right.png"), Left = RunExamples.GetOutputFilePath("left.png"), Back = RunExamples.GetOutputFilePath("back.png"), Front = RunExamples.GetOutputFilePath("front.png"), Bottom = RunExamples.GetOutputFilePath("bottom.png"), Top = RunExamples.GetOutputFilePath("top.png") }; //and call Save method cubemap.Save(fileNames, ImageFormat.Png); //or we just need to use the render result in memory, we can save it to CubeFaceData<Bitmap> //CubeFaceData<Bitmap> bitmaps = new CubeFaceData<Bitmap>(); //cubemap.Save(bitmaps); //bitmaps.Back.Save("back.bmp", ImageFormat.Bmp); } // ExEnd:RenderSceneIntoCubemapwithsixfaces } catch (Exception ex) { Console.WriteLine(ex.Message); } }
public void AttachTextureImage(FramebufferAttachmentPoint attachmentPoint, ITextureCubemap texture, int level, CubemapFace cubemapFace) { var newDesc = new FramebufferAttachmentDescription { Type = FramebufferAttachmentType.Texture, TextureTarget = TextureTarget.TextureCubeMap, Texture = texture, Level = level, Layer = cubemapFace - CubemapFace.PositiveX }; if (IsRedundant(attachmentPoint, ref newDesc)) { return; } var framebufferTarget = context.Bindings.Framebuffers.EditingTarget; context.Bindings.Framebuffers.ByTarget(framebufferTarget).Set(this); GL.FramebufferTexture2D((int)framebufferTarget, (int)attachmentPoint, (int)cubemapFace, texture.Handle, level); UpdateStoredDescription(attachmentPoint, ref newDesc); }
public void AttachTextureAsLayeredImage(FramebufferAttachmentPoint attachmentPoint, ITextureCubemap texture, int level) { var newDesc = new FramebufferAttachmentDescription { Type = FramebufferAttachmentType.TextureLayers, TextureTarget = TextureTarget.TextureCubeMap, Texture = texture, Level = level }; if (IsRedundant(attachmentPoint, ref newDesc)) { return; } var framebufferTarget = context.Bindings.Framebuffers.EditingTarget; context.Bindings.Framebuffers.ByTarget(framebufferTarget).Set(this); //gl.FramebufferTexture(ft, fa, d.Texture.Handle, d.Level); GL.FramebufferTexture2D((int)framebufferTarget, (int)attachmentPoint, (int)texture.Target, texture.Handle, level); UpdateStoredDescription(attachmentPoint, ref newDesc); }
public void AttachTextureImage(FramebufferAttachmentPoint attachmentPoint, ITextureCubemap texture, int level, CubemapFace cubemapFace) { var newDesc = new FramebufferAttachmentDescription { Type = FramebufferAttachmentType.Texture, TextureTarget = TextureTarget.TextureCubeMap, Texture = texture, Level = level, Layer = cubemapFace - CubemapFace.PositiveX }; if (IsRedundant(attachmentPoint, ref newDesc)) return; var framebufferTarget = context.Bindings.Framebuffers.EditingTarget; context.Bindings.Framebuffers.ByTarget(framebufferTarget).Set(this); GL.FramebufferTexture2D((int)framebufferTarget, (int)attachmentPoint, (int)cubemapFace, texture.Handle, level); UpdateStoredDescription(attachmentPoint, ref newDesc); }
public void AttachTextureAsLayeredImage(FramebufferAttachmentPoint attachmentPoint, ITextureCubemap texture, int level) { var newDesc = new FramebufferAttachmentDescription { Type = FramebufferAttachmentType.TextureLayers, TextureTarget = TextureTarget.TextureCubeMap, Texture = texture, Level = level }; if (IsRedundant(attachmentPoint, ref newDesc)) return; var framebufferTarget = context.Bindings.Framebuffers.EditingTarget; context.Bindings.Framebuffers.ByTarget(framebufferTarget).Set(this); //gl.FramebufferTexture(ft, fa, d.Texture.Handle, d.Level); GL.FramebufferTexture2D((int)framebufferTarget, (int)attachmentPoint, (int)texture.Target, texture.Handle, level); UpdateStoredDescription(attachmentPoint, ref newDesc); }
public static void SetData(this ITextureCubemap texture, int level, int faceIndex, IntPtr data, FormatColor format, FormatType type, IBuffer pixelUnpackBuffer = null) { texture.SetData(level, faceIndex, 0, 0, texture.CalculateMipWidth(level), texture.CalculateMipHeight(level), data, format, type, pixelUnpackBuffer); }
public static void SetDataCompressed(this ITextureCubemap texture, int level, int faceIndex, IntPtr data, int compressedSize, IBuffer pixelUnpackBuffer = null) { texture.SetDataCompressed(level, faceIndex, 0, 0, texture.CalculateMipWidth(level), texture.CalculateMipHeight(level), data, compressedSize, pixelUnpackBuffer); }