private void InitRenderer() { //create a default camera, because it's required during the viewport's creation. camera = new Camera(); Scene.RootNode.CreateChildNode("camera", camera); //create the renderer and render window from window's native handle renderer = Renderer.CreateRenderer(); renderer.RegisterEntityRenderer(new LinesRenderer()); renderer.RegisterEntityRenderer(new BackgroundRenderer()); renderer.RegisterEntityRenderer(normalRenderer = new NormalRenderer()); //Right now we only support native window handle from Microsoft Windows //we'll support more platform on user's demand. window = renderer.RenderFactory.CreateRenderWindow(new RenderParameters(), Handle); //renderer.ShaderSet = CreateDepthShader(); //create 4 viewports, the viewport's area is meanless here because we'll change it to the right area in the SetViewports later viewports = new[] { window.CreateViewport(camera, Color.Gray, RelativeRectangle.FromScale(0, 0, 1, 1)), window.CreateViewport(camera, Color.Gray, RelativeRectangle.FromScale(0, 0, 1, 1)), window.CreateViewport(camera, Color.Gray, RelativeRectangle.FromScale(0, 0, 1, 1)), window.CreateViewport(camera, Color.Gray, RelativeRectangle.FromScale(0, 0, 1, 1)) }; SetViewports(1); SelectedViewport = viewports[0]; }
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 static void Run() { try { // ExStart:RenderFisheyeLensEffectof3DScene // The path to the documents directory. string dataDir = RunExamples.GetDataDir(); //load the scene Scene scene = new Scene(dataDir + "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); //create a 2D texture render target with no depth texture used for image processing IRenderTexture final = renderer.RenderFactory.CreateRenderTexture(new RenderParameters(false, 32, 0, 0), 1024, 1024); //a viewport is required on the render target rt.CreateViewport(cam, RelativeRectangle.FromScale(0, 0, 1, 1)); renderer.Render(rt); //execute the fisheye projection post-processing with the previous rendered cube map as input //the fisheye can have field of view more than 180 degree, so a cube map with all direction is required. PostProcessing fisheye = renderer.GetPostProcessing("fisheye"); // we can change the fov to 360 instead of the default value 180. fisheye.FindProperty("fov").Value = 360.0; //Specify the cube map rendered from the scene as this post processing's input fisheye.Input = rt.Targets[0]; //Execute the post processing effect and save the result to render target final renderer.Execute(fisheye, final); //save the texture into disk ((ITexture2D)final.Targets[0]).Save(dataDir + "fisheye.png", ImageFormat.Png); } // ExEnd:RenderFisheyeLensEffectof3DScene } catch (Exception ex) { Console.WriteLine(ex.Message); } }
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); } }
private void InitRenderer() { //create a default camera, because it's required during the viewport's creation. camera = new Camera(); Scene.RootNode.CreateChildNode("camera", camera); //create the renderer and render window from window's native handle renderer = Renderer.CreateRenderer(); //Right now we only support native window handle from Microsoft Windows //we'll support more platform on user's demand. window = renderer.RenderFactory.CreateRenderWindow(new RenderParameters(), Handle); //create 4 viewports, the viewport's area is meanless here because we'll change it to the right area in the SetViewports later viewports = new[] { window.CreateViewport(camera, Color.Gray, RelativeRectangle.FromScale(0, 0, 1, 1)), window.CreateViewport(camera, Color.Gray, RelativeRectangle.FromScale(0, 0, 1, 1)), window.CreateViewport(camera, Color.Gray, RelativeRectangle.FromScale(0, 0, 1, 1)), window.CreateViewport(camera, Color.Gray, RelativeRectangle.FromScale(0, 0, 1, 1)) }; SetViewports(1); //initialize shader for grid GLSLSource src = new GLSLSource(); src.VertexShader = @"#version 330 core layout (location = 0) in vec3 position; uniform mat4 matWorldViewProj; void main() { gl_Position = matWorldViewProj * vec4(position, 1.0f); }"; src.FragmentShader = @"#version 330 core out vec4 color; void main() { color = vec4(1, 1, 1, 1); }"; //define the input format used by GLSL vertex shader //the format is // struct ControlPoint { // FVector3 Position; //} VertexDeclaration fd = new VertexDeclaration(); fd.AddField(VertexFieldDataType.FVector3, VertexFieldSemantic.Position); //compile shader from GLSL source code and specify the vertex input format gridShader = renderer.RenderFactory.CreateShaderProgram(src, fd); //connect GLSL uniform to renderer's internal variable gridShader.Variables = new ShaderVariable[] { new ShaderVariable("matWorldViewProj", VariableSemantic.MatrixWorldViewProj) }; SceneUpdated(""); }
public static void Run() { try { // ExStart:RenderPanaromaViewof3DScene //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); //create a 2D texture render target with no depth texture used for image processing IRenderTexture final = renderer.RenderFactory.CreateRenderTexture(new RenderParameters(false, 32, 0, 0), 1024 * 3, 1024); //a viewport is required on the render target rt.CreateViewport(cam, RelativeRectangle.FromScale(0, 0, 1, 1)); renderer.Render(rt); //execute the equirectangular projection post-processing with the previous rendered cube map as input PostProcessing equirectangular = renderer.GetPostProcessing("equirectangular"); //Specify the cube map rendered from the scene as this post processing's input equirectangular.Input = rt.Targets[0]; //Execute the post processing effect and save the result to render target final renderer.Execute(equirectangular, final); //save the texture into disk ((ITexture2D)final.Targets[0]).Save(RunExamples.GetOutputFilePath("panaroma.png"), ImageFormat.Png); } // ExEnd:RenderPanaromaViewof3DScene } catch (Exception ex) { Console.WriteLine(ex.Message); } }
// ExStart:RenderSceneWithPanoramaInDepth public static void Run() { // The path to the documents directory. string dataDir = RunExamples.GetDataDir(); //load the scene Scene scene = new Scene(dataDir + "skybox.obj"); //create a camera for capturing the cube map Camera cam = new Camera(ProjectionType.Perspective); cam.NearPlane = 0.1; cam.FarPlane = 200; scene.RootNode.CreateChildNode(cam).Transform.Translation = new Vector3(5, 6, 0); cam.RotationMode = RotationMode.FixedDirection; //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() { LightType = LightType.Point, ConstantAttenuation = 0.1, Color = new Vector3(Color.CadetBlue) }).Transform.Translation = new Vector3(49, 0, 49); //create a render target 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); //create a 2D texture render target with no depth texture used for image processing IRenderTexture final = renderer.RenderFactory.CreateRenderTexture(new RenderParameters(false, 32, 0, 0), 1024 * 3, 1024); //a viewport is required on the render target rt.CreateViewport(cam, RelativeRectangle.FromScale(0, 0, 1, 1)); renderer.ShaderSet = CreateDepthShader(renderer); renderer.Render(rt); //execute the equirectangular projection post-processing with the previous rendered cube map as input PostProcessing equirectangular = renderer.GetPostProcessing("equirectangular"); equirectangular.Input = rt.Targets[0]; renderer.Execute(equirectangular, final); //save the texture into disk ((ITexture2D)final.Targets[0]).Save(dataDir + "RenderSceneWithPanoramaInDepth_Out.png", ImageFormat.Png); } }