You've already forked UnrealEngineUWP
mirror of
https://github.com/izzy2lost/UnrealEngineUWP.git
synced 2026-03-26 18:15:20 -07:00
#lockdown Nick.Penwarden
==========================
MAJOR FEATURES + CHANGES
==========================
Change 3012064 on 2016/06/13 by Nick.Whiting
Merging Main -> DevVR
Change 3048060 on 2016/07/13 by Nick.Whiting
Integrating CL 3045721 from //depot/Partners/Google/AndroidVR-DevVR
Upgrade Android and iOS GVR SDK to the latest.
Fix the flipped vignette issue when using Unreal's post processing distortion.
Change the Daydream & Cardboard mode to use scanline racing.
Deprecate the ability to turn off individual UI elements.
Change 3235307 on 2016/12/14 by Keli.Hlodversson
Filter out excluded HMD modules during FEngineLoop:PreInitHMDDevice. The final selection still happens in UEngine::InitializeHMDDevice as all HMD plugins have not been loaded during PreInit
Change 3235308 on 2016/12/14 by Ryan.Vance
#jira UEVR-478
Monoscopic far field improvements
Shader changes are now gated behind the read only cvar vr.MonoscopicFarField. Changing this requires a shader compile.
Moved the mono rendering mode to the cvar vr.MonoscopicFarFieldMode. This is writable, so users can enable/disable mono rendering on the fly if the above cvar is enabled.
Only write to the alpha channel in the mobile base pass if the object is opaque and MONOSCOPIC_FAR_FIELD is defined.
Addressed code review comments.
Change 3235397 on 2016/12/14 by Keli.Hlodversson
[Oculus] Only enable GearVR platform on Windows if Oculus service is running
Original author: Loren.McQuade
Change 3235762 on 2016/12/14 by Keli.Hlodversson
Add explicit parentheses to placate the build bots.
Change 3242318 on 2016/12/21 by Ryan.Vance
Working around pixel density crash.
Change 3242522 on 2016/12/21 by Ryan.Vance
Missing flag clear so our adaptive test was always returning true.
Change 3243173 on 2016/12/22 by Ryan.Vance
Integrating post present callback implementation from 4.14.1
Change 3248633 on 2017/01/05 by Keli.Hlodversson
Copying //Tasks/UE4/Dev-VR-Refactoring to Dev-VR-Minimal (//UE4/Dev-VR-Minimal)
Change 3248723 on 2017/01/05 by Keli.Hlodversson
Fix after merge. EnablePositionalTracking no longer exists.
Change 3249484 on 2017/01/06 by Keli.Hlodversson
Add missing includes
Change 3249714 on 2017/01/06 by Keli.Hlodversson
Remove monolithic header include
Change 3249980 on 2017/01/06 by Keli.Hlodversson
SteamVR: Remove leftover unused WindowMirrorMode member variable
Change 3252432 on 2017/01/10 by Keli.Hlodversson
Submitting change by Loren McQuade to fix monolithic builds.
Unshelved from pending changelist '3251436':
Change 3257373 on 2017/01/13 by Keli.Hlodversson
#jira UEVR-411: Finish renaming/removing/remodelling the remaining Oculus (Rift+GearVR) commands
#jira UEVR-412: Rename and merge remaining Morpheus console commands
#jira UEVR-417: Remove Exec from IHeadMountedDisplay
Change 3269971 on 2017/01/24 by Jeff.Fisher
UEVR-498 move controller is missing world to meters
UEVR-522 PS4 motion controller worldscale support.
-Passing world to meters scale into getControllerOrientationAndPosition because the thing asking about it ought to be part of a world, and know what it should be. This also avoids making PS4 motion controllers dependent on the HMD. Note Google VR Controller doesn't do position, so doesnt' care about scale. Oculus already had internal threadsafe tracking of world scale, so I left that. Steam handles world scale below our input level.
-Also adding PlayerIndex member to FSceneView so we can figure out which view the MotionControllerComponent should get its worldscale from for the late render thread update.
#jira UEVR-498
#review-3384107
Change 3288308 on 2017/02/06 by Jeff.Fisher
UEVR-517 Detect MotionController Connectivity
-PS4 can only track 2 controllers and 1 hmd. Support for dealing with that is needed.
-Also need to support multiple motion controller components mapped to a single controller. Licencees have done that before.
-Created a new interface IMotionTrackingSystemManagement, and implements it for PS4Tracker on PS4.
-Created a MotionTrackedDeviceFunctionLibrary to expose that interface to blueprint.
-With those one can enable and disable tracking on ps4 controllers and query their state to stay within the controller tracking limit.
-PS4Tracker also keeps a blackboard of the enable/disable state so that one can enable or disable controllers that have not been connected yet, and have them enable tracking or not when they are connected.
-DS4 controller no longer jumps back to 000 if it loses tracking.
#review-3384107
#jira UEVR-517
Change 3288309 on 2017/02/06 by Keli.Hlodversson
Add file missing from CL#3257373.
Change 3288311 on 2017/02/06 by Jeff.Fisher
UEVR-517 Detect MotionController Connectivity - Test content.
-tm-motionControllers has a third mode where all playstation motion controllers for player 0 are availalbe. You can toggle them to track or not with ctrl-P,G,L,R for pad, gun, leftmove, rightmove or with alt-P,G,L,R. Ctrl tests doing so via MotionControllerComponent. Alt tests doing so by player index and controller type enum.
-ctrl-A disables tracking of all controllers
-alt-A disables tracking of all controllers for player 0
-ctrl-D toggles enabling new controllers by default
-Also fixed one button not working in one of the other test modes for the Aim (gun) controller.
-The controller 'models' have an arrow out the front. It is black if disabled. Red if enabled, but no tracker is active, yellow if tracked but inertial only, and green if fully tracked by the camera.
-This logic is in the QA_MoCoAll blueprint.
Change 3291601 on 2017/02/07 by Jeff.Fisher
UEVR-536 PSVR motion controller tracking problem with multiple controllers
-Previous code called GetRelativeTransform from the render thread, but the game thread could update it at any time. This caches that transform so that it can be safely used in the render thread.
#jira UEVR-536
#review-3384107 @Ryan.Vance
Change 3292460 on 2017/02/08 by Jeff.Fisher
PS4 sceVrTrackerGetResult() error warning logging improved, and explanatory comment added.
Change 3308771 on 2017/02/17 by Keli.Hlodversson
Rename GoogleVR console commands
#jira UEVR-412
Change 3309156 on 2017/02/17 by Keli.Hlodversson
Track changes in r.ScreenPercentage on GoogleVR and set RenderTargetSize accordingly.
Change 3311999 on 2017/02/20 by Keli.Hlodversson
Create a default implementation for RecordAnalytics.
Also create an initial stub for FHeadMountedDisplayBase for future default implementations of common HMD functionality.
Make implementing IHeadMountedDisplay::GetDeviceName mandatory instead of defaulting to "Unknown"
#jira UE-21878
#jira UEVR-213
Change 3313467 on 2017/02/20 by Ryan.Vance
#jira UE-41604
3278583
pCustomPresent->AllocateRenderTargetTexture may return false, if we blindly return true we can end up with an invalid render target since the fall back sceneviewport will be skipped.
3278536
Adding ovrError_NoHmd to our sanity check in OnStartGameFrame.
Change 3314002 on 2017/02/21 by Keli.Hlodversson
Fix compilation on PS4 and Linux
Change 3326722 on 2017/03/01 by Jeff.Fisher
Merging //UE4/Dev-Main to Dev-VR (//UE4/Dev-VR)
Integrating 4.15 from main.
Change 3327567 on 2017/03/01 by Jeff.Fisher
UEVR-588 Oculus crash on "stereo on" when the proximity sensor is not triggered.
Duplicating from Release-4.15 cl 3327481, 3327542
-Don't ovr_SubmitFrame when the layers need to be recreated. They stay dirty until rendering is unpaused.
#jira UEVR-588
#review-3384107
Change 3328098 on 2017/03/01 by Jeff.Fisher
4.15 merge fixes
-Fixed deprecated enum name function usage.
-Fixed world scale usage in GoogleVRController.
-Fixed compile break in PS4Tracker.
Change 3328271 on 2017/03/01 by Jeff.Fisher
2.15 merge
-restroging GoogleVRController::GetWorldToMetersScale... cause it is used everywhere.
Change 3328307 on 2017/03/01 by Jeff.Fisher
4.15 merge
-More googlevr worldscale fixes.
Change 3328312 on 2017/03/01 by Jeff.Fisher
4.15 merge
-removing 2 unused includes
Change 3330610 on 2017/03/02 by Jeff.Fisher
4.15 merge
-fixing linux build
Change 3333952 on 2017/03/06 by Keli.Hlodversson
Implement common stereo layer management base class and use it in SteamVR and PS4. Fixes an outstanding bug in SteamVR where texures are updated every frame regardles of whether the continous update flag is set or not.
#jira UEVR-628
#jira UE-42555
Change 3334961 on 2017/03/07 by Keli.Hlodversson
Add missing include to fix non-unity builds
Change 3336200 on 2017/03/07 by Keli.Hlodversson
Fix compilation issues. (https://ec-01.epicgames.net/commander/link/jobDetails/jobs/7568252?jobName=UE4+Dev-VR+-+CL+3334961+-+Nightly+Build&s=Jobs)
* Pre VS2015 compilers don't like mixing wide and unmarked strings in concatenation. Unfortunately LOCTEXT hides the call to the TEXT macro, completely hinding the prefix (which only gets added to the first fragment.)
* Switch apparently doesn't know how to format a size_t for analytics either.
Also: Typo in backwards compatibility command name alias
Change 3337347 on 2017/03/08 by Jeff.Fisher
UE-42631 Stereo off while prox sensor uncovered causes low framerate
-Setting maxfps appropriately on 'stereo on/off'.
#review-3384107
#jira UE-42631
Change 3338385 on 2017/03/08 by Ryan.Vance
r.DisableDistortion was only being used for the mobile renderer
Change 3342301 on 2017/03/10 by patrickr.donovan
Test updates to TM-VRSmoke.
Increased lightmap resolution on QA_MeshTypes meshes to improve readbility and reliablility of tests involving said asset.
Rebuilt lighting.
Change 3348133 on 2017/03/15 by Ryan.Vance
Moving mono cvars to scene rendering to avoid cross module references. There's not a good reason to have them in the hmd module anyway.
Change 3348836 on 2017/03/15 by Ryan.Vance
Direct multi-view support for gear vr
Monoscopic far field with multi-view (blit and direct) support for gear vr
Support for translucent objects on both sides of the mono clip plane (due to a sorting issue, objects that straddle the plane composite incorrectly)
Fixed missing discards/clears in the multi-view blit
Change 3348843 on 2017/03/15 by Ryan.Vance
Fixing color/depth target size mismatch when screen percentage scaling results in a size that isn't divisible by 16.
Change 3349276 on 2017/03/16 by Keli.Hlodversson
Fixing compile errors in GoogleVR after merge from main.
Change 3350932 on 2017/03/16 by Ryan.Vance
Re-enabling the gearvr plugin on windows.
Change 3351977 on 2017/03/17 by Jeff.Fisher
Fixing masked member variable.
Change 3352314 on 2017/03/17 by Ryan.Vance
We need to ensure that we don't select different lod levels for each eye.
Change 3352993 on 2017/03/17 by Nick.Whiting
Integrating CL 3345824 from Android-DevVR to Dev-VR. Support for device depth pass in SceneCaptureComponent2D
Change 3355185 on 2017/03/20 by Nick.Whiting
Added ability to disable the autoloading splash screen, which would prevent the hide splash screen node from ever working
Change 3355676 on 2017/03/20 by Nick.Whiting
PR #3384: [GNUX] SteamVR, OpenGL patch. (Contributed by yaakuro), with some minor modifications
Change 3357286 on 2017/03/21 by Jeff.Fisher
Fixing GenerateProjectFiles, looks like the .config. was removed from these references in main some time ago.
Change 3357435 on 2017/03/21 by Jeff.Fisher
Fixing editor build break, looks like a merge mistake.
Change 3359960 on 2017/03/23 by Keli.Hlodversson
Prevent potential crash when drawing tracking sensor location. Also only fetch HMD location once instead of once per tracking sensor.
Change 3361230 on 2017/03/23 by Jeff.Fisher
Fixing linux build opengl include problem... maybe.
Change 3361638 on 2017/03/23 by Jeff.Fisher
Another guess at fixing linux build.
Change 3364224 on 2017/03/24 by Keli.Hlodversson
Initial implementation of UEVR-576 - Base emulated layer implementation
#jira UEVR-668 - Base emulated layer implementation: Initial framework for overrideable default implementation
#jira UEVR-669 - Base emulated layer implementation: Face Locked Layers Support
#jira UEVR-670 - Base emulated layer implementation: Tracker Locked Layers Support
#jira UEVR-671 - Base emulated layer implementation: World Locked Layers Support
#jira UEVR-672 - Base emulated layer implementation: Add support for optionally rendering face locked layers into a separate layer
Change 3364242 on 2017/03/24 by Keli.Hlodversson
SteamVR layers do not support negatve Layer priorities
Change 3364263 on 2017/03/24 by Jeff.Fisher
Merging //UE4/Dev-Main to Dev-VR (//UE4/Dev-VR)
Monoscopicfarfieldrendering was just 'accept source', Ryan is going to look at fixing it up.
Change 3364472 on 2017/03/24 by Jeff.Fisher
Merge fix
Change 3364475 on 2017/03/24 by Jeff.Fisher
Fixing gearvr include.
Change 3364486 on 2017/03/24 by Jeff.Fisher
merge fix
Change 3364532 on 2017/03/24 by Ryan.Vance
pso update for mono rendering and stereo layers.
Change 3364599 on 2017/03/24 by Ryan.Vance
Oculus changes for SI1.12
Change 3365159 on 2017/03/26 by Jeff.Fisher
include fix
Change 3365182 on 2017/03/26 by Jeff.Fisher
include fix
Change 3366087 on 2017/03/27 by Ryan.Vance
Remaining files from Oculus changes for SI1.12 merge request.
Fixing a bug in OnlineSubsystem.
Temporarily changing the eye padding change to be a shader clear to work around a clear color binding issue.
Change 3366492 on 2017/03/27 by Ryan.Vance
#jira UE-43294
Moved the clear before we setup state for drawing the mirror window content. It was stomping over state after the pso changes.
Going to leave the shader clear in the rift prerender for clearing the eye padding for now.
Change 3366929 on 2017/03/27 by Ryan.Vance
Fixing compile error
Change 3368549 on 2017/03/28 by Jeff.Fisher
Merging Change: 3357998 from //UE4/Partner-Google-VR/Engine/... to Dev-VR
Upgrade Google VR Plugin to v1.3:
*Upgraded GVR NDK to 1.30.0
*Changed some BlueprintFunction to use BlueprintPure
*Add the missing bDaydream flag in UEDeployAndroid.cs
#review-3384107
Change 3368975 on 2017/03/28 by Ryan.Vance
CIS clean up
#jira UE-43428, UE-43429, UE-43426, UE-43427
Change 3369028 on 2017/03/28 by Ryan.Vance
This is not exacly 'correct', but it's at least what the code was trying to do.
Change 3370203 on 2017/03/29 by Ryan.Vance
Adding gear vr controller component support.
Change 3370918 on 2017/03/29 by Ryan.Vance
Merging 3370569 using Partner-Google-VR_to_DevVR
Change 3371030 on 2017/03/29 by Ryan.Vance
Fixing linux build errors
#jira UE-43426
Change 3371036 on 2017/03/29 by Ryan.Vance
Oculus 4.16 integration.
Not terribly happy with the use of std::string. They promised to clean this up for the next release.
Change 3373495 on 2017/03/30 by Jeff.Fisher
Merging from Dev-Main, in preparation for 4.16
Change 3373578 on 2017/03/30 by Jeff.Fisher
build break, one comma short
Change 3373870 on 2017/03/31 by Jeff.Fisher
Include order fix.
Change 3374001 on 2017/03/31 by Keli.Hlodversson
Use DefaultStereoLayers as base for Morpheus implementation.
#jira UEVR-709 #jira UE-42919
#rb: Jeff.Fisher
Change 3374004 on 2017/03/31 by Keli.Hlodversson
Fix rendering for the default Stereo Layers implementation on mobile.
Depth test was set to "Never" instead of "Always"
Destination texture on GLES is flipped on the Y axis, the coordinates are reversed in the shade when compiled on the relevant platforms.
Change 3375125 on 2017/03/31 by Jeff.Fisher
UE-43506 Ensure using VRPreview with GoogleVR
-Removed the ensure, there is code in there to handle that case, and it works.
#jira UE-43506
Change 3375294 on 2017/03/31 by nick.bullard
Resaving Plugin content to resovle "saved with empty engine version"
#jira UE-43537
Change 3375480 on 2017/03/31 by Jeff.Fisher
UEVR-9 PSVR: Social Screen Support
-Experimental social screen support for 4.16.
-This does the basics of driving output through the Aux port in the proper format for display on the mirror monitor.
-Only supports 30fps on the mirror monitor. 60fps will require the implementation of sony system dialogs to deal with incompatable system features (video streaming, remote play).
-There is a project setting in Morpheus, under experiemental bEnableSocialScreenSeparateMode. This must be set to true to use this feature. When it is false we avoid allocating the back buffers.
-MorpheusFunctionLibrary blueprints now have a node "SetSocialScreenMode" which can switch between SystemMirror (hardware supported mirroring), SeparateTest (alternates black and white), SeparateTexture (displays a texture, eg a render target, specified via blueprint), and SeparateMirror(puts the hmd render buffer on screen - which is both eyes, like a debug mode).
-Also finally updated the bEnabled flag in project settings to tell people it's only for PC.
#jira UEVR-9
#review-3384107
Change 3375540 on 2017/03/31 by Ryan.Vance
#jira UE-43504
Fixing android build break when using a 64 bit isa.
Change 3375655 on 2017/03/31 by Jeff.Fisher
Fixing missing RGBAToYUV shader problem
-This at least unblocks our process. Will revisit before zbr.
Change 3375820 on 2017/04/01 by Jeff.Fisher
Fixing linux build warning about HAS_MORPHEUS
Change 3376050 on 2017/04/02 by Jeff.Fisher
UE-43515 Step 'UE4Editor Static Analysis Win64' - Module.OnlineSubsystemOculus.cpp Warnings
-Temporary fix for static analysis annotation warnings in OnlineSubsytemOculus. Longer term plan is to eliminate the use of the headers that trigger the warnings.
-Just wrap all standard headers in static analysis disables.
#jira UE-43515
Change 3376609 on 2017/04/03 by Jeff.Fisher
Fixing rgbatoyuvshader include.
Change 3377001 on 2017/04/03 by Jeff.Fisher
UE-43547 Launch On PS4 fails during Run command - Missing global shader FRGBAToYUV420CS
- shader c++ must be compiled so that it can be cooked for ps4.
#jira UE-43547
Change 3379858 on 2017/04/04 by Jeff.Fisher
Merging //UE4/Dev-Main to Dev-VR (//UE4/Dev-VR)
pulling main this should get us ps4 sdk 4.508
Change 3379938 on 2017/04/04 by Ryan.Vance
#jira UE-43548
If stereo layers are not being used, don't setup overlay targets as we will never clear/initialize them.
The clear happens as part of the default layers PostRenderView_RenderThread call which wont be called if layers aren't being used in the scene.
Change 3381519 on 2017/04/05 by Jeff.Fisher
UEVR-733 PS4 sdk 4.500 hmd connection api changes break hmd connect.
-Handling failure of sceHmdGetDeviceInformation if the hmd is powered off. It now returns an error code about an invalid handle in that case, rather than reporting unready. We just treat the error code like an unready status.
#jira UEVR-733
#review-3384107
Change 3382019 on 2017/04/05 by Ryan.Vance
Linux: add Vulkan support from dev editor: 3381593
Change 3382021 on 2017/04/05 by Ryan.Vance
SteamVR on Linux using Vulkan
OpenVR rev to 1_0_6
PR #3412: [GNUX] Initial support for SteamVR using Vulkan on GNUX platform. (Contributed by yaakuro)
Change 3382076 on 2017/04/05 by Ryan.Vance
Fixing linux steamvr lib path. It changed to something less silly in 1.0.6
Removing the steamvr plugin from the white list for linux. It's looking for a runtime that no one will have installed.
Change 3383237 on 2017/04/06 by Ryan.Vance
#jira UE-43732
Fixing Android compile issues. We can't wrap portions of a macro with a definie. This should probably be some sort of recursive macro thing since there's so much overlap. Good enough for now.
Change 3383353 on 2017/04/06 by Ryan.Vance
Fixing include cycles.
Change 3383509 on 2017/04/06 by Jeff.Fisher
Merging //UE4/Dev-Main to Dev-VR (//UE4/Dev-VR)
merging the stuff from dev-mobile
[CL 3384106 by Ryan Vance in Main branch]
922 lines
28 KiB
C++
922 lines
28 KiB
C++
// Copyright 1998-2017 Epic Games, Inc. All Rights Reserved.
|
|
|
|
#include "RenderUtils.h"
|
|
#include "Containers/ResourceArray.h"
|
|
#include "Containers/DynamicRHIResourceArray.h"
|
|
#include "RenderResource.h"
|
|
|
|
const uint16 GCubeIndices[12*3] =
|
|
{
|
|
0, 2, 3,
|
|
0, 3, 1,
|
|
4, 5, 7,
|
|
4, 7, 6,
|
|
0, 1, 5,
|
|
0, 5, 4,
|
|
2, 6, 7,
|
|
2, 7, 3,
|
|
0, 4, 6,
|
|
0, 6, 2,
|
|
1, 3, 7,
|
|
1, 7, 5,
|
|
};
|
|
|
|
/** X=127.5, Y=127.5, Z=1/127.5f, W=-1.0 */
|
|
const VectorRegister GVectorPackingConstants = MakeVectorRegister( 127.5f, 127.5f, 1.0f/127.5f, -1.0f );
|
|
|
|
/** Zero Normal **/
|
|
FPackedNormal FPackedNormal::ZeroNormal(127, 127, 127, 127);
|
|
|
|
//
|
|
// FPackedNormal serializer
|
|
//
|
|
FArchive& operator<<(FArchive& Ar,FPackedNormal& N)
|
|
{
|
|
Ar << N.Vector.Packed;
|
|
return Ar;
|
|
}
|
|
|
|
FArchive& operator<<(FArchive& Ar, FPackedRGB10A2N& N)
|
|
{
|
|
Ar << N.Vector.Packed;
|
|
return Ar;
|
|
}
|
|
|
|
FArchive& operator<<(FArchive& Ar, FPackedRGBA16N& N)
|
|
{
|
|
Ar << N.X;
|
|
Ar << N.Y;
|
|
Ar << N.Z;
|
|
Ar << N.W;
|
|
return Ar;
|
|
}
|
|
|
|
//
|
|
// Pixel format information.
|
|
//
|
|
|
|
FPixelFormatInfo GPixelFormats[PF_MAX] =
|
|
{
|
|
// Name BlockSizeX BlockSizeY BlockSizeZ BlockBytes NumComponents PlatformFormat Supported UnrealFormat
|
|
|
|
{ TEXT("unknown"), 0, 0, 0, 0, 0, 0, 0, PF_Unknown },
|
|
{ TEXT("A32B32G32R32F"), 1, 1, 1, 16, 4, 0, 1, PF_A32B32G32R32F },
|
|
{ TEXT("B8G8R8A8"), 1, 1, 1, 4, 4, 0, 1, PF_B8G8R8A8 },
|
|
{ TEXT("G8"), 1, 1, 1, 1, 1, 0, 1, PF_G8 },
|
|
{ TEXT("G16"), 1, 1, 1, 2, 1, 0, 1, PF_G16 },
|
|
{ TEXT("DXT1"), 4, 4, 1, 8, 3, 0, 1, PF_DXT1 },
|
|
{ TEXT("DXT3"), 4, 4, 1, 16, 4, 0, 1, PF_DXT3 },
|
|
{ TEXT("DXT5"), 4, 4, 1, 16, 4, 0, 1, PF_DXT5 },
|
|
{ TEXT("UYVY"), 2, 1, 1, 4, 4, 0, 0, PF_UYVY },
|
|
{ TEXT("FloatRGB"), 1, 1, 1, 0, 3, 0, 1, PF_FloatRGB },
|
|
{ TEXT("FloatRGBA"), 1, 1, 1, 8, 4, 0, 1, PF_FloatRGBA },
|
|
{ TEXT("DepthStencil"), 1, 1, 1, 0, 1, 0, 0, PF_DepthStencil },
|
|
{ TEXT("ShadowDepth"), 1, 1, 1, 4, 1, 0, 0, PF_ShadowDepth },
|
|
{ TEXT("R32_FLOAT"), 1, 1, 1, 4, 1, 0, 1, PF_R32_FLOAT },
|
|
{ TEXT("G16R16"), 1, 1, 1, 4, 2, 0, 1, PF_G16R16 },
|
|
{ TEXT("G16R16F"), 1, 1, 1, 4, 2, 0, 1, PF_G16R16F },
|
|
{ TEXT("G16R16F_FILTER"), 1, 1, 1, 4, 2, 0, 1, PF_G16R16F_FILTER },
|
|
{ TEXT("G32R32F"), 1, 1, 1, 8, 2, 0, 1, PF_G32R32F },
|
|
{ TEXT("A2B10G10R10"), 1, 1, 1, 4, 4, 0, 1, PF_A2B10G10R10 },
|
|
{ TEXT("A16B16G16R16"), 1, 1, 1, 8, 4, 0, 1, PF_A16B16G16R16 },
|
|
{ TEXT("D24"), 1, 1, 1, 4, 1, 0, 1, PF_D24 },
|
|
{ TEXT("PF_R16F"), 1, 1, 1, 2, 1, 0, 1, PF_R16F },
|
|
{ TEXT("PF_R16F_FILTER"), 1, 1, 1, 2, 1, 0, 1, PF_R16F_FILTER },
|
|
{ TEXT("BC5"), 4, 4, 1, 16, 2, 0, 1, PF_BC5 },
|
|
{ TEXT("V8U8"), 1, 1, 1, 2, 2, 0, 1, PF_V8U8 },
|
|
{ TEXT("A1"), 1, 1, 1, 1, 1, 0, 0, PF_A1 },
|
|
{ TEXT("FloatR11G11B10"), 1, 1, 1, 0, 3, 0, 0, PF_FloatR11G11B10 },
|
|
{ TEXT("A8"), 1, 1, 1, 1, 1, 0, 1, PF_A8 },
|
|
{ TEXT("R32_UINT"), 1, 1, 1, 4, 1, 0, 1, PF_R32_UINT },
|
|
{ TEXT("R32_SINT"), 1, 1, 1, 4, 1, 0, 1, PF_R32_SINT },
|
|
|
|
// IOS Support
|
|
{ TEXT("PVRTC2"), 8, 4, 1, 8, 4, 0, 0, PF_PVRTC2 },
|
|
{ TEXT("PVRTC4"), 4, 4, 1, 8, 4, 0, 0, PF_PVRTC4 },
|
|
|
|
{ TEXT("R16_UINT"), 1, 1, 1, 2, 1, 0, 1, PF_R16_UINT },
|
|
{ TEXT("R16_SINT"), 1, 1, 1, 2, 1, 0, 1, PF_R16_SINT },
|
|
{ TEXT("R16G16B16A16_UINT"),1, 1, 1, 8, 4, 0, 1, PF_R16G16B16A16_UINT},
|
|
{ TEXT("R16G16B16A16_SINT"),1, 1, 1, 8, 4, 0, 1, PF_R16G16B16A16_SINT},
|
|
{ TEXT("R5G6B5_UNORM"), 1, 1, 1, 2, 3, 0, 1, PF_R5G6B5_UNORM },
|
|
{ TEXT("R8G8B8A8"), 1, 1, 1, 4, 4, 0, 1, PF_R8G8B8A8 },
|
|
{ TEXT("A8R8G8B8"), 1, 1, 1, 4, 4, 0, 1, PF_A8R8G8B8 },
|
|
{ TEXT("BC4"), 4, 4, 1, 8, 1, 0, 1, PF_BC4 },
|
|
{ TEXT("R8G8"), 1, 1, 1, 2, 2, 0, 1, PF_R8G8 },
|
|
|
|
{ TEXT("ATC_RGB"), 4, 4, 1, 8, 3, 0, 0, PF_ATC_RGB },
|
|
{ TEXT("ATC_RGBA_E"), 4, 4, 1, 16, 4, 0, 0, PF_ATC_RGBA_E },
|
|
{ TEXT("ATC_RGBA_I"), 4, 4, 1, 16, 4, 0, 0, PF_ATC_RGBA_I },
|
|
{ TEXT("X24_G8"), 1, 1, 1, 1, 1, 0, 0, PF_X24_G8 },
|
|
{ TEXT("ETC1"), 4, 4, 1, 8, 3, 0, 0, PF_ETC1 },
|
|
{ TEXT("ETC2_RGB"), 4, 4, 1, 8, 3, 0, 0, PF_ETC2_RGB },
|
|
{ TEXT("ETC2_RGBA"), 4, 4, 1, 16, 4, 0, 0, PF_ETC2_RGBA },
|
|
{ TEXT("PF_R32G32B32A32_UINT"),1, 1, 1, 16, 4, 0, 1, PF_R32G32B32A32_UINT},
|
|
{ TEXT("PF_R16G16_UINT"), 1, 1, 1, 4, 4, 0, 1, PF_R16G16_UINT},
|
|
|
|
// ASTC support
|
|
{ TEXT("ASTC_4x4"), 4, 4, 1, 16, 4, 0, 0, PF_ASTC_4x4 },
|
|
{ TEXT("ASTC_6x6"), 6, 6, 1, 16, 4, 0, 0, PF_ASTC_6x6 },
|
|
{ TEXT("ASTC_8x8"), 8, 8, 1, 16, 4, 0, 0, PF_ASTC_8x8 },
|
|
{ TEXT("ASTC_10x10"), 10, 10, 1, 16, 4, 0, 0, PF_ASTC_10x10 },
|
|
{ TEXT("ASTC_12x12"), 12, 12, 1, 16, 4, 0, 0, PF_ASTC_12x12 },
|
|
|
|
{ TEXT("BC6H"), 4, 4, 1, 16, 3, 0, 1, PF_BC6H },
|
|
{ TEXT("BC7"), 4, 4, 1, 16, 4, 0, 1, PF_BC7 },
|
|
{ TEXT("R8_UINT"), 1, 1, 1, 1, 1, 0, 1, PF_R8_UINT },
|
|
{ TEXT("L8"), 1, 1, 1, 1, 1, 0, 0, PF_L8 },
|
|
};
|
|
|
|
static struct FValidatePixelFormats
|
|
{
|
|
FValidatePixelFormats()
|
|
{
|
|
for (int32 X = 0; X < ARRAY_COUNT(GPixelFormats); ++X)
|
|
{
|
|
// Make sure GPixelFormats has an entry for every unreal format
|
|
check(X == GPixelFormats[X].UnrealFormat);
|
|
}
|
|
}
|
|
} ValidatePixelFormats;
|
|
|
|
//
|
|
// CalculateImageBytes
|
|
//
|
|
|
|
SIZE_T CalculateImageBytes(uint32 SizeX,uint32 SizeY,uint32 SizeZ,uint8 Format)
|
|
{
|
|
if ( Format == PF_A1 )
|
|
{
|
|
// The number of bytes needed to store all 1 bit pixels in a line is the width of the image divided by the number of bits in a byte
|
|
uint32 BytesPerLine = SizeX / 8;
|
|
// The number of actual bytes in a 1 bit image is the bytes per line of pixels times the number of lines
|
|
return sizeof(uint8) * BytesPerLine * SizeY;
|
|
}
|
|
else if( SizeZ > 0 )
|
|
{
|
|
return (SizeX / GPixelFormats[Format].BlockSizeX) * (SizeY / GPixelFormats[Format].BlockSizeY) * (SizeZ / GPixelFormats[Format].BlockSizeZ) * GPixelFormats[Format].BlockBytes;
|
|
}
|
|
else
|
|
{
|
|
return (SizeX / GPixelFormats[Format].BlockSizeX) * (SizeY / GPixelFormats[Format].BlockSizeY) * GPixelFormats[Format].BlockBytes;
|
|
}
|
|
}
|
|
|
|
//
|
|
// FWhiteTexture implementation
|
|
//
|
|
|
|
/**
|
|
* A solid-colored 1x1 texture.
|
|
*/
|
|
template <int32 R, int32 G, int32 B, int32 A>
|
|
class FColoredTexture : public FTexture
|
|
{
|
|
public:
|
|
// FResource interface.
|
|
virtual void InitRHI() override
|
|
{
|
|
// Create the texture RHI.
|
|
FRHIResourceCreateInfo CreateInfo;
|
|
FTexture2DRHIRef Texture2D = RHICreateTexture2D(1, 1, PF_B8G8R8A8, 1, 1, TexCreate_ShaderResource, CreateInfo);
|
|
TextureRHI = Texture2D;
|
|
|
|
// Write the contents of the texture.
|
|
uint32 DestStride;
|
|
FColor* DestBuffer = (FColor*)RHILockTexture2D(Texture2D, 0, RLM_WriteOnly, DestStride, false);
|
|
*DestBuffer = FColor(R, G, B, A);
|
|
RHIUnlockTexture2D(Texture2D, 0, false);
|
|
|
|
// Create the sampler state RHI resource.
|
|
FSamplerStateInitializerRHI SamplerStateInitializer(SF_Point,AM_Wrap,AM_Wrap,AM_Wrap);
|
|
SamplerStateRHI = RHICreateSamplerState(SamplerStateInitializer);
|
|
}
|
|
|
|
/** Returns the width of the texture in pixels. */
|
|
virtual uint32 GetSizeX() const override
|
|
{
|
|
return 1;
|
|
}
|
|
|
|
/** Returns the height of the texture in pixels. */
|
|
virtual uint32 GetSizeY() const override
|
|
{
|
|
return 1;
|
|
}
|
|
};
|
|
|
|
FTexture* GWhiteTexture = new TGlobalResource<FColoredTexture<255,255,255,255> >;
|
|
FTexture* GBlackTexture = new TGlobalResource<FColoredTexture<0,0,0,255> >;
|
|
|
|
/**
|
|
* Bulk data interface for providing a single black color used to initialize a
|
|
* volume texture.
|
|
*/
|
|
class FBlackVolumeTextureResourceBulkDataInterface : public FResourceBulkDataInterface
|
|
{
|
|
public:
|
|
|
|
/** Default constructor. */
|
|
FBlackVolumeTextureResourceBulkDataInterface()
|
|
: Color(0)
|
|
{
|
|
}
|
|
|
|
/**
|
|
* Returns a pointer to the bulk data.
|
|
*/
|
|
virtual const void* GetResourceBulkData() const override
|
|
{
|
|
return &Color;
|
|
}
|
|
|
|
/**
|
|
* @return size of resource memory
|
|
*/
|
|
virtual uint32 GetResourceBulkDataSize() const override
|
|
{
|
|
return sizeof(Color);
|
|
}
|
|
|
|
/**
|
|
* Free memory after it has been used to initialize RHI resource
|
|
*/
|
|
virtual void Discard() override
|
|
{
|
|
}
|
|
|
|
private:
|
|
|
|
/** Storage for the color. */
|
|
FColor Color;
|
|
};
|
|
|
|
/**
|
|
* A class representing a 1x1x1 black volume texture.
|
|
*/
|
|
class FBlackVolumeTexture : public FTexture
|
|
{
|
|
public:
|
|
|
|
/**
|
|
* Initialize RHI resources.
|
|
*/
|
|
virtual void InitRHI() override
|
|
{
|
|
if (GSupportsTexture3D)
|
|
{
|
|
// Create the texture.
|
|
FBlackVolumeTextureResourceBulkDataInterface BlackTextureBulkData;
|
|
FRHIResourceCreateInfo CreateInfo(&BlackTextureBulkData);
|
|
FTexture3DRHIRef Texture3D = RHICreateTexture3D(1,1,1,PF_B8G8R8A8,1,TexCreate_ShaderResource,CreateInfo);
|
|
TextureRHI = Texture3D;
|
|
|
|
// Create the sampler state.
|
|
FSamplerStateInitializerRHI SamplerStateInitializer(SF_Point,AM_Wrap,AM_Wrap,AM_Wrap);
|
|
SamplerStateRHI = RHICreateSamplerState(SamplerStateInitializer);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Return the size of the texture in the X dimension.
|
|
*/
|
|
virtual uint32 GetSizeX() const override
|
|
{
|
|
return 1;
|
|
}
|
|
|
|
/**
|
|
* Return the size of the texture in the Y dimension.
|
|
*/
|
|
virtual uint32 GetSizeY() const override
|
|
{
|
|
return 1;
|
|
}
|
|
};
|
|
|
|
/** Global black volume texture resource. */
|
|
FTexture* GBlackVolumeTexture = new TGlobalResource<FBlackVolumeTexture>();
|
|
|
|
class FBlackArrayTexture : public FTexture
|
|
{
|
|
public:
|
|
// FResource interface.
|
|
virtual void InitRHI() override
|
|
{
|
|
if (GetFeatureLevel() >= ERHIFeatureLevel::SM4)
|
|
{
|
|
// Create the texture RHI.
|
|
FBlackVolumeTextureResourceBulkDataInterface BlackTextureBulkData;
|
|
FRHIResourceCreateInfo CreateInfo(&BlackTextureBulkData);
|
|
FTexture2DArrayRHIRef TextureArray = RHICreateTexture2DArray(1, 1, 1, PF_B8G8R8A8, 1, TexCreate_ShaderResource, CreateInfo);
|
|
TextureRHI = TextureArray;
|
|
|
|
// Create the sampler state RHI resource.
|
|
FSamplerStateInitializerRHI SamplerStateInitializer(SF_Point,AM_Wrap,AM_Wrap,AM_Wrap);
|
|
SamplerStateRHI = RHICreateSamplerState(SamplerStateInitializer);
|
|
}
|
|
}
|
|
|
|
/** Returns the width of the texture in pixels. */
|
|
virtual uint32 GetSizeX() const override
|
|
{
|
|
return 1;
|
|
}
|
|
|
|
/** Returns the height of the texture in pixels. */
|
|
virtual uint32 GetSizeY() const override
|
|
{
|
|
return 1;
|
|
}
|
|
};
|
|
|
|
FTexture* GBlackArrayTexture = new TGlobalResource<FBlackArrayTexture>;
|
|
|
|
//
|
|
// FMipColorTexture implementation
|
|
//
|
|
|
|
/**
|
|
* A texture that has a different solid color in each mip-level
|
|
*/
|
|
class FMipColorTexture : public FTexture
|
|
{
|
|
public:
|
|
enum
|
|
{
|
|
NumMips = 12
|
|
};
|
|
static const FColor MipColors[NumMips];
|
|
|
|
// FResource interface.
|
|
virtual void InitRHI() override
|
|
{
|
|
// Create the texture RHI.
|
|
int32 TextureSize = 1 << (NumMips - 1);
|
|
FRHIResourceCreateInfo CreateInfo;
|
|
FTexture2DRHIRef Texture2D = RHICreateTexture2D(TextureSize,TextureSize,PF_B8G8R8A8,NumMips,1,TexCreate_ShaderResource,CreateInfo);
|
|
TextureRHI = Texture2D;
|
|
|
|
// Write the contents of the texture.
|
|
uint32 DestStride;
|
|
int32 Size = TextureSize;
|
|
for ( int32 MipIndex=0; MipIndex < NumMips; ++MipIndex )
|
|
{
|
|
FColor* DestBuffer = (FColor*)RHILockTexture2D(Texture2D, MipIndex, RLM_WriteOnly, DestStride, false);
|
|
for ( int32 Y=0; Y < Size; ++Y )
|
|
{
|
|
for ( int32 X=0; X < Size; ++X )
|
|
{
|
|
DestBuffer[X] = MipColors[NumMips - 1 - MipIndex];
|
|
}
|
|
DestBuffer += DestStride / sizeof(FColor);
|
|
}
|
|
RHIUnlockTexture2D(Texture2D, MipIndex, false);
|
|
Size >>= 1;
|
|
}
|
|
|
|
// Create the sampler state RHI resource.
|
|
FSamplerStateInitializerRHI SamplerStateInitializer(SF_Point,AM_Wrap,AM_Wrap,AM_Wrap);
|
|
SamplerStateRHI = RHICreateSamplerState(SamplerStateInitializer);
|
|
}
|
|
|
|
/** Returns the width of the texture in pixels. */
|
|
virtual uint32 GetSizeX() const override
|
|
{
|
|
int32 TextureSize = 1 << (NumMips - 1);
|
|
return TextureSize;
|
|
}
|
|
|
|
/** Returns the height of the texture in pixels. */
|
|
// PVS-Studio notices that the implementation of GetSizeX is identical to this one
|
|
// and warns us. In this case, it is intentional, so we disable the warning:
|
|
virtual uint32 GetSizeY() const override //-V524
|
|
{
|
|
int32 TextureSize = 1 << (NumMips - 1);
|
|
return TextureSize;
|
|
}
|
|
};
|
|
|
|
const FColor FMipColorTexture::MipColors[NumMips] =
|
|
{
|
|
FColor( 80, 80, 80, 0 ), // Mip 0: 1x1 (dark grey)
|
|
FColor( 200, 200, 200, 0 ), // Mip 1: 2x2 (light grey)
|
|
FColor( 200, 200, 0, 0 ), // Mip 2: 4x4 (medium yellow)
|
|
FColor( 255, 255, 0, 0 ), // Mip 3: 8x8 (yellow)
|
|
FColor( 160, 255, 40, 0 ), // Mip 4: 16x16 (light green)
|
|
FColor( 0, 255, 0, 0 ), // Mip 5: 32x32 (green)
|
|
FColor( 0, 255, 200, 0 ), // Mip 6: 64x64 (cyan)
|
|
FColor( 0, 170, 170, 0 ), // Mip 7: 128x128 (light blue)
|
|
FColor( 60, 60, 255, 0 ), // Mip 8: 256x256 (dark blue)
|
|
FColor( 255, 0, 255, 0 ), // Mip 9: 512x512 (pink)
|
|
FColor( 255, 0, 0, 0 ), // Mip 10: 1024x1024 (red)
|
|
FColor( 255, 130, 0, 0 ), // Mip 11: 2048x2048 (orange)
|
|
};
|
|
|
|
RENDERCORE_API FTexture* GMipColorTexture = new FMipColorTexture;
|
|
RENDERCORE_API int32 GMipColorTextureMipLevels = FMipColorTexture::NumMips;
|
|
|
|
// 4: 8x8 cubemap resolution, shader needs to use the same value as preprocessing
|
|
RENDERCORE_API const uint32 GDiffuseConvolveMipLevel = 4;
|
|
|
|
//
|
|
// FWhiteTextureCube implementation
|
|
//
|
|
|
|
/** A solid color cube texture. */
|
|
class FSolidColorTextureCube : public FTexture
|
|
{
|
|
public:
|
|
FSolidColorTextureCube(const FColor& InColor, EPixelFormat InPixelFormat = PF_B8G8R8A8)
|
|
: Color(InColor)
|
|
, PixelFormat(InPixelFormat)
|
|
{}
|
|
|
|
// FRenderResource interface.
|
|
virtual void InitRHI() override
|
|
{
|
|
// Create the texture RHI.
|
|
FRHIResourceCreateInfo CreateInfo;
|
|
FTextureCubeRHIRef TextureCube = RHICreateTextureCube(1, PixelFormat,1,0,CreateInfo);
|
|
TextureRHI = TextureCube;
|
|
|
|
// Write the contents of the texture.
|
|
for(uint32 FaceIndex = 0;FaceIndex < 6;FaceIndex++)
|
|
{
|
|
uint32 DestStride;
|
|
FColor* DestBuffer = (FColor*)RHILockTextureCubeFace(TextureCube, FaceIndex, 0, 0, RLM_WriteOnly, DestStride, false);
|
|
*DestBuffer = Color;
|
|
RHIUnlockTextureCubeFace(TextureCube, FaceIndex, 0, 0, false);
|
|
}
|
|
|
|
// Create the sampler state RHI resource.
|
|
FSamplerStateInitializerRHI SamplerStateInitializer(SF_Point,AM_Wrap,AM_Wrap,AM_Wrap);
|
|
SamplerStateRHI = RHICreateSamplerState(SamplerStateInitializer);
|
|
}
|
|
|
|
/** Returns the width of the texture in pixels. */
|
|
virtual uint32 GetSizeX() const override
|
|
{
|
|
return 1;
|
|
}
|
|
|
|
/** Returns the height of the texture in pixels. */
|
|
virtual uint32 GetSizeY() const override
|
|
{
|
|
return 1;
|
|
}
|
|
|
|
private:
|
|
FColor Color;
|
|
EPixelFormat PixelFormat;
|
|
};
|
|
|
|
/** A white cube texture. */
|
|
class FWhiteTextureCube : public FSolidColorTextureCube
|
|
{
|
|
public:
|
|
FWhiteTextureCube() : FSolidColorTextureCube(FColor::White) {}
|
|
};
|
|
FTexture* GWhiteTextureCube = new TGlobalResource<FWhiteTextureCube>;
|
|
|
|
/** A black cube texture. */
|
|
class FBlackTextureCube : public FSolidColorTextureCube
|
|
{
|
|
public:
|
|
FBlackTextureCube(): FSolidColorTextureCube(FColor::Black) {}
|
|
};
|
|
FTexture* GBlackTextureCube = new TGlobalResource<FBlackTextureCube>;
|
|
|
|
/** A black cube texture. */
|
|
class FBlackTextureDepthCube : public FSolidColorTextureCube
|
|
{
|
|
public:
|
|
FBlackTextureDepthCube() : FSolidColorTextureCube(FColor::Black, PF_ShadowDepth) {}
|
|
};
|
|
FTexture* GBlackTextureDepthCube = new TGlobalResource<FBlackTextureDepthCube>;
|
|
|
|
class FBlackCubeArrayTexture : public FTexture
|
|
{
|
|
public:
|
|
// FResource interface.
|
|
virtual void InitRHI() override
|
|
{
|
|
if (GetFeatureLevel() >= ERHIFeatureLevel::SM5)
|
|
{
|
|
// Create the texture RHI.
|
|
FRHIResourceCreateInfo CreateInfo;
|
|
FTextureCubeRHIRef TextureCubeArray = RHICreateTextureCubeArray(1,1,PF_B8G8R8A8,1,TexCreate_ShaderResource,CreateInfo);
|
|
TextureRHI = TextureCubeArray;
|
|
|
|
for(uint32 FaceIndex = 0;FaceIndex < 6;FaceIndex++)
|
|
{
|
|
uint32 DestStride;
|
|
FColor* DestBuffer = (FColor*)RHILockTextureCubeFace(TextureCubeArray, FaceIndex, 0, 0, RLM_WriteOnly, DestStride, false);
|
|
// Note: alpha is used by reflection environment to say how much of the foreground texture is visible, so 0 says it is completely invisible
|
|
*DestBuffer = FColor(0, 0, 0, 0);
|
|
RHIUnlockTextureCubeFace(TextureCubeArray, FaceIndex, 0, 0, false);
|
|
}
|
|
|
|
// Create the sampler state RHI resource.
|
|
FSamplerStateInitializerRHI SamplerStateInitializer(SF_Point,AM_Wrap,AM_Wrap,AM_Wrap);
|
|
SamplerStateRHI = RHICreateSamplerState(SamplerStateInitializer);
|
|
}
|
|
}
|
|
|
|
/** Returns the width of the texture in pixels. */
|
|
virtual uint32 GetSizeX() const override
|
|
{
|
|
return 1;
|
|
}
|
|
|
|
/** Returns the height of the texture in pixels. */
|
|
virtual uint32 GetSizeY() const override
|
|
{
|
|
return 1;
|
|
}
|
|
};
|
|
FTexture* GBlackCubeArrayTexture = new TGlobalResource<FBlackCubeArrayTexture>;
|
|
|
|
/*
|
|
3 XYZ packed in 4 bytes. (11:11:10 for X:Y:Z)
|
|
*/
|
|
|
|
/**
|
|
* operator FVector - unpacked to -1 to 1
|
|
*/
|
|
FPackedPosition::operator FVector() const
|
|
{
|
|
|
|
return FVector(Vector.X/1023.f, Vector.Y/1023.f, Vector.Z/511.f);
|
|
}
|
|
|
|
/**
|
|
* operator VectorRegister
|
|
*/
|
|
VectorRegister FPackedPosition::GetVectorRegister() const
|
|
{
|
|
FVector UnpackedVect = *this;
|
|
|
|
VectorRegister VectorToUnpack = VectorLoadFloat3_W0(&UnpackedVect);
|
|
|
|
return VectorToUnpack;
|
|
}
|
|
|
|
/**
|
|
* Pack this vector(-1 to 1 for XYZ) to 4 bytes XYZ(11:11:10)
|
|
*/
|
|
void FPackedPosition::Set( const FVector& InVector )
|
|
{
|
|
check (FMath::Abs<float>(InVector.X) <= 1.f && FMath::Abs<float>(InVector.Y) <= 1.f && FMath::Abs<float>(InVector.Z) <= 1.f);
|
|
|
|
#if !WITH_EDITORONLY_DATA
|
|
// This should not happen in Console - this should happen during Cooking in PC
|
|
check (false);
|
|
#else
|
|
// Too confusing to use .5f - wanted to use the last bit!
|
|
// Change to int for easier read
|
|
Vector.X = FMath::Clamp<int32>(FMath::TruncToInt(InVector.X * 1023.0f),-1023,1023);
|
|
Vector.Y = FMath::Clamp<int32>(FMath::TruncToInt(InVector.Y * 1023.0f),-1023,1023);
|
|
Vector.Z = FMath::Clamp<int32>(FMath::TruncToInt(InVector.Z * 511.0f),-511,511);
|
|
#endif
|
|
}
|
|
|
|
/**
|
|
* operator << serialize
|
|
*/
|
|
FArchive& operator<<(FArchive& Ar,FPackedPosition& N)
|
|
{
|
|
// Save N.Packed
|
|
return Ar << N.Packed;
|
|
}
|
|
|
|
void CalcMipMapExtent3D( uint32 TextureSizeX, uint32 TextureSizeY, uint32 TextureSizeZ, EPixelFormat Format, uint32 MipIndex, uint32& OutXExtent, uint32& OutYExtent, uint32& OutZExtent )
|
|
{
|
|
OutXExtent = FMath::Max<uint32>(TextureSizeX >> MipIndex, GPixelFormats[Format].BlockSizeX);
|
|
OutYExtent = FMath::Max<uint32>(TextureSizeY >> MipIndex, GPixelFormats[Format].BlockSizeY);
|
|
OutZExtent = FMath::Max<uint32>(TextureSizeZ >> MipIndex, GPixelFormats[Format].BlockSizeZ);
|
|
}
|
|
|
|
SIZE_T CalcTextureMipMapSize3D( uint32 TextureSizeX, uint32 TextureSizeY, uint32 TextureSizeZ, EPixelFormat Format, uint32 MipIndex )
|
|
{
|
|
uint32 XExtent;
|
|
uint32 YExtent;
|
|
uint32 ZExtent;
|
|
CalcMipMapExtent3D(TextureSizeX, TextureSizeY, TextureSizeZ, Format, MipIndex, XExtent, YExtent, ZExtent);
|
|
|
|
// Offset MipExtent to round up result
|
|
XExtent += GPixelFormats[Format].BlockSizeX - 1;
|
|
YExtent += GPixelFormats[Format].BlockSizeY - 1;
|
|
ZExtent += GPixelFormats[Format].BlockSizeZ - 1;
|
|
|
|
const uint32 XPitch = (XExtent / GPixelFormats[Format].BlockSizeX) * GPixelFormats[Format].BlockBytes;
|
|
const uint32 NumRows = YExtent / GPixelFormats[Format].BlockSizeY;
|
|
const uint32 NumLayers = ZExtent / GPixelFormats[Format].BlockSizeZ;
|
|
|
|
return NumLayers * NumRows * XPitch;
|
|
}
|
|
|
|
SIZE_T CalcTextureSize3D( uint32 SizeX, uint32 SizeY, uint32 SizeZ, EPixelFormat Format, uint32 MipCount )
|
|
{
|
|
SIZE_T Size = 0;
|
|
for ( uint32 MipIndex=0; MipIndex < MipCount; ++MipIndex )
|
|
{
|
|
Size += CalcTextureMipMapSize3D(SizeX,SizeY,SizeZ,Format,MipIndex);
|
|
}
|
|
return Size;
|
|
}
|
|
|
|
FIntPoint CalcMipMapExtent( uint32 TextureSizeX, uint32 TextureSizeY, EPixelFormat Format, uint32 MipIndex )
|
|
{
|
|
return FIntPoint(FMath::Max<uint32>(TextureSizeX >> MipIndex, GPixelFormats[Format].BlockSizeX), FMath::Max<uint32>(TextureSizeY >> MipIndex, GPixelFormats[Format].BlockSizeY));
|
|
}
|
|
|
|
SIZE_T CalcTextureMipWidthInBlocks(uint32 TextureSizeX, EPixelFormat Format, uint32 MipIndex)
|
|
{
|
|
const uint32 BlockSizeX = GPixelFormats[Format].BlockSizeX;
|
|
const uint32 WidthInTexels = FMath::Max<uint32>(TextureSizeX >> MipIndex, 1);
|
|
const uint32 WidthInBlocks = (WidthInTexels + BlockSizeX - 1) / BlockSizeX;
|
|
return WidthInBlocks;
|
|
}
|
|
|
|
SIZE_T CalcTextureMipHeightInBlocks(uint32 TextureSizeY, EPixelFormat Format, uint32 MipIndex)
|
|
{
|
|
const uint32 BlockSizeY = GPixelFormats[Format].BlockSizeY;
|
|
const uint32 HeightInTexels = FMath::Max<uint32>(TextureSizeY >> MipIndex, 1);
|
|
const uint32 HeightInBlocks = (HeightInTexels + BlockSizeY - 1) / BlockSizeY;
|
|
return HeightInBlocks;
|
|
}
|
|
|
|
SIZE_T CalcTextureMipMapSize( uint32 TextureSizeX, uint32 TextureSizeY, EPixelFormat Format, uint32 MipIndex )
|
|
{
|
|
const uint32 WidthInBlocks = CalcTextureMipWidthInBlocks(TextureSizeX, Format, MipIndex);
|
|
const uint32 HeightInBlocks = CalcTextureMipHeightInBlocks(TextureSizeY, Format, MipIndex);
|
|
return WidthInBlocks * HeightInBlocks * GPixelFormats[Format].BlockBytes;
|
|
}
|
|
|
|
SIZE_T CalcTextureSize( uint32 SizeX, uint32 SizeY, EPixelFormat Format, uint32 MipCount )
|
|
{
|
|
SIZE_T Size = 0;
|
|
for ( uint32 MipIndex=0; MipIndex < MipCount; ++MipIndex )
|
|
{
|
|
Size += CalcTextureMipMapSize(SizeX,SizeY,Format,MipIndex);
|
|
}
|
|
return Size;
|
|
}
|
|
|
|
void CopyTextureData2D(const void* Source,void* Dest,uint32 SizeY,EPixelFormat Format,uint32 SourceStride,uint32 DestStride)
|
|
{
|
|
const uint32 BlockSizeY = GPixelFormats[Format].BlockSizeY;
|
|
const uint32 NumBlocksY = (SizeY + BlockSizeY - 1) / BlockSizeY;
|
|
|
|
// a DestStride of 0 means to use the SourceStride
|
|
if(SourceStride == DestStride || DestStride == 0)
|
|
{
|
|
// If the source and destination have the same stride, copy the data in one block.
|
|
FMemory::Memcpy(Dest,Source,NumBlocksY * SourceStride);
|
|
}
|
|
else
|
|
{
|
|
// If the source and destination have different strides, copy each row of blocks separately.
|
|
const uint32 NumBytesPerRow = FMath::Min<uint32>(SourceStride, DestStride);
|
|
for(uint32 BlockY = 0;BlockY < NumBlocksY;++BlockY)
|
|
{
|
|
FMemory::Memcpy(
|
|
(uint8*)Dest + DestStride * BlockY,
|
|
(uint8*)Source + SourceStride * BlockY,
|
|
NumBytesPerRow
|
|
);
|
|
}
|
|
}
|
|
}
|
|
|
|
/** Helper functions for text output of texture properties... */
|
|
#ifndef CASE_ENUM_TO_TEXT
|
|
#define CASE_ENUM_TO_TEXT(txt) case txt: return TEXT(#txt);
|
|
#endif
|
|
|
|
#ifndef TEXT_TO_ENUM
|
|
#define TEXT_TO_ENUM(eVal, txt) if (FCString::Stricmp(TEXT(#eVal), txt) == 0) return eVal;
|
|
#endif
|
|
|
|
const TCHAR* GetPixelFormatString(EPixelFormat InPixelFormat)
|
|
{
|
|
switch (InPixelFormat)
|
|
{
|
|
FOREACH_ENUM_EPIXELFORMAT(CASE_ENUM_TO_TEXT)
|
|
default:
|
|
return TEXT("PF_Unknown");
|
|
}
|
|
}
|
|
|
|
EPixelFormat GetPixelFormatFromString(const TCHAR* InPixelFormatStr)
|
|
{
|
|
#define TEXT_TO_PIXELFORMAT(f) TEXT_TO_ENUM(f, InPixelFormatStr);
|
|
FOREACH_ENUM_EPIXELFORMAT(TEXT_TO_PIXELFORMAT)
|
|
#undef TEXT_TO_PIXELFORMAT
|
|
return PF_Unknown;
|
|
}
|
|
|
|
|
|
const TCHAR* GetCubeFaceName(ECubeFace Face)
|
|
{
|
|
switch(Face)
|
|
{
|
|
case CubeFace_PosX:
|
|
return TEXT("PosX");
|
|
case CubeFace_NegX:
|
|
return TEXT("NegX");
|
|
case CubeFace_PosY:
|
|
return TEXT("PosY");
|
|
case CubeFace_NegY:
|
|
return TEXT("NegY");
|
|
case CubeFace_PosZ:
|
|
return TEXT("PosZ");
|
|
case CubeFace_NegZ:
|
|
return TEXT("NegZ");
|
|
default:
|
|
return TEXT("");
|
|
}
|
|
}
|
|
|
|
ECubeFace GetCubeFaceFromName(const FString& Name)
|
|
{
|
|
// not fast but doesn't have to be
|
|
if(Name.EndsWith(TEXT("PosX")))
|
|
{
|
|
return CubeFace_PosX;
|
|
}
|
|
else if(Name.EndsWith(TEXT("NegX")))
|
|
{
|
|
return CubeFace_NegX;
|
|
}
|
|
else if(Name.EndsWith(TEXT("PosY")))
|
|
{
|
|
return CubeFace_PosY;
|
|
}
|
|
else if(Name.EndsWith(TEXT("NegY")))
|
|
{
|
|
return CubeFace_NegY;
|
|
}
|
|
else if(Name.EndsWith(TEXT("PosZ")))
|
|
{
|
|
return CubeFace_PosZ;
|
|
}
|
|
else if(Name.EndsWith(TEXT("NegZ")))
|
|
{
|
|
return CubeFace_NegZ;
|
|
}
|
|
|
|
return CubeFace_MAX;
|
|
}
|
|
|
|
class FVector4VertexDeclaration : public FRenderResource
|
|
{
|
|
public:
|
|
FVertexDeclarationRHIRef VertexDeclarationRHI;
|
|
virtual void InitRHI() override
|
|
{
|
|
FVertexDeclarationElementList Elements;
|
|
Elements.Add(FVertexElement(0, 0, VET_Float4, 0, sizeof(FVector4)));
|
|
VertexDeclarationRHI = RHICreateVertexDeclaration(Elements);
|
|
}
|
|
virtual void ReleaseRHI() override
|
|
{
|
|
VertexDeclarationRHI.SafeRelease();
|
|
}
|
|
};
|
|
|
|
TGlobalResource<FVector4VertexDeclaration> GVector4VertexDeclaration;
|
|
|
|
RENDERCORE_API FVertexDeclarationRHIRef& GetVertexDeclarationFVector4()
|
|
{
|
|
return GVector4VertexDeclaration.VertexDeclarationRHI;
|
|
}
|
|
|
|
class FVector3VertexDeclaration : public FRenderResource
|
|
{
|
|
public:
|
|
FVertexDeclarationRHIRef VertexDeclarationRHI;
|
|
virtual void InitRHI() override
|
|
{
|
|
FVertexDeclarationElementList Elements;
|
|
Elements.Add(FVertexElement(0, 0, VET_Float3, 0, sizeof(FVector)));
|
|
VertexDeclarationRHI = RHICreateVertexDeclaration(Elements);
|
|
}
|
|
virtual void ReleaseRHI() override
|
|
{
|
|
VertexDeclarationRHI.SafeRelease();
|
|
}
|
|
};
|
|
|
|
TGlobalResource<FVector3VertexDeclaration> GVector3VertexDeclaration;
|
|
|
|
RENDERCORE_API FVertexDeclarationRHIRef& GetVertexDeclarationFVector3()
|
|
{
|
|
return GVector3VertexDeclaration.VertexDeclarationRHI;
|
|
}
|
|
|
|
RENDERCORE_API bool PlatformSupportsSimpleForwardShading(EShaderPlatform Platform)
|
|
{
|
|
static const auto SupportSimpleForwardShadingCVar = IConsoleManager::Get().FindTConsoleVariableDataInt(TEXT("r.SupportSimpleForwardShading"));
|
|
// Scalability feature only needed / used on PC
|
|
return IsPCPlatform(Platform) && SupportSimpleForwardShadingCVar->GetValueOnAnyThread() != 0;
|
|
}
|
|
|
|
RENDERCORE_API bool IsSimpleForwardShadingEnabled(EShaderPlatform Platform)
|
|
{
|
|
static const auto CVar = IConsoleManager::Get().FindTConsoleVariableDataInt(TEXT("r.SimpleForwardShading"));
|
|
return CVar->GetValueOnAnyThread() != 0 && PlatformSupportsSimpleForwardShading(Platform);
|
|
}
|
|
|
|
RENDERCORE_API bool IsForwardShadingEnabled(ERHIFeatureLevel::Type FeatureLevel)
|
|
{
|
|
static const auto CVar = IConsoleManager::Get().FindTConsoleVariableDataInt(TEXT("r.ForwardShading"));
|
|
return CVar->GetValueOnAnyThread() != 0
|
|
// Culling uses compute shader
|
|
&& FeatureLevel >= ERHIFeatureLevel::SM5;
|
|
}
|
|
|
|
class FUnitCubeVertexBuffer : public FVertexBuffer
|
|
{
|
|
public:
|
|
/**
|
|
* Initialize the RHI for this rendering resource
|
|
*/
|
|
void InitRHI() override
|
|
{
|
|
const int32 NumVerts = 8;
|
|
TResourceArray<FVector4, VERTEXBUFFER_ALIGNMENT> Verts;
|
|
Verts.SetNumUninitialized(NumVerts);
|
|
|
|
for (uint32 Z = 0; Z < 2; Z++)
|
|
{
|
|
for (uint32 Y = 0; Y < 2; Y++)
|
|
{
|
|
for (uint32 X = 0; X < 2; X++)
|
|
{
|
|
const FVector4 Vertex = FVector4(
|
|
(X ? -1 : 1),
|
|
(Y ? -1 : 1),
|
|
(Z ? -1 : 1),
|
|
1.0f
|
|
);
|
|
|
|
Verts[GetCubeVertexIndex(X, Y, Z)] = Vertex;
|
|
}
|
|
}
|
|
}
|
|
|
|
uint32 Size = Verts.GetResourceDataSize();
|
|
|
|
// Create vertex buffer. Fill buffer with initial data upon creation
|
|
FRHIResourceCreateInfo CreateInfo(&Verts);
|
|
VertexBufferRHI = RHICreateVertexBuffer(Size, BUF_Static, CreateInfo);
|
|
}
|
|
};
|
|
|
|
class FUnitCubeIndexBuffer : public FIndexBuffer
|
|
{
|
|
public:
|
|
/**
|
|
* Initialize the RHI for this rendering resource
|
|
*/
|
|
void InitRHI() override
|
|
{
|
|
TResourceArray<uint16, INDEXBUFFER_ALIGNMENT> Indices;
|
|
|
|
int32 NumIndices = ARRAY_COUNT(GCubeIndices);
|
|
Indices.AddUninitialized(NumIndices);
|
|
FMemory::Memcpy(Indices.GetData(), GCubeIndices, NumIndices * sizeof(uint16));
|
|
|
|
const uint32 Size = Indices.GetResourceDataSize();
|
|
const uint32 Stride = sizeof(uint16);
|
|
|
|
// Create index buffer. Fill buffer with initial data upon creation
|
|
FRHIResourceCreateInfo CreateInfo(&Indices);
|
|
IndexBufferRHI = RHICreateIndexBuffer(Stride, Size, BUF_Static, CreateInfo);
|
|
}
|
|
};
|
|
|
|
static TGlobalResource<FUnitCubeVertexBuffer> GUnitCubeVertexBuffer;
|
|
static TGlobalResource<FUnitCubeIndexBuffer> GUnitCubeIndexBuffer;
|
|
|
|
RENDERCORE_API FVertexBufferRHIRef& GetUnitCubeVertexBuffer()
|
|
{
|
|
return GUnitCubeVertexBuffer.VertexBufferRHI;
|
|
}
|
|
|
|
RENDERCORE_API FIndexBufferRHIRef& GetUnitCubeIndexBuffer()
|
|
{
|
|
return GUnitCubeIndexBuffer.IndexBufferRHI;
|
|
}
|
|
|
|
RENDERCORE_API void QuantizeSceneBufferSize(int32& InOutBufferSizeX, int32& InOutBufferSizeY)
|
|
{
|
|
// Ensure sizes are dividable by DividableBy to get post processing effects with lower resolution working well
|
|
const uint32 DividableBy = 4;
|
|
|
|
const uint32 Mask = ~(DividableBy - 1);
|
|
InOutBufferSizeX = (InOutBufferSizeX + DividableBy - 1) & Mask;
|
|
InOutBufferSizeY = (InOutBufferSizeY + DividableBy - 1) & Mask;
|
|
} |