How to read the stencil buffer in Vulkan? - graphics

I have a combined depth/stencil image with the VK_FORMAT_D32_SFLOAT_S8_UINT format. I am trying to create 2 image views for it, so that I can use them to sample the depth and the stencil values in a shader. I set the image aspect flags to VK_IMAGE_ASPECT_DEPTH_BIT and VK_IMAGE_ASPECT_STENCIL_BIT respectively when the views are created, but I can only sample the depth texture successfully. The stencil image view is created fine but I can't even see it bound in the shader (at least that's what RenderDoc is saying). Also there are no errors or messages from the validation layers.
Is there any specific configuration for the buffer and stencil view that I need to use or any other things to consider in order to set the stencil texture view and sample it?
UPDATE:
The issue with the stencil texture not being set was caused by an error in my code. I can now see it bound in RenderDoc and toggle between the depth and stencil components (they have the right content). So now the question is, how do I sample the stencil component of a combined depth/stencil image, because I can only get the stencil clear color when I sample it?
UPDATE:
I eventually managed to get this working by using a buffer with the VK_FORMAT_D32_SFLOAT_S8_UINT format and a view that has the VK_IMAGE_ASPECT_STENCIL_BIT aspect. Also, in the shader, I used a usampler2DMS sampler and texelFetch to read the stencil value (as I'm using multisampling). texelFetch will return a uint4 value and the stencil value can be accessed from the red channel.

Related

How to force Godot to recalculate control nodes size/position?

Building UI in Godot 3.2.1. Of course I use anchors so UI elements are arranged within the screen automatically according to specified layout. I have UI scale system - nothing fancy - simply change font size (DynamicFont.size). If font size is large enough then some UI nodes may be pushed out of the screen. However, nodes don't return to normal sizes/positions with font size decreasing. The way to fix a mess is to resize game window which is not always an option and doesn't seem like a correct way to handle the issue. So how can I force Godot to recalculate control nodes size/position?
Changing the parent control's minimum size to Vector2(0, 0) after changing the font size might do the trick:
$Control.rect_min_size = Vector2(0, 0)
If it's already set to Vector2(0, 0), you may have to change it twice using call_deferred() for it to work.
In your scene tree, find the top level container that contains all of the elements that you want to recalculate. This would be the lowest common ancestor in the scene tree, in computer science terminology. Now, hide the container, by setting it's 'visible' property to false. Then, add a deferred call to change it's 'visible' property back to true.
var your_container = $".".find_node("your-container")
your_container.visible = false
your_container.call_deferred("set_visible", true)
This seems to cause Godot to recalculate the layout of 'your_container'.
It looks like only CanvasItem derived classes have a 'visible' property, so you would not be able to simply set the 'visible' property on a CanvasLayer, for example.
Fortunately, Containers and Controls both derive from CannvasItem, so this methodology should work fine if your lowest common ancestor node is either a Container or a Control or other CanvasItem derived class instance.
I got this working by emitting a signal from a parent element, which appears to force a refresh:
canvas_item.emit_signal("item_rect_changed")
The problem child got refreshed, and unlike the visibility method, focus was retained.

Shadow mapping issue

I've implemented shadow mapping to generate shadows on a terrain.
I render the scene (or the objects that cast shadows) from the light's perspective and then generate a depth map to be sampled during the second render pass (as all the tutorials on the web explain).
It seemed to work fine but then I noticed that objects on a hill cast more than one shadow:
I think that's the correct behaviour since I don't render the terrain during depth map generation (the small quad on top right shows the depth buffer during the first render pass), so more terrain fragments look like they're behind the object from the light's point of view.
No tutorial on shadow mapping seems to mention this issue though.
Am I missing something or this shadow generation technique is very basic and issues like this one are likely to occur?
EDIT
here's my rendering code:
// in my Render() method:
mShadowRenderer.SetLight(*mLights[0]);
mShadowRenderer.Render();
RenderSkyBox();
RenderEntities();
RenderGeometryTerrain(mTerrains[0],
mShadowRenderer.GetLightViewProjectionMatrix());
shadowRenderer is a class that is in charge of rendering to an off-screen buffer and to return a depth map as a shader resource view. The depth map is added to the terrain when I call the render method so it can be sampled in the terrai pixel shader to generate shadows.
Also, the terrain needs to be rendered to the shadow map/dep map

Dynamic conversion of Text size in custom view getting wrong in android

I am trying to calculate text size of the EditText dynamically in my custom View.
Following is my code snapshot.
in my values/dimens.xml file, I have defined a size
<dimen name="default_view_height">180dp</dimen>
I am using this dimension through custom attributes, so I retrieve this, in my CustomView, I have retrieved this value using the following
default_view_height = attrsArrays.getDimensionPixelSize(R.styleable.CustomView_defaultViewSize,DEFAULT_VIEW_SIZE);
and in my customView I am using this value to calculte the size of my EditText View in following way
mInputText.setTextSize(default_view_height / 6);
Basically I am trying to dynamically handle the size of the EditTextView's text size in proportion to the size of the CustomView.
I am getting the right proportion on all devices including N5,N4, except Samsung high end devices like Samsung S4.
Whats wrong in the code.

Resizable MKOverlay using MKOverlayRenderer

I want to have a custom MKOverlay that's a circle anchored to the user location annotation that the user can resize by pinching. I was able to successfully achieve this using MKOverlayPathRenderer and a custom MKOverlay object by overriding the createPath method and making an arc. The resizing and moving of the overlay was handled by using KVO on the radius and coordinate properties of my overlay. However the resizing was incredibly choppy and the boundingMapRect wasn't correctly calculated.
I've also tried using an image and instead of subclassing MKOverlayPathRenderer just MKOverlayRenderer, overriding - (void)drawMapRect:(MKMapRect)mapRect zoomScale:(MKZoomScale)zoomScale inContext:(CGContextRef)context but when I resize my CPU percentage jumps to 160% usage (not great yeah?) and the boundingRect is again being drawn incorrectly.
I really think the way to do it is with MKOverlayPathRenderer and maybe having an atomic counter of some kind so that a redraw only gets called say every 5 or 10 times the pinch gesture is triggered.
Does anyone have any suggestions? I've also considered but haven't tried making a UIView and adding it as a subview to the map view and putting the pinch gesture on that but that seems hacky and dirty.
When you computed new boundingMapRect on the Overlay, you must invoke invalidatePath on your Renderer. After that, system will invoke createPath for you when appropriate.

Fluid layout: full width not applied in container with undefined size

I'm having trouble creating a fluid layout with Vaadin. As I understand it, in order for a container's size to be calculated based on its contents, I have to use the setSizeUndefined() method.
This works fine, but an issue arises when I want to add components wich take up all the available space to this container with undefined size. I cannot get this to work.
Here's a simplified sample of what I'm trying to do:
VerticalLayout layout = new VerticalLayout();
layout.setSizeUndefined();
layout.setMargin(false);
layout.addComponent(createButton("A somewhat longer label"));
layout.addComponent(createButton("Short label"));
private Button createButton(String label) {
Button button = new Button(label);
button.setSizeFull();
button.setWidth("100%");
return button;
}
The buttons do not take up the entire width of the vertical layout container. I have read here and there that one is not allowed to set "100%" sizes inside containers with undefined size, but then how am I supposed to achieve what I want to achieve bearing in mind that I need that undefined size for my fluid layout?
In case someone thinks the undefined size is not necessary for my use case, I'll be happy to provide more information on that. I have a strong Flex background which may cause met to look at this problem from the wrong angle.
You are correct, you cannot use relatively sized components within a VerticalLayout that has an undefined size. The functionality you are looking for exists in an add-on called WeeLayout.

Resources