Jump to content

How to capture motion blur image at runtime


photo

Recommended Posts

How to capture motion blur image at runtime?

if (player == null)
            {
                Unigine.Console.OnscreenMessageLine(vec4.RED, "No active camera.");
                return;
            }
            viewport.Mode = Render.ViewportMode;
            // We temporarily set exposure adaptation time to 0, otherwise the image may be too dark
            float exposureAdaptation = Render.ExposureAdaptation;
            Render.ExposureAdaptation =0f;
            // We render with velocity buffer turned off to avoid temporal effects artifacts
            viewport.AppendSkipFlags(Viewport.SKIP_VELOCITY_BUFFER);
            viewport.RenderImage2D(player.Camera, image, width, height);
            viewport.RemoveSkipFlags(Viewport.SKIP_VELOCITY_BUFFER);
            Render.ExposureAdaptation = exposureAdaptation;
            if (!alphaChannel || format == Format.jpg)
            {
                if (image.Format == Image.FORMAT_RGBA8)
                {
                    image.ConvertToFormat(Image.FORMAT_RGB8);
                }

                else if (image.Format == Image.FORMAT_RGBA16F)
                {
                    image.ConvertToFormat(Image.FORMAT_RGB16F);
                }

            }
            image.Save(fullName_yuan, 1);

In this way, the images are clear,Motion blur effect cannot be intercepted。

Link to comment

Hi hongguang.li, 

This is happening due to empty velocity buffer for the new viewport. You can try swapping textures around so you won't end up copying it.
Try calling your code from the above in Render.CALLBACK.END_SCREEN for main viewport:

Render.AddCallback(Render.CALLBACK_INDEX.END_SCREEN, MakeScreenShot);

But don't forget to add a check for current viewport to prevent recursion:

public void MakeScreenShot()
{
	if (Render.Viewport == vp)
		return;

	// Store velocity texture
  	velocity = Renderer.TextureGBufferVelocity;

	// Your code goes here
}


And add another callback:

private void swap_velocity_texture()
{
	Renderer.TextureGBufferVelocity.swap(velocity);
}

then add it to the viewport

vp.AddCallback(Render.CALLBACK_INDEX.BEGIN_SCREEN, swap_velocity_texture);
vp.AddCallback(Render.CALLBACK_INDEX.END_SCREEN, swap_velocity_texture);


Hope this helps!

  • Thanks 1
Link to comment
×
×
  • Create New...