Access enoki::DynamicArray with Packet Index
In enoki library v0.1.0, the operator [] of the DynamicArray<Packet<...>>, which stores Packet data, only accepts integer argument. Here is an example:
12345constexpr size_t PacketSize = enoki::max_packet_size / sizeof(float); // = 8using FloatP = Packet<float, PacketSize>;using FloatX = DynamicArray<FloatP>;FloatX data(-1.f, 1.f, 2.f, 3.f, 4.f, 5.f, 6.f, 7.f, 8.f, 9.f, 10.f);
Of course we can access the tenth element by data[9]. Als ...
Beware of VK_IMAGE_LAYOUT_UNDEFINED
As a novice of Vulkan, when I first use VkImageMemoryBarrier, I intuitively thought that VK_IMAGE_LAYOUT_UNDEFINED is a sugar of setting the oldLayout. After I did this last time, it left a hidden danger to me.
According to the official document:
The old layout must either be VK_IMAGE_LAYOUT_UNDEFINED, or match the current layout of the image subresource range.If the old layout matches the current layout of the image subresource range, the transition preserves the contents of that range.If the ...
Get Depth Value of Depth Buffer
In the material editor, when we use the node SceneTexture with texture id SceneDepth, we get the scene depth in clip space. However, we want to get the depth value(called DeviceZ in Common.ush) that is stored in the depth buffer. We can use the function float ConvertToDeviceZ(float SceneDepth) and float ConvertFromDeviceZ(float DeviceZ) to convert between each other.
Since there is no dedicated expression node for either of them, we have to create a custom material expression manually.
Create a ...
Three Steps to Eliminate Lag of Camera Movement
In the project of my HiWi job, the lag of camera translation and rotation is highly noticeable even if I move it slowly. It delayed more than 3 frames visually. Here are 4 places need to be check if the same problem happened to you.
Don’t get the transformation from AActor::GetActorLocatino() and APlayerController::GetControlRotation(). Instead, get location and rotation from APlayerCameraManager::GetCameraCachePOV().Location/Rotation.
Change the tick group, which the getter of transformation i ...
Convert Coordinate in Left-handed System to Right-handed System
UE4 is using left-handed coordinate system which is clockwise when viewing from the top. However the data we use is sampled in right-handed system which is counter-clockwise when viewing from the top. If we use the data directly in UE4, we gets a lying down viewport. So we have to convert the coordinate into left-handed coordinate system at first.
We have already known that $Coordinate;in;Screen;Space = Projection Matrix \times View Matrix \times Model Matrix \times Coordinate;in;Local;Space$. T ...
How to Enable Vulkan Validation Layer
Vulkan validation layer in UE4 is not enabled by default. We can see the codes in VulkanLayers.cpp around line 300:
12345const int32 VulkanValidationOption = GValidationCvar.GetValueOnAnyThread();if (!bVkTrace && VulkanValidationOption > 0){ ...}
The validation layer will be enabled only if VulkanValidationOption has a proper non-zero value when creating VkInstance. The GValidationCvar is defined at the begining of the same file like this:
1234567891011TAutoConsoleVariabl ...
Why Cannot We See Source Files in Visual Studio
In my current project, I need to add a third party library with source files. Before this, I only have expericence that adding prebuilt library such as .lib files. This time, I create a new folder and module files, i.e. IXXLib.h, XXLib.cpp and XXLib.build.cs, under the path ‘UnrealEngine\Engine\Plugins\MyPlugin\Source\ThirdParty\XXLib’ because I don’t want to expose it to other modules explicitly. But After I regenerating the project file, I didn’t find any files under the folder except those th ...
How to Debug UnrealBuildTool
Steps:
Set UnrealBuildTool as startup project.
Open UnrealBuildTool Properties page.
Add arguments to the ‘Command line arguments’ under the section ‘Debug’
If you want to debug the phase of generating project file, use -ProjectFiles
If you want to debug building phase, use parameters from the ‘BuildCommandLine’ of UE4 Property Page which is exactly executed when you build the project as usual.
Tips: Sometime the break points will not be triggered without any reason. It often happens after y ...