Aplicar efectos visuales al guardar las vistas 3D
Contents
[
Hide
]
Con Aspose.3D for .NET API, los desarrolladores pueden aplicar efectos visuales en las vistas de 3D antes de guardar la imagen. Estos efectos visuales también se conocen como efectos de posprocesamiento o filtros que se aplican en tiempo real a todo lo que se muestra en la vista 3D.
Aplicar efectos visuales en la vista 3D
El método GetPostProcessing
de la clase Renderer
permite crear cualquier efecto visual admitido. La clase Renderer ofrece un miembro PostProcessings
para aplicar varios filtros, el método Add de la clase PostProcessings permite incorporar un filtro antes de renderizar.
Muestra de programación
Este ejemplo de código aplica el efecto visual en una vista 3D.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-3d/Aspose.3D-for-.NET | |
// Load an existing 3D scene | |
Scene scene = Scene.FromFile("scene.obj"); | |
// Create an instance of the camera | |
Camera camera = new Camera(); | |
scene.RootNode.CreateChildNode("camera", camera).Transform.Translation = new Vector3(2, 44, 66); | |
// Set the target | |
camera.LookAt = new Vector3(50, 12, 0); | |
// Create a light | |
scene.RootNode.CreateChildNode("light", new Light() { Color = new Vector3(Color.White), LightType = LightType.Point }).Transform.Translation = new Vector3(26, 57, 43); | |
// The CreateRenderer will create a hardware OpenGL-backend renderer, more renderer will be added in the future | |
// And some internal initializations will be done. | |
// When the renderer left using the scope, the unmanaged hardware resources will also be disposed | |
using (var renderer = Renderer.CreateRenderer()) | |
{ | |
renderer.EnableShadows = false; | |
// Create a new render target that renders the scene to texture(s) | |
// Use default render parameters | |
// And one output targets | |
// Size is 1024 x 1024 | |
// This render target can have multiple render output textures, but here we only need one output. | |
// The other textures and depth textures are mainly used by deferred shading in the future. | |
// But you can also access the depth texture through IRenderTexture.DepthTeture | |
using (IRenderTexture rt = renderer.RenderFactory.CreateRenderTexture(new RenderParameters(), 1, 1024, 1024)) | |
{ | |
// This render target has one viewport to render, the viewport occupies the 100% width and 100% height | |
Viewport vp = rt.CreateViewport(camera, new RelativeRectangle() { ScaleWidth = 1, ScaleHeight = 1 }); | |
// Render the target and save the target texture to external file | |
renderer.Render(rt); | |
((ITexture2D)rt.Targets[0]).Save(RunExamples.GetOutputFilePath("Original_viewport_out.png"), ImageFormat.Png); | |
// Create a post-processing effect | |
PostProcessing pixelation = renderer.GetPostProcessing("pixelation"); | |
renderer.PostProcessings.Add(pixelation); | |
renderer.Render(rt); | |
((ITexture2D)rt.Targets[0]).Save(RunExamples.GetOutputFilePath("VisualEffect_pixelation_out.png"), ImageFormat.Png); | |
// Clear previous post-processing effects and try another one | |
PostProcessing grayscale = renderer.GetPostProcessing("grayscale"); | |
renderer.PostProcessings.Clear(); | |
renderer.PostProcessings.Add(grayscale); | |
renderer.Render(rt); | |
((ITexture2D)rt.Targets[0]).Save(RunExamples.GetOutputFilePath("VisualEffect_grayscale_out.png"), ImageFormat.Png); | |
// We can also combine post-processing effects | |
renderer.PostProcessings.Clear(); | |
renderer.PostProcessings.Add(grayscale); | |
renderer.PostProcessings.Add(pixelation); | |
renderer.Render(rt); | |
((ITexture2D)rt.Targets[0]).Save(RunExamples.GetOutputFilePath("VisualEffect_grayscale+pixelation_out.png"), ImageFormat.Png); | |
// Clear previous post-processing effects and try another one | |
PostProcessing edgedetection = renderer.GetPostProcessing("edge-detection"); | |
renderer.PostProcessings.Clear(); | |
renderer.PostProcessings.Add(edgedetection); | |
renderer.Render(rt); | |
((ITexture2D)rt.Targets[0]).Save(RunExamples.GetOutputFilePath("VisualEffect_edgedetection_out.png"), ImageFormat.Png); | |
// Clear previous post-processing effects and try another one | |
PostProcessing blur = renderer.GetPostProcessing("blur"); | |
renderer.PostProcessings.Clear(); | |
renderer.PostProcessings.Add(blur); | |
renderer.Render(rt); | |
((ITexture2D)rt.Targets[0]).Save(RunExamples.GetOutputFilePath("VisualEffect_blur_out.png"), ImageFormat.Png); | |
} | |
} |