Image layout transition inside render pass in Vulkan API - graphics

I made a render pass using Vulkan which contains multiple subpasses. We can assume it has 2 subpasses, subpass A and B. In subpass A, I render to an image I want to use in subpass B as a combined image sampler (i. e. NOT as an input attachment). My question is how should I do the image transition from VK_IMAGE_LAYOUT_COLOR_ATTACHMENT to VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL?
I think the subpass dependency mechanism is not good by itself, because I don't use the image in subpass B as an attachment (I guess it doesn't make sense to use it either as input, color, or preserve attachment.) I wanted to use a simple image barrier with a self-dependency, and I was surprised when the validation layer told me that if an image barrier is used inside a render pass, the new and old layout fields should be equal!
This image layout transition pattern seems kind of natural to me, but I haven't found any solution yet. Maybe I misunderstand the concept of subpasses and render passes and I should use different render passes for A and B? (Although in that case I would have to process my G-buffer in two render pass, and I wouldn't be able to use the "input attachment mechanism" of Vulkan.)

Render pass (and subpasses) are designed for a situation where subpass A writes the same (x, y, layer) pixel as the subpass B will later read. It is not intended for random access from the image.
As you noticed, all the kinds of attachment only access the images this way.
Then there is pPreserveAttachments. If you do include you image there, you are not allowed to touch it; if you don't, then the image will become undefined. It is possibly better to think of attachments as something that is not stored anywhere (i.e. exists only in the cache memories). You would have to copy/store the attachment out to non-attachment image to make it usable this way.
To quote from the Vulkan specification:
Image subresources used as attachments must not be accessed in any other way for the duration of a render pass instance.
and your image is an attachment. You are using it as color attachment in subpass A (, so it has to be).
That being said, you probably need two separate render passes (or make use of the input attachment feature if possible for your kind of problem, as #AntoineMorrier suggests). Especially if no other of your images have optimizable dependency as described above.

When you are creating your renderpass and subpasses, you must use this structure :
typedef struct VkAttachmentReference {
uint32_t attachment;
VkImageLayout layout;
} VkAttachmentReference;
Globally, this structure say that at the beginning of your subpass, your image will be in the layout specified.
So, let's say you want to use the layout COLOR_ATTACHMENT in subpass 0, and INPUT_ATTACHMENT (prefer it than SHADER_READ) in subpass 1, you just have to specify the layout for each subpass description and you have to declare one subpass dependency between the subpass 0 and subpass 1.

Related

vtk render window GetZbufferData method

As I understand it, if I create a vtk render window, then I can add different renderers to it and for each renderer renders from a different perspective. No to actually render the scene I use the vtk render window method render() to render all renderers in parallel. Now there is a vtk render window method called GetZbufferData which apparently returns an array containing the zbuffer. So my question is, to which renderer does this zbuffer correspond to?
Thanks for any clarification.
If you have all renderers in the same window, then they will share the same framebuffer, so also the same z-buffer. So a simple answer to your question is "to all of them". To get the individual z-values, it depends on what you are exactly doing with the renderers.
If you are doing some kind of a "tiled view", you want to assign different viewports (vtkRenderer::SetViewport(), like here) to each of the renderers. Then you can access the z data for a given "tile" (renderer) by passing appropriate x,y coordinates to the GetZBufferData function. For example, to get the whole part of the z buffer that belongs to renderer ren1 of vtkRenderWindow renWin:
double x1 = ren1->GetViewport()[0] * (renWin->GetSize()[0] - 1);
double y1 = ren1->GetViewport()[1] * (renWin->GetSize()[1] - 1);
double x2 = ren1->GetViewport()[2] * (renWin->GetSize()[0] - 1);
double y2 = ren1->GetViewport()[3] * (renWin->GetSize()[1] - 1);
float *ren1Z = renWin->GetZbufferData(
static_cast<int>(x1),static_cast<int>(y1),static_cast<int>(x2),
static_cast<int>(y2));
If you have the same viewport, it would be more complicated. You can have a renderwindow with multiple "layers", by setting vtkRenderWindow::SetNumberOfLayers(int) and then you can assign each renderer to a different layer (vtkRenderer::SetLayer(0-based layer index)). The window then renders from layer 0 to the last layer over each other. If you are interested in getting only one specific renderer's z-data, you should get it if you have it render in the last layer. However, I am not sure if the z-buffer is cleaned in between individual renderer's renders, I would actually bet on that it is not, so you might also get some inconsistent mess.
I would like to complement tomj answer:
Any of the vtkRenderWindow::GetZbufferData() methods query the framebuffer for Z-values, which is contained in the vtkRenderWindow, but there is a slight remark:
You need to set this in your renderers: vtkRenderer::PreserveDepthBufferOn(). This is because as the documentation says:
"By default, the depth buffer is reset for each renderer.
If this flag is true, this renderer will use the existing depth buffer for its rendering."
So, that bring us to the vtkRenderers. There is a layering of vtkRenderers, which tells which "chain" or "precedence order" to make the drawing. Check the method vtkRenderer::SetLayer().
So, you first need to set up your layered vtkRenderers, attach them to the vtkRenderWindow, and then set up correctly if you want to preserve some depth buffers or not.
Notice that if the z-buffer has not been set (first draw of the first vtkRenderer), it will return 1.0. I'm still figuring out why, but currently that is the situation.

How do I completely remove the label or the label's spacing in angular-formly form?

Using angular-formly, I'm trying to build a form, where if the label is removed in fields json, there is no padding or spacing given to the that label in the rendered html.
Here is an example of the actual form and my 'desired' form:
JS Bin
The best solution would require a pull request to the template library's label wrapper template which would use an ng-if to hide the label if one is not provided.
If you don't want to deal with that, then you can choose from one of these options:
Set wrapper to null for the field. But you lose the other wrappers as well (like the one that adds has-error)
Create your own type that allows you to specify your own wrappers.
Both of these are demonstrated here:
https://jsbin.com/quceqi/edit?html,js,output

How do I change the image rendered for just one eye?

I'm new to the google cardboard sdk. I need to draw a slightly different image for the left eye as compared to the right(I know distortion correction is taken care of). I saw the "Eye" class spec (an instance of which is passed to OnDrawEye()) from the docs.It does not seem to contain info of which eye is being referred to. How do I tell if the image is being rendered for the right or left eye and code accordingly?
In the class where you implements the CardboardView.StereoRenderer you have to define the function onDrawEye(), int this function you receive a parameter of type Eye, from that parameter you can know what eye is rendering at the moment with the function getType(). You can check the eye with the constants defined in Eye.Type

Change z-index of marker in openlayers

I've a layer with multiple markers with rather big icons, so they overlap. Via the list on the side of the map users can select a marker and the map will pan (and zoom) to it. But it will still be behind some other makers.
How do I get a individual makers z-index and set it? I would be useful to get the highest used z-index and just add one. (another solution is to add the total number of markers to the z-index)
The markers (or features) are in a myLib.features array. The console doesn't show any z-index type functions.
I can't find a appropriate example or api function for this.
EDIT:
I found this example: http://dev.openlayers.org/examples/ordering.html
I don't really understand it. Somehow the created feature takes the next z-index given by the layer via somekind of symbolizer. I have no idea how to work this static sort into a dynamic one.
Try this:
First of all, make sure you are using a OpenLayers.Layer.Vector layer, not a OpenLayers.Layer.Markers layer. Apparently the Markers layer is old news and all new development is done in the Vector layer. It has more features. (I wasted a pile of time with the Markers layer myself).
Then, each of your markers needs to be a OpenLayers.Feature.Vector object. The constructor takes three arguments, the third of which is called the style. The style is where you set your image attributes, the background shadow, the mouse-over text, and the z-index, which has the property name "graphicZIndex". I think that's what you're looking for.
http://dev.openlayers.org/releases/OpenLayers-2.12/doc/apidocs/files/OpenLayers/Feature/Vector-js.html#OpenLayers.Feature.Vector.OpenLayers.Feature.Vector.style
Add your "markers" (which are Vector's) to your Vector layer with the addFeatures function. And just ignore the "options" argument.
http://dev.openlayers.org/releases/OpenLayers-2.12/doc/apidocs/files/OpenLayers/Layer/Vector-js.html#OpenLayers.Layer.Vector.addFeatures
I found that example page too, and I found it confusing too. It was setting all the markers' styles in the Vector layer's constructor (as default values to be used if the marker style was omitted) instead of the marker's constructor. I think it makes more sense to set the marker style in the marker constructor.
To change the style in real-time, take one of your OpenLayers.Feature.Vector markers, called "marker" and do this. And let's call the Vector Layer "layer".
marker.style.graphicZIndex = 13;
layer.redraw();

Rendering order in JUNG graph visualisation

I'm using JUNG2 to draw some graphs.
This is the image I get:
http://img841.imageshack.us/img841/205/graphvizkk3312164f020b4.png
I'd like to:
1) change the rendering order (labels should be the last objects to be drawn);
2) add a semi-transparent background to the labels.
3) change background color of the whole image.
Any idea on how to do this?
The JUNG2 documentation is not very extensive on these issues.
Mulone
(1) To do this you'd have to hack the rendering code; I don't believe that we support this at the moment.
UPDATE: I took a closer look. Actually JUNG does support this without hacking the existing libraries; the easiest way is perhaps to subclass BasicRenderer and then override the render() method so that things happen in the order that you want. (I recommend that you render vertices after edges.) Once you do that, you create an instance of your custom Renderer, and call VisualizationViewer.setRenderer(customRenderer).
(2) The labels respect HTML code (i.e., surround your label with <html></html> and then put whatever tags you like in it).
(3) BasicVisualizationServer (and its subclasses, e.g. VisualizationViewer) inherit from JComponent, which defines setBackground(Color).

Resources