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 #rb none ========================== MAJOR FEATURES + CHANGES ========================== Change 3050254 on 2016/07/14 by Marc.Audy Merging //UE4/Dev-Main to Dev-Framework (//UE4/Dev-Framework) @ 3049614 Change 3136629 on 2016/09/22 by Marc.Audy bye bye auto Change 3136631 on 2016/09/22 by Marc.Audy Allow objects to be marked as duplicate transient or non PIE duplicate transient ChildActors are not marked consistent with the property that references them as text export transient and non PIE duplicate transient #jira UE-35680 Change 3136636 on 2016/09/22 by Marc.Audy ParticleSystem and Audio Components now route Activate/Deactivate events to blueprints Component Activate/Deactivate events now provide component as a property #jira UE-35191 Change 3136640 on 2016/09/22 by Marc.Audy Expose bReplicates to blueprint component properties #jira UE-34433 Change 3136709 on 2016/09/22 by Ori.Cohen Fix GetBodyInstance returning incorrect bodies when welded kinematics are attached. #JIRA UE-36234 Change 3136710 on 2016/09/22 by Ori.Cohen Fix defer actors not working when the physics scene is simulating. We now flush when the scene is not simulating, as well as a lazy flush that goes through the slow path when needed. This allows us to batch multiple components together. #JIRA UE-35899 Change 3136770 on 2016/09/22 by Marc.Audy Fix compile error Change 3136854 on 2016/09/22 by Marc.Audy Sprite components need to be text export transient #jira UE-36064 Change 3136926 on 2016/09/22 by Ori.Cohen Fix ensure when skeletal mesh bodies have no collision. Change 3137054 on 2016/09/22 by Aaron.McLeran PR #2628: Fix UAudioComponent SubtitlePriority not being initialised (Contributed by alanedwardes) Change 3137058 on 2016/09/22 by Aaron.McLeran PR #2562: ReadCompressedInfo calculates duration for ADPCM audio (Contributed by derekvanvliet) Change 3137060 on 2016/09/22 by Aaron.McLeran UE-36336 Fixing A3D for mono/2D sounds - Making it so if A3D is being loaded but not enabled, we can not have reverb on 2D sounds - Fixing A3D mono sources from failing after a time Change 3137066 on 2016/09/22 by Aaron.McLeran Checking in Ngs2.Build.cs with A3D and USING_A3D set to 0 Change 3137098 on 2016/09/22 by dan.reynolds AEOverview Update: EQ Map, Reverb Map plus improvements on Main array cleanup process. Change 3137132 on 2016/09/22 by Aaron.McLeran PR #2789: Fixed signature of FActiveSound::GetIntParameter (Contributed by Laurie-Hedge) Change 3137175 on 2016/09/22 by Aaron.McLeran Fixing compile error with PhysXCollision.cpp from CL 3136710 Change 3137540 on 2016/09/23 by Thomas.Sarkanen Fixed crash when generating LODs automatically for skeletal meshes Quadric error reduction does not support skeletal meshes, so fails. Client code assumes that it cannot fail so crashed. This guards against immediatly assuming that LODs are valid after simplification. #jira UE-36253 - Crash applying LOD changes in Persona Change 3137720 on 2016/09/23 by Thomas.Sarkanen Changed asset shortcut bar to display asset names & reworked padding #jira UE-36347 - Anim asset shortcut bar has difficult to read/cut-off text Change 3137761 on 2016/09/23 by Martin.Wilson Fix typo in root motion from everything accumulation code Change3137877on 2016/09/23 by Thomas.Sarkanen Fixed undo/redo forcing skeletal meshes into t-pose Re-populated AnimationData in InitAnim for UDebugSkelMeshComponent. #jira UE-35579 - If you undo an animation change to any animation asset (for single preview), the playback controls will no longer function Change 3137885 on 2016/09/23 by Benn.Gallagher Fixed APEX clothing disappearing when time dilation results in a dt of 0. After simulating an actor with 0 APEX will fill positions and normals with NaNs, causing the disappearance. The fix in this case is to not schedule the evaluation task if we're not wanting to do any work. The simulation then freezes as we would expect. #jira UE-35151 Change 3137888 on 2016/09/23 by Benn.Gallagher Fixed transition nodes being able to be pasted or duplicated without 2 valid pin links #jira UE-24860 Change 3137889 on 2016/09/23 by Benn.Gallagher Fixed transform and widget inconsistencies in IK edit mode #jira UE-20628 Change 3137890 on 2016/09/23 by Jurre.deBaare Alembic Cached Geometry Does Not Display in Stand Alone Game #fix required to force load the GeometryCache module during runtime #jira UE-36187 Change3137892on 2016/09/23 by Jurre.deBaare Geometry cache playback should work in sequencer #fix add Interp UProperty tag to specific properties used for playing back the cache, future fix is having same approach as skeletal mesh animation for sequencer (depends on needs, -> skeletal mesh import has better compression anyway) #jira UE-35447 Change 3137893 on 2016/09/23 by Jurre.deBaare Alembic Cache Importer option for Hard Edge Angle Threshold does not work for objects with no normals #fix adhere to the assumed 'standard' no normals in ABC file means completely smooth normals throughout the sequence #jira UE-35091 Change 3137894 on 2016/09/23 by Jurre.deBaare Importing an Alembic File While mesh Distance Fields are Enabled Crashes Editor #fix Needed to save the raw mesh before building the mesh to ensure a LOD resource was created #misc added a new check + message in case this occurs again #jira UE-36059 Change 3137938 on 2016/09/23 by Jurre.deBaare Alembic Importing with Incorrect UV's #fix adding option for flipping UVs on import #jira UE-36190 Alembic import axis not aligned correctly #fix also added option to specify scale and rotation to be applied during import (with preset for Maya and Max) #jira UE-35510 Change 3137949 on 2016/09/23 by Jurre.deBaare Frame range importing causes confusion during Alembic importing #fix this required storing information per Alembic object at which frame index it actual has stored frames, using this data we can determine which frames are empty, and at which frame there is data. This allows us to skip empty frames if we want to import data-only frames, or to import all frames in the sequence including empty (pre-roll) frames. #misc changed settings UI listview layout (extra columns and resized old ones) #jira UE-35498 Change 3137994 on 2016/09/23 by Martin.Wilson Fix for creating an empty state when dragging a montage into a state machine graph #jira UE-33371 Change 3138103 on 2016/09/23 by Aaron.McLeran UE-36312 Fixing sound node distance cross fade for case of looping sounds Change 3138104 on 2016/09/23 by Aaron.McLeran UE-35392 Copy pasting local node into separate project crashes the engine Change 3138224 on 2016/09/23 by Aaron.McLeran UE-36312 Fixing sound node distance cross fade for case of looping sounds - Adding a check for wave instance count to account for virtualized sounds (one-shots) Change 3138666 on 2016/09/23 by Ben.Zeigler #UEFW-204 Add more comprehensive gameplay tag tests Fix issue with HasTag(Tag, IncludeParent, IncludeParent) revealed by tests, this was not returning true correctly in some cases. This use case is weird and will be deprecated soon Change 3138779 on 2016/09/23 by Marc.Audy Get rid of pointless casts Change 3138782 on 2016/09/23 by Marc.Audy remove some GWorlds Change 3139701 on 2016/09/26 by Jurre.deBaare Assert failed on GemetryCache for PS4 package #fix add GeometryCache reference in engine build.cs and fix the serialization of geometry cache files #jira UE-36392 Change 3139704 on 2016/09/26 by Jurre.deBaare Fix for -1 begin frame #fix do the max as an signed int, to make sure we don't wrap around Change 3139748 on 2016/09/26 by Benn.Gallagher PR #2784: Make sure that SceneScratchBufferSize is a multiple of 16K as requested by PhysX (Contributed by DenizPiri) Moved the definition of the boundary to a FPhysScene class static Changed comments on original user settings property to communicate the fact that the value is now rounded to the next 16K boundary #jira UE-35736 Change 3139903 on 2016/09/26 by Benn.Gallagher Fixed exposing subinstance pins stomping over class defaults and setting to uninitialized values #jira UE-34366 Change 3140409 on 2016/09/26 by Lukasz.Furman fixed uninitialized configs of gameplay debugger copy of CL# 3140399 Change 3140516 on 2016/09/26 by dan.reynolds AEOverview Map Update - Ambient Zone + Focus Test Change 3140526 on 2016/09/26 by Jon.Nabozny #rn Fixed CanJump inconsistencies with previous versions. Deferred JumpCurrentCount increment until after jump, made bWasJumping a member variable, and updated how jump count and hold time were compared in CanJump. #jira UE-35524, UE-35582 Change 3140745 on 2016/09/26 by dan.reynolds AEOverview Test Map Update + Occlusion Test Change 3140839 on 2016/09/26 by dan.reynolds AEOverview - minor updates Change 3141101 on 2016/09/27 by Thomas.Sarkanen Preview scene worlds now render correctly Split "Preview" type into "EditorPreview" (the default) and "GamePreview". Deprecated the old "Preview" world type (but kept its index). In-game hidden flags now apply to GamePreview, but not EditorPreview worlds. Deprecated old bHack_Force_UsesGameHiddenFlags_True boolean. GamePReview now serves this purpose. Fixed up UT cases where this was being used. FPreviewScenes now use the editor mode by default, but can be set to non-editor if needed (as is the case with the still-experimental UViewport). Custom depth pass is not enabled for EditorPreview (as before) but is for GamePreview. Fixed erroneous use of TEnumAsByte for non-uproperty WorldType. #jira UE-22883 - Using FPreviewScenes in-game for scene captures Change 3141106 on 2016/09/27 by Thomas.Sarkanen Column toggling improvements Column toggle menu now does not close when items are selected. This requries some Slate changes to how submenus are built to allow for sumbenus to specify whether they close after selection. Also allowed columns to be hidden by default for specific use cases (like the sequence browser). #jira UE-35818 - Anim asset browser column picker should stay up Change 3141131 on 2016/09/27 by Thomas.Sarkanen Fix CIS warnings Fallout from preview world changes Change 3141143 on 2016/09/27 by Jurre.deBaare Fix for CIS errors Change3141235on 2016/09/27 by Thomas.Sarkanen Fix offset of Persona floor mesh when auto-alignment is enabled When auto alignment was disabled, the offset wasnt getting taken into account. #jira UE-35544 - In Persona, Floor Height Offset does nothing with Auto Align Floor to Mesh disabled Change 3141327 on 2016/09/27 by Marc.Audy Ensure that the client side AttachChildren array remains accurate #jira UE-26025 Change 3141474 on 2016/09/27 by mason.seay Updating test map name and moving PlayerStart Change 3141501 on 2016/09/27 by Benn.Gallagher Loading time improvements for destructibles from Nvidia Updated to use new framework custom version instead of global object version Fixed usage of TArray to enable correct loading and saving of the cached data. #jira UE-29680 Change 3141889 on 2016/09/27 by Marc.Audy Fix DestructibleMesh when WITH_APEX is 0 #jira UE-36484 Change 3142034 on 2016/09/27 by Marc.Audy Merging //UE4/Dev-Main to Dev-Framework (//UE4/Dev-Framework) @ 3141971 Change 3142131 on 2016/09/27 by Ori.Cohen Make sure we return eTouch to physx during an overlap query. Fixes bad behavior when multiple objects blocked in an overlap query. #JIRA UE-36381 Change 3142154 on 2016/09/27 by Ori.Cohen Fix build, ModuleCachedData instead of NxApexModuleCachedData Change 3142159 on 2016/09/27 by mason.seay Blueprint for testing Child Actor Templates Change 3142255 on 2016/09/27 by Jon.Nabozny Fix crashes in QAMeshMerge component by making it a UObject, exposing it's method statically, and taking QASkeletalMeshMergeParams as an argument. #jira UE-35199, UE-35197, UE-35201 Change 3142717 on 2016/09/27 by dan.reynolds AEOverview Update + Sound Class Test Change 3142764 on 2016/09/27 by Marc.Audy Fix Ocean deprecation warnings Change 3142962 on 2016/09/28 by Thomas.Sarkanen Fixed bounds calculations for local camera animations Correctly calculated bounds as local to the initial transform in the track. Implemented suggested fixes from UDN user chhaddon (The Coalition). #jira UE-29594 - CameraAnim bounds are incorrect when bRelativeToInitialTransform == true Change 3143007 on 2016/09/28 by Martin.Wilson Added virtual bones to USkeleton API Breaking change: -Added USkeleton pointer to RemoveBonesByName -FReferenceSkeleton::UpdateRefPoseTransform & FReferenceSkeleton::Add made private. Must use FReferenceSkeletonModifier instead #jira UEFW-81 Change 3143040 on 2016/09/28 by James.Golding Strip DrawDebug.. functions from Shipping and Test builds, controlled by new define ENABLE_DRAW_DEBUG Fix up game projects to compile in Shipping/Test after this change PR #2757: (Contributed by projectgheist) #jira UE-35488 Change 3143046 on 2016/09/28 by James.Golding Fix OrionEnvironmentPerfTest.cpp compiling in Shipping (optimizations were not being re-enabled at end of file) Change 3143047 on 2016/09/28 by James.Golding PR #2731: Capsule primitive drawing fix (Contributed by kamrann) #jira UE-35142 Change 3143050 on 2016/09/28 by Martin.Wilson Update DDC key as some animation have stale data Change 3143088 on 2016/09/28 by Martin.Wilson CIS Fixes for Ocean after FReferenceSkeleton changes Change 3143090 on 2016/09/28 by Benn.Gallagher Fixed split pins in animation blueprints losing their pin links on editor restart. The anim nodes had opted out of the Super version of reconstruct, but that's where split pin restoration was added so we were skipping it. #jira UE-36482 Change 3143091 on 2016/09/28 by Thomas.Sarkanen Fix play/pause keyboard shortcut toggle in Persona based editors Correctly handled widget mode switching in the skeleton selection edit mode (previously it was manually handling this rather than hooking into the correct level viewport callbacks). Added the ability for FEdModes to specify whether they can use a widget mode. Added a common set of commands that all Persona-based editors can opt into (only contains TogglePlay for now). #jira UE-35163 - Cannot use Play/Pause shortcut in Persona if viewport is focused Change 3143100 on 2016/09/28 by James.Golding UE-32275 Fix Anim Curve entries losing Auto state when hidden/reshown Change 3143107 on 2016/09/28 by Martin.Wilson Add check to IsRunningParallelEvaluation to verify that the skeletal mesh component in question still references us #jira UE-34431 Change 3143125 on 2016/09/28 by Jurre.deBaare PR #2749: Fix blend space triangulation (Contributed by tmiv) Change 3143225 on 2016/09/28 by Jurre.deBaare Mesh/material merging basic test files Change 3143235 on 2016/09/28 by Martin.Wilson Fix issue where montage wrong section was updated with changes from details panel when clicking on a new section #jira UE-35929 Change 3143312 on 2016/09/28 by Marc.Audy Don't globally reregister components, globally recreate render state instead when force deleting assets Fixes crash force deleting a blueprint with a child actor component in it from the content browser Change 3143340 on 2016/09/28 by Mieszko.Zielinski Improved consistency of loudness usage in AISense_Hearing #UE4 Change 3143359 on 2016/09/28 by Marc.Audy Fix spelling error in comment Change 3143372 on 2016/09/28 by Jurre.deBaare HLOD meshes are causing degenerate triangles #fix Setting flag to ignore degenerate triangles when building the meshes vertex/index buffers #jira UE-34336 Change 3143420 on 2016/09/28 by Mieszko.Zielinski Fix to BlackboardData initialization's dependency on parent asset's initialization #UE4 Change 3143421 on 2016/09/28 by Martin.Wilson Allow reading on animation sequence length in blueprints #jira UE-34168 Change 3143455 on 2016/09/28 by James.Golding Add 'noop' versions of DrawDebug function, so you will not get compile errors by default for calling them in Shipping/Test builds. Added optional SHIPPING_DRAW_DEBUG_ERROR define, which will give compile errors in Shipping/Test if still calling DrawDebug functions Change 3143518 on 2016/09/28 by Jurre.deBaare Meshes with no UV Coordinates will break the UVs of other meshes contained in the same HLOD if they share a material #fix calculate UV bounds and check whether they occupy any space (if not do not use them for baking out the material) #misc set texture sampling for HLOD proxy base material to clamp #jira UE-35221 Change 3143542 on 2016/09/28 by James.Golding Change SHIPPING_DRAW_DEBUG_ERROR define from ifdef to if Fix comment Enable by default for FN Change 3143543 on 2016/09/28 by Benn.Gallagher Changed branch + early return into an ensure during FPxQueryFilterCallback::preFilter. We were checking for invalid shapes in preFilter but that shouldn't happen. More likely to get some information as an ensure instead of earlying out on the funciton. Change 3143556 on 2016/09/28 by Aaron.McLeran UE-36540 Editor Preferences 'Enable Sound' option causes Real Time Audio to Stop Working after PIE Change 3143566 on 2016/09/28 by Benn.Gallagher Readded early out alongside new ensure for catching bad preFilter shapes Change 3143568 on 2016/09/28 by Marc.Audy Fix deprecation warnings in UT Change 3143572 on 2016/09/28 by Jurre.deBaare More test content for mesh/material merging Change 3143581 on 2016/09/28 by Jurre.deBaare More content :D Change 3143585 on 2016/09/28 by Jurre.deBaare Geometry cache cleaning #misc fix for missing materials, not serialized (facepalm) as they were added later on (required custom version bump) #misc cleaning out unecessary code Change 3143594 on 2016/09/28 by Marc.Audy Creating a child actor component by dragging an actor blueprint in to another blueprint now properly creates the template #jira UE-36511 Change 3143658 on 2016/09/28 by Marc.Audy RootComponent can be null by the time we hit PostUnregisterAllComponents so need to protect against the dereference #jira UE-36553 Change 3143776 on 2016/09/28 by Marc.Audy Properly reinstance child actor templates when using the fast reinstancing path #jira UE-36516 Change 3143896 on 2016/09/28 by Ori.Cohen Remove UPROPERTY on aggregate threshold which is always read from the physics settings. Change 3144022 on 2016/09/28 by Ben.Zeigler Move AIMoveTo node from BlueprintGraph to AIGraph and remove BlueprintGraph->AIModule dependency in build system Change 3144252 on 2016/09/28 by mason.seay More blueprints for child actor template testing Change 3144262 on 2016/09/28 by Mason.Seay Deleting assets Change 3144283 on 2016/09/28 by dan.reynolds AEOverview update + Sound Priority Test Change 3144411 on 2016/09/28 by dan.reynolds AEOverview end of day update and tweaks Change 3144679 on 2016/09/29 by Benn.Gallagher Changed skeletal bounds calculation to not consider clothing assets that aren't simulating in the current LOD. In this case we're not rendering the clothing, we're only rendering the skeletal geometry for that section in that LOD which isn't bound to cloth. Change 3144856 on 2016/09/29 by Jurre.deBaare HLOD Outliner scrolls back to the top when generating proxy meshes #fix OnLevelActorsAdded was getting called for actors in the thumbnail worlds, which forced a refresh on the listview #jira UE-30384 Change 3144864 on 2016/09/29 by Thomas.Sarkanen Preview mesh fixes Animation preview meshes are now respected (and saved). Mesh is displayed as empty if none is set (but a default is chosen). Skeleton preview meshes are now shown as empty if none is set (but a default is chosen). #jira UE-36582 - Cannot set preview mesh per-animation Change 3144865 on 2016/09/29 by Jurre.deBaare More test content Change 3144885 on 2016/09/29 by James.Golding UE-35307 Move 'invalid scale' warning to Message Log to be more visible in editor Change scale clamping in UpdateBodyScale to catch cases like (1,0,1) Change 3144903 on 2016/09/29 by Thomas.Sarkanen Deprecating StaticMesh in UStaticMeshComponent Added GetStaticMesh to access the value as read-only. SetStaticMesh is now called in all locations that used to call "StaticMesh =". Lots of fixups. #jira UE-24859 - Deprecate public access to StaticMesh property in UStaticMeshComponent Change 3145020 on 2016/09/29 by Thomas.Sarkanen Fix bounds calculations that include bones to respect LOD (and other requried bones) Sometimes bones would not be updated if we LOD switched, extending the bounds. #jira UE-36525 - UDebugSkelMeshComponent::CalcBounds should filter by LOD Change 3145041 on 2016/09/29 by Jurre.deBaare Setting the Target Lightmap UV Channel to an incorrect value leads to inconsistent results #fix removed target light map channel, we now determine according to the UV channels which are unused in the final mesh #misc ignore the source lightmap uv channels to reduce data #jira UE-36595 Change 3145219 on 2016/09/29 by Benn.Gallagher Fixed clothing actors not casting shadows in editor, after the material editing change the copy of the shadow flag was missed from the clothing association code, which runs on again on older clothing assets to use the new render data skinning. Also added some fix up for assets that have be saved in the mean time. #jira UE-36552 Change 3145222 on 2016/09/29 by Jurre.deBaare Exporting Alembic Skeletal mesh from UE4 to FBX causes a crash #fix on import set _all_ bone influence to 0 #jira UE-36602 Change 3145267 on 2016/09/29 by Ori.Cohen Move OnConstraintBreak delegate so that it fires outside of fetchResults. Fixes crash from user doing unsafe things during fetchResults. #JIRA UE-36483 Change 3145306 on 2016/09/29 by Jon.Nabozny Fixed PhAT so multiple constraints can be selected and edited properly at the same time. #JIRA: UE-31493 Change 3145342 on 2016/09/29 by Marc.Audy Do not update cull distance volumes whenever any property changes * Any movement or property change of a cull distance volume still does a global update * Any movement of a component belong to any other Actor updates only the components of that Actor * Any property change of a primitive component only updates that component #jira UE-36399 Change 3145958 on 2016/09/29 by Marc.Audy In game worlds don't auto activate components until the actor is ready to process them #jira UE-35189 Change 3146110 on 2016/09/29 by dan.reynolds AEOverview update + Soundwave Procedural Test Map Change 3146375 on 2016/09/30 by Benn.Gallagher Fixed crash saving newly created destructible mesh after material refactor. #jira UE-36619 Change 3146378 on 2016/09/30 by James.Golding UE-35908 Line trace against a BodyInstance now returns closest hit for trimesh (was any hit before) Also add stat for FBodyInstance::LineTrace Change 3146379 on 2016/09/30 by James.Golding Add test assets for creating procmesh collision in non-editor builds Change 3146386 on 2016/09/30 by Thomas.Sarkanen Fixed ensures (and functionality) of 'show uncompressed animation' option in Persona viewports Made sure that PreEvaluateAnimation is called for th einstance in use, rather than only the preview instance. This unearthed another issuye where each of the calls to GenSpaceBAses was causing the animation to run faster. Fixed this by resetting the update flag in the update context after it is used. #jira UE-36251 - Ensures showing uncompressed animations in anim blueprints Change 3146464 on 2016/09/30 by Thomas.Sarkanen Fix layered blend per bone odd/even connection counts alternately working/not working Older hacky fix for multi-property to array copies flip-flipped between using fast path and not, when it really should have disabled fast path after the first array pin. Now it disables fast path based on whether this is a new handler or not, rather than looking at the SimpleCopyPropertyName. #jira UE-35648 - Layered Blend Per Bone doesn't work correctly with 3+ inputs Change 3146652 on 2016/09/30 by Benn.Gallagher Fixed subinstance properties appearing in the caller's details panel as oddly named properties. #jira UE-34141 Change 3146673 on 2016/09/30 by Martin.Wilson Make RawAnimationData (and associated anim sequence data) private #jira ue-25869 Change 3146680 on 2016/09/30 by Benn.Gallagher Fixed errant asterisks in tooltips for source and target bone on rotation multiplier controller node #jira UE-29847 Change 3146681 on 2016/09/30 by Benn.Gallagher Fixed incorrect tooltip on left hand IK bone in hand ik retargetting node #jira UE-30885 Change 3146711 on 2016/09/30 by Jon.Nabozny Fix PhAT SnapConstraintToBone. #jira UE-31491 Change 3146717 on 2016/09/30 by Danny.Bouimad Adding Jurres really useful merge actor test assets to somewhere QA can get em. Change3146738on 2016/09/30 by Martin.Wilson Fix pose blending for on non-additive pose blending + remove normalising of weights for weights less than 1 #tests Editor tests with mambo pose asset #jira UE-36189 Change 3146750 on 2016/09/30 by Jurre.deBaare Material baking issue #misc Removed the renderer initialization which causes issue the first time you would render out a material (gradient from top left to bottom right over the texture) #misc Replaced incorrect masks with _way_ better approach thanks to Martin Change 3146755 on 2016/09/30 by Jurre.deBaare Need better progress bar for HLOD #fix replaced the progress updates with new more 'correct' ones according to the actual workload and fixed up the Simplygon progress callback #jira UE-34334 Change 3147085 on 2016/09/30 by Marc.Audy PR #2815: GetNextViewablePlayer now checking and returning correct PlayerState. (Contributed by joshkay) #jira UE-36632 Change 3147224 on 2016/09/30 by Martin.Wilson CIS Fix Change 3147280 on 2016/09/30 by Marc.Audy Mouse smoothing should use application frame rate, not the dilated game frame rate #jira UE-31040 Change 3147446 on 2016/09/30 by Aaron.McLeran UE-36682 SoundCue Delay Not Consuming Input StartTime Correctly Change 3147693 on 2016/09/30 by Ben.Zeigler #jira UE-36657 If a player has an existing Pawn during RestartPlayer, use that pawn's rotation instead of the start spot, because we were already keeping the pawn's location Change 3147697 on 2016/09/30 by Jon.Nabozny Add rotation parameter to FBodyInstance::Sweep and FBodyInstance::InternalSweepPhysX #jira UE-30486 Change 3147761 on 2016/09/30 by Jon.Nabozny Fix AUTRepulsorBubble UPrimitiveComponent::SweepComponent usage. Change 3148533 on 2016/10/03 by Thomas.Sarkanen Fix new deprecation warnings introduced by the pull from main Change 3148567 on 2016/10/03 by Marc.Audy Fix crash when exiting PIE while a panoramic screenshot is being taken Make stereo panorama tick with the world it is operating on #jira UE-36492 Change 3148571 on 2016/10/03 by Marc.Audy Allow modification of components that are EditAnywhere but don't exist in the CDO #jira UE-36694 Change 3148607 on 2016/10/03 by Martin.Wilson Properly end notify states when we clear the anim instance on a skeletal mesh. #jira UE-32488 Change 3148711 on 2016/10/03 by Martin.Wilson Fix type in virtual bone tooltip #jira UE-36703 Change 3148746 on 2016/10/03 by Benn.Gallagher Fixed a few cases where post process and sub instance anim calls weren't being made correctly. #jira UE-36529 Change 3148807 on 2016/10/03 by Martin.Wilson Fix mismatch skeleton error when undoing virtual bone changes #jira UE-36705 Change 3148812 on 2016/10/03 by Martin.Wilson Add undo support to removing virtual bones #jira UE-36706 Change 3148975 on 2016/10/03 by Jurre.deBaare Issue with combining meshes both with/without normal maps #fix make sure we always output atleast the default normal value when baking out materials, this to ensure we output non-black values for meshes without normal maps (this would cause the normal to be incorrect) #misc fixed issue in function to set texture rectangle to a single colour #misc spotted comparison error Change 3148976 on 2016/10/03 by Ori.Cohen Make sure that shape queries that we pass into physx are never size 0. Fixes some NaNs #JIRA UE-36639 Change 3148991 on 2016/10/03 by Jurre.deBaare Changing LOD materials on Merged Actors Crashes Editor #fix take into account LOD that is using the material when remapping (removing duplicate) materials #jira UE-35883 Change 3148997 on 2016/10/03 by Jurre.deBaare Make sure we remove matrix samples that fall outside of the import range and remap those that are in range Change 3149002 on 2016/10/03 by Jurre.deBaare Issues with importing Alembic caches using matrix transformations #fix Apply conversion matrix to imported matrix samples to make them match the DCC package they were exported from Change 3149030 on 2016/10/03 by Martin.Wilson Dont show save warning on animations when we have curve data #jira UE-34145 Change 3149115 on 2016/10/03 by Mieszko.Zielinski Made PathfollowingComponent distinct between patrial and full paths in terms of acceptance radius used, when trying to determin if pathing agent is at goal location #UE4 #jira UE-35153 Change 3149186 on 2016/10/03 by Ben.Zeigler #UE-36722 Fix failure to spawn when trying to spawn 4 capsules in the exact same location There's no "Correct" direction to move out of a penetrating capsule, but old PhysX appeared to be consistent. New PhysX is not, so now we save and restore the adjustment instead of letting previous iterations modify it. This code is weird but this solution is better than the old version and handles inconsistent results Change 3149235 on 2016/10/03 by Martin.Wilson Change inline curve name editing to only change the name of that specific curve, instead of renaming the smart name itself. #jira UE-20005 Change 3149245 on 2016/10/03 by Marc.Audy Remove duplicate entries from AttachChildren caused by lack of atomic cross-object updates. Change 3149397 on 2016/10/03 by Ori.Cohen Fix collision profile writing out response values to channels that don't exist. #JIRA UE-36359 Change 3149679 on 2016/10/03 by Zak.Middleton #ue4 - Don't mark CharacterMovementComponent::bUseControllerDesiredRotation as an advanced property. Consolidate rotation settings (RotationRate, bUseControllerDesiredRotation, bOrientRotationToMovement) in a new "Rotation Settings" category. Change 3149929 on 2016/10/04 by Jurre.deBaare Fix for CIS errors #fix Mac didn't like undefined struct Change 3149977 on 2016/10/04 by danny.bouimad Massive update to Merge Actor test files Change 3150014 on 2016/10/04 by James.Golding UE-36686 Fix crash when slicing and not creating other section Change 3150016 on 2016/10/04 by James.Golding UE-35335 MergeActors now converts box collision to convex, so collision scales correctly after merging Change 3150019 on 2016/10/04 by James.Golding UE-36737 Fix LineTraceComponent not returning face index Change3150020on 2016/10/04 by James.Golding UE-36672 Export PhysicsContstraintComponent class so it can be subclassed outside Engine module Change 3150027 on 2016/10/04 by Ben.Marsh Add PhysX build option into Dev-Framework. Change 3150042 on 2016/10/04 by Benn.Gallagher Fixed clothing example 1.3 collision glitches Change 3150172 on 2016/10/04 by Benn.Gallagher Made Skeletal Mesh LOD reimports clear any existing simplification flag so we don't show "generated" next to LOD entries for them. #jira UE-36589 Change 3150319 on 2016/10/04 by Ori.Cohen Go back to only deferring body creation per component. This can now use the slow path when needed. Can't support deferring of multiple components without changing locking API so we'll do that in the future. #JIRA UE-36535, UE-36504 Change 3150355 on 2016/10/04 by Zak.Middleton #ue4 - Change checkSlow() to check() in GetDefaultObject<> because this is potentially an unsafe static cast. Change 3150370 on 2016/10/04 by Ori.Cohen Fix deferred actors not getting flushed. Change 3150386 on 2016/10/04 by Martin.Wilson Fix additive animation check failing in cooked builds when using virtual bones #jira UE-36743 Change 3150424 on 2016/10/04 by Ori.Cohen Exclude kinematic actors from active transforms generation. Change 3150613 on 2016/10/04 by Zak.Middleton #ue4 - Fix bad GetDefaultObject<> in AbilitySystemGlobals. Turned up since changing checkSlow() to check() in GetDefaultObject. (Mirror CL 3138304 in Orion-DevGeneral) #jira UE-36810 #tests compiled Change 3150679 on 2016/10/04 by Ben.Zeigler Crash fix with no async scene Change 3150765 on 2016/10/04 by Ben.Zeigler Deprecate UStructProperty::ExportTextItem_Static and ImportItem_Static, and add ExportText and ImportText directly to UScriptStruct Add bAllowNativeOverride to specify rather to call the native override. For unclear reasons the static export skipped the native override while the static import included it This allows calling the generic ImportText from inside a native ImportTextItem and then doing some post processing Change 3150796 on 2016/10/04 by Marc.Audy Fix LOCTEXT warnings related to blueprint class menu options Change 3150806 on 2016/10/04 by Ben.Zeigler Fix bad text format in import error message, lead to double error Change 3150891 on 2016/10/04 by Ben.Zeigler #jira UE-36170 Fix duplicate GUID spam when async loading levels during PIE by checking the package flag instead of the runtime global Change 3150914 on 2016/10/04 by Marc.Audy Don't try to recreate render state if it has already been recreated while the recreate context was active #jira UE-36590 Change 3151195 on 2016/10/04 by Dan.Reynolds Updates to QASoundWaveProcedural QASoundWaveProcedural edited to be a GameplayStatic which spawns an Audio Component Handler as well as a Procedural Sound Wave. Support for envelope shaping (Attack, Sustain, Release) as well as multiple waveforms (Sine, Triangle, Sawtooth, Square). Blueprint API expanded to include separate functions for setting QASoundWaveProcedural settings and Playing. Change 3151233 on 2016/10/04 by Ben.Zeigler #jira UE-36836 Fix variable shadowing warnings Change 3151328 on 2016/10/04 by dan.reynolds AEOverview Update - Added Sound Wave Procedural test map and added support for mobile (tested on Android) menu selection - Still a WIP Change 3151461 on 2016/10/05 by Thomas.Sarkanen Fix localization warnings #jira UE-36720 - //UE4/Main: Step 'Build Engine Localization' - 2 Warnings Change 3151546 on 2016/10/05 by Martin.Wilson Fix pose watch regression due to persona refactor changes. #jira UE-36851 Change 3151587 on 2016/10/05 by Jurre.deBaare Updating Simplygon to SDK version 8.0 #misc removed redundant files #misc fixed landscape culling in merge actor path #misc added support for volume culling using simplygon #misc fixed when or not to use mesh data for material baking #notes Change: 3137650 Date: 23/09/2016 07:57 Client: Mustafa.Tungekar_Dev-Partner-Simplygon User: Mustafa.Tungekar Status: submitted Type: restricted ImportedBy: Identity: Description: -Renamed commandline variables for ZipUtils AutomationScript -Implemented Execute instead of ExecuteBuild -Updated commandline arguments in SimplygonSwarm JobStatus: Jobs: Files: //UE4/Dev-Partner-Simplygon/Engine/Source/Developer/SimplygonSwarm/Private/SimplygonSwarm.cpp#4 //UE4/Dev-Partner-Simplygon/Engine/Source/Programs/AutomationTool/Scripts/ZipUtils.Automation.cs#2 Change: 3137649 Date: 23/09/2016 07:56 Client: Mustafa.Tungekar_Dev-Partner-Simplygon User: Mustafa.Tungekar Status: submitted Type: restricted ImportedBy: Identity: Description: Moved file hash computation to ImportObject JobStatus: Jobs: Files: //UE4/Dev-Partner-Simplygon/Engine/Source/Editor/UnrealEd/Classes/Factories/Factory.h#4 //UE4/Dev-Partner-Simplygon/Engine/Source/Editor/UnrealEd/Private/Factories/Factory.cpp#4 Change: 3137646 Date: 23/09/2016 07:55 Client: Mustafa.Tungekar_Dev-Partner-Simplygon User: Mustafa.Tungekar Status: submitted Type: restricted ImportedBy: Identity: Description: Fixes CL3099204 EditorPerProjectUserSetting Removed ConfigRestartRequired attribute from properties where it was not required MeshUtilities -Added FProxyFailedDelegate -Extended IMeshMerging to include FProxyFailed delegate -Added ProxyGenerationFailed method to FProxyGenerationProcessor class -Setup FailedDelegate for both MeshMerging and DistributedMeshMerging SimplygonMeshReduction -Added check for invalid texture id -Updated notes and removed commented code that is not required. -Setup failed delegate -Fixed issue where image data was never hooked into the texture. -Fixed issue where texture table was never passed into casters SimplygonSwarm -Setup failed delegate -Fixed RawMesh pointer usage. -Move helper method into SimplygonSwarmHelpers.h. -Added SimplygonSwarmHelpers -Removed redundant constant path to 7-zip -Removed GetSimplygonDirectory instead using inplace. -Removed commented code that is currently not required. -Fixed Typos JobStatus: Jobs: Files: //UE4/Dev-Partner-Simplygon/Engine/Source/Developer/MeshUtilities/Private/MeshUtilities.cpp#3 //UE4/Dev-Partner-Simplygon/Engine/Source/Developer/MeshUtilities/Public/MeshUtilities.h#3 //UE4/Dev-Partner-Simplygon/Engine/Source/Developer/SimplygonMeshReduction/Private/SimplygonMeshReduction.cpp#4 //UE4/Dev-Partner-Simplygon/Engine/Source/Developer/SimplygonSwarm/Private/SimplygonSwarm.cpp#3 //UE4/Dev-Partner-Simplygon/Engine/Source/Developer/SimplygonSwarm/Public/SimplygonSwarmHelpers.h#1 //UE4/Dev-Partner-Simplygon/Engine/Source/Editor/UnrealEd/Classes/Editor/EditorPerProjectUserSettings.h#3 Change: 3099204 Date: 24/08/2016 07:56 Client: Mustafa.Tungekar_Dev-Partner-Simplygon User: Mustafa.Tungekar Status: submitted Type: restricted ImportedBy: Identity: Description: Simplygon 8.0 Updates Deprecated support for 7.0 and updated SimplygonSwarm and SimplygonMeshReduction to use 8.0 EditorPerProjectSettings *SwarmMaxUploadChunkSizeInMB for limiting the max upload size for swarm. Note the Simplygon Grid has a limitation of 2GB *SwarmNumOfConcurrentJobs for executing number of concurrent jobs *Fixed issue where SG_MATERIAL_CHANNEL_METALLIC to SG_MATERIAL_CHANNEL_METALNESS (Chage in 8.0 SDK) SPL, SimplygonSwarm, RESTClient *Bumped up SPL Version to 8 *Fixed code paths to use ZipUtils UAT script for zipping and unzipping CL3094374 *Removed SPL Templates for version 7.0 *Added conditional logging to REST methods *Added multi part upload. The RESTClient automatically decided if large files need to be split up before uploading to simplygon grid. *Updated method to take in texturepath SimplygonMeshReduction *Removed minimum version requirement. *Bumped up minimum version *Chagned license file name to refelect 8.0 changes *MaterialBaking related method now take in TextureTable as an extra parameter. This is due to 8.0 move away from old way of setting up materials and using SimplygonShadingNetowrk based appraoch. JobStatus: Jobs: Files: //UE4/Dev-Partner-Simplygon/Engine/Source/Developer/SimplygonMeshReduction/Private/SimplygonMeshReduction.cpp#3 //UE4/Dev-Partner-Simplygon/Engine/Source/Developer/SimplygonMeshReduction/Public/SimplygonTypes.h#2 //UE4/Dev-Partner-Simplygon/Engine/Source/Developer/SimplygonSwarm/Private/SimplygonRESTClient.cpp#3 //UE4/Dev-Partner-Simplygon/Engine/Source/Developer/SimplygonSwarm/Private/SimplygonSwarm.cpp#2 //UE4/Dev-Partner-Simplygon/Engine/Source/Developer/SimplygonSwarm/Public/SimplygonRESTClient.h#2 //UE4/Dev-Partner-Simplygon/Engine/Source/Developer/SimplygonSwarm/Public/SimplygonSwarmPrivatePCH.h#2 //UE4/Dev-Partner-Simplygon/Engine/Source/Editor/UnrealEd/Classes/Editor/EditorPerProjectUserSettings.h#2 //UE4/Dev-Partner-Simplygon/Engine/Source/Editor/UnrealEd/Private/Settings/EditorPerProjectUserSettings.cpp#2 Change: 3099200 Date: 24/08/2016 07:48 Client: Mustafa.Tungekar_Dev-Partner-Simplygon User: Mustafa.Tungekar Status: submitted Type: restricted ImportedBy: Identity: Description: #fix Copy constructor for FMeshReduciton mapped ShadingImportance to SilhouetteImportance JobStatus: Jobs: Files: //UE4/Dev-Partner-Simplygon/Engine/Source/Runtime/Engine/Classes/Engine/MeshMerging.h#2 Change: 3099199 Date: 24/08/2016 07:47 Client: Mustafa.Tungekar_Dev-Partner-Simplygon User: Mustafa.Tungekar Status: submitted Type: restricted ImportedBy: Identity: Description: Added Automation Script ZipUtils to zip file and unzip files from SimplygonSwarm. This will remove any dependency on external zip program and should work across platforms JobStatus: Jobs: Files: //UE4/Dev-Partner-Simplygon/Engine/Source/Programs/AutomationTool/Scripts/AutomationScripts.Automation.csproj#2 //UE4/Dev-Partner-Simplygon/Engine/Source/Programs/AutomationTool/Scripts/ZipUtils.Automation.cs#1 Change: 3099197 Date: 24/08/2016 07:40 Client: Mustafa.Tungekar_Dev-Partner-Simplygon User: Mustafa.Tungekar Status: submitted Type: restricted ImportedBy: Identity: Description: *Speed improvements for FBX Scene Importer *Added a static method to compute Hash. JobStatus: Jobs: Files: //UE4/Dev-Partner-Simplygon/Engine/Source/Editor/UnrealEd/Classes/Factories/Factory.h#3 //UE4/Dev-Partner-Simplygon/Engine/Source/Editor/UnrealEd/Private/Factories/Factory.cpp#3 //UE4/Dev-Partner-Simplygon/Engine/Source/Editor/UnrealEd/Private/Fbx/FbxStaticMeshImport.cpp#2 //UE4/Dev-Partner-Simplygon/Engine/Source/Runtime/Engine/Classes/EditorFramework/AssetImportData.h#2 //UE4/Dev-Partner-Simplygon/Engine/Source/Runtime/Engine/Private/EditorFramework/AssetImportData.cpp#2 Change 3151664 on 2016/10/05 by Richard.Hinckley Fixing ACharacter template for "New C++ Class" feature. Avoiding naming a function parameter the same as an existing class member. Change 3151729 on 2016/10/05 by Thomas.Sarkanen Audit of remaining NaN checks Some checks remain on in shipping (generally those called from blueprint): - AActor::TeleportTo - AActor::SetActorRelativeScale3D #jira UE-30999 - Optimize ⌠ContainsNaN÷ and ⌠ContainsNaNOrInfinite÷, audit those still in shipping/test Change 3151742 on 2016/10/05 by Ori.Cohen Make sure that if physical animation component doesn't find a body and bone it doesn't crash. #JIRA UE-36839 Change 3151756 on 2016/10/05 by Jurre.deBaare Fixing d3dcompiler_47.dll missing issue #fix added runtime dependency and dll name to build.cs file #fix now load the d3dcompiler_47.dll from the Binaries/ThirdParty/Windows folder before loading the simplygon DLL Change 3151761 on 2016/10/05 by Thomas.Sarkanen Fix deprecation warning from last integration Moved Preview to EditorPreview in FEditorWorldManager::OnWorldContextAdd. #jira UE-36858 - Compile UE4Editor* completed with 1 warning Change 3151782 on 2016/10/05 by Jurre.deBaare Simplygon patch up #misc linker errors popping up from JSONCPP #misc incorporated emissive material property fix from other shelve #misc static analysis fix Change 3151804 on 2016/10/05 by Marc.Audy Clear need end of frame update when unregistering a component Change 3151928 on 2016/10/05 by Ori.Cohen Fix runtime DLLs not including all delay loaded physx dll files. #JIRA UE-36816 Change 3151977 on 2016/10/05 by Martin.Wilson Notifies can no longer occupy the same time on the same track. #jira UE-30658 Change 3151989 on 2016/10/05 by Jon.Nabozny Fix ArchVis character rotation pitch when looking up/down. #jira UE-35706 Change 3152083 on 2016/10/05 by Marc.Audy Ensure that pending kill components get their marked for end of frame state cleared. Change 3152086 on 2016/10/05 by Ben.Zeigler #jira UE-36169 Fix it so missing linker errors that point to Blueprint CDOs are skipped, the same way it skips linker errors going to the actual class. Fixes a lot of spurious warnings from deleting components from blueprints or native classes Clean up the VerifyImport error handling so it also displays in -game and cook, and fix the missing class warning to work properly, previously it would happen 0% in development 100% in debug even if the class was valid Change 3152093 on 2016/10/05 by Marc.Audy Change logic for when location cannot be changed for a static component to be independent of has begun play and have to do with whether construction script is running or the level is in the process of loading (mostly for backwards compatibility adjustments in post load). #jira UE-36146 #jira UE-24647 Change 3152100 on 2016/10/05 by Ben.Zeigler Remove pragma optmize Change 3152112 on 2016/10/05 by Marc.Audy Merging //UE4/Dev-Main to Dev-Framework (//UE4/Dev-Framework) @ 3152072 Change 3152134 on 2016/10/05 by Jurre.deBaare Simplygon/Merge actor issues #fix for emissive output on meshes that do not have emissive properties #fix for texture binning, not removing invalid split area causing overlapped textures Change 3152136 on 2016/10/05 by James.Golding UE-36859 Fix tooltip saying you can click to stop recording Change 3152169 on 2016/10/05 by James.Golding UE-31209 UE-30935 : Expose bDeformableMesh and bFastCook options in FTriMeshCollisionData ProceduralMeshComponent will now cook using 'fast' and 'deformable' options, so updating collision on sections should work correctly Change ERuntimePhysxCookOptimizationFlags to EPhysXMeshCookFlags and use that to pass options to CookConvex and CookTriMesh Change 3152202 on 2016/10/05 by Jurre.deBaare Mac/Linux fix Change 3152303 on 2016/10/05 by Marc.Audy Fix deprecation warning post merge from main Change 3152320 on 2016/10/05 by Martin.Wilson Fix root motion from everything calculating incorrect root motion when animations haven't been ticking #jira UE-35364 Change 3152354 on 2016/10/05 by James.Golding PoseDriver should pass through if no poses activated Change 3152357 on 2016/10/05 by James.Golding UE-36844 Remove unused OnAssetModifiedNotifier delegate from PoseAsset, ensure OnPoseListChanged is called when updating PoseAsset from anim. Change 3152556 on 2016/10/05 by Marc.Audy Remove autos Change 3152560 on 2016/10/05 by Marc.Audy Don't allow child actor references to be dragged from the outliner to a level script #jira UE-16700 Change 3152568 on 2016/10/05 by Marc.Audy Don't allow non-networking code to set bRemoteOwned in the actor spawn parameters Remove deprecated bNoCollisionFail #jira UE-35928 Change 3152575 on 2016/10/05 by Marc.Audy Allow construction script to run post move for native classes. Actor can determine whether it should only occur on finish or every call to post edit move Change 3153101 on 2016/10/06 by Thomas.Sarkanen Fix crash re-opening the viewport in Persona-based editors #jira UE-36775 - Editor crashes when re-opening viewport in Persona Change 3153139 on 2016/10/06 by James.Golding UE-36908 Remove GetRuntimeOnlyCookOptimizationFlags if cooking is not supported Change 3153160 on 2016/10/06 by Thomas.Sarkanen Fix for crash when deleting additive layer track Code had not been updated to use the new delgate system (was still using reciprocal FPersona ptr). #jira UE-36740 - Crash when removing or disabling an additive layer track in Persona Change 3153175 on 2016/10/06 by Benn.Gallagher Fixed crashes when using subinstances in non-default states. we previously initialized the anim instances in the node initialize, but in states that haven't been hit by an initialize this will happen off the game thread which is not allowed. #jira UE-36900 Change 3153223 on 2016/10/06 by Thomas.Sarkanen Fixed crash when opening an asset from the blend space editor Code was still trying to open 'old' Persona when it was disabled. Also fix other call sites where this was being done outside of asset type actions. #jira UE-36766 - Crash attempting to open an asset from Aim Offset graph in Persona Change 3153324 on 2016/10/06 by Thomas.Sarkanen Prevented invalid GUIDs from being saved into smart name containers AddOrFindName now checks to see if existing GUIDs are valid before using them. AddName now requires a valid GUID to be passed in. Also added Modify() call to the skeleton when FindOrAddSmartName is called from VerifySmartNameInternal, as without this the skeleton might not get saved. Also add Laurent's fix for fixing up already-saved invalid GUIDs (CL 3138068). #jira UE-36367 - It is possible for curves with an invalid GUID to be saved into the USkeleton asset Change 3153348 on 2016/10/06 by Martin.Wilson Re add ticking code so all Persona editors viewports tick during drag events (went missing in Persona refactor) #jira UE-36751 Change 3153426 on 2016/10/06 by Mieszko.Zielinski Added missing elements of block comments support in BT editor #UE4 Change 3153454 on 2016/10/06 by Benn.Gallagher Fixed crash using anim debug with subinstances that are preceded by branching nodes. #jira UE-36935 [CL 3153517 by Ori Cohen in Main branch]
3113 lines
107 KiB
C++
3113 lines
107 KiB
C++
// Copyright 1998-2016 Epic Games, Inc. All Rights Reserved.
|
|
|
|
/*=============================================================================
|
|
LandscapeRender.cpp: New terrain rendering
|
|
=============================================================================*/
|
|
|
|
#include "LandscapePrivatePCH.h"
|
|
#include "LandscapeMeshProxyComponent.h"
|
|
#include "Materials/MaterialExpressionTextureCoordinate.h"
|
|
#include "Materials/MaterialExpressionLandscapeLayerCoords.h"
|
|
#include "ShaderParameters.h"
|
|
#include "ShaderParameterUtils.h"
|
|
#include "RHIStaticStates.h"
|
|
#include "LandscapeRender.h"
|
|
#include "LandscapeEdit.h"
|
|
#include "LevelUtils.h"
|
|
#include "MaterialCompiler.h"
|
|
#include "LandscapeMaterialInstanceConstant.h"
|
|
#include "RawIndexBuffer.h"
|
|
#include "Engine/LevelStreaming.h"
|
|
#include "Engine/ShadowMapTexture2D.h"
|
|
#include "Engine/Engine.h"
|
|
#include "EngineGlobals.h"
|
|
#include "UnrealEngine.h"
|
|
#include "LandscapeLight.h"
|
|
#include "Algo/Find.h"
|
|
|
|
IMPLEMENT_UNIFORM_BUFFER_STRUCT(FLandscapeUniformShaderParameters, TEXT("LandscapeParameters"));
|
|
|
|
#define LANDSCAPE_LOD_DISTANCE_FACTOR 2.f
|
|
#define LANDSCAPE_MAX_COMPONENT_SIZE 255
|
|
#define LANDSCAPE_LOD_SQUARE_ROOT_FACTOR 1.5f
|
|
|
|
int32 GLandscapeMeshLODBias = 0;
|
|
FAutoConsoleVariableRef CVarLandscapeMeshLODBias(
|
|
TEXT("r.LandscapeLODBias"),
|
|
GLandscapeMeshLODBias,
|
|
TEXT("LOD bias for landscape/terrain meshes."),
|
|
ECVF_Scalability
|
|
);
|
|
|
|
/*------------------------------------------------------------------------------
|
|
Forsyth algorithm for cache optimizing index buffers.
|
|
------------------------------------------------------------------------------*/
|
|
|
|
// Forsyth algorithm to optimize post-transformed vertex cache
|
|
namespace
|
|
{
|
|
// code for computing vertex score was taken, as much as possible
|
|
// directly from the original publication.
|
|
float ComputeVertexCacheScore(int32 CachePosition, uint32 VertexCacheSize)
|
|
{
|
|
const float FindVertexScoreCacheDecayPower = 1.5f;
|
|
const float FindVertexScoreLastTriScore = 0.75f;
|
|
|
|
float Score = 0.0f;
|
|
if (CachePosition < 0)
|
|
{
|
|
// Vertex is not in FIFO cache - no score.
|
|
}
|
|
else
|
|
{
|
|
if (CachePosition < 3)
|
|
{
|
|
// This vertex was used in the last triangle,
|
|
// so it has a fixed score, whichever of the three
|
|
// it's in. Otherwise, you can get very different
|
|
// answers depending on whether you add
|
|
// the triangle 1,2,3 or 3,1,2 - which is silly.
|
|
Score = FindVertexScoreLastTriScore;
|
|
}
|
|
else
|
|
{
|
|
check(CachePosition < (int32)VertexCacheSize);
|
|
// Points for being high in the cache.
|
|
const float Scaler = 1.0f / (VertexCacheSize - 3);
|
|
Score = 1.0f - (CachePosition - 3) * Scaler;
|
|
Score = FMath::Pow(Score, FindVertexScoreCacheDecayPower);
|
|
}
|
|
}
|
|
|
|
return Score;
|
|
}
|
|
|
|
float ComputeVertexValenceScore(uint32 numActiveFaces)
|
|
{
|
|
const float FindVertexScoreValenceBoostScale = 2.0f;
|
|
const float FindVertexScoreValenceBoostPower = 0.5f;
|
|
|
|
float Score = 0.f;
|
|
|
|
// Bonus points for having a low number of tris still to
|
|
// use the vert, so we get rid of lone verts quickly.
|
|
float ValenceBoost = FMath::Pow(float(numActiveFaces), -FindVertexScoreValenceBoostPower);
|
|
Score += FindVertexScoreValenceBoostScale * ValenceBoost;
|
|
|
|
return Score;
|
|
}
|
|
|
|
const uint32 MaxVertexCacheSize = 64;
|
|
const uint32 MaxPrecomputedVertexValenceScores = 64;
|
|
float VertexCacheScores[MaxVertexCacheSize + 1][MaxVertexCacheSize];
|
|
float VertexValenceScores[MaxPrecomputedVertexValenceScores];
|
|
bool bVertexScoresComputed = false; //ComputeVertexScores();
|
|
|
|
bool ComputeVertexScores()
|
|
{
|
|
for (uint32 CacheSize = 0; CacheSize <= MaxVertexCacheSize; ++CacheSize)
|
|
{
|
|
for (uint32 CachePos = 0; CachePos < CacheSize; ++CachePos)
|
|
{
|
|
VertexCacheScores[CacheSize][CachePos] = ComputeVertexCacheScore(CachePos, CacheSize);
|
|
}
|
|
}
|
|
|
|
for (uint32 Valence = 0; Valence < MaxPrecomputedVertexValenceScores; ++Valence)
|
|
{
|
|
VertexValenceScores[Valence] = ComputeVertexValenceScore(Valence);
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
inline float FindVertexCacheScore(uint32 CachePosition, uint32 MaxSizeVertexCache)
|
|
{
|
|
return VertexCacheScores[MaxSizeVertexCache][CachePosition];
|
|
}
|
|
|
|
inline float FindVertexValenceScore(uint32 NumActiveTris)
|
|
{
|
|
return VertexValenceScores[NumActiveTris];
|
|
}
|
|
|
|
float FindVertexScore(uint32 NumActiveFaces, uint32 CachePosition, uint32 VertexCacheSize)
|
|
{
|
|
check(bVertexScoresComputed);
|
|
|
|
if (NumActiveFaces == 0)
|
|
{
|
|
// No tri needs this vertex!
|
|
return -1.0f;
|
|
}
|
|
|
|
float Score = 0.f;
|
|
if (CachePosition < VertexCacheSize)
|
|
{
|
|
Score += VertexCacheScores[VertexCacheSize][CachePosition];
|
|
}
|
|
|
|
if (NumActiveFaces < MaxPrecomputedVertexValenceScores)
|
|
{
|
|
Score += VertexValenceScores[NumActiveFaces];
|
|
}
|
|
else
|
|
{
|
|
Score += ComputeVertexValenceScore(NumActiveFaces);
|
|
}
|
|
|
|
return Score;
|
|
}
|
|
|
|
struct OptimizeVertexData
|
|
{
|
|
float Score;
|
|
uint32 ActiveFaceListStart;
|
|
uint32 ActiveFaceListSize;
|
|
uint32 CachePos0;
|
|
uint32 CachePos1;
|
|
OptimizeVertexData() : Score(0.f), ActiveFaceListStart(0), ActiveFaceListSize(0), CachePos0(0), CachePos1(0) { }
|
|
};
|
|
|
|
//-----------------------------------------------------------------------------
|
|
// OptimizeFaces
|
|
//-----------------------------------------------------------------------------
|
|
// Parameters:
|
|
// InIndexList
|
|
// input index list
|
|
// OutIndexList
|
|
// a pointer to a preallocated buffer the same size as indexList to
|
|
// hold the optimized index list
|
|
// LRUCacheSize
|
|
// the size of the simulated post-transform cache (max:64)
|
|
//-----------------------------------------------------------------------------
|
|
|
|
template <typename INDEX_TYPE>
|
|
void OptimizeFaces(const TArray<INDEX_TYPE>& InIndexList, TArray<INDEX_TYPE>& OutIndexList, uint16 LRUCacheSize)
|
|
{
|
|
uint32 VertexCount = 0;
|
|
const uint32 IndexCount = InIndexList.Num();
|
|
|
|
// compute face count per vertex
|
|
for (uint32 i = 0; i < IndexCount; ++i)
|
|
{
|
|
uint32 Index = InIndexList[i];
|
|
VertexCount = FMath::Max(Index, VertexCount);
|
|
}
|
|
VertexCount++;
|
|
|
|
TArray<OptimizeVertexData> VertexDataList;
|
|
VertexDataList.Empty(VertexCount);
|
|
for (uint32 i = 0; i < VertexCount; i++)
|
|
{
|
|
VertexDataList.Add(OptimizeVertexData());
|
|
}
|
|
|
|
OutIndexList.Empty(IndexCount);
|
|
OutIndexList.AddZeroed(IndexCount);
|
|
|
|
// compute face count per vertex
|
|
for (uint32 i = 0; i < IndexCount; ++i)
|
|
{
|
|
uint32 Index = InIndexList[i];
|
|
OptimizeVertexData& VertexData = VertexDataList[Index];
|
|
VertexData.ActiveFaceListSize++;
|
|
}
|
|
|
|
TArray<uint32> ActiveFaceList;
|
|
|
|
const uint32 EvictedCacheIndex = TNumericLimits<uint32>::Max();
|
|
|
|
{
|
|
// allocate face list per vertex
|
|
uint32 CurActiveFaceListPos = 0;
|
|
for (uint32 i = 0; i < VertexCount; ++i)
|
|
{
|
|
OptimizeVertexData& VertexData = VertexDataList[i];
|
|
VertexData.CachePos0 = EvictedCacheIndex;
|
|
VertexData.CachePos1 = EvictedCacheIndex;
|
|
VertexData.ActiveFaceListStart = CurActiveFaceListPos;
|
|
CurActiveFaceListPos += VertexData.ActiveFaceListSize;
|
|
VertexData.Score = FindVertexScore(VertexData.ActiveFaceListSize, VertexData.CachePos0, LRUCacheSize);
|
|
VertexData.ActiveFaceListSize = 0;
|
|
}
|
|
ActiveFaceList.Empty(CurActiveFaceListPos);
|
|
ActiveFaceList.AddZeroed(CurActiveFaceListPos);
|
|
}
|
|
|
|
// fill out face list per vertex
|
|
for (uint32 i = 0; i < IndexCount; i += 3)
|
|
{
|
|
for (uint32 j = 0; j < 3; ++j)
|
|
{
|
|
uint32 Index = InIndexList[i + j];
|
|
OptimizeVertexData& VertexData = VertexDataList[Index];
|
|
ActiveFaceList[VertexData.ActiveFaceListStart + VertexData.ActiveFaceListSize] = i;
|
|
VertexData.ActiveFaceListSize++;
|
|
}
|
|
}
|
|
|
|
TArray<uint8> ProcessedFaceList;
|
|
ProcessedFaceList.Empty(IndexCount);
|
|
ProcessedFaceList.AddZeroed(IndexCount);
|
|
|
|
uint32 VertexCacheBuffer[(MaxVertexCacheSize + 3) * 2];
|
|
uint32* Cache0 = VertexCacheBuffer;
|
|
uint32* Cache1 = VertexCacheBuffer + (MaxVertexCacheSize + 3);
|
|
uint32 EntriesInCache0 = 0;
|
|
|
|
uint32 BestFace = 0;
|
|
float BestScore = -1.f;
|
|
|
|
const float MaxValenceScore = FindVertexScore(1, EvictedCacheIndex, LRUCacheSize) * 3.f;
|
|
|
|
for (uint32 i = 0; i < IndexCount; i += 3)
|
|
{
|
|
if (BestScore < 0.f)
|
|
{
|
|
// no verts in the cache are used by any unprocessed faces so
|
|
// search all unprocessed faces for a new starting point
|
|
for (uint32 j = 0; j < IndexCount; j += 3)
|
|
{
|
|
if (ProcessedFaceList[j] == 0)
|
|
{
|
|
uint32 Face = j;
|
|
float FaceScore = 0.f;
|
|
for (uint32 k = 0; k < 3; ++k)
|
|
{
|
|
uint32 Index = InIndexList[Face + k];
|
|
OptimizeVertexData& VertexData = VertexDataList[Index];
|
|
check(VertexData.ActiveFaceListSize > 0);
|
|
check(VertexData.CachePos0 >= LRUCacheSize);
|
|
FaceScore += VertexData.Score;
|
|
}
|
|
|
|
if (FaceScore > BestScore)
|
|
{
|
|
BestScore = FaceScore;
|
|
BestFace = Face;
|
|
|
|
check(BestScore <= MaxValenceScore);
|
|
if (BestScore >= MaxValenceScore)
|
|
{
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
check(BestScore >= 0.f);
|
|
}
|
|
|
|
ProcessedFaceList[BestFace] = 1;
|
|
uint32 EntriesInCache1 = 0;
|
|
|
|
// add bestFace to LRU cache and to newIndexList
|
|
for (uint32 V = 0; V < 3; ++V)
|
|
{
|
|
INDEX_TYPE Index = InIndexList[BestFace + V];
|
|
OutIndexList[i + V] = Index;
|
|
|
|
OptimizeVertexData& VertexData = VertexDataList[Index];
|
|
|
|
if (VertexData.CachePos1 >= EntriesInCache1)
|
|
{
|
|
VertexData.CachePos1 = EntriesInCache1;
|
|
Cache1[EntriesInCache1++] = Index;
|
|
|
|
if (VertexData.ActiveFaceListSize == 1)
|
|
{
|
|
--VertexData.ActiveFaceListSize;
|
|
continue;
|
|
}
|
|
}
|
|
|
|
check(VertexData.ActiveFaceListSize > 0);
|
|
uint32 FindIndex;
|
|
for (FindIndex = VertexData.ActiveFaceListStart; FindIndex < VertexData.ActiveFaceListStart + VertexData.ActiveFaceListSize; FindIndex++)
|
|
{
|
|
if (ActiveFaceList[FindIndex] == BestFace)
|
|
{
|
|
break;
|
|
}
|
|
}
|
|
check(FindIndex != VertexData.ActiveFaceListStart + VertexData.ActiveFaceListSize);
|
|
|
|
if (FindIndex != VertexData.ActiveFaceListStart + VertexData.ActiveFaceListSize - 1)
|
|
{
|
|
uint32 SwapTemp = ActiveFaceList[FindIndex];
|
|
ActiveFaceList[FindIndex] = ActiveFaceList[VertexData.ActiveFaceListStart + VertexData.ActiveFaceListSize - 1];
|
|
ActiveFaceList[VertexData.ActiveFaceListStart + VertexData.ActiveFaceListSize - 1] = SwapTemp;
|
|
}
|
|
|
|
--VertexData.ActiveFaceListSize;
|
|
VertexData.Score = FindVertexScore(VertexData.ActiveFaceListSize, VertexData.CachePos1, LRUCacheSize);
|
|
|
|
}
|
|
|
|
// move the rest of the old verts in the cache down and compute their new scores
|
|
for (uint32 C0 = 0; C0 < EntriesInCache0; ++C0)
|
|
{
|
|
uint32 Index = Cache0[C0];
|
|
OptimizeVertexData& VertexData = VertexDataList[Index];
|
|
|
|
if (VertexData.CachePos1 >= EntriesInCache1)
|
|
{
|
|
VertexData.CachePos1 = EntriesInCache1;
|
|
Cache1[EntriesInCache1++] = Index;
|
|
VertexData.Score = FindVertexScore(VertexData.ActiveFaceListSize, VertexData.CachePos1, LRUCacheSize);
|
|
}
|
|
}
|
|
|
|
// find the best scoring triangle in the current cache (including up to 3 that were just evicted)
|
|
BestScore = -1.f;
|
|
for (uint32 C1 = 0; C1 < EntriesInCache1; ++C1)
|
|
{
|
|
uint32 Index = Cache1[C1];
|
|
OptimizeVertexData& VertexData = VertexDataList[Index];
|
|
VertexData.CachePos0 = VertexData.CachePos1;
|
|
VertexData.CachePos1 = EvictedCacheIndex;
|
|
for (uint32 j = 0; j < VertexData.ActiveFaceListSize; ++j)
|
|
{
|
|
uint32 Face = ActiveFaceList[VertexData.ActiveFaceListStart + j];
|
|
float FaceScore = 0.f;
|
|
for (uint32 V = 0; V < 3; V++)
|
|
{
|
|
uint32 FaceIndex = InIndexList[Face + V];
|
|
OptimizeVertexData& FaceVertexData = VertexDataList[FaceIndex];
|
|
FaceScore += FaceVertexData.Score;
|
|
}
|
|
if (FaceScore > BestScore)
|
|
{
|
|
BestScore = FaceScore;
|
|
BestFace = Face;
|
|
}
|
|
}
|
|
}
|
|
|
|
uint32* SwapTemp = Cache0;
|
|
Cache0 = Cache1;
|
|
Cache1 = SwapTemp;
|
|
|
|
EntriesInCache0 = FMath::Min(EntriesInCache1, (uint32)LRUCacheSize);
|
|
}
|
|
}
|
|
|
|
} // namespace
|
|
|
|
struct FLandscapeDebugOptions
|
|
{
|
|
FLandscapeDebugOptions()
|
|
: bShowPatches(false)
|
|
, bDisableStatic(false)
|
|
, bDisableCombine(false)
|
|
, PatchesConsoleCommand(
|
|
TEXT("Landscape.Patches"),
|
|
TEXT("Show/hide Landscape patches"),
|
|
FConsoleCommandDelegate::CreateRaw(this, &FLandscapeDebugOptions::Patches))
|
|
, StaticConsoleCommand(
|
|
TEXT("Landscape.Static"),
|
|
TEXT("Enable/disable Landscape static drawlists"),
|
|
FConsoleCommandDelegate::CreateRaw(this, &FLandscapeDebugOptions::Static))
|
|
, CombineConsoleCommand(
|
|
TEXT("Landscape.Combine"),
|
|
TEXT("Enable/disable Landscape component combining"),
|
|
FConsoleCommandDelegate::CreateRaw(this, &FLandscapeDebugOptions::Combine))
|
|
{
|
|
}
|
|
|
|
bool bShowPatches;
|
|
bool bDisableStatic;
|
|
bool bDisableCombine;
|
|
|
|
private:
|
|
FAutoConsoleCommand PatchesConsoleCommand;
|
|
FAutoConsoleCommand StaticConsoleCommand;
|
|
FAutoConsoleCommand CombineConsoleCommand;
|
|
|
|
void Patches()
|
|
{
|
|
bShowPatches = !bShowPatches;
|
|
UE_LOG(LogLandscape, Display, TEXT("Landscape.Patches: %s"), bShowPatches ? TEXT("Show") : TEXT("Hide"));
|
|
}
|
|
|
|
void Static()
|
|
{
|
|
bDisableStatic = !bDisableStatic;
|
|
UE_LOG(LogLandscape, Display, TEXT("Landscape.Static: %s"), bDisableStatic ? TEXT("Disabled") : TEXT("Enabled"));
|
|
}
|
|
|
|
void Combine()
|
|
{
|
|
bDisableCombine = !bDisableCombine;
|
|
UE_LOG(LogLandscape, Display, TEXT("Landscape.Combine: %s"), bDisableCombine ? TEXT("Disabled") : TEXT("Enabled"));
|
|
}
|
|
};
|
|
|
|
FLandscapeDebugOptions GLandscapeDebugOptions;
|
|
|
|
|
|
#if WITH_EDITOR
|
|
LANDSCAPE_API bool GLandscapeEditModeActive = false;
|
|
LANDSCAPE_API ELandscapeViewMode::Type GLandscapeViewMode = ELandscapeViewMode::Normal;
|
|
LANDSCAPE_API int32 GLandscapeEditRenderMode = ELandscapeEditRenderMode::None;
|
|
LANDSCAPE_API int32 GLandscapePreviewMeshRenderMode = 0;
|
|
UMaterialInterface* GLayerDebugColorMaterial = nullptr;
|
|
UMaterialInterface* GSelectionColorMaterial = nullptr;
|
|
UMaterialInterface* GSelectionRegionMaterial = nullptr;
|
|
UMaterialInterface* GMaskRegionMaterial = nullptr;
|
|
UTexture2D* GLandscapeBlackTexture = nullptr;
|
|
UMaterialInterface* GLandscapeLayerUsageMaterial = nullptr;
|
|
|
|
// Game thread update
|
|
void FLandscapeEditToolRenderData::Update(UMaterialInterface* InToolMaterial)
|
|
{
|
|
ENQUEUE_UNIQUE_RENDER_COMMAND_TWOPARAMETER(
|
|
UpdateEditToolRenderData,
|
|
FLandscapeEditToolRenderData*, LandscapeEditToolRenderData, this,
|
|
UMaterialInterface*, NewToolMaterial, InToolMaterial,
|
|
{
|
|
LandscapeEditToolRenderData->ToolMaterial = NewToolMaterial;
|
|
});
|
|
}
|
|
|
|
void FLandscapeEditToolRenderData::UpdateGizmo(UMaterialInterface* InGizmoMaterial)
|
|
{
|
|
ENQUEUE_UNIQUE_RENDER_COMMAND_TWOPARAMETER(
|
|
UpdateEditToolRenderData,
|
|
FLandscapeEditToolRenderData*, LandscapeEditToolRenderData, this,
|
|
UMaterialInterface*, NewGizmoMaterial, InGizmoMaterial,
|
|
{
|
|
LandscapeEditToolRenderData->GizmoMaterial = NewGizmoMaterial;
|
|
});
|
|
}
|
|
|
|
// Allows game thread to queue the deletion by the render thread
|
|
void FLandscapeEditToolRenderData::Cleanup()
|
|
{
|
|
ENQUEUE_UNIQUE_RENDER_COMMAND_ONEPARAMETER(
|
|
CleanupEditToolRenderData,
|
|
FLandscapeEditToolRenderData*, LandscapeEditToolRenderData, this,
|
|
{
|
|
delete LandscapeEditToolRenderData;
|
|
}
|
|
);
|
|
}
|
|
|
|
|
|
void FLandscapeEditToolRenderData::UpdateDebugColorMaterial()
|
|
{
|
|
if (!LandscapeComponent)
|
|
{
|
|
return;
|
|
}
|
|
|
|
// Debug Color Rendering Material....
|
|
DebugChannelR = INDEX_NONE, DebugChannelG = INDEX_NONE, DebugChannelB = INDEX_NONE;
|
|
LandscapeComponent->GetLayerDebugColorKey(DebugChannelR, DebugChannelG, DebugChannelB);
|
|
}
|
|
|
|
void FLandscapeEditToolRenderData::UpdateSelectionMaterial(int32 InSelectedType)
|
|
{
|
|
if (!LandscapeComponent)
|
|
{
|
|
return;
|
|
}
|
|
|
|
// Check selection
|
|
if (SelectedType != InSelectedType && (SelectedType & ST_REGION) && !(InSelectedType & ST_REGION))
|
|
{
|
|
// Clear Select textures...
|
|
if (DataTexture)
|
|
{
|
|
FLandscapeEditDataInterface LandscapeEdit(LandscapeComponent->GetLandscapeInfo());
|
|
LandscapeEdit.ZeroTexture(DataTexture);
|
|
}
|
|
}
|
|
|
|
ENQUEUE_UNIQUE_RENDER_COMMAND_TWOPARAMETER(
|
|
UpdateSelectionMaterial,
|
|
FLandscapeEditToolRenderData*, LandscapeEditToolRenderData, this,
|
|
int32, InSelectedType, InSelectedType,
|
|
{
|
|
LandscapeEditToolRenderData->SelectedType = InSelectedType;
|
|
});
|
|
}
|
|
#endif
|
|
|
|
|
|
//
|
|
// FLandscapeComponentSceneProxy
|
|
//
|
|
TMap<uint32, FLandscapeSharedBuffers*>FLandscapeComponentSceneProxy::SharedBuffersMap;
|
|
TMap<uint32, FLandscapeSharedAdjacencyIndexBuffer*>FLandscapeComponentSceneProxy::SharedAdjacencyIndexBufferMap;
|
|
TMap<FLandscapeNeighborInfo::FLandscapeKey, TMap<FIntPoint, const FLandscapeNeighborInfo*> > FLandscapeNeighborInfo::SharedSceneProxyMap;
|
|
|
|
const static FName NAME_LandscapeResourceNameForDebugging(TEXT("Landscape"));
|
|
|
|
FLandscapeComponentSceneProxy::FLandscapeComponentSceneProxy(ULandscapeComponent* InComponent, TArrayView<UMaterialInterface* const> InMaterialInterfacesByLOD, FLandscapeEditToolRenderData* InEditToolRenderData)
|
|
: FPrimitiveSceneProxy(InComponent, NAME_LandscapeResourceNameForDebugging)
|
|
, FLandscapeNeighborInfo(InComponent->GetWorld(), InComponent->GetLandscapeProxy()->GetLandscapeGuid(), InComponent->GetSectionBase() / InComponent->ComponentSizeQuads, InComponent->HeightmapTexture, InComponent->ForcedLOD, InComponent->LODBias)
|
|
, MaxLOD(FMath::CeilLogTwo(InComponent->SubsectionSizeQuads + 1) - 1)
|
|
, FirstLOD(0)
|
|
, LastLOD(FMath::CeilLogTwo(InComponent->SubsectionSizeQuads + 1) - 1)
|
|
, NumSubsections(InComponent->NumSubsections)
|
|
, SubsectionSizeQuads(InComponent->SubsectionSizeQuads)
|
|
, SubsectionSizeVerts(InComponent->SubsectionSizeQuads + 1)
|
|
, ComponentSizeQuads(InComponent->ComponentSizeQuads)
|
|
, ComponentSizeVerts(InComponent->ComponentSizeQuads + 1)
|
|
, StaticLightingLOD(InComponent->GetLandscapeProxy()->StaticLightingLOD)
|
|
, SectionBase(InComponent->GetSectionBase())
|
|
, WeightmapScaleBias(InComponent->WeightmapScaleBias)
|
|
, WeightmapSubsectionOffset(InComponent->WeightmapSubsectionOffset)
|
|
, WeightmapTextures(InComponent->WeightmapTextures)
|
|
, NumWeightmapLayerAllocations(InComponent->WeightmapLayerAllocations.Num())
|
|
, NormalmapTexture(InComponent->HeightmapTexture)
|
|
, BaseColorForGITexture(InComponent->GIBakedBaseColorTexture)
|
|
, HeightmapScaleBias(InComponent->HeightmapScaleBias)
|
|
, XYOffsetmapTexture(InComponent->XYOffsetmapTexture)
|
|
, SharedBuffersKey(0)
|
|
, SharedBuffers(nullptr)
|
|
, VertexFactory(nullptr)
|
|
, EditToolRenderData(InEditToolRenderData)
|
|
, ComponentLightInfo(nullptr)
|
|
, LandscapeComponent(InComponent)
|
|
, LODFalloff(InComponent->GetLandscapeProxy()->LODFalloff)
|
|
#if WITH_EDITOR || !(UE_BUILD_SHIPPING || UE_BUILD_TEST)
|
|
, CollisionMipLevel(InComponent->CollisionMipLevel)
|
|
, SimpleCollisionMipLevel(InComponent->SimpleCollisionMipLevel)
|
|
, CollisionResponse(InComponent->GetLandscapeProxy()->BodyInstance.GetResponseToChannels())
|
|
#endif
|
|
#if !(UE_BUILD_SHIPPING || UE_BUILD_TEST)
|
|
, LightMapResolution(InComponent->GetStaticLightMapResolution())
|
|
#endif
|
|
{
|
|
MaterialInterfacesByLOD.Append(InMaterialInterfacesByLOD.GetData(), InMaterialInterfacesByLOD.Num());
|
|
|
|
if (!IsComponentLevelVisible())
|
|
{
|
|
bNeedsLevelAddedToWorldNotification = true;
|
|
}
|
|
|
|
LevelColor = FLinearColor(1.f, 1.f, 1.f);
|
|
|
|
const auto FeatureLevel = GetScene().GetFeatureLevel();
|
|
if (FeatureLevel <= ERHIFeatureLevel::ES3_1)
|
|
{
|
|
HeightmapTexture = nullptr;
|
|
HeightmapSubsectionOffsetU = 0;
|
|
HeightmapSubsectionOffsetV = 0;
|
|
}
|
|
else
|
|
{
|
|
HeightmapSubsectionOffsetU = ((float)(InComponent->SubsectionSizeQuads + 1) / (float)HeightmapTexture->GetSizeX());
|
|
HeightmapSubsectionOffsetV = ((float)(InComponent->SubsectionSizeQuads + 1) / (float)HeightmapTexture->GetSizeY());
|
|
}
|
|
|
|
LODBias = FMath::Clamp<int8>(LODBias, -MaxLOD, MaxLOD);
|
|
|
|
if (InComponent->GetLandscapeProxy()->MaxLODLevel >= 0)
|
|
{
|
|
MaxLOD = FMath::Min<int8>(MaxLOD, InComponent->GetLandscapeProxy()->MaxLODLevel);
|
|
}
|
|
|
|
FirstLOD = (ForcedLOD >= 0) ? FMath::Min<int32>(ForcedLOD, MaxLOD) : FMath::Max<int32>(LODBias, 0);
|
|
LastLOD = (ForcedLOD >= 0) ? FirstLOD : MaxLOD; // we always need to go to MaxLOD regardless of LODBias as we could need the lowest LODs due to streaming.
|
|
|
|
float LODDistanceFactor;
|
|
switch (LODFalloff)
|
|
{
|
|
case ELandscapeLODFalloff::SquareRoot:
|
|
LODDistanceFactor = FMath::Square(FMath::Min(LANDSCAPE_LOD_SQUARE_ROOT_FACTOR * InComponent->GetLandscapeProxy()->LODDistanceFactor, MAX_LANDSCAPE_LOD_DISTANCE_FACTOR));
|
|
break;
|
|
case ELandscapeLODFalloff::Linear:
|
|
default:
|
|
LODDistanceFactor = InComponent->GetLandscapeProxy()->LODDistanceFactor;
|
|
break;
|
|
}
|
|
|
|
LODDistance = FMath::Sqrt(2.f * FMath::Square((float)SubsectionSizeQuads)) * LANDSCAPE_LOD_DISTANCE_FACTOR / LODDistanceFactor; // vary in 0...1
|
|
DistDiff = -FMath::Sqrt(2.f * FMath::Square(0.5f*(float)SubsectionSizeQuads));
|
|
|
|
if (InComponent->StaticLightingResolution > 0.f)
|
|
{
|
|
StaticLightingResolution = InComponent->StaticLightingResolution;
|
|
}
|
|
else
|
|
{
|
|
StaticLightingResolution = InComponent->GetLandscapeProxy()->StaticLightingResolution;
|
|
}
|
|
|
|
ComponentLightInfo = MakeUnique<FLandscapeLCI>(InComponent);
|
|
check(ComponentLightInfo);
|
|
|
|
const bool bHasStaticLighting = InComponent->bHasCachedStaticLighting;
|
|
|
|
// Check material usage
|
|
if (ensure(MaterialInterfacesByLOD.Num() > 0))
|
|
{
|
|
for (UMaterialInterface*& MaterialInterface : MaterialInterfacesByLOD)
|
|
{
|
|
if (MaterialInterface == nullptr ||
|
|
(bHasStaticLighting && !MaterialInterface->CheckMaterialUsage(MATUSAGE_StaticLighting)))
|
|
{
|
|
MaterialInterface = UMaterial::GetDefaultMaterial(MD_Surface);
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
MaterialInterfacesByLOD.Add(UMaterial::GetDefaultMaterial(MD_Surface));
|
|
}
|
|
|
|
// TODO - LOD Materials - Currently all LOD materials are instances of [0] so have the same relevance
|
|
MaterialRelevance = MaterialInterfacesByLOD[0]->GetRelevance(FeatureLevel);
|
|
|
|
#if !(UE_BUILD_SHIPPING || UE_BUILD_TEST) || (UE_BUILD_SHIPPING && WITH_EDITOR)
|
|
if (GIsEditor)
|
|
{
|
|
ALandscapeProxy* Proxy = InComponent->GetLandscapeProxy();
|
|
// Try to find a color for level coloration.
|
|
if (Proxy)
|
|
{
|
|
ULevel* Level = Proxy->GetLevel();
|
|
ULevelStreaming* LevelStreaming = FLevelUtils::FindStreamingLevel(Level);
|
|
if (LevelStreaming)
|
|
{
|
|
LevelColor = LevelStreaming->LevelColor;
|
|
}
|
|
}
|
|
}
|
|
#endif
|
|
|
|
// We dissallow tessellation after LOD 0 so bRequiresAdjacencyInformation can only be true if LOD 0 needs it
|
|
bRequiresAdjacencyInformation = MaterialSettingsRequireAdjacencyInformation_GameThread(MaterialInterfacesByLOD[0], XYOffsetmapTexture == nullptr ? &FLandscapeVertexFactory::StaticType : &FLandscapeXYOffsetVertexFactory::StaticType, InComponent->GetWorld()->FeatureLevel);
|
|
|
|
const int8 SubsectionSizeLog2 = FMath::CeilLogTwo(InComponent->SubsectionSizeQuads + 1);
|
|
SharedBuffersKey = (SubsectionSizeLog2 & 0xf) | ((NumSubsections & 0xf) << 4) |
|
|
(FeatureLevel <= ERHIFeatureLevel::ES3_1 ? 0 : 1 << 30) | (XYOffsetmapTexture == nullptr ? 0 : 1 << 31);
|
|
|
|
bSupportsHeightfieldRepresentation = true;
|
|
|
|
#if WITH_EDITOR
|
|
for (auto& Allocation : InComponent->WeightmapLayerAllocations)
|
|
{
|
|
if (ensure(Allocation.LayerInfo) && Allocation.LayerInfo != ALandscapeProxy::VisibilityLayer)
|
|
{
|
|
// Use black for hole layer
|
|
LayerColors.Add(Allocation.LayerInfo->LayerUsageDebugColor);
|
|
LayerNames.Add(Allocation.LayerInfo->LayerName);
|
|
}
|
|
}
|
|
#endif
|
|
}
|
|
|
|
void FLandscapeComponentSceneProxy::CreateRenderThreadResources()
|
|
{
|
|
check(HeightmapTexture != nullptr);
|
|
|
|
if (IsComponentLevelVisible())
|
|
{
|
|
RegisterNeighbors();
|
|
}
|
|
|
|
auto FeatureLevel = GetScene().GetFeatureLevel();
|
|
|
|
SharedBuffers = FLandscapeComponentSceneProxy::SharedBuffersMap.FindRef(SharedBuffersKey);
|
|
if (SharedBuffers == nullptr)
|
|
{
|
|
SharedBuffers = new FLandscapeSharedBuffers(
|
|
SharedBuffersKey, SubsectionSizeQuads, NumSubsections,
|
|
FeatureLevel, bRequiresAdjacencyInformation);
|
|
|
|
FLandscapeComponentSceneProxy::SharedBuffersMap.Add(SharedBuffersKey, SharedBuffers);
|
|
|
|
if (!XYOffsetmapTexture)
|
|
{
|
|
FLandscapeVertexFactory* LandscapeVertexFactory = new FLandscapeVertexFactory();
|
|
LandscapeVertexFactory->Data.PositionComponent = FVertexStreamComponent(SharedBuffers->VertexBuffer, 0, sizeof(FLandscapeVertex), VET_Float4);
|
|
LandscapeVertexFactory->InitResource();
|
|
SharedBuffers->VertexFactory = LandscapeVertexFactory;
|
|
}
|
|
else
|
|
{
|
|
FLandscapeXYOffsetVertexFactory* LandscapeXYOffsetVertexFactory = new FLandscapeXYOffsetVertexFactory();
|
|
LandscapeXYOffsetVertexFactory->Data.PositionComponent = FVertexStreamComponent(SharedBuffers->VertexBuffer, 0, sizeof(FLandscapeVertex), VET_Float4);
|
|
LandscapeXYOffsetVertexFactory->InitResource();
|
|
SharedBuffers->VertexFactory = LandscapeXYOffsetVertexFactory;
|
|
}
|
|
}
|
|
|
|
SharedBuffers->AddRef();
|
|
|
|
if (bRequiresAdjacencyInformation)
|
|
{
|
|
if (SharedBuffers->AdjacencyIndexBuffers == nullptr)
|
|
{
|
|
ensure(SharedBuffers->NumIndexBuffers > 0);
|
|
if (SharedBuffers->IndexBuffers[0])
|
|
{
|
|
// Recreate Index Buffers, this case happens only there are Landscape Components using different material (one uses tessellation, other don't use it)
|
|
if (SharedBuffers->bUse32BitIndices && !((FRawStaticIndexBuffer16or32<uint32>*)SharedBuffers->IndexBuffers[0])->Num())
|
|
{
|
|
SharedBuffers->CreateIndexBuffers<uint32>(FeatureLevel, bRequiresAdjacencyInformation);
|
|
}
|
|
else if (!((FRawStaticIndexBuffer16or32<uint16>*)SharedBuffers->IndexBuffers[0])->Num())
|
|
{
|
|
SharedBuffers->CreateIndexBuffers<uint16>(FeatureLevel, bRequiresAdjacencyInformation);
|
|
}
|
|
}
|
|
|
|
SharedBuffers->AdjacencyIndexBuffers = new FLandscapeSharedAdjacencyIndexBuffer(SharedBuffers);
|
|
FLandscapeComponentSceneProxy::SharedAdjacencyIndexBufferMap.Add(SharedBuffersKey, SharedBuffers->AdjacencyIndexBuffers);
|
|
}
|
|
SharedBuffers->AdjacencyIndexBuffers->AddRef();
|
|
|
|
// Delayed Initialize for IndexBuffers
|
|
for (int32 i = 0; i < SharedBuffers->NumIndexBuffers; i++)
|
|
{
|
|
SharedBuffers->IndexBuffers[i]->InitResource();
|
|
}
|
|
}
|
|
|
|
// Assign vertex factory
|
|
VertexFactory = SharedBuffers->VertexFactory;
|
|
|
|
// Assign LandscapeUniformShaderParameters
|
|
LandscapeUniformShaderParameters.InitResource();
|
|
|
|
#if WITH_EDITOR
|
|
// Create MeshBatch for grass rendering
|
|
if(SharedBuffers->GrassIndexBuffer)
|
|
{
|
|
const int32 NumMips = FMath::CeilLogTwo(SubsectionSizeVerts);
|
|
GrassMeshBatch.Elements.Empty(NumMips);
|
|
GrassMeshBatch.Elements.AddDefaulted(NumMips);
|
|
GrassBatchParams.Empty(NumMips);
|
|
GrassBatchParams.AddDefaulted(NumMips);
|
|
|
|
FMaterialRenderProxy* RenderProxy = MaterialInterfacesByLOD[0]->GetRenderProxy(false);
|
|
GrassMeshBatch.VertexFactory = VertexFactory;
|
|
GrassMeshBatch.MaterialRenderProxy = RenderProxy;
|
|
GrassMeshBatch.LCI = nullptr;
|
|
GrassMeshBatch.ReverseCulling = false;
|
|
GrassMeshBatch.CastShadow = false;
|
|
GrassMeshBatch.Type = PT_PointList;
|
|
GrassMeshBatch.DepthPriorityGroup = SDPG_World;
|
|
|
|
// Combined grass rendering batch element
|
|
FMeshBatchElement* GrassBatchElement = &GrassMeshBatch.Elements[0];
|
|
FLandscapeBatchElementParams* BatchElementParams = &GrassBatchParams[0];
|
|
BatchElementParams->LocalToWorldNoScalingPtr = &LocalToWorldNoScaling;
|
|
BatchElementParams->LandscapeUniformShaderParametersResource = &LandscapeUniformShaderParameters;
|
|
BatchElementParams->SceneProxy = this;
|
|
BatchElementParams->SubX = -1;
|
|
BatchElementParams->SubY = -1;
|
|
BatchElementParams->CurrentLOD = 0;
|
|
GrassBatchElement->UserData = BatchElementParams;
|
|
if (NeedsUniformBufferUpdate())
|
|
{
|
|
UpdateUniformBuffer();
|
|
}
|
|
GrassBatchElement->PrimitiveUniformBufferResource = &GetUniformBuffer();
|
|
GrassBatchElement->IndexBuffer = SharedBuffers->GrassIndexBuffer;
|
|
GrassBatchElement->NumPrimitives = FMath::Square(NumSubsections) * FMath::Square(SubsectionSizeVerts);
|
|
GrassBatchElement->FirstIndex = 0;
|
|
GrassBatchElement->MinVertexIndex = 0;
|
|
GrassBatchElement->MaxVertexIndex = SharedBuffers->NumVertices - 1;
|
|
|
|
for (int32 Mip = 1; Mip < NumMips; ++Mip)
|
|
{
|
|
const int32 MipSubsectionSizeVerts = SubsectionSizeVerts >> Mip;
|
|
|
|
FMeshBatchElement* CollisionBatchElement = &GrassMeshBatch.Elements[Mip];
|
|
*CollisionBatchElement = *GrassBatchElement;
|
|
FLandscapeBatchElementParams* CollisionBatchElementParams = &GrassBatchParams[Mip];
|
|
*CollisionBatchElementParams = *BatchElementParams;
|
|
CollisionBatchElementParams->CurrentLOD = Mip;
|
|
CollisionBatchElement->UserData = CollisionBatchElementParams;
|
|
CollisionBatchElement->NumPrimitives = FMath::Square(NumSubsections) * FMath::Square(MipSubsectionSizeVerts);
|
|
CollisionBatchElement->FirstIndex = SharedBuffers->GrassIndexMipOffsets[Mip];
|
|
}
|
|
}
|
|
#endif
|
|
}
|
|
|
|
void FLandscapeComponentSceneProxy::OnLevelAddedToWorld()
|
|
{
|
|
RegisterNeighbors();
|
|
}
|
|
|
|
FLandscapeComponentSceneProxy::~FLandscapeComponentSceneProxy()
|
|
{
|
|
UnregisterNeighbors();
|
|
|
|
// Free the subsection uniform buffer
|
|
LandscapeUniformShaderParameters.ReleaseResource();
|
|
|
|
if (SharedBuffers)
|
|
{
|
|
check(SharedBuffers == FLandscapeComponentSceneProxy::SharedBuffersMap.FindRef(SharedBuffersKey));
|
|
if (SharedBuffers->Release() == 0)
|
|
{
|
|
FLandscapeComponentSceneProxy::SharedBuffersMap.Remove(SharedBuffersKey);
|
|
}
|
|
SharedBuffers = nullptr;
|
|
}
|
|
}
|
|
|
|
int32 GAllowLandscapeShadows = 1;
|
|
static FAutoConsoleVariableRef CVarAllowLandscapeShadows(
|
|
TEXT("r.AllowLandscapeShadows"),
|
|
GAllowLandscapeShadows,
|
|
TEXT("Allow Landscape Shadows")
|
|
);
|
|
|
|
bool FLandscapeComponentSceneProxy::CanBeOccluded() const
|
|
{
|
|
return !MaterialRelevance.bDisableDepthTest;
|
|
}
|
|
|
|
FPrimitiveViewRelevance FLandscapeComponentSceneProxy::GetViewRelevance(const FSceneView* View) const
|
|
{
|
|
FPrimitiveViewRelevance Result;
|
|
Result.bDrawRelevance = IsShown(View) && View->Family->EngineShowFlags.Landscape;
|
|
|
|
auto FeatureLevel = View->GetFeatureLevel();
|
|
|
|
#if WITH_EDITOR
|
|
if (!GLandscapeEditModeActive)
|
|
{
|
|
// No tools to render, just use the cached material relevance.
|
|
#endif
|
|
MaterialRelevance.SetPrimitiveViewRelevance(Result);
|
|
#if WITH_EDITOR
|
|
}
|
|
else
|
|
{
|
|
// Also add the tool material(s)'s relevance to the MaterialRelevance
|
|
FMaterialRelevance ToolRelevance = MaterialRelevance;
|
|
|
|
// Tool brushes and Gizmo
|
|
if (EditToolRenderData)
|
|
{
|
|
if (EditToolRenderData->ToolMaterial)
|
|
{
|
|
Result.bDynamicRelevance = true;
|
|
ToolRelevance |= EditToolRenderData->ToolMaterial->GetRelevance_Concurrent(FeatureLevel);
|
|
}
|
|
|
|
if (EditToolRenderData->GizmoMaterial)
|
|
{
|
|
Result.bDynamicRelevance = true;
|
|
ToolRelevance |= EditToolRenderData->GizmoMaterial->GetRelevance_Concurrent(FeatureLevel);
|
|
}
|
|
}
|
|
|
|
// Region selection
|
|
if (EditToolRenderData && EditToolRenderData->SelectedType)
|
|
{
|
|
if ((GLandscapeEditRenderMode & ELandscapeEditRenderMode::SelectRegion) && (EditToolRenderData->SelectedType & FLandscapeEditToolRenderData::ST_REGION)
|
|
&& !(GLandscapeEditRenderMode & ELandscapeEditRenderMode::Mask) && GSelectionRegionMaterial)
|
|
{
|
|
Result.bDynamicRelevance = true;
|
|
ToolRelevance |= GSelectionRegionMaterial->GetRelevance_Concurrent(FeatureLevel);
|
|
}
|
|
if ((GLandscapeEditRenderMode & ELandscapeEditRenderMode::SelectComponent) && (EditToolRenderData->SelectedType & FLandscapeEditToolRenderData::ST_COMPONENT) && GSelectionColorMaterial)
|
|
{
|
|
Result.bDynamicRelevance = true;
|
|
ToolRelevance |= GSelectionColorMaterial->GetRelevance_Concurrent(FeatureLevel);
|
|
}
|
|
}
|
|
|
|
// Mask
|
|
if ((GLandscapeEditRenderMode & ELandscapeEditRenderMode::Mask) && GMaskRegionMaterial != nullptr &&
|
|
((EditToolRenderData && (EditToolRenderData->SelectedType & FLandscapeEditToolRenderData::ST_REGION)) || (!(GLandscapeEditRenderMode & ELandscapeEditRenderMode::InvertedMask))))
|
|
{
|
|
Result.bDynamicRelevance = true;
|
|
ToolRelevance |= GMaskRegionMaterial->GetRelevance_Concurrent(FeatureLevel);
|
|
}
|
|
|
|
ToolRelevance.SetPrimitiveViewRelevance(Result);
|
|
}
|
|
|
|
// Various visualizations need to render using dynamic relevance
|
|
if ((View->Family->EngineShowFlags.Bounds && IsSelected()) ||
|
|
GLandscapeDebugOptions.bShowPatches)
|
|
{
|
|
Result.bDynamicRelevance = true;
|
|
}
|
|
#endif
|
|
|
|
#if WITH_EDITOR || !(UE_BUILD_SHIPPING || UE_BUILD_TEST)
|
|
const bool bInCollisionView = View->Family->EngineShowFlags.CollisionVisibility || View->Family->EngineShowFlags.CollisionPawn;
|
|
#endif
|
|
|
|
// Use the dynamic path for rendering landscape components pass only for Rich Views or if the static path is disabled for debug.
|
|
if (IsRichView(*View->Family) ||
|
|
#if WITH_EDITOR || !(UE_BUILD_SHIPPING || UE_BUILD_TEST)
|
|
bInCollisionView ||
|
|
#endif
|
|
GLandscapeDebugOptions.bDisableStatic ||
|
|
View->Family->EngineShowFlags.Wireframe ||
|
|
#if WITH_EDITOR
|
|
(IsSelected() && !GLandscapeEditModeActive) ||
|
|
GLandscapeViewMode != ELandscapeViewMode::Normal ||
|
|
#else
|
|
IsSelected() ||
|
|
#endif
|
|
!IsStaticPathAvailable())
|
|
{
|
|
Result.bDynamicRelevance = true;
|
|
}
|
|
else
|
|
{
|
|
Result.bStaticRelevance = true;
|
|
}
|
|
|
|
Result.bShadowRelevance = (GAllowLandscapeShadows > 0) && IsShadowCast(View);
|
|
return Result;
|
|
}
|
|
|
|
/**
|
|
* Determines the relevance of this primitive's elements to the given light.
|
|
* @param LightSceneProxy The light to determine relevance for
|
|
* @param bDynamic (output) The light is dynamic for this primitive
|
|
* @param bRelevant (output) The light is relevant for this primitive
|
|
* @param bLightMapped (output) The light is light mapped for this primitive
|
|
*/
|
|
void FLandscapeComponentSceneProxy::GetLightRelevance(const FLightSceneProxy* LightSceneProxy, bool& bDynamic, bool& bRelevant, bool& bLightMapped, bool& bShadowMapped) const
|
|
{
|
|
// Attach the light to the primitive's static meshes.
|
|
bDynamic = true;
|
|
bRelevant = false;
|
|
bLightMapped = true;
|
|
bShadowMapped = true;
|
|
|
|
if (ComponentLightInfo)
|
|
{
|
|
ELightInteractionType InteractionType = ComponentLightInfo->GetInteraction(LightSceneProxy).GetType();
|
|
|
|
if (InteractionType != LIT_CachedIrrelevant)
|
|
{
|
|
bRelevant = true;
|
|
}
|
|
|
|
if (InteractionType != LIT_CachedLightMap && InteractionType != LIT_CachedIrrelevant)
|
|
{
|
|
bLightMapped = false;
|
|
}
|
|
|
|
if (InteractionType != LIT_Dynamic)
|
|
{
|
|
bDynamic = false;
|
|
}
|
|
|
|
if (InteractionType != LIT_CachedSignedDistanceFieldShadowMap2D)
|
|
{
|
|
bShadowMapped = false;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
bRelevant = true;
|
|
bLightMapped = false;
|
|
}
|
|
}
|
|
|
|
FLightInteraction FLandscapeComponentSceneProxy::FLandscapeLCI::GetInteraction(const class FLightSceneProxy* LightSceneProxy) const
|
|
{
|
|
// ask base class
|
|
ELightInteractionType LightInteraction = GetStaticInteraction(LightSceneProxy, IrrelevantLights);
|
|
|
|
if(LightInteraction != LIT_MAX)
|
|
{
|
|
return FLightInteraction(LightInteraction);
|
|
}
|
|
|
|
// Use dynamic lighting if the light doesn't have static lighting.
|
|
return FLightInteraction::Dynamic();
|
|
}
|
|
|
|
#if WITH_EDITOR
|
|
namespace DebugColorMask
|
|
{
|
|
const FLinearColor Masks[5] =
|
|
{
|
|
FLinearColor(1.f, 0.f, 0.f, 0.f),
|
|
FLinearColor(0.f, 1.f, 0.f, 0.f),
|
|
FLinearColor(0.f, 0.f, 1.f, 0.f),
|
|
FLinearColor(0.f, 0.f, 0.f, 1.f),
|
|
FLinearColor(0.f, 0.f, 0.f, 0.f)
|
|
};
|
|
};
|
|
#endif
|
|
|
|
void FLandscapeComponentSceneProxy::OnTransformChanged()
|
|
{
|
|
// Set Lightmap ScaleBias
|
|
int32 PatchExpandCountX = 0;
|
|
int32 PatchExpandCountY = 0;
|
|
int32 DesiredSize = 1; // output by GetTerrainExpandPatchCount but not used below
|
|
const float LightMapRatio = ::GetTerrainExpandPatchCount(StaticLightingResolution, PatchExpandCountX, PatchExpandCountY, ComponentSizeQuads, (NumSubsections * (SubsectionSizeQuads + 1)), DesiredSize, StaticLightingLOD);
|
|
const float LightmapLODScaleX = LightMapRatio / ((ComponentSizeVerts >> StaticLightingLOD) + 2 * PatchExpandCountX);
|
|
const float LightmapLODScaleY = LightMapRatio / ((ComponentSizeVerts >> StaticLightingLOD) + 2 * PatchExpandCountY);
|
|
const float LightmapBiasX = PatchExpandCountX * LightmapLODScaleX;
|
|
const float LightmapBiasY = PatchExpandCountY * LightmapLODScaleY;
|
|
const float LightmapScaleX = LightmapLODScaleX * (float)((ComponentSizeVerts >> StaticLightingLOD) - 1) / ComponentSizeQuads;
|
|
const float LightmapScaleY = LightmapLODScaleY * (float)((ComponentSizeVerts >> StaticLightingLOD) - 1) / ComponentSizeQuads;
|
|
const float LightmapExtendFactorX = (float)SubsectionSizeQuads * LightmapScaleX;
|
|
const float LightmapExtendFactorY = (float)SubsectionSizeQuads * LightmapScaleY;
|
|
|
|
// cache component's WorldToLocal
|
|
FMatrix LtoW = GetLocalToWorld();
|
|
WorldToLocal = LtoW.InverseFast();
|
|
|
|
// cache component's LocalToWorldNoScaling
|
|
LocalToWorldNoScaling = LtoW;
|
|
LocalToWorldNoScaling.RemoveScaling();
|
|
|
|
// Set FLandscapeUniformVSParameters for this subsection
|
|
FLandscapeUniformShaderParameters LandscapeParams;
|
|
LandscapeParams.HeightmapUVScaleBias = HeightmapScaleBias;
|
|
LandscapeParams.WeightmapUVScaleBias = WeightmapScaleBias;
|
|
LandscapeParams.LocalToWorldNoScaling = LocalToWorldNoScaling;
|
|
|
|
LandscapeParams.LandscapeLightmapScaleBias = FVector4(
|
|
LightmapScaleX,
|
|
LightmapScaleY,
|
|
LightmapBiasY,
|
|
LightmapBiasX);
|
|
LandscapeParams.SubsectionSizeVertsLayerUVPan = FVector4(
|
|
SubsectionSizeVerts,
|
|
1.f / (float)SubsectionSizeQuads,
|
|
SectionBase.X,
|
|
SectionBase.Y
|
|
);
|
|
LandscapeParams.SubsectionOffsetParams = FVector4(
|
|
HeightmapSubsectionOffsetU,
|
|
HeightmapSubsectionOffsetV,
|
|
WeightmapSubsectionOffset,
|
|
SubsectionSizeQuads
|
|
);
|
|
LandscapeParams.LightmapSubsectionOffsetParams = FVector4(
|
|
LightmapExtendFactorX,
|
|
LightmapExtendFactorY,
|
|
0,
|
|
0
|
|
);
|
|
|
|
LandscapeUniformShaderParameters.SetContents(LandscapeParams);
|
|
}
|
|
|
|
/**
|
|
* Draw the scene proxy as a dynamic element
|
|
*
|
|
* @param PDI - draw interface to render to
|
|
* @param View - current view
|
|
*/
|
|
|
|
void FLandscapeComponentSceneProxy::DrawStaticElements(FStaticPrimitiveDrawInterface* PDI)
|
|
{
|
|
const int32 NumBatchesPerLOD = (ForcedLOD < 0 && NumSubsections > 1) ? (FMath::Square(NumSubsections) + 1) : 1;
|
|
const int32 NumBatchesLastLOD = (ForcedLOD < 0) ? (1 + LastLOD - FirstLOD) * NumBatchesPerLOD : 1;
|
|
|
|
StaticBatchParamArray.Empty(ForcedLOD < 0 ? (1 + LastLOD - FirstLOD) * NumBatchesPerLOD : 1);
|
|
|
|
const int32 LastMaterialIndex = MaterialInterfacesByLOD.Num() - 1;
|
|
const int32 LastMaterialLOD = FMath::Min(LastLOD, LastMaterialIndex);
|
|
|
|
for (int i = FirstLOD; i <= LastLOD; ++i)
|
|
{
|
|
// the LastMaterialLOD covers all LODs up to LastLOD
|
|
const bool bLast = (i >= LastMaterialLOD);
|
|
|
|
FMeshBatch MeshBatch;
|
|
MeshBatch.Elements.Empty(bLast ? NumBatchesLastLOD : NumBatchesPerLOD);
|
|
|
|
UMaterialInterface* MaterialInterface = MaterialInterfacesByLOD[FMath::Min(i, LastMaterialIndex)];
|
|
|
|
// Could be different from bRequiresAdjacencyInformation during shader compilation
|
|
bool bCurrentRequiresAdjacencyInformation = MaterialRenderingRequiresAdjacencyInformation_RenderingThread(MaterialInterface, VertexFactory->GetType(), GetScene().GetFeatureLevel());
|
|
|
|
if (bCurrentRequiresAdjacencyInformation)
|
|
{
|
|
check(SharedBuffers->AdjacencyIndexBuffers);
|
|
}
|
|
|
|
FMaterialRenderProxy* RenderProxy = MaterialInterface->GetRenderProxy(false);
|
|
|
|
MeshBatch.VertexFactory = VertexFactory;
|
|
MeshBatch.MaterialRenderProxy = RenderProxy;
|
|
MeshBatch.LCI = ComponentLightInfo.Get();
|
|
MeshBatch.ReverseCulling = IsLocalToWorldDeterminantNegative();
|
|
MeshBatch.CastShadow = true;
|
|
MeshBatch.Type = bCurrentRequiresAdjacencyInformation ? PT_12_ControlPointPatchList : PT_TriangleList;
|
|
MeshBatch.DepthPriorityGroup = SDPG_World;
|
|
MeshBatch.LODIndex = 0;
|
|
MeshBatch.bRequiresPerElementVisibility = true;
|
|
|
|
for (int32 LOD = i; LOD <= (bLast ? LastLOD : i); LOD++)
|
|
{
|
|
int32 LodSubsectionSizeVerts = SubsectionSizeVerts >> LOD;
|
|
|
|
if (ForcedLOD < 0 && NumSubsections > 1)
|
|
{
|
|
// Per-subsection batch elements
|
|
for (int32 SubY = 0; SubY < NumSubsections; SubY++)
|
|
{
|
|
for (int32 SubX = 0; SubX < NumSubsections; SubX++)
|
|
{
|
|
FMeshBatchElement* BatchElement = new(MeshBatch.Elements) FMeshBatchElement;
|
|
FLandscapeBatchElementParams* BatchElementParams = new(StaticBatchParamArray)FLandscapeBatchElementParams;
|
|
BatchElement->UserData = BatchElementParams;
|
|
BatchElement->PrimitiveUniformBufferResource = &GetUniformBuffer();
|
|
BatchElementParams->LandscapeUniformShaderParametersResource = &LandscapeUniformShaderParameters;
|
|
BatchElementParams->LocalToWorldNoScalingPtr = &LocalToWorldNoScaling;
|
|
BatchElementParams->SceneProxy = this;
|
|
BatchElementParams->SubX = SubX;
|
|
BatchElementParams->SubY = SubY;
|
|
BatchElementParams->CurrentLOD = LOD;
|
|
uint32 NumPrimitives = FMath::Square((LodSubsectionSizeVerts - 1)) * 2;
|
|
if (bCurrentRequiresAdjacencyInformation)
|
|
{
|
|
BatchElement->IndexBuffer = SharedBuffers->AdjacencyIndexBuffers->IndexBuffers[LOD];
|
|
BatchElement->FirstIndex = (SubX + SubY * NumSubsections) * NumPrimitives * 12;
|
|
}
|
|
else
|
|
{
|
|
BatchElement->IndexBuffer = SharedBuffers->IndexBuffers[LOD];
|
|
BatchElement->FirstIndex = (SubX + SubY * NumSubsections) * NumPrimitives * 3;
|
|
}
|
|
BatchElement->NumPrimitives = NumPrimitives;
|
|
BatchElement->MinVertexIndex = SharedBuffers->IndexRanges[LOD].MinIndex[SubX][SubY];
|
|
BatchElement->MaxVertexIndex = SharedBuffers->IndexRanges[LOD].MaxIndex[SubX][SubY];
|
|
}
|
|
}
|
|
}
|
|
|
|
// Combined batch element
|
|
FMeshBatchElement* BatchElement = new(MeshBatch.Elements) FMeshBatchElement;
|
|
FLandscapeBatchElementParams* BatchElementParams = new(StaticBatchParamArray)FLandscapeBatchElementParams;
|
|
BatchElementParams->LocalToWorldNoScalingPtr = &LocalToWorldNoScaling;
|
|
BatchElement->UserData = BatchElementParams;
|
|
BatchElement->PrimitiveUniformBufferResource = &GetUniformBuffer();
|
|
BatchElementParams->LandscapeUniformShaderParametersResource = &LandscapeUniformShaderParameters;
|
|
BatchElementParams->SceneProxy = this;
|
|
BatchElementParams->SubX = -1;
|
|
BatchElementParams->SubY = -1;
|
|
BatchElementParams->CurrentLOD = LOD;
|
|
BatchElement->IndexBuffer = bCurrentRequiresAdjacencyInformation ? SharedBuffers->AdjacencyIndexBuffers->IndexBuffers[LOD] : SharedBuffers->IndexBuffers[LOD];
|
|
BatchElement->NumPrimitives = FMath::Square((LodSubsectionSizeVerts - 1)) * FMath::Square(NumSubsections) * 2;
|
|
BatchElement->FirstIndex = 0;
|
|
BatchElement->MinVertexIndex = SharedBuffers->IndexRanges[LOD].MinIndexFull;
|
|
BatchElement->MaxVertexIndex = SharedBuffers->IndexRanges[LOD].MaxIndexFull;
|
|
}
|
|
|
|
PDI->DrawMesh(MeshBatch, FLT_MAX);
|
|
|
|
if (bLast)
|
|
{
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
uint64 FLandscapeVertexFactory::GetStaticBatchElementVisibility(const class FSceneView& View, const struct FMeshBatch* Batch) const
|
|
{
|
|
const FLandscapeComponentSceneProxy* SceneProxy = ((FLandscapeBatchElementParams*)Batch->Elements[0].UserData)->SceneProxy;
|
|
return SceneProxy->GetStaticBatchElementVisibility(View, Batch);
|
|
}
|
|
|
|
uint64 FLandscapeComponentSceneProxy::GetStaticBatchElementVisibility(const class FSceneView& View, const struct FMeshBatch* Batch) const
|
|
{
|
|
uint64 BatchesToRenderMask = 0;
|
|
|
|
SCOPE_CYCLE_COUNTER(STAT_LandscapeStaticDrawLODTime);
|
|
if (ForcedLOD >= 0)
|
|
{
|
|
// When forcing LOD we only create one Batch Element
|
|
ensure(Batch->Elements.Num() == 1);
|
|
int32 BatchElementIndex = 0;
|
|
BatchesToRenderMask |= (((uint64)1) << BatchElementIndex);
|
|
INC_DWORD_STAT(STAT_LandscapeDrawCalls);
|
|
INC_DWORD_STAT_BY(STAT_LandscapeTriangles, Batch->Elements[BatchElementIndex].NumPrimitives);
|
|
}
|
|
else
|
|
{
|
|
// camera position in local heightmap space
|
|
FVector CameraLocalPos3D = WorldToLocal.TransformPosition(View.ViewMatrices.ViewOrigin);
|
|
FVector2D CameraLocalPos(CameraLocalPos3D.X, CameraLocalPos3D.Y);
|
|
|
|
int32 BatchesPerLOD = NumSubsections > 1 ? FMath::Square(NumSubsections) + 1 : 1;
|
|
int32 CalculatedLods[LANDSCAPE_MAX_SUBSECTION_NUM][LANDSCAPE_MAX_SUBSECTION_NUM];
|
|
int32 CombinedLOD = -1;
|
|
int32 bAllSameLOD = true;
|
|
|
|
int32 BatchLOD = ((FLandscapeBatchElementParams*)Batch->Elements[0].UserData)->CurrentLOD;
|
|
|
|
for (int32 SubY = 0; SubY < NumSubsections; SubY++)
|
|
{
|
|
for (int32 SubX = 0; SubX < NumSubsections; SubX++)
|
|
{
|
|
int32 ThisSubsectionLOD = CalcLODForSubsection(View, SubX, SubY, CameraLocalPos);
|
|
// check if all LODs are the same.
|
|
if (ThisSubsectionLOD != CombinedLOD && CombinedLOD != -1)
|
|
{
|
|
bAllSameLOD = false;
|
|
}
|
|
CombinedLOD = ThisSubsectionLOD;
|
|
CalculatedLods[SubX][SubY] = ThisSubsectionLOD;
|
|
}
|
|
}
|
|
|
|
if (bAllSameLOD && NumSubsections > 1 && !GLandscapeDebugOptions.bDisableCombine)
|
|
{
|
|
// choose the combined batch element
|
|
int32 BatchElementIndex = (CombinedLOD - BatchLOD + 1) * BatchesPerLOD - 1;
|
|
if (Batch->Elements.IsValidIndex(BatchElementIndex))
|
|
{
|
|
BatchesToRenderMask |= (((uint64)1) << BatchElementIndex);
|
|
INC_DWORD_STAT(STAT_LandscapeDrawCalls);
|
|
INC_DWORD_STAT_BY(STAT_LandscapeTriangles, Batch->Elements[BatchElementIndex].NumPrimitives);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
for (int32 SubY = 0; SubY < NumSubsections; SubY++)
|
|
{
|
|
for (int32 SubX = 0; SubX < NumSubsections; SubX++)
|
|
{
|
|
int32 BatchElementIndex = (CalculatedLods[SubX][SubY] - BatchLOD) * BatchesPerLOD + SubY * NumSubsections + SubX;
|
|
if (Batch->Elements.IsValidIndex(BatchElementIndex))
|
|
{
|
|
BatchesToRenderMask |= (((uint64)1) << BatchElementIndex);
|
|
INC_DWORD_STAT(STAT_LandscapeDrawCalls);
|
|
INC_DWORD_STAT_BY(STAT_LandscapeTriangles, Batch->Elements[BatchElementIndex].NumPrimitives);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
INC_DWORD_STAT(STAT_LandscapeComponents);
|
|
|
|
return BatchesToRenderMask;
|
|
}
|
|
|
|
float FLandscapeComponentSceneProxy::CalcDesiredLOD(const FSceneView& View, const FVector2D& CameraLocalPos, int32 SubX, int32 SubY) const
|
|
{
|
|
int32 OverrideLOD = GetCVarForceLOD();
|
|
#if WITH_EDITOR
|
|
if (View.Family->LandscapeLODOverride >= 0)
|
|
{
|
|
OverrideLOD = View.Family->LandscapeLODOverride;
|
|
}
|
|
#endif
|
|
if (OverrideLOD >= 0)
|
|
{
|
|
return FMath::Clamp<int32>(OverrideLOD, FirstLOD, LastLOD);
|
|
}
|
|
|
|
// FLandscapeComponentSceneProxy::NumSubsections, SubsectionSizeQuads, MaxLOD, LODFalloff and LODDistance are the same for all components and so are safe to use in the neighbour LOD calculations
|
|
// HeightmapTexture, LODBias, ForcedLOD are component-specific with neighbor lookup
|
|
const bool bIsInThisComponent = (SubX >= 0 && SubX < NumSubsections && SubY >= 0 && SubY < NumSubsections);
|
|
|
|
auto* SubsectionHeightmapTexture = HeightmapTexture;
|
|
int8 SubsectionForcedLOD = ForcedLOD;
|
|
int8 SubsectionLODBias = LODBias;
|
|
|
|
if (SubX < 0)
|
|
{
|
|
SubsectionHeightmapTexture = Neighbors[1] ? Neighbors[1]->HeightmapTexture : nullptr;
|
|
SubsectionForcedLOD = Neighbors[1] ? Neighbors[1]->ForcedLOD : -1;
|
|
SubsectionLODBias = Neighbors[1] ? Neighbors[1]->LODBias : 0;
|
|
}
|
|
else if (SubX >= NumSubsections)
|
|
{
|
|
SubsectionHeightmapTexture = Neighbors[2] ? Neighbors[2]->HeightmapTexture : nullptr;
|
|
SubsectionForcedLOD = Neighbors[2] ? Neighbors[2]->ForcedLOD : -1;
|
|
SubsectionLODBias = Neighbors[2] ? Neighbors[2]->LODBias : 0;
|
|
}
|
|
else if (SubY < 0)
|
|
{
|
|
SubsectionHeightmapTexture = Neighbors[0] ? Neighbors[0]->HeightmapTexture : nullptr;
|
|
SubsectionForcedLOD = Neighbors[0] ? Neighbors[0]->ForcedLOD : -1;
|
|
SubsectionLODBias = Neighbors[0] ? Neighbors[0]->LODBias : 0;
|
|
}
|
|
else if (SubY >= NumSubsections)
|
|
{
|
|
SubsectionHeightmapTexture = Neighbors[3] ? Neighbors[3]->HeightmapTexture : nullptr;
|
|
SubsectionForcedLOD = Neighbors[3] ? Neighbors[3]->ForcedLOD : -1;
|
|
SubsectionLODBias = Neighbors[3] ? Neighbors[3]->LODBias : 0;
|
|
}
|
|
|
|
SubsectionLODBias = FMath::Clamp<int8>(SubsectionLODBias + GLandscapeMeshLODBias, FirstLOD, LastLOD);
|
|
|
|
const int32 MinStreamedLOD = SubsectionHeightmapTexture ? FMath::Min<int32>(((FTexture2DResource*)SubsectionHeightmapTexture->Resource)->GetCurrentFirstMip(), FMath::CeilLogTwo(SubsectionSizeVerts) - 1) : 0;
|
|
|
|
float fLOD = FLT_MAX;
|
|
|
|
if (SubsectionForcedLOD >= 0)
|
|
{
|
|
fLOD = SubsectionForcedLOD;
|
|
}
|
|
else
|
|
{
|
|
if (View.IsPerspectiveProjection())
|
|
{
|
|
FVector2D ComponentPosition(0.5f * (float)SubsectionSizeQuads, 0.5f * (float)SubsectionSizeQuads);
|
|
FVector2D CurrentCameraLocalPos = CameraLocalPos - FVector2D(SubX * SubsectionSizeQuads, SubY * SubsectionSizeQuads);
|
|
float ComponentDistance = FVector2D(CurrentCameraLocalPos - ComponentPosition).Size() + DistDiff;
|
|
switch (LODFalloff)
|
|
{
|
|
case ELandscapeLODFalloff::SquareRoot:
|
|
fLOD = FMath::Sqrt(FMath::Max(0.f, ComponentDistance / LODDistance));
|
|
break;
|
|
default:
|
|
case ELandscapeLODFalloff::Linear:
|
|
fLOD = ComponentDistance / LODDistance;
|
|
break;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
float Scale = 1.0f / (View.ViewRect.Width() * View.ViewMatrices.ProjMatrix.M[0][0]);
|
|
|
|
// The "/ 5.0f" is totally arbitrary
|
|
switch (LODFalloff)
|
|
{
|
|
case ELandscapeLODFalloff::SquareRoot:
|
|
fLOD = FMath::Sqrt(Scale / 5.0f);
|
|
break;
|
|
default:
|
|
case ELandscapeLODFalloff::Linear:
|
|
fLOD = Scale / 5.0f;
|
|
break;
|
|
}
|
|
}
|
|
|
|
fLOD = FMath::Clamp<float>(fLOD, SubsectionLODBias, FMath::Min<int32>(MaxLOD, MaxLOD + SubsectionLODBias));
|
|
}
|
|
|
|
// ultimately due to texture streaming we sometimes need to go past MaxLOD
|
|
fLOD = FMath::Max<float>(fLOD, MinStreamedLOD);
|
|
|
|
return fLOD;
|
|
}
|
|
|
|
int32 FLandscapeComponentSceneProxy::CalcLODForSubsection(const FSceneView& View, int32 SubX, int32 SubY, const FVector2D& CameraLocalPos) const
|
|
{
|
|
return FMath::FloorToInt(CalcDesiredLOD(View, CameraLocalPos, SubX, SubY));
|
|
}
|
|
|
|
void FLandscapeComponentSceneProxy::CalcLODParamsForSubsection(const FSceneView& View, const FVector2D& CameraLocalPos, int32 SubX, int32 SubY, int32 BatchLOD, float& OutfLOD, FVector4& OutNeighborLODs) const
|
|
{
|
|
OutfLOD = FMath::Max<float>(BatchLOD, CalcDesiredLOD(View, CameraLocalPos, SubX, SubY));
|
|
|
|
OutNeighborLODs[0] = FMath::Max<float>(OutfLOD, CalcDesiredLOD(View, CameraLocalPos, SubX, SubY - 1));
|
|
OutNeighborLODs[1] = FMath::Max<float>(OutfLOD, CalcDesiredLOD(View, CameraLocalPos, SubX - 1, SubY ));
|
|
OutNeighborLODs[2] = FMath::Max<float>(OutfLOD, CalcDesiredLOD(View, CameraLocalPos, SubX + 1, SubY ));
|
|
OutNeighborLODs[3] = FMath::Max<float>(OutfLOD, CalcDesiredLOD(View, CameraLocalPos, SubX, SubY + 1));
|
|
}
|
|
|
|
namespace
|
|
{
|
|
FLinearColor GetColorForLod(int32 CurrentLOD, int32 ForcedLOD)
|
|
{
|
|
int32 ColorIndex = INDEX_NONE;
|
|
if (GEngine->LODColorationColors.Num() > 0)
|
|
{
|
|
ColorIndex = CurrentLOD;
|
|
ColorIndex = FMath::Clamp(ColorIndex, 0, GEngine->LODColorationColors.Num() - 1);
|
|
}
|
|
const FLinearColor& LODColor = ColorIndex != INDEX_NONE ? GEngine->LODColorationColors[ColorIndex] : FLinearColor::Gray;
|
|
return ForcedLOD >= 0 ? LODColor : LODColor * 0.2f;
|
|
}
|
|
}
|
|
|
|
void FLandscapeComponentSceneProxy::GetDynamicMeshElements(const TArray<const FSceneView*>& Views, const FSceneViewFamily& ViewFamily, uint32 VisibilityMap, FMeshElementCollector& Collector) const
|
|
{
|
|
QUICK_SCOPE_CYCLE_COUNTER(STAT_FLandscapeComponentSceneProxy_GetMeshElements);
|
|
|
|
#if WITH_EDITOR || !(UE_BUILD_SHIPPING || UE_BUILD_TEST)
|
|
const bool bInCollisionView = ViewFamily.EngineShowFlags.CollisionVisibility || ViewFamily.EngineShowFlags.CollisionPawn;
|
|
const bool bDrawSimpleCollision = ViewFamily.EngineShowFlags.CollisionPawn && CollisionResponse.GetResponse(ECC_Pawn) != ECR_Ignore;
|
|
const bool bDrawComplexCollision = ViewFamily.EngineShowFlags.CollisionVisibility && CollisionResponse.GetResponse(ECC_Visibility) != ECR_Ignore;
|
|
#endif
|
|
|
|
int32 NumPasses = 0;
|
|
int32 NumTriangles = 0;
|
|
int32 NumDrawCalls = 0;
|
|
const bool bIsWireframe = ViewFamily.EngineShowFlags.Wireframe;
|
|
|
|
for (int32 ViewIndex = 0; ViewIndex < Views.Num(); ViewIndex++)
|
|
{
|
|
if (VisibilityMap & (1 << ViewIndex))
|
|
{
|
|
const FSceneView* View = Views[ViewIndex];
|
|
FVector CameraLocalPos3D = WorldToLocal.TransformPosition(View->ViewMatrices.ViewOrigin);
|
|
FVector2D CameraLocalPos(CameraLocalPos3D.X, CameraLocalPos3D.Y);
|
|
|
|
FLandscapeElementParamArray& ParameterArray = Collector.AllocateOneFrameResource<FLandscapeElementParamArray>();
|
|
ParameterArray.ElementParams.Empty(NumSubsections * NumSubsections);
|
|
ParameterArray.ElementParams.AddDefaulted(NumSubsections * NumSubsections);
|
|
|
|
FMeshBatch& Mesh = Collector.AllocateMesh();
|
|
Mesh.LCI = ComponentLightInfo.Get();
|
|
Mesh.CastShadow = true;
|
|
Mesh.VertexFactory = VertexFactory;
|
|
Mesh.ReverseCulling = IsLocalToWorldDeterminantNegative();
|
|
|
|
#if WITH_EDITOR
|
|
FMeshBatch& MeshTools = Collector.AllocateMesh();
|
|
MeshTools.LCI = ComponentLightInfo.Get();
|
|
MeshTools.Type = PT_TriangleList;
|
|
MeshTools.CastShadow = false;
|
|
MeshTools.VertexFactory = VertexFactory;
|
|
MeshTools.ReverseCulling = IsLocalToWorldDeterminantNegative();
|
|
#endif
|
|
|
|
// Calculate the LOD to use for the material
|
|
// TODO: Render different subsections with different material LODs like the static render pass does
|
|
int32 MaterialLOD = MaterialInterfacesByLOD.Num() - 1;
|
|
|
|
// Setup the LOD parameters
|
|
int32 CalculatedLods[LANDSCAPE_MAX_SUBSECTION_NUM][LANDSCAPE_MAX_SUBSECTION_NUM];
|
|
for (int32 SubY = 0; SubY < NumSubsections; SubY++)
|
|
{
|
|
for (int32 SubX = 0; SubX < NumSubsections; SubX++)
|
|
{
|
|
int32 CurrentLOD = CalcLODForSubsection(*View, SubX, SubY, CameraLocalPos);
|
|
#if WITH_EDITOR || !(UE_BUILD_SHIPPING || UE_BUILD_TEST)
|
|
if (bInCollisionView)
|
|
{
|
|
if (bDrawSimpleCollision)
|
|
{
|
|
CurrentLOD = FMath::Max(CollisionMipLevel, SimpleCollisionMipLevel);
|
|
}
|
|
else if (bDrawComplexCollision)
|
|
{
|
|
CurrentLOD = CollisionMipLevel;
|
|
}
|
|
}
|
|
#endif
|
|
CalculatedLods[SubY][SubX] = CurrentLOD;
|
|
MaterialLOD = FMath::Min(MaterialLOD, CurrentLOD);
|
|
}
|
|
}
|
|
|
|
UMaterialInterface* const MaterialInterface = MaterialInterfacesByLOD[MaterialLOD];
|
|
|
|
// Could be different from bRequiresAdjacencyInformation during shader compilation
|
|
const bool bCurrentRequiresAdjacencyInformation = MaterialRenderingRequiresAdjacencyInformation_RenderingThread(MaterialInterface, VertexFactory->GetType(), View->GetFeatureLevel());
|
|
Mesh.Type = bCurrentRequiresAdjacencyInformation ? PT_12_ControlPointPatchList : PT_TriangleList;
|
|
|
|
for (int32 SubY = 0; SubY < NumSubsections; SubY++)
|
|
{
|
|
for (int32 SubX = 0; SubX < NumSubsections; SubX++)
|
|
{
|
|
const int32 SubSectionIdx = SubX + SubY*NumSubsections;
|
|
const int32 CurrentLOD = CalculatedLods[SubY][SubX];
|
|
#if !(UE_BUILD_SHIPPING || UE_BUILD_TEST)
|
|
// We simplify this by considering only the biggest LOD index for this mesh element.
|
|
Mesh.VisualizeLODIndex = (int8)FMath::Max((int32)Mesh.VisualizeLODIndex, CurrentLOD);
|
|
#endif
|
|
FMeshBatchElement& BatchElement = (SubX == 0 && SubY == 0) ? *Mesh.Elements.GetData() : *(new(Mesh.Elements) FMeshBatchElement);
|
|
BatchElement.PrimitiveUniformBufferResource = &GetUniformBuffer();
|
|
FLandscapeBatchElementParams& BatchElementParams = ParameterArray.ElementParams[SubSectionIdx];
|
|
BatchElementParams.LocalToWorldNoScalingPtr = &LocalToWorldNoScaling;
|
|
BatchElement.UserData = &BatchElementParams;
|
|
|
|
BatchElementParams.LandscapeUniformShaderParametersResource = &LandscapeUniformShaderParameters;
|
|
BatchElementParams.SceneProxy = this;
|
|
BatchElementParams.SubX = SubX;
|
|
BatchElementParams.SubY = SubY;
|
|
BatchElementParams.CurrentLOD = CurrentLOD;
|
|
|
|
int32 LodSubsectionSizeVerts = (SubsectionSizeVerts >> CurrentLOD);
|
|
uint32 NumPrimitives = FMath::Square((LodSubsectionSizeVerts - 1)) * 2;
|
|
if (bCurrentRequiresAdjacencyInformation)
|
|
{
|
|
check(SharedBuffers->AdjacencyIndexBuffers);
|
|
BatchElement.IndexBuffer = SharedBuffers->AdjacencyIndexBuffers->IndexBuffers[CurrentLOD];
|
|
BatchElement.FirstIndex = (SubX + SubY * NumSubsections) * NumPrimitives * 12;
|
|
}
|
|
else
|
|
{
|
|
BatchElement.IndexBuffer = SharedBuffers->IndexBuffers[CurrentLOD];
|
|
BatchElement.FirstIndex = (SubX + SubY * NumSubsections) * NumPrimitives * 3;
|
|
}
|
|
BatchElement.NumPrimitives = NumPrimitives;
|
|
BatchElement.MinVertexIndex = SharedBuffers->IndexRanges[CurrentLOD].MinIndex[SubX][SubY];
|
|
BatchElement.MaxVertexIndex = SharedBuffers->IndexRanges[CurrentLOD].MaxIndex[SubX][SubY];
|
|
|
|
#if WITH_EDITOR
|
|
FMeshBatchElement& BatchElementTools = (SubX == 0 && SubY == 0) ? *MeshTools.Elements.GetData() : *(new(MeshTools.Elements) FMeshBatchElement);
|
|
BatchElementTools.PrimitiveUniformBufferResource = &GetUniformBuffer();
|
|
BatchElementTools.UserData = &BatchElementParams;
|
|
|
|
// Tools never use tessellation
|
|
BatchElementTools.IndexBuffer = SharedBuffers->IndexBuffers[CurrentLOD];
|
|
BatchElementTools.NumPrimitives = NumPrimitives;
|
|
BatchElementTools.FirstIndex = (SubX + SubY * NumSubsections) * NumPrimitives * 3;
|
|
BatchElementTools.MinVertexIndex = SharedBuffers->IndexRanges[CurrentLOD].MinIndex[SubX][SubY];
|
|
BatchElementTools.MaxVertexIndex = SharedBuffers->IndexRanges[CurrentLOD].MaxIndex[SubX][SubY];
|
|
#endif
|
|
}
|
|
}
|
|
|
|
// Render the landscape component
|
|
#if WITH_EDITOR
|
|
const bool bMaterialModifiesMeshPosition = MaterialInterface->GetRenderProxy(false)->GetMaterial(View->GetFeatureLevel())->MaterialModifiesMeshPosition_RenderThread();
|
|
|
|
switch (GLandscapeViewMode)
|
|
{
|
|
case ELandscapeViewMode::DebugLayer:
|
|
if (GLayerDebugColorMaterial && EditToolRenderData)
|
|
{
|
|
auto DebugColorMaterialInstance = new FLandscapeDebugMaterialRenderProxy(GLayerDebugColorMaterial->GetRenderProxy(false),
|
|
(EditToolRenderData->DebugChannelR >= 0 ? WeightmapTextures[EditToolRenderData->DebugChannelR / 4] : nullptr),
|
|
(EditToolRenderData->DebugChannelG >= 0 ? WeightmapTextures[EditToolRenderData->DebugChannelG / 4] : nullptr),
|
|
(EditToolRenderData->DebugChannelB >= 0 ? WeightmapTextures[EditToolRenderData->DebugChannelB / 4] : nullptr),
|
|
(EditToolRenderData->DebugChannelR >= 0 ? DebugColorMask::Masks[EditToolRenderData->DebugChannelR % 4] : DebugColorMask::Masks[4]),
|
|
(EditToolRenderData->DebugChannelG >= 0 ? DebugColorMask::Masks[EditToolRenderData->DebugChannelG % 4] : DebugColorMask::Masks[4]),
|
|
(EditToolRenderData->DebugChannelB >= 0 ? DebugColorMask::Masks[EditToolRenderData->DebugChannelB % 4] : DebugColorMask::Masks[4])
|
|
);
|
|
|
|
MeshTools.MaterialRenderProxy = DebugColorMaterialInstance;
|
|
Collector.RegisterOneFrameMaterialProxy(DebugColorMaterialInstance);
|
|
|
|
MeshTools.bCanApplyViewModeOverrides = true;
|
|
MeshTools.bUseWireframeSelectionColoring = IsSelected();
|
|
|
|
Collector.AddMesh(ViewIndex, MeshTools);
|
|
|
|
NumPasses++;
|
|
NumTriangles += MeshTools.GetNumPrimitives();
|
|
NumDrawCalls += MeshTools.Elements.Num();
|
|
}
|
|
break;
|
|
|
|
case ELandscapeViewMode::LayerDensity:
|
|
if (EditToolRenderData)
|
|
{
|
|
int32 ColorIndex = FMath::Min<int32>(NumWeightmapLayerAllocations, GEngine->ShaderComplexityColors.Num());
|
|
auto LayerDensityMaterialInstance = new FColoredMaterialRenderProxy(GEngine->LevelColorationUnlitMaterial->GetRenderProxy(false), ColorIndex ? GEngine->ShaderComplexityColors[ColorIndex - 1] : FLinearColor::Black);
|
|
|
|
MeshTools.MaterialRenderProxy = LayerDensityMaterialInstance;
|
|
Collector.RegisterOneFrameMaterialProxy(LayerDensityMaterialInstance);
|
|
|
|
MeshTools.bCanApplyViewModeOverrides = true;
|
|
MeshTools.bUseWireframeSelectionColoring = IsSelected();
|
|
|
|
Collector.AddMesh(ViewIndex, MeshTools);
|
|
|
|
NumPasses++;
|
|
NumTriangles += MeshTools.GetNumPrimitives();
|
|
NumDrawCalls += MeshTools.Elements.Num();
|
|
}
|
|
break;
|
|
|
|
case ELandscapeViewMode::LayerUsage:
|
|
if (EditToolRenderData && GLandscapeLayerUsageMaterial)
|
|
{
|
|
float Rotation = ((SectionBase.X / ComponentSizeQuads) ^ (SectionBase.Y / ComponentSizeQuads)) & 1 ? 0 : 2.f * PI;
|
|
auto LayerUsageMaterialInstance = new FLandscapeLayerUsageRenderProxy(GLandscapeLayerUsageMaterial->GetRenderProxy(false), ComponentSizeVerts, LayerColors, Rotation);
|
|
MeshTools.MaterialRenderProxy = LayerUsageMaterialInstance;
|
|
Collector.RegisterOneFrameMaterialProxy(LayerUsageMaterialInstance);
|
|
MeshTools.bCanApplyViewModeOverrides = true;
|
|
MeshTools.bUseWireframeSelectionColoring = IsSelected();
|
|
Collector.AddMesh(ViewIndex, MeshTools);
|
|
NumPasses++;
|
|
NumTriangles += MeshTools.GetNumPrimitives();
|
|
NumDrawCalls += MeshTools.Elements.Num();
|
|
}
|
|
break;
|
|
|
|
case ELandscapeViewMode::LOD:
|
|
{
|
|
auto& TemplateMesh = bIsWireframe ? Mesh : MeshTools;
|
|
for (int32 i = 0; i < TemplateMesh.Elements.Num(); i++)
|
|
{
|
|
FMeshBatch& LODMesh = Collector.AllocateMesh();
|
|
LODMesh = TemplateMesh;
|
|
LODMesh.Elements.Empty(1);
|
|
LODMesh.Elements.Add(TemplateMesh.Elements[i]);
|
|
int32 CurrentLOD = ((FLandscapeBatchElementParams*)TemplateMesh.Elements[i].UserData)->CurrentLOD;
|
|
LODMesh.VisualizeLODIndex = CurrentLOD;
|
|
FLinearColor Color = GetColorForLod(CurrentLOD, ForcedLOD);
|
|
FMaterialRenderProxy* LODMaterialProxy =
|
|
bMaterialModifiesMeshPosition && bIsWireframe
|
|
? (FMaterialRenderProxy*)new FOverrideSelectionColorMaterialRenderProxy(MaterialInterface->GetRenderProxy(false), Color)
|
|
: (FMaterialRenderProxy*)new FColoredMaterialRenderProxy(GEngine->LevelColorationUnlitMaterial->GetRenderProxy(false), Color);
|
|
Collector.RegisterOneFrameMaterialProxy(LODMaterialProxy);
|
|
LODMesh.MaterialRenderProxy = LODMaterialProxy;
|
|
LODMesh.bCanApplyViewModeOverrides = !bIsWireframe;
|
|
LODMesh.bWireframe = bIsWireframe;
|
|
LODMesh.bUseWireframeSelectionColoring = IsSelected();
|
|
Collector.AddMesh(ViewIndex, LODMesh);
|
|
|
|
NumPasses++;
|
|
NumTriangles += TemplateMesh.Elements[i].NumPrimitives;
|
|
NumDrawCalls++;
|
|
}
|
|
}
|
|
break;
|
|
|
|
case ELandscapeViewMode::WireframeOnTop:
|
|
{
|
|
// base mesh
|
|
Mesh.MaterialRenderProxy = MaterialInterface->GetRenderProxy(false);
|
|
Mesh.bCanApplyViewModeOverrides = false;
|
|
Collector.AddMesh(ViewIndex, Mesh);
|
|
NumPasses++;
|
|
NumTriangles += Mesh.GetNumPrimitives();
|
|
NumDrawCalls += Mesh.Elements.Num();
|
|
|
|
// wireframe on top
|
|
FMeshBatch& WireMesh = Collector.AllocateMesh();
|
|
WireMesh = MeshTools;
|
|
auto WireMaterialInstance = new FColoredMaterialRenderProxy(GEngine->LevelColorationUnlitMaterial->GetRenderProxy(false), FLinearColor(0, 0, 1));
|
|
WireMesh.MaterialRenderProxy = WireMaterialInstance;
|
|
Collector.RegisterOneFrameMaterialProxy(WireMaterialInstance);
|
|
WireMesh.bCanApplyViewModeOverrides = false;
|
|
WireMesh.bWireframe = true;
|
|
Collector.AddMesh(ViewIndex, WireMesh);
|
|
NumPasses++;
|
|
NumTriangles += WireMesh.GetNumPrimitives();
|
|
NumDrawCalls++;
|
|
}
|
|
break;
|
|
|
|
default:
|
|
|
|
#endif // WITH_EDITOR
|
|
|
|
#if WITH_EDITOR || !(UE_BUILD_SHIPPING || UE_BUILD_TEST)
|
|
if (AllowDebugViewmodes() && bInCollisionView)
|
|
{
|
|
if (bDrawSimpleCollision || bDrawComplexCollision)
|
|
{
|
|
// Override the mesh's material with our material that draws the collision color
|
|
auto CollisionMaterialInstance = new FColoredMaterialRenderProxy(
|
|
GEngine->ShadedLevelColorationUnlitMaterial->GetRenderProxy(IsSelected(), IsHovered()),
|
|
WireframeColor
|
|
);
|
|
Collector.RegisterOneFrameMaterialProxy(CollisionMaterialInstance);
|
|
|
|
Mesh.MaterialRenderProxy = CollisionMaterialInstance;
|
|
Mesh.bCanApplyViewModeOverrides = true;
|
|
Mesh.bUseWireframeSelectionColoring = IsSelected();
|
|
|
|
Collector.AddMesh(ViewIndex, Mesh);
|
|
|
|
NumPasses++;
|
|
NumTriangles += Mesh.GetNumPrimitives();
|
|
NumDrawCalls += Mesh.Elements.Num();
|
|
}
|
|
}
|
|
else
|
|
#endif
|
|
// Regular Landscape rendering. Only use the dynamic path if we're rendering a rich view or we've disabled the static path for debugging.
|
|
if( IsRichView(ViewFamily) ||
|
|
GLandscapeDebugOptions.bDisableStatic ||
|
|
bIsWireframe ||
|
|
#if WITH_EDITOR
|
|
(IsSelected() && !GLandscapeEditModeActive) ||
|
|
#else
|
|
IsSelected() ||
|
|
#endif
|
|
!IsStaticPathAvailable())
|
|
{
|
|
Mesh.MaterialRenderProxy = MaterialInterface->GetRenderProxy(false);
|
|
|
|
Mesh.bCanApplyViewModeOverrides = true;
|
|
Mesh.bUseWireframeSelectionColoring = IsSelected();
|
|
|
|
Collector.AddMesh(ViewIndex, Mesh);
|
|
|
|
NumPasses++;
|
|
NumTriangles += Mesh.GetNumPrimitives();
|
|
NumDrawCalls += Mesh.Elements.Num();
|
|
}
|
|
|
|
#if WITH_EDITOR
|
|
} // switch
|
|
#endif
|
|
|
|
#if WITH_EDITOR
|
|
// Extra render passes for landscape tools
|
|
if (GLandscapeEditModeActive)
|
|
{
|
|
// Region selection
|
|
if (EditToolRenderData && EditToolRenderData->SelectedType)
|
|
{
|
|
if ((GLandscapeEditRenderMode & ELandscapeEditRenderMode::SelectRegion) && (EditToolRenderData->SelectedType & FLandscapeEditToolRenderData::ST_REGION)
|
|
&& !(GLandscapeEditRenderMode & ELandscapeEditRenderMode::Mask))
|
|
{
|
|
FMeshBatch& SelectMesh = Collector.AllocateMesh();
|
|
SelectMesh = MeshTools;
|
|
auto SelectMaterialInstance = new FLandscapeSelectMaterialRenderProxy(GSelectionRegionMaterial->GetRenderProxy(false), EditToolRenderData->DataTexture ? EditToolRenderData->DataTexture : GLandscapeBlackTexture);
|
|
SelectMesh.MaterialRenderProxy = SelectMaterialInstance;
|
|
Collector.RegisterOneFrameMaterialProxy(SelectMaterialInstance);
|
|
Collector.AddMesh(ViewIndex, SelectMesh);
|
|
NumPasses++;
|
|
NumTriangles += SelectMesh.GetNumPrimitives();
|
|
NumDrawCalls += SelectMesh.Elements.Num();
|
|
}
|
|
|
|
if ((GLandscapeEditRenderMode & ELandscapeEditRenderMode::SelectComponent) && (EditToolRenderData->SelectedType & FLandscapeEditToolRenderData::ST_COMPONENT))
|
|
{
|
|
FMeshBatch& SelectMesh = Collector.AllocateMesh();
|
|
SelectMesh = MeshTools;
|
|
SelectMesh.MaterialRenderProxy = GSelectionColorMaterial->GetRenderProxy(0);
|
|
Collector.AddMesh(ViewIndex, SelectMesh);
|
|
NumPasses++;
|
|
NumTriangles += SelectMesh.GetNumPrimitives();
|
|
NumDrawCalls += SelectMesh.Elements.Num();
|
|
}
|
|
}
|
|
|
|
// Mask
|
|
if ((GLandscapeEditRenderMode & ELandscapeEditRenderMode::SelectRegion) && (GLandscapeEditRenderMode & ELandscapeEditRenderMode::Mask))
|
|
{
|
|
if (EditToolRenderData && (EditToolRenderData->SelectedType & FLandscapeEditToolRenderData::ST_REGION))
|
|
{
|
|
FMeshBatch& MaskMesh = Collector.AllocateMesh();
|
|
MaskMesh = MeshTools;
|
|
auto MaskMaterialInstance = new FLandscapeMaskMaterialRenderProxy(GMaskRegionMaterial->GetRenderProxy(false), EditToolRenderData->DataTexture ? EditToolRenderData->DataTexture : GLandscapeBlackTexture, !!(GLandscapeEditRenderMode & ELandscapeEditRenderMode::InvertedMask));
|
|
MaskMesh.MaterialRenderProxy = MaskMaterialInstance;
|
|
Collector.RegisterOneFrameMaterialProxy(MaskMaterialInstance);
|
|
Collector.AddMesh(ViewIndex, MaskMesh);
|
|
NumPasses++;
|
|
NumTriangles += MaskMesh.GetNumPrimitives();
|
|
NumDrawCalls += MaskMesh.Elements.Num();
|
|
}
|
|
else if (!(GLandscapeEditRenderMode & ELandscapeEditRenderMode::InvertedMask))
|
|
{
|
|
FMeshBatch& MaskMesh = Collector.AllocateMesh();
|
|
MaskMesh = MeshTools;
|
|
auto MaskMaterialInstance = new FLandscapeMaskMaterialRenderProxy(GMaskRegionMaterial->GetRenderProxy(false), GLandscapeBlackTexture, false);
|
|
MaskMesh.MaterialRenderProxy = MaskMaterialInstance;
|
|
Collector.RegisterOneFrameMaterialProxy(MaskMaterialInstance);
|
|
Collector.AddMesh(ViewIndex, MaskMesh);
|
|
NumPasses++;
|
|
NumTriangles += MaskMesh.GetNumPrimitives();
|
|
NumDrawCalls += MaskMesh.Elements.Num();
|
|
}
|
|
}
|
|
|
|
// Edit mode tools
|
|
if (EditToolRenderData)
|
|
{
|
|
if (EditToolRenderData->ToolMaterial)
|
|
{
|
|
FMeshBatch& EditMesh = Collector.AllocateMesh();
|
|
EditMesh = MeshTools;
|
|
EditMesh.MaterialRenderProxy = EditToolRenderData->ToolMaterial->GetRenderProxy(0);
|
|
Collector.AddMesh(ViewIndex, EditMesh);
|
|
NumPasses++;
|
|
NumTriangles += EditMesh.GetNumPrimitives();
|
|
NumDrawCalls += EditMesh.Elements.Num();
|
|
}
|
|
|
|
if (EditToolRenderData->GizmoMaterial && GLandscapeEditRenderMode & ELandscapeEditRenderMode::Gizmo)
|
|
{
|
|
FMeshBatch& EditMesh = Collector.AllocateMesh();
|
|
EditMesh = MeshTools;
|
|
EditMesh.MaterialRenderProxy = EditToolRenderData->GizmoMaterial->GetRenderProxy(0);
|
|
Collector.AddMesh(ViewIndex, EditMesh);
|
|
NumPasses++;
|
|
NumTriangles += EditMesh.GetNumPrimitives();
|
|
NumDrawCalls += EditMesh.Elements.Num();
|
|
}
|
|
}
|
|
}
|
|
#endif // WITH_EDITOR
|
|
|
|
if (GLandscapeDebugOptions.bShowPatches)
|
|
{
|
|
DrawWireBox(Collector.GetPDI(ViewIndex), GetBounds().GetBox(), FColor(255, 255, 0), SDPG_World);
|
|
}
|
|
|
|
RenderBounds(Collector.GetPDI(ViewIndex), ViewFamily.EngineShowFlags, GetBounds(), IsSelected());
|
|
}
|
|
}
|
|
|
|
INC_DWORD_STAT_BY(STAT_LandscapeComponents, NumPasses);
|
|
INC_DWORD_STAT_BY(STAT_LandscapeDrawCalls, NumDrawCalls);
|
|
INC_DWORD_STAT_BY(STAT_LandscapeTriangles, NumTriangles * NumPasses);
|
|
}
|
|
|
|
|
|
//
|
|
// FLandscapeVertexBuffer
|
|
//
|
|
|
|
/**
|
|
* Initialize the RHI for this rendering resource
|
|
*/
|
|
void FLandscapeVertexBuffer::InitRHI()
|
|
{
|
|
// create a static vertex buffer
|
|
FRHIResourceCreateInfo CreateInfo;
|
|
void* BufferData = nullptr;
|
|
VertexBufferRHI = RHICreateAndLockVertexBuffer(NumVertices * sizeof(FLandscapeVertex), BUF_Static, CreateInfo, BufferData);
|
|
FLandscapeVertex* Vertex = (FLandscapeVertex*)BufferData;
|
|
int32 VertexIndex = 0;
|
|
for (int32 SubY = 0; SubY < NumSubsections; SubY++)
|
|
{
|
|
for (int32 SubX = 0; SubX < NumSubsections; SubX++)
|
|
{
|
|
for (int32 y = 0; y < SubsectionSizeVerts; y++)
|
|
{
|
|
for (int32 x = 0; x < SubsectionSizeVerts; x++)
|
|
{
|
|
Vertex->VertexX = x;
|
|
Vertex->VertexY = y;
|
|
Vertex->SubX = SubX;
|
|
Vertex->SubY = SubY;
|
|
Vertex++;
|
|
VertexIndex++;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
check(NumVertices == VertexIndex);
|
|
RHIUnlockVertexBuffer(VertexBufferRHI);
|
|
}
|
|
|
|
//
|
|
// FLandscapeSharedBuffers
|
|
//
|
|
|
|
template <typename INDEX_TYPE>
|
|
void FLandscapeSharedBuffers::CreateIndexBuffers(ERHIFeatureLevel::Type InFeatureLevel, bool bRequiresAdjacencyInformation)
|
|
{
|
|
if (InFeatureLevel <= ERHIFeatureLevel::ES3_1)
|
|
{
|
|
if (!bVertexScoresComputed)
|
|
{
|
|
bVertexScoresComputed = ComputeVertexScores();
|
|
}
|
|
}
|
|
|
|
TMap<uint64, INDEX_TYPE> VertexMap;
|
|
INDEX_TYPE VertexCount = 0;
|
|
int32 SubsectionSizeQuads = SubsectionSizeVerts - 1;
|
|
|
|
// Layout index buffer to determine best vertex order
|
|
int32 MaxLOD = NumIndexBuffers - 1;
|
|
for (int32 Mip = MaxLOD; Mip >= 0; Mip--)
|
|
{
|
|
int32 LodSubsectionSizeQuads = (SubsectionSizeVerts >> Mip) - 1;
|
|
|
|
TArray<INDEX_TYPE> NewIndices;
|
|
int32 ExpectedNumIndices = FMath::Square(NumSubsections) * FMath::Square(LodSubsectionSizeQuads) * 6;
|
|
NewIndices.Empty(ExpectedNumIndices);
|
|
|
|
int32& MaxIndexFull = IndexRanges[Mip].MaxIndexFull;
|
|
int32& MinIndexFull = IndexRanges[Mip].MinIndexFull;
|
|
MaxIndexFull = 0;
|
|
MinIndexFull = MAX_int32;
|
|
|
|
if (InFeatureLevel <= ERHIFeatureLevel::ES3_1)
|
|
{
|
|
// ES2 version
|
|
float MipRatio = (float)SubsectionSizeQuads / (float)LodSubsectionSizeQuads; // Morph current MIP to base MIP
|
|
|
|
for (int32 SubY = 0; SubY < NumSubsections; SubY++)
|
|
{
|
|
for (int32 SubX = 0; SubX < NumSubsections; SubX++)
|
|
{
|
|
TArray<INDEX_TYPE> SubIndices;
|
|
SubIndices.Empty(FMath::Square(LodSubsectionSizeQuads) * 6);
|
|
|
|
int32& MaxIndex = IndexRanges[Mip].MaxIndex[SubX][SubY];
|
|
int32& MinIndex = IndexRanges[Mip].MinIndex[SubX][SubY];
|
|
MaxIndex = 0;
|
|
MinIndex = MAX_int32;
|
|
|
|
for (int32 y = 0; y < LodSubsectionSizeQuads; y++)
|
|
{
|
|
for (int32 x = 0; x < LodSubsectionSizeQuads; x++)
|
|
{
|
|
int32 x0 = FMath::RoundToInt((float)x * MipRatio);
|
|
int32 y0 = FMath::RoundToInt((float)y * MipRatio);
|
|
int32 x1 = FMath::RoundToInt((float)(x + 1) * MipRatio);
|
|
int32 y1 = FMath::RoundToInt((float)(y + 1) * MipRatio);
|
|
|
|
FLandscapeVertexRef V00(x0, y0, SubX, SubY);
|
|
FLandscapeVertexRef V10(x1, y0, SubX, SubY);
|
|
FLandscapeVertexRef V11(x1, y1, SubX, SubY);
|
|
FLandscapeVertexRef V01(x0, y1, SubX, SubY);
|
|
|
|
uint64 Key00 = V00.MakeKey();
|
|
uint64 Key10 = V10.MakeKey();
|
|
uint64 Key11 = V11.MakeKey();
|
|
uint64 Key01 = V01.MakeKey();
|
|
|
|
INDEX_TYPE i00;
|
|
INDEX_TYPE i10;
|
|
INDEX_TYPE i11;
|
|
INDEX_TYPE i01;
|
|
|
|
INDEX_TYPE* KeyPtr = VertexMap.Find(Key00);
|
|
if (KeyPtr == nullptr)
|
|
{
|
|
i00 = VertexCount++;
|
|
VertexMap.Add(Key00, i00);
|
|
}
|
|
else
|
|
{
|
|
i00 = *KeyPtr;
|
|
}
|
|
|
|
KeyPtr = VertexMap.Find(Key10);
|
|
if (KeyPtr == nullptr)
|
|
{
|
|
i10 = VertexCount++;
|
|
VertexMap.Add(Key10, i10);
|
|
}
|
|
else
|
|
{
|
|
i10 = *KeyPtr;
|
|
}
|
|
|
|
KeyPtr = VertexMap.Find(Key11);
|
|
if (KeyPtr == nullptr)
|
|
{
|
|
i11 = VertexCount++;
|
|
VertexMap.Add(Key11, i11);
|
|
}
|
|
else
|
|
{
|
|
i11 = *KeyPtr;
|
|
}
|
|
|
|
KeyPtr = VertexMap.Find(Key01);
|
|
if (KeyPtr == nullptr)
|
|
{
|
|
i01 = VertexCount++;
|
|
VertexMap.Add(Key01, i01);
|
|
}
|
|
else
|
|
{
|
|
i01 = *KeyPtr;
|
|
}
|
|
|
|
// Update the min/max index ranges
|
|
MaxIndex = FMath::Max<int32>(MaxIndex, i00);
|
|
MinIndex = FMath::Min<int32>(MinIndex, i00);
|
|
MaxIndex = FMath::Max<int32>(MaxIndex, i10);
|
|
MinIndex = FMath::Min<int32>(MinIndex, i10);
|
|
MaxIndex = FMath::Max<int32>(MaxIndex, i11);
|
|
MinIndex = FMath::Min<int32>(MinIndex, i11);
|
|
MaxIndex = FMath::Max<int32>(MaxIndex, i01);
|
|
MinIndex = FMath::Min<int32>(MinIndex, i01);
|
|
|
|
SubIndices.Add(i00);
|
|
SubIndices.Add(i11);
|
|
SubIndices.Add(i10);
|
|
|
|
SubIndices.Add(i00);
|
|
SubIndices.Add(i01);
|
|
SubIndices.Add(i11);
|
|
}
|
|
}
|
|
|
|
// update min/max for full subsection
|
|
MaxIndexFull = FMath::Max<int32>(MaxIndexFull, MaxIndex);
|
|
MinIndexFull = FMath::Min<int32>(MinIndexFull, MinIndex);
|
|
|
|
TArray<INDEX_TYPE> NewSubIndices;
|
|
::OptimizeFaces<INDEX_TYPE>(SubIndices, NewSubIndices, 32);
|
|
NewIndices.Append(NewSubIndices);
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
// non-ES2 version
|
|
int32 SubOffset = 0;
|
|
for (int32 SubY = 0; SubY < NumSubsections; SubY++)
|
|
{
|
|
for (int32 SubX = 0; SubX < NumSubsections; SubX++)
|
|
{
|
|
int32& MaxIndex = IndexRanges[Mip].MaxIndex[SubX][SubY];
|
|
int32& MinIndex = IndexRanges[Mip].MinIndex[SubX][SubY];
|
|
MaxIndex = 0;
|
|
MinIndex = MAX_int32;
|
|
|
|
for (int32 y = 0; y < LodSubsectionSizeQuads; y++)
|
|
{
|
|
for (int32 x = 0; x < LodSubsectionSizeQuads; x++)
|
|
{
|
|
INDEX_TYPE i00 = (x + 0) + (y + 0) * SubsectionSizeVerts + SubOffset;
|
|
INDEX_TYPE i10 = (x + 1) + (y + 0) * SubsectionSizeVerts + SubOffset;
|
|
INDEX_TYPE i11 = (x + 1) + (y + 1) * SubsectionSizeVerts + SubOffset;
|
|
INDEX_TYPE i01 = (x + 0) + (y + 1) * SubsectionSizeVerts + SubOffset;
|
|
|
|
NewIndices.Add(i00);
|
|
NewIndices.Add(i11);
|
|
NewIndices.Add(i10);
|
|
|
|
NewIndices.Add(i00);
|
|
NewIndices.Add(i01);
|
|
NewIndices.Add(i11);
|
|
|
|
// Update the min/max index ranges
|
|
MaxIndex = FMath::Max<int32>(MaxIndex, i00);
|
|
MinIndex = FMath::Min<int32>(MinIndex, i00);
|
|
MaxIndex = FMath::Max<int32>(MaxIndex, i10);
|
|
MinIndex = FMath::Min<int32>(MinIndex, i10);
|
|
MaxIndex = FMath::Max<int32>(MaxIndex, i11);
|
|
MinIndex = FMath::Min<int32>(MinIndex, i11);
|
|
MaxIndex = FMath::Max<int32>(MaxIndex, i01);
|
|
MinIndex = FMath::Min<int32>(MinIndex, i01);
|
|
}
|
|
}
|
|
|
|
// update min/max for full subsection
|
|
MaxIndexFull = FMath::Max<int32>(MaxIndexFull, MaxIndex);
|
|
MinIndexFull = FMath::Min<int32>(MinIndexFull, MinIndex);
|
|
|
|
SubOffset += FMath::Square(SubsectionSizeVerts);
|
|
}
|
|
}
|
|
|
|
check(MinIndexFull <= (uint32)((INDEX_TYPE)(~(INDEX_TYPE)0)));
|
|
check(NewIndices.Num() == ExpectedNumIndices);
|
|
}
|
|
|
|
// Create and init new index buffer with index data
|
|
FRawStaticIndexBuffer16or32<INDEX_TYPE>* IndexBuffer = (FRawStaticIndexBuffer16or32<INDEX_TYPE>*)IndexBuffers[Mip];
|
|
if (!IndexBuffer)
|
|
{
|
|
IndexBuffer = new FRawStaticIndexBuffer16or32<INDEX_TYPE>(false);
|
|
}
|
|
IndexBuffer->AssignNewBuffer(NewIndices);
|
|
|
|
// Delay init resource to keep CPU data until create AdjacencyIndexbuffers
|
|
if (!bRequiresAdjacencyInformation)
|
|
{
|
|
IndexBuffer->InitResource();
|
|
}
|
|
|
|
IndexBuffers[Mip] = IndexBuffer;
|
|
}
|
|
}
|
|
|
|
#if WITH_EDITOR
|
|
template <typename INDEX_TYPE>
|
|
void FLandscapeSharedBuffers::CreateGrassIndexBuffer()
|
|
{
|
|
TArray<INDEX_TYPE> NewIndices;
|
|
|
|
int32 ExpectedNumIndices = FMath::Square(NumSubsections) * (FMath::Square(SubsectionSizeVerts) * 4/3 - 1); // *4/3 is for mips, -1 because we only go down to 2x2 not 1x1
|
|
NewIndices.Empty(ExpectedNumIndices);
|
|
|
|
int32 NumMips = FMath::CeilLogTwo(SubsectionSizeVerts);
|
|
|
|
for (int32 Mip = 0; Mip < NumMips; ++Mip)
|
|
{
|
|
// Store offset to the start of this mip in the index buffer
|
|
GrassIndexMipOffsets.Add(NewIndices.Num());
|
|
|
|
int32 MipSubsectionSizeVerts = SubsectionSizeVerts >> Mip;
|
|
int32 SubOffset = 0;
|
|
for (int32 SubY = 0; SubY < NumSubsections; SubY++)
|
|
{
|
|
for (int32 SubX = 0; SubX < NumSubsections; SubX++)
|
|
{
|
|
for (int32 y = 0; y < MipSubsectionSizeVerts; y++)
|
|
{
|
|
for (int32 x = 0; x < MipSubsectionSizeVerts; x++)
|
|
{
|
|
// intentionally using SubsectionSizeVerts not MipSubsectionSizeVerts, this is a vert buffer index not a mip vert index
|
|
NewIndices.Add(x + y * SubsectionSizeVerts + SubOffset);
|
|
}
|
|
}
|
|
|
|
// intentionally using SubsectionSizeVerts not MipSubsectionSizeVerts (as above)
|
|
SubOffset += FMath::Square(SubsectionSizeVerts);
|
|
}
|
|
}
|
|
}
|
|
|
|
check(NewIndices.Num() == ExpectedNumIndices);
|
|
|
|
// Create and init new index buffer with index data
|
|
FRawStaticIndexBuffer16or32<INDEX_TYPE>* IndexBuffer = new FRawStaticIndexBuffer16or32<INDEX_TYPE>(false);
|
|
IndexBuffer->AssignNewBuffer(NewIndices);
|
|
IndexBuffer->InitResource();
|
|
GrassIndexBuffer = IndexBuffer;
|
|
}
|
|
#endif
|
|
|
|
FLandscapeSharedBuffers::FLandscapeSharedBuffers(const int32 InSharedBuffersKey, const int32 InSubsectionSizeQuads, const int32 InNumSubsections, const ERHIFeatureLevel::Type InFeatureLevel, const bool bRequiresAdjacencyInformation)
|
|
: SharedBuffersKey(InSharedBuffersKey)
|
|
, NumIndexBuffers(FMath::CeilLogTwo(InSubsectionSizeQuads + 1))
|
|
, SubsectionSizeVerts(InSubsectionSizeQuads + 1)
|
|
, NumSubsections(InNumSubsections)
|
|
, VertexFactory(nullptr)
|
|
, VertexBuffer(nullptr)
|
|
, AdjacencyIndexBuffers(nullptr)
|
|
, bUse32BitIndices(false)
|
|
#if WITH_EDITOR
|
|
, GrassIndexBuffer(nullptr)
|
|
#endif
|
|
{
|
|
NumVertices = FMath::Square(SubsectionSizeVerts) * FMath::Square(NumSubsections);
|
|
if (InFeatureLevel > ERHIFeatureLevel::ES3_1)
|
|
{
|
|
// Vertex Buffer cannot be shared
|
|
VertexBuffer = new FLandscapeVertexBuffer(InFeatureLevel, NumVertices, SubsectionSizeVerts, NumSubsections);
|
|
}
|
|
IndexBuffers = new FIndexBuffer*[NumIndexBuffers];
|
|
FMemory::Memzero(IndexBuffers, sizeof(FIndexBuffer*)* NumIndexBuffers);
|
|
IndexRanges = new FLandscapeIndexRanges[NumIndexBuffers]();
|
|
|
|
// See if we need to use 16 or 32-bit index buffers
|
|
if (NumVertices > 65535)
|
|
{
|
|
bUse32BitIndices = true;
|
|
CreateIndexBuffers<uint32>(InFeatureLevel, bRequiresAdjacencyInformation);
|
|
#if WITH_EDITOR
|
|
if (InFeatureLevel > ERHIFeatureLevel::ES3_1)
|
|
{
|
|
CreateGrassIndexBuffer<uint32>();
|
|
}
|
|
#endif
|
|
}
|
|
else
|
|
{
|
|
CreateIndexBuffers<uint16>(InFeatureLevel, bRequiresAdjacencyInformation);
|
|
#if WITH_EDITOR
|
|
if (InFeatureLevel > ERHIFeatureLevel::ES3_1)
|
|
{
|
|
CreateGrassIndexBuffer<uint16>();
|
|
}
|
|
#endif
|
|
}
|
|
}
|
|
|
|
FLandscapeSharedBuffers::~FLandscapeSharedBuffers()
|
|
{
|
|
delete VertexBuffer;
|
|
|
|
for (int32 i = 0; i < NumIndexBuffers; i++)
|
|
{
|
|
IndexBuffers[i]->ReleaseResource();
|
|
delete IndexBuffers[i];
|
|
}
|
|
delete[] IndexBuffers;
|
|
delete[] IndexRanges;
|
|
|
|
#if WITH_EDITOR
|
|
if (GrassIndexBuffer)
|
|
{
|
|
GrassIndexBuffer->ReleaseResource();
|
|
delete GrassIndexBuffer;
|
|
}
|
|
#endif
|
|
|
|
if (AdjacencyIndexBuffers)
|
|
{
|
|
if (AdjacencyIndexBuffers->Release() == 0)
|
|
{
|
|
FLandscapeComponentSceneProxy::SharedAdjacencyIndexBufferMap.Remove(SharedBuffersKey);
|
|
}
|
|
AdjacencyIndexBuffers = nullptr;
|
|
}
|
|
|
|
delete VertexFactory;
|
|
}
|
|
|
|
template<typename IndexType>
|
|
static void BuildLandscapeAdjacencyIndexBuffer(int32 LODSubsectionSizeQuads, int32 NumSubsections, const FRawStaticIndexBuffer16or32<IndexType>* Indices, TArray<IndexType>& OutPnAenIndices)
|
|
{
|
|
if (Indices && Indices->Num())
|
|
{
|
|
// Landscape use regular grid, so only expand Index buffer works
|
|
// PN AEN Dominant Corner
|
|
uint32 TriCount = LODSubsectionSizeQuads*LODSubsectionSizeQuads * 2;
|
|
|
|
uint32 ExpandedCount = 12 * TriCount * NumSubsections * NumSubsections;
|
|
|
|
OutPnAenIndices.Empty(ExpandedCount);
|
|
OutPnAenIndices.AddUninitialized(ExpandedCount);
|
|
|
|
for (int32 SubY = 0; SubY < NumSubsections; SubY++)
|
|
{
|
|
for (int32 SubX = 0; SubX < NumSubsections; SubX++)
|
|
{
|
|
uint32 SubsectionTriIndex = (SubX + SubY * NumSubsections) * TriCount;
|
|
|
|
for (uint32 TriIdx = SubsectionTriIndex; TriIdx < SubsectionTriIndex + TriCount; ++TriIdx)
|
|
{
|
|
uint32 OutStartIdx = TriIdx * 12;
|
|
uint32 InStartIdx = TriIdx * 3;
|
|
OutPnAenIndices[OutStartIdx + 0] = Indices->Get(InStartIdx + 0);
|
|
OutPnAenIndices[OutStartIdx + 1] = Indices->Get(InStartIdx + 1);
|
|
OutPnAenIndices[OutStartIdx + 2] = Indices->Get(InStartIdx + 2);
|
|
|
|
OutPnAenIndices[OutStartIdx + 3] = Indices->Get(InStartIdx + 0);
|
|
OutPnAenIndices[OutStartIdx + 4] = Indices->Get(InStartIdx + 1);
|
|
OutPnAenIndices[OutStartIdx + 5] = Indices->Get(InStartIdx + 1);
|
|
OutPnAenIndices[OutStartIdx + 6] = Indices->Get(InStartIdx + 2);
|
|
OutPnAenIndices[OutStartIdx + 7] = Indices->Get(InStartIdx + 2);
|
|
OutPnAenIndices[OutStartIdx + 8] = Indices->Get(InStartIdx + 0);
|
|
|
|
OutPnAenIndices[OutStartIdx + 9] = Indices->Get(InStartIdx + 0);
|
|
OutPnAenIndices[OutStartIdx + 10] = Indices->Get(InStartIdx + 1);
|
|
OutPnAenIndices[OutStartIdx + 11] = Indices->Get(InStartIdx + 2);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
OutPnAenIndices.Empty();
|
|
}
|
|
}
|
|
|
|
|
|
FLandscapeSharedAdjacencyIndexBuffer::FLandscapeSharedAdjacencyIndexBuffer(FLandscapeSharedBuffers* Buffers)
|
|
{
|
|
check(Buffers && Buffers->IndexBuffers);
|
|
|
|
// Currently only support PN-AEN-Dominant Corner, which is the only mode for UE4 for now
|
|
IndexBuffers.Empty(Buffers->NumIndexBuffers);
|
|
|
|
bool b32BitIndex = Buffers->NumVertices > 65535;
|
|
for (int32 i = 0; i < Buffers->NumIndexBuffers; ++i)
|
|
{
|
|
if (b32BitIndex)
|
|
{
|
|
TArray<uint32> OutPnAenIndices;
|
|
BuildLandscapeAdjacencyIndexBuffer<uint32>((Buffers->SubsectionSizeVerts >> i) - 1, Buffers->NumSubsections, (FRawStaticIndexBuffer16or32<uint32>*)Buffers->IndexBuffers[i], OutPnAenIndices);
|
|
|
|
FRawStaticIndexBuffer16or32<uint32>* IndexBuffer = new FRawStaticIndexBuffer16or32<uint32>();
|
|
IndexBuffer->AssignNewBuffer(OutPnAenIndices);
|
|
IndexBuffers.Add(IndexBuffer);
|
|
}
|
|
else
|
|
{
|
|
TArray<uint16> OutPnAenIndices;
|
|
BuildLandscapeAdjacencyIndexBuffer<uint16>((Buffers->SubsectionSizeVerts >> i) - 1, Buffers->NumSubsections, (FRawStaticIndexBuffer16or32<uint16>*)Buffers->IndexBuffers[i], OutPnAenIndices);
|
|
|
|
FRawStaticIndexBuffer16or32<uint16>* IndexBuffer = new FRawStaticIndexBuffer16or32<uint16>();
|
|
IndexBuffer->AssignNewBuffer(OutPnAenIndices);
|
|
IndexBuffers.Add(IndexBuffer);
|
|
}
|
|
|
|
IndexBuffers[i]->InitResource();
|
|
}
|
|
}
|
|
|
|
FLandscapeSharedAdjacencyIndexBuffer::~FLandscapeSharedAdjacencyIndexBuffer()
|
|
{
|
|
for (int32 i = 0; i < IndexBuffers.Num(); ++i)
|
|
{
|
|
IndexBuffers[i]->ReleaseResource();
|
|
delete IndexBuffers[i];
|
|
}
|
|
}
|
|
|
|
//
|
|
// FLandscapeVertexFactoryVertexShaderParameters
|
|
//
|
|
|
|
/** Shader parameters for use with FLandscapeVertexFactory */
|
|
class FLandscapeVertexFactoryVertexShaderParameters : public FVertexFactoryShaderParameters
|
|
{
|
|
public:
|
|
/**
|
|
* Bind shader constants by name
|
|
* @param ParameterMap - mapping of named shader constants to indices
|
|
*/
|
|
virtual void Bind(const FShaderParameterMap& ParameterMap) override
|
|
{
|
|
HeightmapTextureParameter.Bind(ParameterMap, TEXT("HeightmapTexture"));
|
|
HeightmapTextureParameterSampler.Bind(ParameterMap, TEXT("HeightmapTextureSampler"));
|
|
LodValuesParameter.Bind(ParameterMap, TEXT("LodValues"));
|
|
NeighborSectionLodParameter.Bind(ParameterMap, TEXT("NeighborSectionLod"));
|
|
LodBiasParameter.Bind(ParameterMap, TEXT("LodBias"));
|
|
SectionLodsParameter.Bind(ParameterMap, TEXT("SectionLods"));
|
|
XYOffsetTextureParameter.Bind(ParameterMap, TEXT("XYOffsetmapTexture"));
|
|
XYOffsetTextureParameterSampler.Bind(ParameterMap, TEXT("XYOffsetmapTextureSampler"));
|
|
}
|
|
|
|
/**
|
|
* Serialize shader params to an archive
|
|
* @param Ar - archive to serialize to
|
|
*/
|
|
virtual void Serialize(FArchive& Ar) override
|
|
{
|
|
Ar << HeightmapTextureParameter;
|
|
Ar << HeightmapTextureParameterSampler;
|
|
Ar << LodValuesParameter;
|
|
Ar << NeighborSectionLodParameter;
|
|
Ar << LodBiasParameter;
|
|
Ar << SectionLodsParameter;
|
|
Ar << XYOffsetTextureParameter;
|
|
Ar << XYOffsetTextureParameterSampler;
|
|
}
|
|
|
|
/**
|
|
* Set any shader data specific to this vertex factory
|
|
*/
|
|
virtual void SetMesh(FRHICommandList& RHICmdList, FShader* VertexShader, const class FVertexFactory* VertexFactory, const class FSceneView& View, const struct FMeshBatchElement& BatchElement, uint32 DataFlags) const override
|
|
{
|
|
SCOPE_CYCLE_COUNTER(STAT_LandscapeVFDrawTime);
|
|
|
|
const FLandscapeBatchElementParams* BatchElementParams = (const FLandscapeBatchElementParams*)BatchElement.UserData;
|
|
check(BatchElementParams);
|
|
|
|
const FLandscapeComponentSceneProxy* SceneProxy = BatchElementParams->SceneProxy;
|
|
SetUniformBufferParameter(RHICmdList, VertexShader->GetVertexShader(), VertexShader->GetUniformBufferParameter<FLandscapeUniformShaderParameters>(), *BatchElementParams->LandscapeUniformShaderParametersResource);
|
|
|
|
if (HeightmapTextureParameter.IsBound())
|
|
{
|
|
SetTextureParameter(
|
|
RHICmdList,
|
|
VertexShader->GetVertexShader(),
|
|
HeightmapTextureParameter,
|
|
HeightmapTextureParameterSampler,
|
|
TStaticSamplerState<SF_Point>::GetRHI(),
|
|
SceneProxy->HeightmapTexture->Resource->TextureRHI
|
|
);
|
|
}
|
|
|
|
if (LodBiasParameter.IsBound())
|
|
{
|
|
FVector4 LodBias(
|
|
0.0f, // unused
|
|
0.0f, // unused
|
|
((FTexture2DResource*)SceneProxy->HeightmapTexture->Resource)->GetCurrentFirstMip(),
|
|
SceneProxy->XYOffsetmapTexture ? ((FTexture2DResource*)SceneProxy->XYOffsetmapTexture->Resource)->GetCurrentFirstMip() : 0.0f
|
|
);
|
|
SetShaderValue(RHICmdList, VertexShader->GetVertexShader(), LodBiasParameter, LodBias);
|
|
}
|
|
|
|
// Calculate LOD params
|
|
FVector CameraLocalPos3D = SceneProxy->WorldToLocal.TransformPosition(View.ViewMatrices.ViewOrigin);
|
|
FVector2D CameraLocalPos = FVector2D(CameraLocalPos3D.X, CameraLocalPos3D.Y);
|
|
|
|
FVector4 fCurrentLODs;
|
|
FVector4 CurrentNeighborLODs[4];
|
|
|
|
if (BatchElementParams->SubX == -1)
|
|
{
|
|
for (int32 SubY = 0; SubY < SceneProxy->NumSubsections; SubY++)
|
|
{
|
|
for (int32 SubX = 0; SubX < SceneProxy->NumSubsections; SubX++)
|
|
{
|
|
int32 SubIndex = SubX + 2 * SubY;
|
|
SceneProxy->CalcLODParamsForSubsection(View, CameraLocalPos, SubX, SubY, BatchElementParams->CurrentLOD, fCurrentLODs[SubIndex], CurrentNeighborLODs[SubIndex]);
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
int32 SubIndex = BatchElementParams->SubX + 2 * BatchElementParams->SubY;
|
|
SceneProxy->CalcLODParamsForSubsection(View, CameraLocalPos, BatchElementParams->SubX, BatchElementParams->SubY, BatchElementParams->CurrentLOD, fCurrentLODs[SubIndex], CurrentNeighborLODs[SubIndex]);
|
|
}
|
|
|
|
if (SectionLodsParameter.IsBound())
|
|
{
|
|
SetShaderValue(RHICmdList, VertexShader->GetVertexShader(), SectionLodsParameter, fCurrentLODs);
|
|
}
|
|
|
|
if (NeighborSectionLodParameter.IsBound())
|
|
{
|
|
SetShaderValue(RHICmdList, VertexShader->GetVertexShader(), NeighborSectionLodParameter, CurrentNeighborLODs);
|
|
}
|
|
|
|
if (LodValuesParameter.IsBound())
|
|
{
|
|
FVector4 LodValues(
|
|
BatchElementParams->CurrentLOD,
|
|
0.0f, // unused
|
|
(float)((SceneProxy->SubsectionSizeVerts >> BatchElementParams->CurrentLOD) - 1),
|
|
1.f / (float)((SceneProxy->SubsectionSizeVerts >> BatchElementParams->CurrentLOD) - 1));
|
|
|
|
SetShaderValue(RHICmdList, VertexShader->GetVertexShader(), LodValuesParameter, LodValues);
|
|
}
|
|
|
|
if (XYOffsetTextureParameter.IsBound() && SceneProxy->XYOffsetmapTexture)
|
|
{
|
|
SetTextureParameter(
|
|
RHICmdList,
|
|
VertexShader->GetVertexShader(),
|
|
XYOffsetTextureParameter,
|
|
XYOffsetTextureParameterSampler,
|
|
TStaticSamplerState<SF_Point>::GetRHI(),
|
|
SceneProxy->XYOffsetmapTexture->Resource->TextureRHI
|
|
);
|
|
}
|
|
}
|
|
|
|
virtual uint32 GetSize() const override
|
|
{
|
|
return sizeof(*this);
|
|
}
|
|
|
|
protected:
|
|
FShaderParameter LodValuesParameter;
|
|
FShaderParameter NeighborSectionLodParameter;
|
|
FShaderParameter LodBiasParameter;
|
|
FShaderParameter SectionLodsParameter;
|
|
FShaderResourceParameter HeightmapTextureParameter;
|
|
FShaderResourceParameter HeightmapTextureParameterSampler;
|
|
FShaderResourceParameter XYOffsetTextureParameter;
|
|
FShaderResourceParameter XYOffsetTextureParameterSampler;
|
|
TShaderUniformBufferParameter<FLandscapeUniformShaderParameters> LandscapeShaderParameters;
|
|
};
|
|
|
|
//
|
|
// FLandscapeVertexFactoryPixelShaderParameters
|
|
//
|
|
/**
|
|
* Bind shader constants by name
|
|
* @param ParameterMap - mapping of named shader constants to indices
|
|
*/
|
|
void FLandscapeVertexFactoryPixelShaderParameters::Bind(const FShaderParameterMap& ParameterMap)
|
|
{
|
|
NormalmapTextureParameter.Bind(ParameterMap, TEXT("NormalmapTexture"));
|
|
NormalmapTextureParameterSampler.Bind(ParameterMap, TEXT("NormalmapTextureSampler"));
|
|
LocalToWorldNoScalingParameter.Bind(ParameterMap, TEXT("LocalToWorldNoScaling"));
|
|
}
|
|
|
|
/**
|
|
* Serialize shader params to an archive
|
|
* @param Ar - archive to serialize to
|
|
*/
|
|
void FLandscapeVertexFactoryPixelShaderParameters::Serialize(FArchive& Ar)
|
|
{
|
|
Ar << NormalmapTextureParameter
|
|
<< NormalmapTextureParameterSampler
|
|
<< LocalToWorldNoScalingParameter;
|
|
}
|
|
|
|
/**
|
|
* Set any shader data specific to this vertex factory
|
|
*/
|
|
void FLandscapeVertexFactoryPixelShaderParameters::SetMesh(FRHICommandList& RHICmdList, FShader* PixelShader, const FVertexFactory* VertexFactory, const FSceneView& View, const FMeshBatchElement& BatchElement, uint32 DataFlags) const
|
|
{
|
|
SCOPE_CYCLE_COUNTER(STAT_LandscapeVFDrawTime);
|
|
|
|
const FLandscapeBatchElementParams* BatchElementParams = (const FLandscapeBatchElementParams*)BatchElement.UserData;
|
|
|
|
if (LocalToWorldNoScalingParameter.IsBound())
|
|
{
|
|
SetShaderValue(RHICmdList, PixelShader->GetPixelShader(), LocalToWorldNoScalingParameter, *BatchElementParams->LocalToWorldNoScalingPtr);
|
|
}
|
|
|
|
if (NormalmapTextureParameter.IsBound())
|
|
{
|
|
SetTextureParameter(
|
|
RHICmdList,
|
|
PixelShader->GetPixelShader(),
|
|
NormalmapTextureParameter,
|
|
NormalmapTextureParameterSampler,
|
|
BatchElementParams->SceneProxy->NormalmapTexture->Resource);
|
|
}
|
|
}
|
|
|
|
|
|
//
|
|
// FLandscapeVertexFactory
|
|
//
|
|
|
|
void FLandscapeVertexFactory::InitRHI()
|
|
{
|
|
// list of declaration items
|
|
FVertexDeclarationElementList Elements;
|
|
|
|
// position decls
|
|
Elements.Add(AccessStreamComponent(Data.PositionComponent, 0));
|
|
|
|
// create the actual device decls
|
|
InitDeclaration(Elements);
|
|
}
|
|
|
|
FVertexFactoryShaderParameters* FLandscapeVertexFactory::ConstructShaderParameters(EShaderFrequency ShaderFrequency)
|
|
{
|
|
switch (ShaderFrequency)
|
|
{
|
|
case SF_Vertex:
|
|
return new FLandscapeVertexFactoryVertexShaderParameters();
|
|
break;
|
|
case SF_Pixel:
|
|
return new FLandscapeVertexFactoryPixelShaderParameters();
|
|
break;
|
|
default:
|
|
return nullptr;
|
|
}
|
|
}
|
|
|
|
void FLandscapeVertexFactory::ModifyCompilationEnvironment(EShaderPlatform Platform, const FMaterial* Material, FShaderCompilerEnvironment& OutEnvironment)
|
|
{
|
|
FVertexFactory::ModifyCompilationEnvironment(Platform, Material, OutEnvironment);
|
|
}
|
|
|
|
|
|
IMPLEMENT_VERTEX_FACTORY_TYPE(FLandscapeVertexFactory, "LandscapeVertexFactory", true, true, true, false, false);
|
|
|
|
/**
|
|
* Copy the data from another vertex factory
|
|
* @param Other - factory to copy from
|
|
*/
|
|
void FLandscapeVertexFactory::Copy(const FLandscapeVertexFactory& Other)
|
|
{
|
|
//SetSceneProxy(Other.Proxy());
|
|
ENQUEUE_UNIQUE_RENDER_COMMAND_TWOPARAMETER(
|
|
FLandscapeVertexFactoryCopyData,
|
|
FLandscapeVertexFactory*, VertexFactory, this,
|
|
const FDataType*, DataCopy, &Other.Data,
|
|
{
|
|
VertexFactory->Data = *DataCopy;
|
|
});
|
|
BeginUpdateResourceRHI(this);
|
|
}
|
|
|
|
//
|
|
// FLandscapeXYOffsetVertexFactory
|
|
//
|
|
|
|
void FLandscapeXYOffsetVertexFactory::ModifyCompilationEnvironment(EShaderPlatform Platform, const FMaterial* Material, FShaderCompilerEnvironment& OutEnvironment)
|
|
{
|
|
FLandscapeVertexFactory::ModifyCompilationEnvironment(Platform, Material, OutEnvironment);
|
|
OutEnvironment.SetDefine(TEXT("LANDSCAPE_XYOFFSET"), TEXT("1"));
|
|
}
|
|
|
|
IMPLEMENT_VERTEX_FACTORY_TYPE(FLandscapeXYOffsetVertexFactory, "LandscapeVertexFactory", true, true, true, false, false);
|
|
|
|
/** ULandscapeMaterialInstanceConstant */
|
|
ULandscapeMaterialInstanceConstant::ULandscapeMaterialInstanceConstant(const FObjectInitializer& ObjectInitializer)
|
|
: Super(ObjectInitializer)
|
|
{
|
|
bIsLayerThumbnail = false;
|
|
}
|
|
|
|
class FLandscapeMaterialResource : public FMaterialResource
|
|
{
|
|
const bool bIsLayerThumbnail;
|
|
const bool bDisableTessellation;
|
|
|
|
public:
|
|
FLandscapeMaterialResource(ULandscapeMaterialInstanceConstant* Parent)
|
|
: bIsLayerThumbnail(Parent->bIsLayerThumbnail)
|
|
, bDisableTessellation(Parent->bDisableTessellation)
|
|
{
|
|
}
|
|
|
|
void GetShaderMapId(EShaderPlatform Platform, FMaterialShaderMapId& OutId) const override
|
|
{
|
|
FMaterialResource::GetShaderMapId(Platform, OutId);
|
|
|
|
if (bIsLayerThumbnail || bDisableTessellation)
|
|
{
|
|
FSHA1 Hash;
|
|
Hash.Update(OutId.BasePropertyOverridesHash.Hash, ARRAY_COUNT(OutId.BasePropertyOverridesHash.Hash));
|
|
|
|
const FString HashString = TEXT("bOverride_TessellationMode");
|
|
Hash.UpdateWithString(*HashString, HashString.Len());
|
|
|
|
Hash.Final();
|
|
Hash.GetHash(OutId.BasePropertyOverridesHash.Hash);
|
|
}
|
|
}
|
|
|
|
bool IsUsedWithLandscape() const override
|
|
{
|
|
return !bIsLayerThumbnail;
|
|
}
|
|
|
|
bool IsUsedWithStaticLighting() const override
|
|
{
|
|
if (bIsLayerThumbnail)
|
|
{
|
|
return false;
|
|
}
|
|
return FMaterialResource::IsUsedWithStaticLighting();
|
|
}
|
|
|
|
bool IsUsedWithSkeletalMesh() const override { return false; }
|
|
bool IsUsedWithParticleSystem() const override { return false; }
|
|
bool IsUsedWithParticleSprites() const override { return false; }
|
|
bool IsUsedWithBeamTrails() const override { return false; }
|
|
bool IsUsedWithMeshParticles() const override { return false; }
|
|
bool IsUsedWithMorphTargets() const override { return false; }
|
|
bool IsUsedWithSplineMeshes() const override { return false; }
|
|
bool IsUsedWithInstancedStaticMeshes() const override { return false; }
|
|
bool IsUsedWithAPEXCloth() const override { return false; }
|
|
EMaterialTessellationMode GetTessellationMode() const override { return (bIsLayerThumbnail || bDisableTessellation) ? MTM_NoTessellation : FMaterialResource::GetTessellationMode(); };
|
|
|
|
bool ShouldCache(EShaderPlatform Platform, const FShaderType* ShaderType, const FVertexFactoryType* VertexFactoryType) const override
|
|
{
|
|
if (VertexFactoryType)
|
|
{
|
|
if (bIsLayerThumbnail)
|
|
{
|
|
// Thumbnail MICs are only rendered in the preview scene using a simple LocalVertexFactory
|
|
static const FName LocalVertexFactory = FName(TEXT("FLocalVertexFactory"));
|
|
if (VertexFactoryType->GetFName() == LocalVertexFactory)
|
|
{
|
|
// reduce the number of shaders compiled for the thumbnail materials by only compiling with shader types known to be used by the preview scene
|
|
// (out of 41 known total shader types)
|
|
static const TArray<FName> AllowedShaderTypes =
|
|
{
|
|
FName(TEXT("TBasePassVSFNoLightMapPolicy")),
|
|
FName(TEXT("TBasePassPSFNoLightMapPolicy")),
|
|
FName(TEXT("TBasePassVSFCachedPointIndirectLightingPolicy")),
|
|
FName(TEXT("TBasePassPSFCachedPointIndirectLightingPolicy")),
|
|
FName(TEXT("TShadowDepthVSVertexShadowDepth_OutputDepthfalse")),
|
|
FName(TEXT("TShadowDepthPSPixelShadowDepth_NonPerspectiveCorrectfalse")),
|
|
FName(TEXT("TDepthOnlyVS<false>")),
|
|
FName(TEXT("TDepthOnlyVS<true>")),
|
|
FName(TEXT("FDepthOnlyPS")),
|
|
};
|
|
if (Algo::Find(AllowedShaderTypes, ShaderType->GetFName()))
|
|
{
|
|
return FMaterialResource::ShouldCache(Platform, ShaderType, VertexFactoryType);
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
// Landscape MICs are only for use with the Landscape vertex factories
|
|
// Todo: only compile LandscapeXYOffsetVertexFactory if we are using it
|
|
static const FName LandscapeVertexFactory = FName(TEXT("FLandscapeVertexFactory"));
|
|
static const FName LandscapeXYOffsetVertexFactory = FName(TEXT("FLandscapeXYOffsetVertexFactory"));
|
|
static const FName LandscapeVertexFactoryMobile = FName(TEXT("FLandscapeVertexFactoryMobile"));
|
|
if (VertexFactoryType->GetFName() == LandscapeVertexFactory ||
|
|
VertexFactoryType->GetFName() == LandscapeXYOffsetVertexFactory ||
|
|
VertexFactoryType->GetFName() == LandscapeVertexFactoryMobile)
|
|
{
|
|
return FMaterialResource::ShouldCache(Platform, ShaderType, VertexFactoryType);
|
|
}
|
|
}
|
|
}
|
|
|
|
return false;
|
|
}
|
|
};
|
|
|
|
FMaterialResource* ULandscapeMaterialInstanceConstant::AllocatePermutationResource()
|
|
{
|
|
return new FLandscapeMaterialResource(this);
|
|
}
|
|
|
|
bool ULandscapeMaterialInstanceConstant::HasOverridenBaseProperties() const
|
|
{
|
|
if (Parent)
|
|
{
|
|
// force a static permutation for ULandscapeMaterialInstanceConstants
|
|
if (!Parent->IsA<ULandscapeMaterialInstanceConstant>())
|
|
{
|
|
return true;
|
|
}
|
|
ULandscapeMaterialInstanceConstant* LandscapeMICParent = CastChecked<ULandscapeMaterialInstanceConstant>(Parent);
|
|
if (bDisableTessellation != LandscapeMICParent->bDisableTessellation)
|
|
{
|
|
return true;
|
|
}
|
|
}
|
|
|
|
return Super::HasOverridenBaseProperties();
|
|
}
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
void ULandscapeComponent::GetStreamingTextureInfo(FStreamingTextureLevelContext& LevelContext, TArray<FStreamingTexturePrimitiveInfo>& OutStreamingTextures) const
|
|
{
|
|
ALandscapeProxy* Proxy = Cast<ALandscapeProxy>(GetOuter());
|
|
FSphere BoundingSphere = Bounds.GetSphere();
|
|
float LocalStreamingDistanceMultiplier = 1.f;
|
|
float TexelFactor = 0.0f;
|
|
if (Proxy)
|
|
{
|
|
LocalStreamingDistanceMultiplier = FMath::Max(0.0f, Proxy->StreamingDistanceMultiplier);
|
|
TexelFactor = 0.75f * LocalStreamingDistanceMultiplier * ComponentSizeQuads * FMath::Abs(Proxy->GetRootComponent()->RelativeScale3D.X);
|
|
}
|
|
|
|
// TODO - LOD Materials - Currently all LOD materials are instances of [0] so have the same textures
|
|
UMaterialInterface* MaterialInterface = GetWorld()->FeatureLevel >= ERHIFeatureLevel::SM4 ? MaterialInstances[0] : MobileMaterialInterface;
|
|
|
|
// Normal usage...
|
|
// Enumerate the textures used by the material.
|
|
if (MaterialInterface)
|
|
{
|
|
TArray<UTexture*> Textures;
|
|
MaterialInterface->GetUsedTextures(Textures, EMaterialQualityLevel::Num, false, GetWorld()->FeatureLevel, false);
|
|
// Add each texture to the output with the appropriate parameters.
|
|
// TODO: Take into account which UVIndex is being used.
|
|
for (int32 TextureIndex = 0; TextureIndex < Textures.Num(); TextureIndex++)
|
|
{
|
|
UTexture2D* Texture2D = Cast<UTexture2D>(Textures[TextureIndex]);
|
|
if (!Texture2D) continue;
|
|
|
|
FStreamingTexturePrimitiveInfo& StreamingTexture = *new(OutStreamingTextures)FStreamingTexturePrimitiveInfo;
|
|
StreamingTexture.Bounds = BoundingSphere;
|
|
StreamingTexture.TexelFactor = TexelFactor;
|
|
StreamingTexture.Texture = Texture2D;
|
|
}
|
|
|
|
UMaterial* Material = MaterialInterface->GetMaterial();
|
|
if (Material)
|
|
{
|
|
int32 NumExpressions = Material->Expressions.Num();
|
|
for (int32 ExpressionIndex = 0; ExpressionIndex < NumExpressions; ExpressionIndex++)
|
|
{
|
|
UMaterialExpression* Expression = Material->Expressions[ExpressionIndex];
|
|
UMaterialExpressionTextureSample* TextureSample = Cast<UMaterialExpressionTextureSample>(Expression);
|
|
|
|
// TODO: This is only works for direct Coordinate Texture Sample cases
|
|
if (TextureSample && TextureSample->Coordinates.IsConnected())
|
|
{
|
|
UMaterialExpressionTextureCoordinate* TextureCoordinate = nullptr;
|
|
UMaterialExpressionLandscapeLayerCoords* TerrainTextureCoordinate = nullptr;
|
|
|
|
for (UMaterialExpression* FindExp : Material->Expressions)
|
|
{
|
|
if (FindExp && FindExp->GetFName() == TextureSample->Coordinates.ExpressionName)
|
|
{
|
|
TextureCoordinate = Cast<UMaterialExpressionTextureCoordinate>(FindExp);
|
|
if (!TextureCoordinate)
|
|
{
|
|
TerrainTextureCoordinate = Cast<UMaterialExpressionLandscapeLayerCoords>(FindExp);
|
|
}
|
|
break;
|
|
}
|
|
}
|
|
|
|
if (TextureCoordinate || TerrainTextureCoordinate)
|
|
{
|
|
for (int32 i = 0; i < OutStreamingTextures.Num(); ++i)
|
|
{
|
|
FStreamingTexturePrimitiveInfo& StreamingTexture = OutStreamingTextures[i];
|
|
if (StreamingTexture.Texture == TextureSample->Texture)
|
|
{
|
|
if (TextureCoordinate)
|
|
{
|
|
StreamingTexture.TexelFactor = TexelFactor * FPlatformMath::Max(TextureCoordinate->UTiling, TextureCoordinate->VTiling);
|
|
}
|
|
else //if ( TerrainTextureCoordinate )
|
|
{
|
|
StreamingTexture.TexelFactor = TexelFactor * TerrainTextureCoordinate->MappingScale;
|
|
}
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
// Lightmap
|
|
const auto FeatureLevel = GetWorld() ? GetWorld()->FeatureLevel : GMaxRHIFeatureLevel;
|
|
|
|
FLightMap2D* Lightmap = LightMap ? LightMap->GetLightMap2D() : nullptr;
|
|
uint32 LightmapIndex = AllowHighQualityLightmaps(FeatureLevel) ? 0 : 1;
|
|
if (Lightmap && Lightmap->IsValid(LightmapIndex))
|
|
{
|
|
const FVector2D& Scale = Lightmap->GetCoordinateScale();
|
|
if (Scale.X > SMALL_NUMBER && Scale.Y > SMALL_NUMBER)
|
|
{
|
|
float LightmapFactorX = TexelFactor / Scale.X;
|
|
float LightmapFactorY = TexelFactor / Scale.Y;
|
|
FStreamingTexturePrimitiveInfo& StreamingTexture = *new(OutStreamingTextures)FStreamingTexturePrimitiveInfo;
|
|
StreamingTexture.Bounds = BoundingSphere;
|
|
StreamingTexture.TexelFactor = FMath::Max(LightmapFactorX, LightmapFactorY);
|
|
StreamingTexture.Texture = Lightmap->GetTexture(LightmapIndex);
|
|
}
|
|
}
|
|
|
|
// Shadowmap
|
|
FShadowMap2D* Shadowmap = ShadowMap ? ShadowMap->GetShadowMap2D() : nullptr;
|
|
if (Shadowmap && Shadowmap->IsValid())
|
|
{
|
|
const FVector2D& Scale = Shadowmap->GetCoordinateScale();
|
|
if (Scale.X > SMALL_NUMBER && Scale.Y > SMALL_NUMBER)
|
|
{
|
|
float ShadowmapFactorX = TexelFactor / Scale.X;
|
|
float ShadowmapFactorY = TexelFactor / Scale.Y;
|
|
FStreamingTexturePrimitiveInfo& StreamingTexture = *new(OutStreamingTextures)FStreamingTexturePrimitiveInfo;
|
|
StreamingTexture.Bounds = BoundingSphere;
|
|
StreamingTexture.TexelFactor = FMath::Max(ShadowmapFactorX, ShadowmapFactorY);
|
|
StreamingTexture.Texture = Shadowmap->GetTexture();
|
|
}
|
|
}
|
|
}
|
|
|
|
// Weightmap
|
|
for (int32 TextureIndex = 0; TextureIndex < WeightmapTextures.Num(); TextureIndex++)
|
|
{
|
|
FStreamingTexturePrimitiveInfo& StreamingWeightmap = *new(OutStreamingTextures)FStreamingTexturePrimitiveInfo;
|
|
StreamingWeightmap.Bounds = BoundingSphere;
|
|
StreamingWeightmap.TexelFactor = TexelFactor;
|
|
StreamingWeightmap.Texture = WeightmapTextures[TextureIndex];
|
|
}
|
|
|
|
// Heightmap
|
|
if (HeightmapTexture)
|
|
{
|
|
FStreamingTexturePrimitiveInfo& StreamingHeightmap = *new(OutStreamingTextures)FStreamingTexturePrimitiveInfo;
|
|
StreamingHeightmap.Bounds = BoundingSphere;
|
|
|
|
float HeightmapTexelFactor = TexelFactor * (static_cast<float>(HeightmapTexture->GetSizeY()) / (ComponentSizeQuads + 1));
|
|
StreamingHeightmap.TexelFactor = ForcedLOD >= 0 ? -(1 << (13 - ForcedLOD)) : HeightmapTexelFactor; // Minus Value indicate forced resolution (Mip 13 for 8k texture)
|
|
StreamingHeightmap.Texture = HeightmapTexture;
|
|
}
|
|
|
|
// XYOffset
|
|
if (XYOffsetmapTexture)
|
|
{
|
|
FStreamingTexturePrimitiveInfo& StreamingXYOffset = *new(OutStreamingTextures)FStreamingTexturePrimitiveInfo;
|
|
StreamingXYOffset.Bounds = BoundingSphere;
|
|
StreamingXYOffset.TexelFactor = TexelFactor;
|
|
StreamingXYOffset.Texture = XYOffsetmapTexture;
|
|
}
|
|
|
|
#if WITH_EDITOR
|
|
if (GIsEditor && EditToolRenderData && EditToolRenderData->DataTexture)
|
|
{
|
|
FStreamingTexturePrimitiveInfo& StreamingDatamap = *new(OutStreamingTextures)FStreamingTexturePrimitiveInfo;
|
|
StreamingDatamap.Bounds = BoundingSphere;
|
|
StreamingDatamap.TexelFactor = TexelFactor;
|
|
StreamingDatamap.Texture = EditToolRenderData->DataTexture;
|
|
}
|
|
#endif
|
|
}
|
|
|
|
void ALandscapeProxy::ChangeLODDistanceFactor(float InLODDistanceFactor)
|
|
{
|
|
LODDistanceFactor = FMath::Clamp<float>(InLODDistanceFactor, 0.1f, MAX_LANDSCAPE_LOD_DISTANCE_FACTOR);
|
|
float LODFactor;
|
|
switch (LODFalloff)
|
|
{
|
|
case ELandscapeLODFalloff::SquareRoot:
|
|
LODFactor = FMath::Square(FMath::Min(LANDSCAPE_LOD_SQUARE_ROOT_FACTOR * LODDistanceFactor, MAX_LANDSCAPE_LOD_DISTANCE_FACTOR));
|
|
break;
|
|
default:
|
|
case ELandscapeLODFalloff::Linear:
|
|
LODFactor = LODDistanceFactor;
|
|
break;
|
|
}
|
|
|
|
if (LandscapeComponents.Num())
|
|
{
|
|
int32 CompNum = LandscapeComponents.Num();
|
|
FLandscapeComponentSceneProxy** Proxies = new FLandscapeComponentSceneProxy*[CompNum];
|
|
for (int32 Idx = 0; Idx < CompNum; ++Idx)
|
|
{
|
|
Proxies[Idx] = (FLandscapeComponentSceneProxy*)(LandscapeComponents[Idx]->SceneProxy);
|
|
}
|
|
|
|
ENQUEUE_UNIQUE_RENDER_COMMAND_THREEPARAMETER(
|
|
LandscapeChangeLODDistanceFactorCommand,
|
|
FLandscapeComponentSceneProxy**, Proxies, Proxies,
|
|
int32, CompNum, CompNum,
|
|
float, InLODDistanceFactor, FMath::Sqrt(2.f * FMath::Square((float)SubsectionSizeQuads)) * LANDSCAPE_LOD_DISTANCE_FACTOR / LODFactor,
|
|
{
|
|
for (int32 Idx = 0; Idx < CompNum; ++Idx)
|
|
{
|
|
Proxies[Idx]->ChangeLODDistanceFactor_RenderThread(InLODDistanceFactor);
|
|
}
|
|
delete[] Proxies;
|
|
}
|
|
);
|
|
}
|
|
};
|
|
|
|
void FLandscapeComponentSceneProxy::ChangeLODDistanceFactor_RenderThread(float InLODDistanceFactor)
|
|
{
|
|
LODDistance = InLODDistanceFactor;
|
|
}
|
|
|
|
void FLandscapeComponentSceneProxy::GetHeightfieldRepresentation(UTexture2D*& OutHeightmapTexture, UTexture2D*& OutDiffuseColorTexture, FHeightfieldComponentDescription& OutDescription)
|
|
{
|
|
OutHeightmapTexture = HeightmapTexture;
|
|
OutDiffuseColorTexture = BaseColorForGITexture;
|
|
OutDescription.HeightfieldScaleBias = HeightmapScaleBias;
|
|
|
|
OutDescription.MinMaxUV = FVector4(
|
|
HeightmapScaleBias.Z,
|
|
HeightmapScaleBias.W,
|
|
HeightmapScaleBias.Z + SubsectionSizeVerts * NumSubsections * HeightmapScaleBias.X,
|
|
HeightmapScaleBias.W + SubsectionSizeVerts * NumSubsections * HeightmapScaleBias.Y);
|
|
|
|
if (NumSubsections > 1)
|
|
{
|
|
OutDescription.MinMaxUV.Z -= HeightmapScaleBias.X;
|
|
OutDescription.MinMaxUV.W -= HeightmapScaleBias.Y;
|
|
}
|
|
|
|
OutDescription.HeightfieldRect = FIntRect(SectionBase.X, SectionBase.Y, SectionBase.X + NumSubsections * SubsectionSizeQuads, SectionBase.Y + NumSubsections * SubsectionSizeQuads);
|
|
|
|
OutDescription.NumSubsections = NumSubsections;
|
|
|
|
OutDescription.SubsectionScaleAndBias = FVector4(SubsectionSizeQuads, SubsectionSizeQuads, HeightmapSubsectionOffsetU, HeightmapSubsectionOffsetV);
|
|
}
|
|
|
|
void FLandscapeComponentSceneProxy::GetLCIs(FLCIArray& LCIs)
|
|
{
|
|
FLightCacheInterface* LCI = ComponentLightInfo.Get();
|
|
if (LCI)
|
|
{
|
|
LCIs.Push(LCI);
|
|
}
|
|
}
|
|
|
|
//
|
|
// FLandscapeNeighborInfo
|
|
//
|
|
void FLandscapeNeighborInfo::RegisterNeighbors()
|
|
{
|
|
if (!bRegistered)
|
|
{
|
|
// Register ourselves in the map.
|
|
TMap<FIntPoint, const FLandscapeNeighborInfo*>& SceneProxyMap = SharedSceneProxyMap.FindOrAdd(LandscapeKey);
|
|
|
|
const FLandscapeNeighborInfo* Existing = SceneProxyMap.FindRef(ComponentBase);
|
|
if (Existing == nullptr)//(ensure(Existing == nullptr))
|
|
{
|
|
SceneProxyMap.Add(ComponentBase, this);
|
|
bRegistered = true;
|
|
|
|
// Find Neighbors
|
|
Neighbors[0] = SceneProxyMap.FindRef(ComponentBase + FIntPoint(0, -1));
|
|
Neighbors[1] = SceneProxyMap.FindRef(ComponentBase + FIntPoint(-1, 0));
|
|
Neighbors[2] = SceneProxyMap.FindRef(ComponentBase + FIntPoint(1, 0));
|
|
Neighbors[3] = SceneProxyMap.FindRef(ComponentBase + FIntPoint(0, 1));
|
|
|
|
// Add ourselves to our neighbors
|
|
if (Neighbors[0])
|
|
{
|
|
Neighbors[0]->Neighbors[3] = this;
|
|
}
|
|
if (Neighbors[1])
|
|
{
|
|
Neighbors[1]->Neighbors[2] = this;
|
|
}
|
|
if (Neighbors[2])
|
|
{
|
|
Neighbors[2]->Neighbors[1] = this;
|
|
}
|
|
if (Neighbors[3])
|
|
{
|
|
Neighbors[3]->Neighbors[0] = this;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
UE_LOG(LogLandscape, Warning, TEXT("Duplicate ComponentBase %d, %d"), ComponentBase.X, ComponentBase.Y);
|
|
}
|
|
}
|
|
}
|
|
|
|
void FLandscapeNeighborInfo::UnregisterNeighbors()
|
|
{
|
|
if (bRegistered)
|
|
{
|
|
// Remove ourselves from the map
|
|
TMap<FIntPoint, const FLandscapeNeighborInfo*>* SceneProxyMap = SharedSceneProxyMap.Find(LandscapeKey);
|
|
check(SceneProxyMap);
|
|
|
|
const FLandscapeNeighborInfo* MapEntry = SceneProxyMap->FindRef(ComponentBase);
|
|
if (MapEntry == this) //(/*ensure*/(MapEntry == this))
|
|
{
|
|
SceneProxyMap->Remove(ComponentBase);
|
|
|
|
if (SceneProxyMap->Num() == 0)
|
|
{
|
|
// remove the entire LandscapeKey entry as this is the last scene proxy
|
|
SharedSceneProxyMap.Remove(LandscapeKey);
|
|
}
|
|
else
|
|
{
|
|
// remove reference to us from our neighbors
|
|
if (Neighbors[0])
|
|
{
|
|
Neighbors[0]->Neighbors[3] = nullptr;
|
|
}
|
|
if (Neighbors[1])
|
|
{
|
|
Neighbors[1]->Neighbors[2] = nullptr;
|
|
}
|
|
if (Neighbors[2])
|
|
{
|
|
Neighbors[2]->Neighbors[1] = nullptr;
|
|
}
|
|
if (Neighbors[3])
|
|
{
|
|
Neighbors[3]->Neighbors[0] = nullptr;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
//
|
|
// FLandscapeMeshProxySceneProxy
|
|
//
|
|
FLandscapeMeshProxySceneProxy::FLandscapeMeshProxySceneProxy(UStaticMeshComponent* InComponent, const FGuid& InGuid, const TArray<FIntPoint>& InProxyComponentBases, int8 InProxyLOD)
|
|
: FStaticMeshSceneProxy(InComponent)
|
|
{
|
|
if (!IsComponentLevelVisible())
|
|
{
|
|
bNeedsLevelAddedToWorldNotification = true;
|
|
}
|
|
|
|
ProxyNeighborInfos.Empty(InProxyComponentBases.Num());
|
|
for (FIntPoint ComponentBase : InProxyComponentBases)
|
|
{
|
|
new(ProxyNeighborInfos) FLandscapeNeighborInfo(InComponent->GetWorld(), InGuid, ComponentBase, nullptr, InProxyLOD, 0);
|
|
}
|
|
}
|
|
|
|
void FLandscapeMeshProxySceneProxy::CreateRenderThreadResources()
|
|
{
|
|
FStaticMeshSceneProxy::CreateRenderThreadResources();
|
|
|
|
if (IsComponentLevelVisible())
|
|
{
|
|
for (FLandscapeNeighborInfo& Info : ProxyNeighborInfos)
|
|
{
|
|
Info.RegisterNeighbors();
|
|
}
|
|
}
|
|
}
|
|
|
|
void FLandscapeMeshProxySceneProxy::OnLevelAddedToWorld()
|
|
{
|
|
for (FLandscapeNeighborInfo& Info : ProxyNeighborInfos)
|
|
{
|
|
Info.RegisterNeighbors();
|
|
}
|
|
}
|
|
|
|
FLandscapeMeshProxySceneProxy::~FLandscapeMeshProxySceneProxy()
|
|
{
|
|
for (FLandscapeNeighborInfo& Info : ProxyNeighborInfos)
|
|
{
|
|
Info.UnregisterNeighbors();
|
|
}
|
|
}
|
|
|
|
FPrimitiveSceneProxy* ULandscapeMeshProxyComponent::CreateSceneProxy()
|
|
{
|
|
if (GetStaticMesh() == NULL
|
|
|| GetStaticMesh()->RenderData == NULL
|
|
|| GetStaticMesh()->RenderData->LODResources.Num() == 0
|
|
|| GetStaticMesh()->RenderData->LODResources[0].VertexBuffer.GetNumVertices() == 0)
|
|
{
|
|
return NULL;
|
|
}
|
|
|
|
return new FLandscapeMeshProxySceneProxy(this, LandscapeGuid, ProxyComponentBases, ProxyLOD);
|
|
}
|